diff options
-rw-r--r-- | bot/seasons/evergreen/fun.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py index ce3484f7..9aa2ddc5 100644 --- a/bot/seasons/evergreen/fun.py +++ b/bot/seasons/evergreen/fun.py @@ -2,6 +2,7 @@ import logging import random from discord.ext import commands +from discord.ext.commands import Context, MessageConverter from bot.constants import Emojis @@ -27,6 +28,36 @@ class Fun(commands.Cog): output += getattr(Emojis, terning, '') await ctx.send(output) + @commands.group(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",), invoke_without_command=True) + async def randomcase_group(self, ctx: Context, *, text: str) -> None: + """Commands for returning text in randomcase""" + await ctx.invoke(self.convert_randomcase, text=text) + + @randomcase_group.command(name="convert") + async def convert_randomcase(self, ctx: Context, *, text: str) -> None: + """Randomly converts the casing of a given `text`""" + text = await Fun.text_to_message(ctx, text) + converted = ( + char.upper() if round(random.random()) else char.lower() for char in text + ) + await ctx.send(f">>> {''.join(converted)}") + + @staticmethod + async def text_to_message(ctx: Context, text: str) -> str: + """ + Attempts to convert a given `text` to a discord Message, then return the contents. + + Returns `text` if the conversion fails. + """ + try: + message = await MessageConverter().convert(ctx, text) + except commands.BadArgument: + log.debug(f"Input {text} is not a valid Discord Message") + else: + text = message.content + finally: + return text + def setup(bot): """Fun Cog load.""" |