SpiceBot/spicebot_command_spongemock/__init__.py
deathbybandaid 65b22a2975 test
2022-05-05 16:11:25 -04:00

50 lines
1.1 KiB
Python

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