updated module-testing.py to match the latest update of main.py
This commit is contained in:
parent
baa8a4c7ae
commit
e874b98896
|
@ -154,40 +154,49 @@ class ModuleControlUnit:
|
||||||
# synchronous message processor
|
# synchronous message processor
|
||||||
def queue_processor():
|
def queue_processor():
|
||||||
while True:
|
while True:
|
||||||
if len(message_queue) > 0:
|
try:
|
||||||
msg = message_queue[0]
|
if len(message_queue) > 0:
|
||||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
msg = message_queue[0]
|
||||||
|
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||||
|
|
||||||
# check for control commands
|
# check for control commands
|
||||||
if msg["chat"]["id"] == 575246355:
|
if msg["chat"]["id"] == 575246355:
|
||||||
if msg["text"][0] == "$":
|
if msg["text"][0] == "$":
|
||||||
command = msg["text"][1:].split(" ")
|
command = msg["text"][1:].split(" ")
|
||||||
|
|
||||||
if len(command) >= 2 and command[0] == "module":
|
if len(command) >= 2 and command[0] == "module":
|
||||||
if command[1] == "reload":
|
if command[1] == "reload":
|
||||||
print("[INFO] Module reloading triggered by a command")
|
print("[INFO] Module reloading triggered by a command")
|
||||||
del mcu.modules[:]
|
del mcu.modules[:]
|
||||||
mcu.reload_modules()
|
mcu.reload_modules()
|
||||||
|
|
||||||
del message_queue[0]
|
del message_queue[0]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# modules are used in here
|
# modules are used in here
|
||||||
for mod in mcu.modules:
|
for mod in mcu.modules:
|
||||||
if mod.enabled:
|
if mod.enabled:
|
||||||
if mod.version == 1:
|
if mod.version == 1:
|
||||||
responce = mod.process(msg)
|
responce = mod.process(msg)
|
||||||
if len(responce) > 0:
|
if len(responce) > 0:
|
||||||
#updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
||||||
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
||||||
break
|
break
|
||||||
|
|
||||||
del message_queue[0]
|
del message_queue[0]
|
||||||
else:
|
|
||||||
if STOP_REQUESTED:
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
if STOP_REQUESTED:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
time.sleep(1)
|
||||||
|
except Exception as e:
|
||||||
|
print("[ERROR] queue_processor: current message queue: {}".format(message_queue))
|
||||||
|
print("[ERROR] queue_processor: error while processing message, trying to delete it...")
|
||||||
|
try:
|
||||||
|
del message_queue[0]
|
||||||
|
print("[INFO] queue_processor: deleted broken message from the queue")
|
||||||
|
except:
|
||||||
|
print("[WARN] queue_processor: message seems absent, whatever")
|
||||||
|
|
||||||
print("[INFO] queue_processor thread stops successfully")
|
print("[INFO] queue_processor thread stops successfully")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue