diff options
-rw-r--r-- | bot/exts/fun/uwu.py | 80 |
1 files changed, 35 insertions, 45 deletions
diff --git a/bot/exts/fun/uwu.py b/bot/exts/fun/uwu.py index ce2ed45d..733dae20 100644 --- a/bot/exts/fun/uwu.py +++ b/bot/exts/fun/uwu.py @@ -11,8 +11,7 @@ from bot.exts.fun.fun import Fun from bot.utils import helpers -# Wepwacement -WEPWACE_HASH = { +WORD_REPLACE_HASH = { "small": "smol", "cute": "kawaii~", "fluff": "floof", @@ -31,59 +30,50 @@ EMOJI_LUT = [ "o.O", "-.-", ">w<", - "(⑅˘꒳˘)", - "(ꈍᴗꈍ)", - "(˘ω˘)", - "(U ᵕ U❁)", "σωσ", "òωó", - "(///ˬ///✿)", - "(U ﹏ U)", - "( ͡o ω ͡o )", "ʘwʘ", ":3", - ":3", # important enough to have twice "XD", "nyaa~~", "mya", ">_<", - "😳", - "🥺", - "😳😳😳", "rawr", "uwu", "^^", "^^;;", - "(ˆ ﻌ ˆ)♡", - "^•ﻌ•^", - "/(^•ω•^)", - "(✿oωo)", ] -wepwace_regex = re.compile(r"(?<![w])[lr](?![w])") +word_replace_regex = re.compile(r"(?<![w])[lr](?![w])") +punctuation_regex = re.compile(r"[.!?\r\n\t]") -def _word_replace(input_string: str) -> str: - for word in WEPWACE_HASH: - input_string = input_string.replace(word, WEPWACE_HASH[word]) +stutter_regex = re.compile(r"(\s)([a-zA-Z])") +stutter_substitute = "\\g<1>\\g<2>-\\g<2>" - return input_string +nya_regex = re.compile(r"n([aeou])([^aeiou])") +nya_substitute = "ny\\g<1>\\g<2>" -def _char_replace(input_string: str) -> str: - return wepwace_regex.sub("w", input_string) +def _word_replace(input_string: str) -> str: + """Replaces words that are keys in the word replacement hash to the values specified.""" + for word in WORD_REPLACE_HASH: + input_string = input_string.replace(word, WORD_REPLACE_HASH[word]) + return input_string -# Stuttering -stutter_regex = re.compile(r"(\s)([a-zA-Z])") -stutter_subst = "\\g<1>\\g<2>-\\g<2>" +def _char_replace(input_string: str) -> str: + """Replaces characters with 'w'.""" + return word_replace_regex.sub("w", input_string) def _stutter(strength: float, input_string: str) -> str: + """Adds stuttering to a string.""" return stutter_regex.sub(partial(_stutter_replace, strength=strength), input_string, 0) def _stutter_replace(match: Callable, strength: float = 0.0) -> str: + """Replaces a single character with a stuttered character.""" match_string = match.string[slice(*match.span())] if random.random() < strength: char = match_string[-1] @@ -91,34 +81,26 @@ def _stutter_replace(match: Callable, strength: float = 0.0) -> str: return match_string -# Nyaification -nya_regex = re.compile(r"n([aeou])([^aeiou])") -nya_subst = "ny\\g<1>\\g<2>" - - def _nyaify(input_string: str) -> str: - return nya_regex.sub(nya_subst, input_string, 0) - - -# Emoji -punctuation_regex = re.compile(r"\s+") + """Nyaifies a string.""" + return nya_regex.sub(nya_substitute, input_string, 0) def _emoji(strength: float, input_string: str) -> str: + """Replaces some punctuation with emoticons.""" return punctuation_regex.sub(partial(_emoji_replace, strength=strength), input_string, 0) def _emoji_replace(match: Callable, strength: float = 0.0) -> str: + """Replaces a punctuation character with an emoticon.""" match_string = match.string[slice(*match.span())] if random.random() < strength: return f" {EMOJI_LUT[random.randint(0, len(EMOJI_LUT) - 1)]} " - return match_string -# Main - -def _uwuify(input_string: str, *, stutter_strength: float = 0.2, emoji_strength: float = 0.2) -> str: +def _uwuify(input_string: str, *, stutter_strength: float = 0.2, emoji_strength: float = 0.1) -> str: + """Takes a string and returns an uwuified version of it.""" input_string = input_string.lower() input_string = _word_replace(input_string) input_string = _nyaify(input_string) @@ -129,21 +111,29 @@ def _uwuify(input_string: str, *, stutter_strength: float = 0.2, emoji_strength: class Uwu(Cog): - """Cog for uwuification.""" + """Cog for the uwu command.""" def __init__(self, bot: Bot): self.bot = bot @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) async def uwu_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: - """Converts a given `text` into it's uwu equivalent.""" + """ + Echoes an uwuified version of a message. + + Example: + '.uwu Hello, my name is John' returns something like + 'hewwo, m-my name is j-john nyaa~'. + """ text, embed = await Fun._get_text_and_embed(ctx, text) - # Convert embed if it exists + + # Grabs the text from the embed for uwuification. if embed is not None: embed = Fun._convert_embed(_uwuify, embed) converted_text = _uwuify(text) converted_text = helpers.suppress_links(converted_text) - # Don't put >>> if only embed present + + # Adds the text harvested from an embed to be put into another quote block. if converted_text: converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) |