From 376ffd4957820b4c245bc50d16f6ec3a97640229 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Tue, 3 Oct 2023 16:57:49 +0300 Subject: [PATCH] core: add control commands for enabling and disabling modules on the fly --- main.py | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index de63159..57f8bd6 100644 --- a/main.py +++ b/main.py @@ -180,15 +180,52 @@ def queue_processor(): if len(command) >= 2 and command[0] == "module": if command[1] == "reload": - print("[INFO] Module reloading triggered by a command") + if len(command) == 2: + print("[INFO] Full module reloading triggered by a command") + updater.bot.send_message(msg.chat.id, f"Reloading all modules...") - # properly reload all v2 modules - for mod in mcu.modules: - if mod.version == 2: - importlib.reload(mod.obj) + # properly reload all v2 modules + for mod in mcu.modules: + if mod.version == 2: + importlib.reload(mod.obj) - del mcu.modules[:] - mcu.reload_modules() + del mcu.modules[:] + mcu.reload_modules() + else: + # TO DO: make it possible to reload individual modules by their + # alias or containing folder + pass + + elif command[1] == "enable" and len(command) == 3: + if command[2] == "all": + for mod in mcu.modules: + mod.enabled = True + print(f"[INFO] module {mod.alias} was enabled") + else: + for mod in mcu.modules: + if mod.alias == command[2]: + mod.enabled = True + print(f"[INFO] module {mod.alias} was enabled") + + elif command[1] == "disable" and len(command) == 3: + if command[2] == "all": + for mod in mcu.modules: + mod.enabled = False + print(f"[INFO] module {mod.alias} was disabled") + else: + for mod in mcu.modules: + if mod.alias == command[2]: + mod.enabled = False + print(f"[INFO] module {mod.alias} was disabled") + + elif command[1] == "status" and len(command) == 3: + if command[2] == "all": + for mod in mcu.modules: + print(f"[INFO] module {mod.alias} is {mod.enabled}") + else: + for mod in mcu.modules: + if mod.alias == command[2]: + print(f"[INFO] module {mod.alias} is {mod.enabled}") elif (2 <= len(command) <= 3) and command[0] == "delay": l = len(command) @@ -233,6 +270,7 @@ def queue_processor(): elif l == 2: print(f"[INFO]: DELAY_AFTER_IDLE = {DELAY_AFTER_IDLE}") updater.bot.send_message(msg.chat.id, f"[INFO]: DELAY_AFTER_IDLE = {DELAY_AFTER_IDLE}") + continue # modules are used in here