This commit is contained in:
deathbybandaid 2022-05-05 16:11:25 -04:00
parent d624800839
commit 65b22a2975
2 changed files with 50 additions and 0 deletions

View File

@ -33,3 +33,4 @@ sopel.plugins =
spicebot_command_lower = spicebot_command_lower spicebot_command_lower = spicebot_command_lower
spicebot_command_upper = spicebot_command_upper spicebot_command_upper = spicebot_command_upper
spicebot_command_echo = spicebot_command_echo spicebot_command_echo = spicebot_command_echo
spicebot_command_spongemock = spicebot_command_spongemock

View File

@ -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