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
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import config
|
||||
import random
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
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')
|
||||
async def ASC(ctx):
|
||||
num = random.randint(1,100000)
|
||||
dispatcher = updater.dispatcher
|
||||
|
||||
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}'
|
||||
if ctx.channel.id != ID:
|
||||
await ctx.send(f"Please keep this stuff in <#{ID}>")
|
||||
return
|
||||
else:
|
||||
await ctx.send(message)
|
||||
return
|
||||
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||
asc_handler = CommandHandler('aurora', asc)
|
||||
dispatcher.add_handler(asc_handler)
|
||||
|
||||
@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')
|
||||
data = response.json()
|
||||
kp = data[-1][1]
|
||||
message = f'The current Kp index is {kp}'
|
||||
|
||||
if ctx.channel.id != ID:
|
||||
await ctx.send(f"Please keep this stuff in <#{ID}>")
|
||||
return
|
||||
else:
|
||||
await ctx.send(message)
|
||||
return
|
||||
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||
kp_handler = CommandHandler('kp', kp)
|
||||
dispatcher.add_handler(kp_handler)
|
||||
|
||||
|
||||
@bot.command(name='solarWind', help='Shows graph with solar wind and magnetic field info')
|
||||
async def ASC(ctx):
|
||||
num = random.randint(1,100000)
|
||||
|
||||
def sw(update, ctx):
|
||||
num = datetime.now().timestamp()
|
||||
message = f'https://www.spaceweather.se/content/irf-kp.png?{num}'
|
||||
if ctx.channel.id != ID:
|
||||
await ctx.send(f"Please keep this stuff in <#{ID}>")
|
||||
return
|
||||
else:
|
||||
await ctx.send(message)
|
||||
return
|
||||
ctx.bot.send_message(chat_id=update.effective_chat.id, text=message)
|
||||
sw_handler = CommandHandler('sw', sw)
|
||||
dispatcher.add_handler(sw_handler)
|
||||
|
||||
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