1
|
|
|
#!/usr/bin/python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
from modules.logging import log_command |
4
|
|
|
from telegram.ext import CommandHandler |
5
|
|
|
from datetime import datetime |
6
|
|
|
from functools import reduce |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
def module_init(gd): |
10
|
|
|
global leet_dictionary, extensions |
11
|
|
|
leet_dictionary = gd.config["leet_dictionary"] |
12
|
|
|
commands = gd.config["commands"] |
13
|
|
|
for command in commands: |
14
|
|
|
gd.dp.add_handler(CommandHandler(command, leet, pass_args=True)) |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
def leet(bot, update, args): |
18
|
|
|
current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S") |
19
|
|
|
if update.message.reply_to_message is not None: |
20
|
|
|
args = update.message.reply_to_message.text |
21
|
|
|
args = args.split(" ") |
22
|
|
|
text_leet = " ".join(args).lower() |
23
|
|
|
if text_leet == "": |
24
|
|
|
return |
25
|
|
|
replace_dict = [] |
26
|
|
|
with open(leet_dictionary, "r", encoding="UTF-8") as file: |
|
|
|
|
27
|
|
|
for i in file.readlines(): |
28
|
|
|
tmp = i.split(",") |
29
|
|
|
try: |
30
|
|
|
replace_dict.append((tmp[0], tmp[1])) |
31
|
|
|
except: |
32
|
|
|
pass |
33
|
|
|
text_leet = reduce(lambda a, kv: a.replace(*kv), replace_dict, text_leet) |
34
|
|
|
update.message.reply_text(text_leet) |
35
|
|
|
print(current_time, ">", "/leetspeak", ">", update.message.from_user.username) |
36
|
|
|
log_command(bot, update, current_time, "leetspeak") |
37
|
|
|
|