aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kosayoda <[email protected]>2019-08-17 21:11:23 +0800
committerGravatar kosayoda <[email protected]>2019-08-17 21:11:23 +0800
commit5d97116f3f4ed038248688937cbaa0f34a6ebac0 (patch)
treeaf01ea301dddb373be4e02317bd9ac1c3e2a8058
parentMerge pull request #257 from vivax3794/minesweeper-lenght-fix (diff)
Implement randomcase
-rw-r--r--bot/seasons/evergreen/fun.py31
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."""