diff options
| -rw-r--r-- | bot/constants.py | 5 | ||||
| -rw-r--r-- | bot/exts/evergreen/catify.py | 78 | 
2 files changed, 83 insertions, 0 deletions
diff --git a/bot/constants.py b/bot/constants.py index a64882db..bcbdcba0 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -8,6 +8,7 @@ from typing import Dict, NamedTuple  __all__ = (      "AdventOfCode",      "Branding", +    "Cats",      "Channels",      "Categories",      "Client", @@ -93,6 +94,10 @@ class Branding:      cycle_frequency = int(environ.get("CYCLE_FREQUENCY", 3))  # 0: never, 1: every day, 2: every other day, ... +class Cats: +    cats = ["ᓚᘏᗢ", "ᘡᘏᗢ", "🐈", "ᓕᘏᗢ", "ᓇᘏᗢ", "ᓂᘏᗢ", "ᘣᘏᗢ", "ᕦᘏᗢ", "ᕂᘏᗢ"] + +  class Channels(NamedTuple):      advent_of_code = int(environ.get("AOC_CHANNEL_ID", 782715290437943306))      advent_of_code_commands = int(environ.get("AOC_COMMANDS_CHANNEL_ID", 607247579608121354)) diff --git a/bot/exts/evergreen/catify.py b/bot/exts/evergreen/catify.py new file mode 100644 index 00000000..a0121403 --- /dev/null +++ b/bot/exts/evergreen/catify.py @@ -0,0 +1,78 @@ +import random +from typing import Optional + +from discord import AllowedMentions, Embed +from discord.ext import commands + +from bot.constants import Cats, Colours, NEGATIVE_REPLIES + + +class Catify(commands.Cog): +    """Cog for the catify command.""" + +    def __init__(self, bot: commands.Bot): +        self.bot = bot + +    @commands.command(aliases=["ᓚᘏᗢify", "ᓚᘏᗢ"]) +    async def catify(self, ctx: commands.Context, *, text: Optional[str]) -> None: +        """ +        Convert the provided text into a cat themed sentence by interspercing cats throughout text. + +        If no text is given then the users nickname is edited. +        """ +        if not text: +            display_name = ctx.author.display_name + +            if len(display_name) > 26: +                embed = Embed( +                    title=random.choice(NEGATIVE_REPLIES), +                    description="Your nickname is too long to be catified! Please change it to be under 26 characters.", +                    color=Colours.soft_red +                ) +                await ctx.send(embed=embed) +                return + +            else: +                display_name += f" | {random.choice(Cats.cats)}" +                await ctx.send(f"Your catified username is: `{display_name}`") +                await ctx.author.edit(nick=display_name) +        else: +            if len(text) >= 1500: +                embed = Embed( +                    title=random.choice(NEGATIVE_REPLIES), +                    description="Submitted text was too large! Please submit something under 1500 characters.", +                    color=Colours.soft_red +                ) +                await ctx.send(embed=embed) +                return + +            string_list = text.split() +            for index, name in enumerate(string_list): +                if "cat" in name: +                    if random.randint(0, 5) == 5: +                        string_list[index] = string_list[index].replace("cat", f"**{random.choice(Cats.cats)}**") +                    else: +                        string_list[index] = string_list[index].replace("cat", random.choice(Cats.cats)) +                for element in Cats.cats: +                    if element in name: +                        string_list[index] = string_list[index].replace(element, "cat") + +        string_len = len(string_list) // 3 or len(string_list) + +        for _ in range(random.randint(1, string_len)): +            # insert cat at random index +            if random.randint(0, 5) == 5: +                string_list.insert(random.randint(0, len(string_list)), f"**{random.choice(Cats.cats)}**") +            else: +                string_list.insert(random.randint(0, len(string_list)), random.choice(Cats.cats)) + +        text = " ".join(string_list) +        await ctx.send( +            f">>> {text}", +            allowed_mentions=AllowedMentions.none() +        ) + + +def setup(bot: commands.Bot) -> None: +    """Loads the catify cog.""" +    bot.add_cog(Catify(bot))  |