2018-07-24 10:36:56 -07:00
|
|
|
import aiohttp
|
|
|
|
|
import discord
|
|
|
|
|
from redbot.core import commands
|
|
|
|
|
|
|
|
|
|
|
2019-06-25 10:49:17 -07:00
|
|
|
class Inspirobot(commands.Cog):
|
2018-08-19 20:23:44 -07:00
|
|
|
"""Posts images generated by https://inspirobot.me"""
|
2020-08-26 17:57:43 +01:00
|
|
|
|
|
|
|
|
async def red_delete_data_for_user(self, **kwargs):
|
|
|
|
|
""" Nothing to delete """
|
|
|
|
|
return
|
|
|
|
|
|
2018-07-24 10:36:56 -07:00
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
self.session = aiohttp.ClientSession()
|
|
|
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
|
async def inspireme(self, ctx):
|
|
|
|
|
"""Fetch a random "inspirational message" from the bot."""
|
|
|
|
|
try:
|
2020-08-26 17:57:43 +01:00
|
|
|
async with self.session.request("GET", "http://inspirobot.me/api?generate=true") as page:
|
2018-08-08 21:54:06 -07:00
|
|
|
pic = await page.text(encoding="utf-8")
|
2018-07-24 10:36:56 -07:00
|
|
|
em = discord.Embed()
|
|
|
|
|
em.set_image(url=pic)
|
|
|
|
|
await ctx.send(embed=em)
|
|
|
|
|
except Exception as e:
|
2018-08-08 21:54:06 -07:00
|
|
|
await ctx.send(f"Oops, there was a problem: {e}")
|
2018-07-24 10:36:56 -07:00
|
|
|
|
2019-06-25 10:49:17 -07:00
|
|
|
def cog_unload(self):
|
|
|
|
|
self.bot.loop.create_task(self.session.close())
|