modular-bot-framework-for-t.../modules/qna-basic/index.py

26 lines
708 B
Python
Raw Normal View History

2022-10-31 22:14:53 +02:00
msg = self.MESSAGE["text"].lower()
2023-05-08 10:28:26 +03:00
response_given = False
2022-10-31 22:14:53 +02:00
for file in os.listdir(self.path + "db/"):
2023-05-08 10:28:26 +03:00
if response_given:
2022-10-31 22:14:53 +02:00
break
try:
2023-05-08 10:28:26 +03:00
criteria = json.loads(readfile(self.path + "db/" + file))
2022-10-31 22:14:53 +02:00
2023-05-08 10:28:26 +03:00
for word_set in criteria["trigger_lists"]:
2022-10-31 22:14:53 +02:00
all_words_in = True
2023-05-08 10:28:26 +03:00
for word in word_set:
if word not in msg:
2022-10-31 22:14:53 +02:00
all_words_in = False
break
if all_words_in:
2023-05-08 10:28:26 +03:00
self.RESPONSE = criteria["response_text"]
response_given = True
2022-10-31 22:14:53 +02:00
break
except Exception as e:
print("[WARN] module : qna-basic: db file {} raised exception \"{}\"".format(file, e))