2023-04-26 13:34:48 +03:00
|
|
|
command = self.MESSAGE['text'].split(" ", 2)
|
|
|
|
command_length = len(command)
|
2023-04-26 13:12:15 +03:00
|
|
|
|
2023-09-06 17:22:26 +03:00
|
|
|
def escaped_string(unescaped_string):
|
|
|
|
result_string = str(unescaped_string)
|
|
|
|
|
|
|
|
for i in ["/", "<", ">"]:
|
|
|
|
result_string = result_string.replace(i, f"\\{i}")
|
|
|
|
|
|
|
|
return result_string
|
|
|
|
|
2023-04-26 13:34:48 +03:00
|
|
|
if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
2023-04-07 00:19:39 +03:00
|
|
|
try:
|
|
|
|
models = json.loads(readfile(self.path + "translate_models.json"))
|
|
|
|
|
2023-04-26 13:34:48 +03:00
|
|
|
if command_length == 1:
|
2023-04-26 13:12:15 +03:00
|
|
|
chosen_model = "cz-ua"
|
|
|
|
else:
|
2023-04-26 13:34:48 +03:00
|
|
|
chosen_model = command[1]
|
2023-04-26 13:12:15 +03:00
|
|
|
|
2023-04-26 13:34:48 +03:00
|
|
|
if command_length == 3:
|
|
|
|
text_to_decode = command[2]
|
2023-04-26 13:12:15 +03:00
|
|
|
else:
|
2023-04-26 13:34:48 +03:00
|
|
|
text_to_decode = self.MESSAGE['reply_to_message']['text']
|
2023-04-10 17:50:20 +03:00
|
|
|
|
2023-04-26 13:34:48 +03:00
|
|
|
decoded_text = text_to_decode
|
2023-04-07 00:19:39 +03:00
|
|
|
if chosen_model not in models:
|
2023-05-08 10:28:26 +03:00
|
|
|
self.RESPONSE = f"Такого варіанту транслітерації не існує. Доступні варіанти: " \
|
|
|
|
f"{', '.join(list(models.keys()))}"
|
2023-04-07 00:19:39 +03:00
|
|
|
else:
|
|
|
|
for i in models[chosen_model]:
|
2023-04-26 13:34:48 +03:00
|
|
|
decoded_text = decoded_text.replace(i[0], i[1])
|
|
|
|
decoded_text = decoded_text.replace(i[0].capitalize(), i[1].capitalize())
|
|
|
|
decoded_text = decoded_text.replace(i[0].upper(), i[1].upper())
|
2023-04-10 17:50:20 +03:00
|
|
|
|
2023-09-06 17:22:26 +03:00
|
|
|
self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
|
|
|
|
self.FORMAT = "HTML"
|
2023-04-26 13:12:15 +03:00
|
|
|
|
2023-04-07 00:19:39 +03:00
|
|
|
except Exception as e:
|
|
|
|
print(f"[translit-decoder] Got exception: {e}")
|