diff options
| author | 2018-11-20 15:14:46 +0100 | |
|---|---|---|
| committer | 2018-11-20 15:14:46 +0100 | |
| commit | 87580f3414d3873a688b31352832ebd1a1527a2a (patch) | |
| tree | 9ee1331f24e36d6f1de4190c469b94eb12f93f9e /bot/cogs | |
| parent | Merge branch 'meooow25-spookysound' (diff) | |
| parent | Fixing flake8 errors, and making the gif post inside an embed. (diff) | |
Merge branch 'markylon-gif'
Diffstat (limited to 'bot/cogs')
| -rw-r--r-- | bot/cogs/gif.py | 32 | ||||
| -rw-r--r-- | bot/cogs/hacktober/halloween_facts.py | 2 | ||||
| -rw-r--r-- | bot/cogs/hacktober/scarymovie.py (renamed from bot/cogs/hacktober/movie.py) | 4 | ||||
| -rw-r--r-- | bot/cogs/hacktober/spookygif.py | 36 | 
4 files changed, 71 insertions, 3 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)) diff --git a/bot/cogs/hacktober/halloween_facts.py b/bot/cogs/hacktober/halloween_facts.py index bd164e30..7b5b866b 100644 --- a/bot/cogs/hacktober/halloween_facts.py +++ b/bot/cogs/hacktober/halloween_facts.py @@ -39,7 +39,7 @@ class HalloweenFacts:      async def _fact_publisher_task(self):          """          A background task that runs forever, sending Halloween facts at random to the Discord channel with id equal to -        HACKTOBERFEST_CHANNEL_ID every INTERVAL seconds. +        HACKTOBER_CHANNEL_ID every INTERVAL seconds.          """          facts = list(enumerate(self.halloween_facts))          while True: diff --git a/bot/cogs/hacktober/movie.py b/bot/cogs/hacktober/scarymovie.py index 925f813f..97e9f424 100644 --- a/bot/cogs/hacktober/movie.py +++ b/bot/cogs/hacktober/scarymovie.py @@ -10,7 +10,7 @@ TMDB_API_KEY = environ.get('TMDB_API_KEY')  TMDB_TOKEN = environ.get('TMDB_TOKEN') -class Movie: +class ScaryMovie:      """      Selects a random scary movie and embeds info into discord chat      """ @@ -133,4 +133,4 @@ class Movie:  def setup(bot): -    bot.add_cog(Movie(bot)) +    bot.add_cog(ScaryMovie(bot)) diff --git a/bot/cogs/hacktober/spookygif.py b/bot/cogs/hacktober/spookygif.py new file mode 100644 index 00000000..1249905d --- /dev/null +++ b/bot/cogs/hacktober/spookygif.py @@ -0,0 +1,36 @@ +import aiohttp +import discord +from discord.ext import commands + +from bot.constants import GIPHY_TOKEN + + +class SpookyGif: +    """ +    A cog to fetch a random spooky gif from the web! +    """ + +    def __init__(self, bot): +        self.bot = bot + +    @commands.command(name="spookygif", aliases=["sgif", "scarygif"]) +    async def spookygif(self, ctx): +        """ +        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) + + +def setup(bot): +    bot.add_cog(SpookyGif(bot))  |