diff --git a/setup.cfg b/setup.cfg index a7d8960..709d0b2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,3 +33,4 @@ sopel.plugins = spicebot_command_lower = spicebot_command_lower spicebot_command_upper = spicebot_command_upper spicebot_command_echo = spicebot_command_echo + spicebot_command_spongemock = spicebot_command_spongemock diff --git a/spicebot_command_spongemock/__init__.py b/spicebot_command_spongemock/__init__.py new file mode 100644 index 0000000..fcbb333 --- /dev/null +++ b/spicebot_command_spongemock/__init__.py @@ -0,0 +1,49 @@ + +import unicodedata +import random + +from sopel import plugin + +from sopel_SpiceBot_Core_Prerun import prerun + + +@prerun() +@plugin.command('spongemock', 'smock') +def upper(bot, trigger, comrun): + comrun.say(mock_case(comrun.command["trigger_str"])) + + +def mock_case(text): + text = text.strip() + + out = text[0].lower() + lower = True + repeat = 1 + + for char in text[1:]: + lo = char.lower() + up = char.upper() + + if unicodedata.category(char) == 'Zs' or lo == up: + # whitespace shouldn't affect the case-repeat counting + # nor should characters whose case cannot be transformed + out += char + continue + + if repeat == 2: + repeat = 1 + lower = not lower + out += lo if lower else up + else: + which = random.choice([True, False]) + if which: + out += lo + else: + out += up + if lower == which: + repeat += 1 + else: + repeat = 1 + lower = which + + return out