Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | None | 0 0
  1. import requests
  2. import os
  3. import discord
  4.  
  5. #sleep(20)
  6. try:
  7.     #load_dotenv()
  8.     token = 'XXX'
  9.     client = discord.Client()
  10.    
  11.     @client.event
  12.     async def on_ready():
  13.         print(f'{client.user.name} has connected to Discord!')
  14.    
  15.     observing = False
  16.     @client.event
  17.     async def on_message(message):
  18.         global observing
  19.         if message.author == client.user:
  20.             return
  21.        
  22.         if '<@639462705723605013>' in message.content and len(message.content.split()) == 3 and message.content.split()[1].lower() == 'observe':
  23.             if not observing and  message.content.split()[2].isdigit() and int(message.content.split()[2]) >= 10 and int(message.content.split()[2]) <= 3600:
  24.                 duration = message.content.split()[2]
  25.                 await message.add_reaction('✅')
  26.                 await message.channel.send('Observing for **'+duration+' seconds** with PICTOR. Please wait...')
  27.                 await client.change_presence(status=discord.Status.idle, activity=discord.Game('Hello there!'))
  28.                 observing = True
  29.                 myobj = {'obs_name': 'discord_obs', 'f_center': '1420', 'bandwidth': '2.4mhz', 'channels': '2048', 'nbins': '1000', 'duration': duration, 'email': 'coto_dup@hotmail.com', 'submit_btn': '1'}
  30.                 requests.post('https://pictortelescope.com/observe.php', data = myobj)
  31.                 try:
  32.                     os.remove('/home/pictor/Desktop/pictortelescope/observation.dat')
  33.                     os.remove('/home/pictor/Desktop/pictortelescope/plot.png')
  34.                     print(8)
  35.                 except OSError:
  36.                     pass
  37.                
  38.                 asyncio.sleep(5)
  39.                 while not os.path.exists('/home/pictor/Desktop/pictortelescope/plot.png'):
  40.                     print('doesnt exist')
  41.                     asyncio.sleep(1)
  42.                 asyncio.sleep(4)
  43.                 print('out')
  44.                 await message.channel.send('<@'+str(message.author.id)+ '> **Your observation has been carried out by PICTOR successfully!**\nHere is your observation\'s data:', file=discord.File('/home/pictor/Desktop/pictortelescope/plot.png'))
  45.                 observing = False
  46.             elif observing:
  47.                 await message.add_reaction('❌')
  48.                 await message.channel.send('The telescope is currently observing. Please wait until it\'s done before submitting your observation...')
  49.             else:
  50.                 await message.add_reaction('❌')
  51.                 await message.channel.send('Please ensure the given observation duration is greater than 10 and less than 3600 seconds.')
  52.        
  53.         elif '<@639462705723605013>' in message.content:
  54.             await message.channel.send('**PICTOR** is an open-source radio telescope that allows anyone to observe the radio sky using its convenient web platform for **free**. This bot allows you to submit observations directly from Discord. For more info, visit https://www.pictortelescope.com.\n\n**Usage:**\n```@PICTOR observe <duration (in seconds)>```\n**Example:**\n```@PICTOR observe 60```\n**Default observation parameters:**\n```\nCenter frequency: 1420 MHz\nBandwidth: 2.4 MHz\nNumber of channels: 2048\nNumber of bins: 1000```')
  55.    
  56.     client.run(token)
  57. except Exception as e:
  58.     print(e)
  59.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement