Compare commits
No commits in common. "4502e7fbe144f86be6818350f6dbbce71753c7ff" and "34439e944bbcf829d4123b3dcfd5b2c4e5dcb469" have entirely different histories.
4502e7fbe1
...
34439e944b
|
@ -4,36 +4,37 @@ command_length = len(command)
|
||||||
def escaped_string(unescaped_string):
|
def escaped_string(unescaped_string):
|
||||||
result_string = str(unescaped_string)
|
result_string = str(unescaped_string)
|
||||||
|
|
||||||
for i in ["<", ">"]:
|
for i in ["/", "<", ">"]:
|
||||||
result_string = result_string.replace(i, f"\\{i}")
|
result_string = result_string.replace(i, f"\\{i}")
|
||||||
|
|
||||||
return result_string
|
return result_string
|
||||||
|
|
||||||
if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
||||||
models = json.loads(readfile(self.path + "translate_models.json"))
|
try:
|
||||||
|
models = json.loads(readfile(self.path + "translate_models.json"))
|
||||||
|
|
||||||
if command_length == 1:
|
if command_length == 1:
|
||||||
chosen_model = "cz-ua"
|
chosen_model = "cz-ua"
|
||||||
else:
|
else:
|
||||||
chosen_model = command[1]
|
chosen_model = command[1]
|
||||||
|
|
||||||
if command_length == 3:
|
if command_length == 3:
|
||||||
text_to_decode = command[2]
|
text_to_decode = command[2]
|
||||||
else:
|
else:
|
||||||
if self.MESSAGE['reply_to_message'].caption:
|
text_to_decode = self.MESSAGE['reply_to_message']['text']
|
||||||
text_to_decode = self.MESSAGE['reply_to_message'].caption
|
|
||||||
elif self.MESSAGE['reply_to_message'].text:
|
decoded_text = text_to_decode
|
||||||
text_to_decode = self.MESSAGE['reply_to_message'].text
|
if chosen_model not in models:
|
||||||
|
self.RESPONSE = f"Такого варіанту транслітерації не існує. Доступні варіанти: " \
|
||||||
|
f"{', '.join(list(models.keys()))}"
|
||||||
|
else:
|
||||||
|
for i in models[chosen_model]:
|
||||||
|
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())
|
||||||
|
|
||||||
|
self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
|
||||||
|
self.FORMAT = "HTML"
|
||||||
|
|
||||||
decoded_text = text_to_decode
|
except Exception as e:
|
||||||
if chosen_model not in models:
|
print(f"[translit-decoder] Got exception: {e}")
|
||||||
self.RESPONSE = f"Такого варіанту транслітерації не існує. Доступні варіанти: " \
|
|
||||||
f"{', '.join(list(models.keys()))}"
|
|
||||||
else:
|
|
||||||
for i in models[chosen_model]:
|
|
||||||
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())
|
|
||||||
|
|
||||||
self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
|
|
||||||
self.FORMAT = "HTML"
|
|
||||||
|
|
Loading…
Reference in New Issue