diff options
| author | 2018-11-20 15:14:32 +0100 | |
|---|---|---|
| committer | 2018-11-20 15:14:32 +0100 | |
| commit | 42e5af85dd55b754d93374263ea7bcee85075f34 (patch) | |
| tree | 9ee1331f24e36d6f1de4190c469b94eb12f93f9e /bot | |
| parent | Merge branch 'gif' of https://github.com/markylon/hacktoberbot into markylon-gif (diff) | |
Fixing flake8 errors, and making the gif post inside an embed.
Diffstat (limited to 'bot')
| -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 | ||||
| -rw-r--r-- | bot/constants.py | 3 | ||||
| -rw-r--r-- | bot/resources/halloween/candy_collection.json | 9 | 
5 files changed, 43 insertions, 11 deletions
| 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)) diff --git a/bot/constants.py b/bot/constants.py index f2bf04a2..7c2561a7 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,2 +1,5 @@ +import os +  HACKTOBER_CHANNEL_ID = 414574275865870337  HACKTOBER_VOICE_CHANNEL_ID = 514420006474219521 +GIPHY_TOKEN = os.environ.get("GIPHY_TOKEN") diff --git a/bot/resources/halloween/candy_collection.json b/bot/resources/halloween/candy_collection.json index 6313dd10..bebcd4fc 100644 --- a/bot/resources/halloween/candy_collection.json +++ b/bot/resources/halloween/candy_collection.json @@ -1,8 +1 @@ -{ -  "msg_reacted": [ - -   ], -  "records": [ -     -  ] -} +{"msg_reacted": [{"reaction": "\ud83c\udf6c", "msg_id": 514442189359546375, "won": true, "user_reacted": 95872159741644800}, {"reaction": "\ud83c\udf6c", "msg_id": 514442502460276740, "won": true, "user_reacted": 178876748224659457}], "records": [{"userid": 95872159741644800, "record": 1}, {"userid": 178876748224659457, "record": 1}]}
\ No newline at end of file | 
