From 45b0a5973ca724218df0c0d409a7d704c8ae15c0 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Wed, 26 Apr 2023 13:12:15 +0300 Subject: [PATCH] transliteration-decoder: add !dc command trigger, allow cz-ua model to be default and make code more readable --- modules/transliteration-decoder/index.py | 18 +++++++++++++----- modules/transliteration-decoder/meta.json | 3 ++- modules/transliteration-decoder/predefine.py | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 modules/transliteration-decoder/predefine.py diff --git a/modules/transliteration-decoder/index.py b/modules/transliteration-decoder/index.py index cd955c1..1367952 100644 --- a/modules/transliteration-decoder/index.py +++ b/modules/transliteration-decoder/index.py @@ -1,11 +1,18 @@ -if self.MESSAGE['text'].split()[0] == "!decode" and (2 <= len(self.MESSAGE['text'].split(" ", 2)) <= 3): +cmd = self.MESSAGE['text'].split(" ", 2) +l = len(cmd) + +if (cmd[0] in self.aliases) and (1 <= l <= 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: + if l == 1: + chosen_model = "cz-ua" + else: + chosen_model = cmd[1] + + if l == 3: + t = cmd[2] + else: t = self.MESSAGE['reply_to_message']['text'] translated_t = t @@ -18,5 +25,6 @@ if self.MESSAGE['text'].split()[0] == "!decode" and (2 <= len(self.MESSAGE['text 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}") diff --git a/modules/transliteration-decoder/meta.json b/modules/transliteration-decoder/meta.json index 4bcbdeb..94db3ee 100644 --- a/modules/transliteration-decoder/meta.json +++ b/modules/transliteration-decoder/meta.json @@ -2,5 +2,6 @@ "version": 1, "index_file": "index.py", "start_on_boot": true, - "alias": "translit-decoder" + "alias": "translit-decoder", + "predefine": "predefine.py" } diff --git a/modules/transliteration-decoder/predefine.py b/modules/transliteration-decoder/predefine.py new file mode 100644 index 0000000..cb45e84 --- /dev/null +++ b/modules/transliteration-decoder/predefine.py @@ -0,0 +1 @@ +self.aliases = ["!decode", "!dc"]