updated module-testing.py to match the latest update of main.py

This commit is contained in:
dymik739 2022-11-06 13:08:51 +02:00
parent baa8a4c7ae
commit e874b98896
1 changed files with 42 additions and 33 deletions

View File

@ -154,40 +154,49 @@ class ModuleControlUnit:
# synchronous message processor
def queue_processor():
while True:
if len(message_queue) > 0:
msg = message_queue[0]
print("[DEBUG] queue_processor: {}".format(msg)) # debug
try:
if len(message_queue) > 0:
msg = message_queue[0]
print("[DEBUG] queue_processor: {}".format(msg)) # debug
# check for control commands
if msg["chat"]["id"] == 575246355:
if msg["text"][0] == "$":
command = msg["text"][1:].split(" ")
# check for control commands
if msg["chat"]["id"] == 575246355:
if msg["text"][0] == "$":
command = msg["text"][1:].split(" ")
if len(command) >= 2 and command[0] == "module":
if command[1] == "reload":
print("[INFO] Module reloading triggered by a command")
del mcu.modules[:]
mcu.reload_modules()
if len(command) >= 2 and command[0] == "module":
if command[1] == "reload":
print("[INFO] Module reloading triggered by a command")
del mcu.modules[:]
mcu.reload_modules()
del message_queue[0]
continue
del message_queue[0]
continue
# modules are used in here
for mod in mcu.modules:
if mod.enabled:
if mod.version == 1:
responce = mod.process(msg)
if len(responce) > 0:
#updater.bot.send_message(chat_id = msg.chat.id, text = responce)
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
break
# modules are used in here
for mod in mcu.modules:
if mod.enabled:
if mod.version == 1:
responce = mod.process(msg)
if len(responce) > 0:
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
break
del message_queue[0]
else:
if STOP_REQUESTED:
break
del message_queue[0]
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")