Compare commits
No commits in common. "cf2223f40a68d17627f503119818ac0bd3a717e0" and "30f53c08d4dd4fb19684fb223f04bac6f2d0482d" have entirely different histories.
cf2223f40a
...
30f53c08d4
19
main.py
19
main.py
|
@ -21,27 +21,17 @@ def readfile(filename):
|
|||
|
||||
# module object classes
|
||||
class ModuleV1:
|
||||
def __init__(self, path, code, enabled, alias, predefine):
|
||||
def __init__(self, path, code, enabled, alias):
|
||||
self.version = 1
|
||||
self.enabled = enabled
|
||||
self.code = code
|
||||
self.alias = alias
|
||||
self.path = path
|
||||
self.predefine = predefine
|
||||
|
||||
if self.predefine:
|
||||
self.predefine()
|
||||
|
||||
# set environmental variables
|
||||
def set_env(self):
|
||||
self.RESPONCE = ""
|
||||
|
||||
def predefine(self):
|
||||
try:
|
||||
exec(self.predefine)
|
||||
except Exception as e:
|
||||
print("[ERROR] module: module \"{}\" ({}) raised exception \"{}\" during predefine stage, disabling it...".format(self.path, self.alias, e))
|
||||
|
||||
# running the module
|
||||
def process(self, msg):
|
||||
self.set_env()
|
||||
|
@ -93,12 +83,7 @@ class ModuleControlUnit:
|
|||
else:
|
||||
alias = None
|
||||
|
||||
if "predefine" in meta:
|
||||
predefine = readfile("modules/{}/{}".format(folder, meta["predefine"]))
|
||||
else:
|
||||
predefine = False
|
||||
|
||||
self.modules.append( ModuleV1( "modules/{}/".format(folder), code, enabled, alias, predefine ) )
|
||||
self.modules.append( ModuleV1( "modules/{}/".format(folder), code, enabled, alias ) )
|
||||
|
||||
print("[INFO] reload_modules: successfully loaded {} as {} (start_on_boot: {})".format(folder, alias, enabled))
|
||||
else:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"start_on_boot": false
|
||||
"start_on_boot": true
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"trigger_lists": [
|
||||
["коли", "тест", "обж"]
|
||||
],
|
||||
"responce_text": "Тести з ОБЖ необхідно проходити лише тим студентам, які не були на практичному занятті. Якщо Ви були на практиці, але все одно пройдете тест, то ризикуєте отримати нижчу оцінку та знизити свій загальний бал"
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
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))
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"start_on_boot": true,
|
||||
"alias": "qna-basic"
|
||||
}
|
Loading…
Reference in New Issue