aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-11-20 14:50:48 +0100
committerGravatar Leon Sandøy <[email protected]>2018-11-20 14:50:48 +0100
commit42c649e4b217f8bedb0a5f6eb97985ae6a021502 (patch)
treea1f74fada95326ce30a677c4d4c2155c629c1156
parentMerge branch 'meooow25-spookysound' (diff)
parentRefactoring. (diff)
Merge branch 'gif' of https://github.com/markylon/hacktoberbot into markylon-gif
-rw-r--r--bot/cogs/gif.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/bot/cogs/gif.py b/bot/cogs/gif.py
new file mode 100644
index 00000000..cacb77ce
--- /dev/null
+++ b/bot/cogs/gif.py
@@ -0,0 +1,32 @@
+from os import environ
+
+import aiohttp
+from discord.ext import commands
+
+
+class SpookyGif:
+ """
+ A cog to fetch a random spooky gif from the web!
+ """
+
+ def __init__(self, bot):
+ self.bot = bot
+ self.GIPHY_TOKEN = environ.get('GIPHY_TOKEN')
+
+ @commands.command()
+ async def gif(self, ctx):
+ """
+ Fetches a random gif from the GIPHY API and responds with it.
+ """
+
+ async with aiohttp.ClientSession() as session:
+ params = {'api_key': self.GIPHY_TOKEN, 'tag': 'halloween', 'rating': 'g'}
+ # Make a GET request to the Giphy API to get a random halloween gif.
+ async with session.get('http://api.giphy.com/v1/gifs/random', params=params) as resp:
+ data = await resp.json()
+ url = data['data']['url']
+ await ctx.send(url)
+
+
+def setup(bot):
+ bot.add_cog(SpookyGif(bot))