23 lines
1.1 KiB
Python
23 lines
1.1 KiB
Python
if self.MESSAGE['text'].split()[0] == "!decode" and (2 <= len(self.MESSAGE['text'].split(" ", 2)) <= 3):
|
|
try:
|
|
models = json.loads(readfile(self.path + "translate_models.json"))
|
|
chosen_model = self.MESSAGE['text'].split(" ", 2)[1]
|
|
|
|
if len(self.MESSAGE['text'].split(" ", 2)) == 3:
|
|
t = self.MESSAGE['text'].split(" ", 2)[2]
|
|
elif len(self.MESSAGE['text'].split(" ", 2)) == 2:
|
|
t = self.MESSAGE['reply_to_message']['text']
|
|
|
|
translated_t = t
|
|
if chosen_model not in models:
|
|
self.RESPONCE = f"Такого варіанту транслітерації не існує. Доступні варіанти: {', '.join(list(models.keys()))}"
|
|
else:
|
|
for i in models[chosen_model]:
|
|
translated_t = translated_t.replace(i[0], i[1])
|
|
translated_t = translated_t.replace(i[0].capitalize(), i[1].capitalize())
|
|
translated_t = translated_t.replace(i[0].upper(), i[1].upper())
|
|
|
|
self.RESPONCE = f"Результат: {translated_t}"
|
|
except Exception as e:
|
|
print(f"[translit-decoder] Got exception: {e}")
|