Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
546aa93b7e | |||
268e569d76 |
69
auroraBot.py
Normal file → Executable file
69
auroraBot.py
Normal file → Executable file
|
@ -1,54 +1,55 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import discord
|
|
||||||
from discord.ext import commands
|
|
||||||
import config
|
import config
|
||||||
import random
|
from datetime import datetime
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
TOKEN = config.token
|
TOKEN = config.token
|
||||||
ID = config.channel_id
|
|
||||||
|
|
||||||
intents = discord.Intents.all()
|
from telegram.ext import Updater
|
||||||
|
from telegram.ext import CommandHandler
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix='!', intents=intents)
|
updater = Updater(token=TOKEN, use_context=True)
|
||||||
|
|
||||||
@bot.command(name='sky', help='Shows the latest image from the All Sky Camera in Kiruna')
|
dispatcher = updater.dispatcher
|
||||||
async def ASC(ctx):
|
|
||||||
num = random.randint(1,100000)
|
def start(update, context):
|
||||||
|
context.bot.send_message(chat_id=update.effective_chat.id, text="Sóc un bot, prova a dir-me /aurora")
|
||||||
|
start_handler = CommandHandler('start', start)
|
||||||
|
dispatcher.add_handler(start_handler)
|
||||||
|
|
||||||
|
def asc(update, ctx):
|
||||||
|
num = datetime.now().timestamp()
|
||||||
message = f'https://www.irf.se/alis/allsky/krn/latest.jpeg?{num}'
|
message = f'https://www.irf.se/alis/allsky/krn/latest.jpeg?{num}'
|
||||||
if ctx.channel.id != ID:
|
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||||
await ctx.send(f"Please keep this stuff in <#{ID}>")
|
asc_handler = CommandHandler('aurora', asc)
|
||||||
return
|
dispatcher.add_handler(asc_handler)
|
||||||
else:
|
|
||||||
await ctx.send(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
@bot.command(name='kp', help='Shows the current Kp index')
|
|
||||||
async def kp(ctx):
|
def kp(update, ctx):
|
||||||
response = requests.get('https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json')
|
response = requests.get('https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json')
|
||||||
data = response.json()
|
data = response.json()
|
||||||
kp = data[-1][1]
|
kp = data[-1][1]
|
||||||
message = f'The current Kp index is {kp}'
|
message = f'The current Kp index is {kp}'
|
||||||
|
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||||
if ctx.channel.id != ID:
|
kp_handler = CommandHandler('kp', kp)
|
||||||
await ctx.send(f"Please keep this stuff in <#{ID}>")
|
dispatcher.add_handler(kp_handler)
|
||||||
return
|
|
||||||
else:
|
|
||||||
await ctx.send(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@bot.command(name='solarWind', help='Shows graph with solar wind and magnetic field info')
|
|
||||||
async def ASC(ctx):
|
def sw(update, ctx):
|
||||||
num = random.randint(1,100000)
|
num = datetime.now().timestamp()
|
||||||
message = f'https://www.spaceweather.se/content/irf-kp.png?{num}'
|
message = f'https://www.spaceweather.se/content/irf-kp.png?{num}'
|
||||||
if ctx.channel.id != ID:
|
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||||
await ctx.send(f"Please keep this stuff in <#{ID}>")
|
sw_handler = CommandHandler('sw', sw)
|
||||||
return
|
dispatcher.add_handler(sw_handler)
|
||||||
else:
|
|
||||||
await ctx.send(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
bot.run(TOKEN)
|
def vid(update, ctx):
|
||||||
|
num = datetime.now().timestamp()
|
||||||
|
message = f'https://www.irf.se/alis/allsky/krn/latest_movie.mp4?{num}'
|
||||||
|
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||||
|
vid_handler = CommandHandler('video', vid)
|
||||||
|
dispatcher.add_handler(vid_handler)
|
||||||
|
|
||||||
|
updater.start_polling()
|
Loading…
Reference in New Issue
Block a user