From cf2223f40a68d17627f503119818ac0bd3a717e0 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Mon, 31 Oct 2022 22:14:53 +0200 Subject: [PATCH] added new module: qna-basic --- modules/qna-basic/db/obj.json | 6 ++++++ modules/qna-basic/index.py | 25 +++++++++++++++++++++++++ modules/qna-basic/meta.json | 6 ++++++ 3 files changed, 37 insertions(+) create mode 100644 modules/qna-basic/db/obj.json create mode 100644 modules/qna-basic/index.py create mode 100644 modules/qna-basic/meta.json diff --git a/modules/qna-basic/db/obj.json b/modules/qna-basic/db/obj.json new file mode 100644 index 0000000..b2fad31 --- /dev/null +++ b/modules/qna-basic/db/obj.json @@ -0,0 +1,6 @@ +{ + "trigger_lists": [ + ["коли", "тест", "обж"] + ], + "responce_text": "Тести з ОБЖ необхідно проходити лише тим студентам, які не були на практичному занятті. Якщо Ви були на практиці, але все одно пройдете тест, то ризикуєте отримати нижчу оцінку та знизити свій загальний бал" +} diff --git a/modules/qna-basic/index.py b/modules/qna-basic/index.py new file mode 100644 index 0000000..75dfd76 --- /dev/null +++ b/modules/qna-basic/index.py @@ -0,0 +1,25 @@ +msg = self.MESSAGE["text"].lower() + +responce_given = False + +for file in os.listdir(self.path + "db/"): + if responce_given: + break + + try: + criteria = json.loads( readfile(self.path + "db/" + file) ) + + for wordset in criteria["trigger_lists"]: + all_words_in = True + for word in wordset: + if not word in msg: + all_words_in = False + break + + if all_words_in: + self.RESPONCE = criteria["responce_text"] + responce_given = True + break + + except Exception as e: + print("[WARN] module : qna-basic: db file {} raised exception \"{}\"".format(file, e)) diff --git a/modules/qna-basic/meta.json b/modules/qna-basic/meta.json new file mode 100644 index 0000000..73757df --- /dev/null +++ b/modules/qna-basic/meta.json @@ -0,0 +1,6 @@ +{ + "version": 1, + "index_file": "index.py", + "start_on_boot": true, + "alias": "qna-basic" +}