aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/holidays/halloween/spookygif.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/holidays/halloween/spookygif.py')
-rw-r--r--bot/exts/holidays/halloween/spookygif.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/bot/exts/holidays/halloween/spookygif.py b/bot/exts/holidays/halloween/spookygif.py
new file mode 100644
index 00000000..9511d407
--- /dev/null
+++ b/bot/exts/holidays/halloween/spookygif.py
@@ -0,0 +1,38 @@
+import logging
+
+import discord
+from discord.ext import commands
+
+from bot.bot import Bot
+from bot.constants import Colours, Tokens
+
+log = logging.getLogger(__name__)
+
+API_URL = "http://api.giphy.com/v1/gifs/random"
+
+
+class SpookyGif(commands.Cog):
+ """A cog to fetch a random spooky gif from the web!"""
+
+ def __init__(self, bot: Bot):
+ self.bot = bot
+
+ @commands.command(name="spookygif", aliases=("sgif", "scarygif"))
+ async def spookygif(self, ctx: commands.Context) -> None:
+ """Fetches a random gif from the GIPHY API and responds with it."""
+ async with ctx.typing():
+ params = {"api_key": Tokens.giphy, "tag": "halloween", "rating": "g"}
+ # Make a GET request to the Giphy API to get a random halloween gif.
+ async with self.bot.http_session.get(API_URL, params=params) as resp:
+ data = await resp.json()
+ url = data["data"]["image_url"]
+
+ embed = discord.Embed(title="A spooooky gif!", colour=Colours.purple)
+ embed.set_image(url=url)
+
+ await ctx.send(embed=embed)
+
+
+def setup(bot: Bot) -> None:
+ """Spooky GIF Cog load."""
+ bot.add_cog(SpookyGif(bot))