From 44825f97ea399fc077ec2d964d1a6c9da2069fed Mon Sep 17 00:00:00 2001 From: sco1 Date: Tue, 20 Nov 2018 15:45:53 -0500 Subject: Add typing context manager where appropriate Some minor syntax & logic fixes where noticed --- bot/cogs/hacktober/spookygif.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'bot/cogs/hacktober/spookygif.py') diff --git a/bot/cogs/hacktober/spookygif.py b/bot/cogs/hacktober/spookygif.py index 1249905d..98a411f6 100644 --- a/bot/cogs/hacktober/spookygif.py +++ b/bot/cogs/hacktober/spookygif.py @@ -18,18 +18,19 @@ class SpookyGif: """ Fetches a random gif from the GIPHY API and responds with it. """ - - async with aiohttp.ClientSession() as session: - params = {'api_key': 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']['image_url'] - - embed = discord.Embed(colour=0x9b59b6) - embed.title = "A spooooky gif!" - embed.set_image(url=url) - await ctx.send(embed=embed) + async with ctx.typing(): + async with aiohttp.ClientSession() as session: + params = {'api_key': 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']['image_url'] + + embed = discord.Embed(colour=0x9b59b6) + embed.title = "A spooooky gif!" + embed.set_image(url=url) + + await ctx.send(embed=embed) def setup(bot): -- cgit v1.2.3