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

26 lines
708 B
Python

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