From 6c0c302125ffdd32233e35a2d1673568098e2d1f Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Tue, 24 Jul 2018 10:36:56 -0700 Subject: [PATCH] [V3 Inspirobot] Initial commit --- inspirobot/inspirobot.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 inspirobot/inspirobot.py diff --git a/inspirobot/inspirobot.py b/inspirobot/inspirobot.py new file mode 100644 index 0000000..9c6ca27 --- /dev/null +++ b/inspirobot/inspirobot.py @@ -0,0 +1,24 @@ +import aiohttp +import discord +from redbot.core import commands + +class Inspirobot: + + 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: + async with self.session.request("GET", "http://inspirobot.me/api?generate=true") as page: + pic = await page.text(encoding='utf-8') + em = discord.Embed() + em.set_image(url=pic) + await ctx.send(embed=em) + except Exception as e: + await ctx.send(f"Oops, there was a problem: {e}") + + def __unload(self): + self.session.close()