aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/fun/fun.py3
-rw-r--r--bot/exts/fun/uwu.py40
2 files changed, 25 insertions, 18 deletions
diff --git a/bot/exts/fun/fun.py b/bot/exts/fun/fun.py
index 773c2ffb..a27ad85f 100644
--- a/bot/exts/fun/fun.py
+++ b/bot/exts/fun/fun.py
@@ -1,4 +1,3 @@
-import functools
import json
import logging
import random
@@ -10,13 +9,13 @@ from discord import Embed, Message
from discord.ext import commands
from discord.ext.commands import BadArgument, Cog, Context, MessageConverter, clean_content
-from bot import utils
from bot.bot import Bot
from bot.constants import Client, Colours, Emojis
from bot.utils import helpers
log = logging.getLogger(__name__)
+
def caesar_cipher(text: str, offset: int) -> Iterable[str]:
"""
Implements a lazy Caesar Cipher algorithm.
diff --git a/bot/exts/fun/uwu.py b/bot/exts/fun/uwu.py
index a6be7c3d..ef838d56 100644
--- a/bot/exts/fun/uwu.py
+++ b/bot/exts/fun/uwu.py
@@ -1,8 +1,5 @@
-#!/usr/bin/env python3
-
import re
import random
-import re
from functools import partial
from bot.utils import helpers
@@ -11,7 +8,6 @@ from bot.bot import Bot
from bot.exts.fun.fun import Fun
-from discord import Message
from discord.ext import commands
from discord.ext.commands import Cog, Context, clean_content
@@ -46,7 +42,7 @@ EMOJI_LUT = [
"( ͡o ω ͡o )",
"ʘwʘ",
":3",
- ":3", # important enough to have twice
+ ":3", # important enough to have twice
"XD",
"nyaa~~",
"mya",
@@ -66,60 +62,71 @@ EMOJI_LUT = [
wepwace_regex = re.compile(r"(?<![w])[lr](?![w])")
+
def word_replace(input_string: str) -> str:
for word in WEPWACE_HASH:
input_string = input_string.replace(word, WEPWACE_HASH[word])
return input_string
+
def char_replace(input_string: str) -> str:
return wepwace_regex.sub("w", input_string)
+
# Stuttering
stutter_regex = re.compile(r"(\s)([a-zA-Z])")
stutter_subst = "\\g<1>\\g<2>-\\g<2>"
+
def stutter(strength: float, input_string: str):
- return stutter_regex.sub(partial(stutter_replace, strength=strength), input_string, 0)
+ return stutter_regex.sub(partial(stutter_replace, strength=strength), input_string, 0)
-def stutter_replace(match, strength = 0.0):
+
+def stutter_replace(match, strength=0.0):
match_string = match.string[slice(*match.span())]
if random.random() < strength:
char = match_string[-1]
return f"{match_string}-{char}"
return match_string
+
# Nyaification
nya_regex = re.compile(r"n([aeou])([^aeiou])")
nya_subst = "ny\\g<1>\\g<2>"
+
def nyaify(input_string):
return nya_regex.sub(nya_subst, input_string, 0)
+
# Emoji
punctuation_regex = re.compile(r"\s+")
+
def emoji(strength: float, input_string: str):
- return punctuation_regex.sub(partial(emoji_replace, strength=strength), input_string, 0)
+ return punctuation_regex.sub(partial(emoji_replace, strength=strength), input_string, 0)
-def emoji_replace(match, strength = 0.0):
+def emoji_replace(match, strength=0.0):
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:
- input_string = input_string.lower()
- input_string = word_replace(input_string)
- input_string = nyaify(input_string)
- input_string = char_replace(input_string)
- input_string = stutter(stutter_strength, input_string)
- input_string = emoji(emoji_strength, input_string)
- return input_string
+ input_string = input_string.lower()
+ input_string = word_replace(input_string)
+ input_string = nyaify(input_string)
+ input_string = char_replace(input_string)
+ input_string = stutter(stutter_strength, input_string)
+ input_string = emoji(emoji_strength, input_string)
+ return input_string
+
class Uwu(Cog):
"""
@@ -142,6 +149,7 @@ class Uwu(Cog):
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))