示例#1
0
 async def uwu_command(
     self, ctx: Context, *,
     text: clean_content(fix_channel_mentions=True)) -> None:
     """Converts a given `text` into it's uwu equivalent."""
     conversion_func = functools.partial(utils.replace_many,
                                         replacements=UWU_WORDS,
                                         ignore_case=True,
                                         match_case=True)
     text, embed = await Fun._get_text_and_embed(ctx, text)
     # Convert embed if it exists
     if embed is not None:
         embed = Fun._convert_embed(conversion_func, embed)
     converted_text = conversion_func(text)
     converted_text = helpers.suppress_links(converted_text)
     # Don't put >>> if only embed present
     if converted_text:
         converted_text = f">>> {converted_text.lstrip('> ')}"
     await ctx.send(content=converted_text, embed=embed)
示例#2
0
    async def randomcase_command(
        self, ctx: Context, *,
        text: clean_content(fix_channel_mentions=True)) -> None:
        """Randomly converts the casing of a given `text`."""
        def conversion_func(text: str) -> str:
            """Randomly converts the casing of a given string."""
            return "".join(
                char.upper() if round(random.random()) else char.lower()
                for char in text)

        text, embed = await Fun._get_text_and_embed(ctx, text)
        # Convert embed if it exists
        if embed is not None:
            embed = Fun._convert_embed(conversion_func, embed)
        converted_text = conversion_func(text)
        converted_text = helpers.suppress_links(converted_text)
        # Don't put >>> if only embed present
        if converted_text:
            converted_text = f">>> {converted_text.lstrip('> ')}"
        await ctx.send(content=converted_text, embed=embed)
示例#3
0
    ))
    async def uwu_command(
        self, ctx: Context, *,
        text: clean_content(fix_channel_mentions=True)) -> None:
        """
        Echo an uwuified version the passed text.

        Example:
        '.uwu Hello, my name is John' returns something like
        'hewwo, m-my name is j-john nyaa~'.
        """
        if (fun_cog := ctx.bot.get_cog("Fun")):
            text, embed = await fun_cog._get_text_and_embed(ctx, text)

            # Grabs the text from the embed for uwuification.
            if embed is not None:
                embed = fun_cog._convert_embed(self._uwuify, embed)
        else:
            embed = None
        converted_text = self._uwuify(text)
        converted_text = helpers.suppress_links(converted_text)

        # Adds the text harvested from an embed to be put into another quote block.
        converted_text = f">>> {converted_text.lstrip('> ')}"
        await ctx.send(content=converted_text, embed=embed)


def setup(bot: Bot) -> None:
    """Load the uwu cog."""
    bot.add_cog(Uwu(bot))
示例#4
0
    async def eggdecorate(
        self, ctx: commands.Context, *colours: Union[discord.Colour, str]
    ) -> Union[Image.Image, discord.Message]:
        """
        Picks a random egg design and decorates it using the given colours.

        Colours are split by spaces, unless you wrap the colour name in double quotes.
        Discord colour names, HTML colour names, XKCD colour names and hex values are accepted.
        """
        if len(colours) < 2:
            return await ctx.send("You must include at least 2 colours!")

        invalid = []
        colours = list(colours)
        for idx, colour in enumerate(colours):
            if isinstance(colour, discord.Colour):
                continue
            value = self.replace_invalid(colour)
            if value:
                colours[idx] = discord.Colour(value)
            else:
                invalid.append(helpers.suppress_links(colour))

        if len(invalid) > 1:
            return await ctx.send(
                f"Sorry, I don't know these colours: {' '.join(invalid)}")
        elif len(invalid) == 1:
            return await ctx.send(
                f"Sorry, I don't know the colour {invalid[0]}!")

        async with ctx.typing():
            # Expand list to 8 colours
            colours_n = len(colours)
            if colours_n < 8:
                q, r = divmod(8, colours_n)
                colours = colours * q + colours[:r]
            num = random.randint(1, 6)
            im = Image.open(
                Path(f"bot/resources/easter/easter_eggs/design{num}.png"))
            data = list(im.getdata())

            replaceable = {x for x in data if x not in IRREPLACEABLE}
            replaceable = sorted(replaceable, key=COLOURS.index)

            replacing_colours = {
                colour: colours[i]
                for i, colour in enumerate(replaceable)
            }
            new_data = []
            for x in data:
                if x in replacing_colours:
                    new_data.append((*replacing_colours[x].to_rgb(), 255))
                    # Also ensures that the alpha channel has a value
                else:
                    new_data.append(x)
            new_im = Image.new(im.mode, im.size)
            new_im.putdata(new_data)

            bufferedio = BytesIO()
            new_im.save(bufferedio, format="PNG")

            bufferedio.seek(0)

            file = discord.File(
                bufferedio,
                filename="egg.png")  # Creates file to be used in embed
            embed = discord.Embed(
                title="Your Colourful Easter Egg",
                description="Here is your pretty little egg. Hope you like it!"
            )
            embed.set_image(url="attachment://egg.png")
            embed.set_footer(text=f"Made by {ctx.author.display_name}",
                             icon_url=ctx.author.avatar_url)

        await ctx.send(file=file, embed=embed)
        return new_im
    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 display name 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 nickname is: `{display_name}`",
                               allowed_mentions=AllowedMentions.none())

                with suppress(Forbidden):
                    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):
                name = name.lower()
                if "cat" in name:
                    if random.randint(0, 5) == 5:
                        string_list[index] = name.replace(
                            "cat", f"**{random.choice(Cats.cats)}**")
                    else:
                        string_list[index] = name.replace(
                            "cat", random.choice(Cats.cats))
                for element in Cats.cats:
                    if element in name:
                        string_list[index] = name.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 = helpers.suppress_links(" ".join(string_list))
            await ctx.send(f">>> {text}",
                           allowed_mentions=AllowedMentions.none())