Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- import discord
- #sleep(20)
- try:
- #load_dotenv()
- token = 'XXX'
- client = discord.Client()
- @client.event
- async def on_ready():
- print(f'{client.user.name} has connected to Discord!')
- observing = False
- @client.event
- async def on_message(message):
- global observing
- if message.author == client.user:
- return
- if '<@639462705723605013>' in message.content and len(message.content.split()) == 3 and message.content.split()[1].lower() == 'observe':
- if not observing and message.content.split()[2].isdigit() and int(message.content.split()[2]) >= 10 and int(message.content.split()[2]) <= 3600:
- duration = message.content.split()[2]
- await message.add_reaction('✅')
- await message.channel.send('Observing for **'+duration+' seconds** with PICTOR. Please wait...')
- await client.change_presence(status=discord.Status.idle, activity=discord.Game('Hello there!'))
- observing = True
- 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'}
- requests.post('https://pictortelescope.com/observe.php', data = myobj)
- try:
- os.remove('/home/pictor/Desktop/pictortelescope/observation.dat')
- os.remove('/home/pictor/Desktop/pictortelescope/plot.png')
- print(8)
- except OSError:
- pass
- asyncio.sleep(5)
- while not os.path.exists('/home/pictor/Desktop/pictortelescope/plot.png'):
- print('doesnt exist')
- asyncio.sleep(1)
- asyncio.sleep(4)
- print('out')
- 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'))
- observing = False
- elif observing:
- await message.add_reaction('❌')
- await message.channel.send('The telescope is currently observing. Please wait until it\'s done before submitting your observation...')
- else:
- await message.add_reaction('❌')
- await message.channel.send('Please ensure the given observation duration is greater than 10 and less than 3600 seconds.')
- elif '<@639462705723605013>' in message.content:
- 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```')
- client.run(token)
- except Exception as e:
- print(e)
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement