-
Notifications
You must be signed in to change notification settings - Fork 3
/
mewbot.py
71 lines (60 loc) · 2.31 KB
/
mewbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#Author smilegodly
import requests
import subprocess
import discord
from discord.ext import commands
from discord import Game
import asyncio
from datetime import datetime
from datetime import time
import youtube_dl
from utils.funcs import Funcs
from utils.ytplayer import Music
from utils.secretgrabber import getSecret
from utils.apod import Apod
from itertools import cycle
import io
import aiohttp
import os
PREFIX = ("!", "?", "./", "~")
bot = commands.Bot(command_prefix=PREFIX)
bot.remove_command('help')
secret = getSecret()
@bot.event
async def on_ready():
game = discord.Game("RuneLite")
await bot.change_presence(status=discord.Status.idle, activity=game)
print("Logged in as ")
print(bot.user.name)
print(bot.user.id)
print("-------------")
async def apod_task():
await bot.wait_until_ready()
morningTime = time.fromisoformat('08:00')
channel = bot.get_channel(518253505669103617) # channel ID
while not bot.is_closed():
now = datetime.now()
if(now.hour == morningTime.hour):
apodData = Apod.getApodData()
if(apodData['media_type'] == 'image'):
#gets image from a URL
async with aiohttp.ClientSession() as session:
async with session.get(apodData['url']) as resp:
if resp.status != 200:
return await channel.send('Could not download file...')
data = io.BytesIO(await resp.read()) #create BytesIO instance
await channel.send(":rocket:"+ "\t" + "__**" + apodData['title'] + "**__" +"\t" + ":rocket:" +
"\t" + "__**" + apodData['date'] + "**__" + "\t" + ":rocket:" + "\n")
await channel.send(file=discord.File(data, 'apod.png'))
await channel.send("```" + "\n" + apodData['explanation'] + "\n" + "```")
elif(apodData['media_type'] == 'video'):
await channel.send(":rocket:"+ "\t" + "__**" + apodData['title'] + "**__" +"\t" + ":rocket:" +
"\t" + "__**" + apodData['date'] + "**__" + "\t" + ":rocket:" + "\n")
await channel.send(apodData['url'].replace("?rel=0", "").replace("embed/", "watch?v=") + "\n")
await channel.send("```" + "\n" + apodData['explanation'] + "\n" + "```")
await asyncio.sleep(1*(60*60)) # task to run once hourly
bot.add_cog(Music(bot))
bot.add_cog(Funcs(bot))
task = bot.loop.create_task(apod_task())
#token = os.environ.get("BOT_TOKEN")
bot.run(secret)