SpiceBot/spicebot_command_leetspeak/__init__.py
deathbybandaid e3f6c6e369 test
2022-05-05 16:44:42 -04:00

65 lines
2.4 KiB
Python

import random
from sopel import plugin
from sopel_SpiceBot_Core_Prerun import prerun
@prerun()
@plugin.command('leetspeak', 'leet', '1337')
def leatspeak(bot, trigger, comrun):
comrun.say(leet_convert(comrun.command["trigger_str"]))
def leet_convert(message):
message = message.strip()
replacements = (('hacker', 'haxor'), ('elite', 'eleet'), ('a', '4'), ('e', '3'),
('l', '1'), ('o', '0'), ('t', '+'))
char_map = {
"a": ["4", "@", "/-\\", "^"],
"b": ["I3", "8", "13", "|3"],
"c": ["[", "{", "<", "("],
"d": [")", "|)", "[)", "|>"],
"e": ["3", "[-"],
"f": ["|=", "ph", "|#", "/="],
"g": ["&", "6", "(_+]", "9", "C-", "gee"],
"h": ["#", "/-/", "[-]", "]-[", ")-(", "(-)", ":-:", "|-|", "}{"],
"i": ["1", "[]", "!", "|", "eye", "3y3", "]["],
"j": [",_|", "_|", "._|", "._]", ",_]", "]"],
"k": [">|", "|<", "/<", "1<", "|c", "|(", "|{"],
"l": ["1", "7", "|_", "|"],
"m": ["/\\/\\", "/V\\", "JVI", "[V]", "[]V[]", "|\\/|", "^^"],
"n": ["^/", "|\\|", "/\\/", "[\]", "<\\>", "{\\}", "|V", "/V"],
"o": ["0", "Q", "()", "oh", "[]"],
"p": ["|*", "|o", "?", "|^", "[]D"],
"q": ["(_,)", "()_", "2", "O_"],
"r": ["12", "|`", "|~", "|?", "/2", "|^", "Iz", "|9"],
"s": ["$", "5", "z", "ehs", "es"],
"t": ["7", "+", "-|-", "']['", '"|"', "~|~"],
"u": ["|_|", "(_)", "V", "L|"],
"v": ["\\/", "|/", "\\|"],
"w": ["\\/\\/", "VV", "\\N", "'//", "\\\\'", "\\^/", "\\X/"],
"x": ["><", ">|<", "}{", "ecks"],
"y": ["j", "`/", "\\|/", "\\//"],
"z": ["2", "7_", "-/_", "%", ">_", "~/_", "-\_", "-|_"],
}
leetspeak = ""
for word in message.split(" "):
if word.lower() in [old for old, new in replacements]:
leet_word = word.replace([old for old, new in replacements][0], [new for old, new in replacements][0])
leetspeak = leetspeak + leet_word
else:
for char in word:
if char.lower() in char_map and random.random() <= 0.70: # 70% convert
possible_replacements = char_map[char.lower()]
leet_replacement = random.choice(possible_replacements)
leetspeak = leetspeak + leet_replacement
else:
leetspeak = leetspeak + char
return leetspeak