From 0def45c6ce8670696a3755956cadc5bb4a65b8fb Mon Sep 17 00:00:00 2001 From: dymik739 Date: Mon, 10 Apr 2023 17:50:20 +0300 Subject: [PATCH] transliteration-decoder: add the ability to read the reply_to message text as decoding argument --- modules/transliteration-decoder/index.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/transliteration-decoder/index.py b/modules/transliteration-decoder/index.py index b35f0d1..8b291aa 100644 --- a/modules/transliteration-decoder/index.py +++ b/modules/transliteration-decoder/index.py @@ -1,10 +1,13 @@ -if self.MESSAGE['text'].split()[0] == "!decode" and len(self.MESSAGE['text'].split(" ", 2)) == 3: +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] - t = self.MESSAGE['text'].split(" ", 2)[2] - + 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()))}" @@ -12,7 +15,7 @@ if self.MESSAGE['text'].split()[0] == "!decode" and len(self.MESSAGE['text'].spl for i in models[chosen_model]: translated_t = translated_t.replace(i[0], i[1]) 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}")