diff options
| author | 2020-04-02 14:39:24 +0200 | |
|---|---|---|
| committer | 2020-04-02 14:39:24 +0200 | |
| commit | d77a2bbc50305d05371197f4cfe3354cfca4c627 (patch) | |
| tree | be1eed54972d9843f66114311f93b68b579046ac /bot/exts/halloween/halloweenify.py | |
| parent | Merge pull request #382 from ks129/game-fuzzy (diff) | |
| parent | Merge master: adjust `Space` cog location (diff) | |
Merge pull request #329 from python-discord/seasonal-purge
Deseasonify: Make all cogs available year-round, and manage only branding by season.
Diffstat (limited to 'bot/exts/halloween/halloweenify.py')
| -rw-r--r-- | bot/exts/halloween/halloweenify.py | 51 | 
1 files changed, 51 insertions, 0 deletions
| diff --git a/bot/exts/halloween/halloweenify.py b/bot/exts/halloween/halloweenify.py new file mode 100644 index 00000000..5c433a81 --- /dev/null +++ b/bot/exts/halloween/halloweenify.py @@ -0,0 +1,51 @@ +import logging +from json import load +from pathlib import Path +from random import choice + +import discord +from discord.ext import commands +from discord.ext.commands.cooldowns import BucketType + +log = logging.getLogger(__name__) + + +class Halloweenify(commands.Cog): +    """A cog to change a invokers nickname to a spooky one!""" + +    def __init__(self, bot: commands.Bot): +        self.bot = bot + +    @commands.cooldown(1, 300, BucketType.user) +    @commands.command() +    async def halloweenify(self, ctx: commands.Context) -> None: +        """Change your nickname into a much spookier one!""" +        async with ctx.typing(): +            with open(Path("bot/resources/halloween/halloweenify.json"), "r") as f: +                data = load(f) + +            # Choose a random character from our list we loaded above and set apart the nickname and image url. +            character = choice(data["characters"]) +            nickname = ''.join([nickname for nickname in character]) +            image = ''.join([character[nickname] for nickname in character]) + +            # Build up a Embed +            embed = discord.Embed() +            embed.colour = discord.Colour.dark_orange() +            embed.title = "Not spooky enough?" +            embed.description = ( +                f"**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, " +                f"{ctx.author.display_name} isn\'t scary at all! " +                "Let me think of something better. Hmm... I got it!\n\n " +                f"Your new nickname will be: \n :ghost: **{nickname}** :jack_o_lantern:" +            ) +            embed.set_image(url=image) + +            await ctx.author.edit(nick=nickname) + +        await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: +    """Halloweenify Cog load.""" +    bot.add_cog(Halloweenify(bot)) | 
