67 lines
2.5 KiB
Python
67 lines
2.5 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.append(leet_word)
|
|
else:
|
|
word_chars = []
|
|
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)
|
|
word_chars.append(leet_replacement)
|
|
else:
|
|
word_chars.append(char)
|
|
leetspeak.append("".join(word_chars))
|
|
|
|
return " ".join(leetspeak)
|