core: add control commands for enabling and disabling modules on the fly
This commit is contained in:
parent
a530272408
commit
376ffd4957
52
main.py
52
main.py
|
@ -180,15 +180,52 @@ def queue_processor():
|
||||||
|
|
||||||
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")
|
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
|
# properly reload all v2 modules
|
||||||
for mod in mcu.modules:
|
for mod in mcu.modules:
|
||||||
if mod.version == 2:
|
if mod.version == 2:
|
||||||
importlib.reload(mod.obj)
|
importlib.reload(mod.obj)
|
||||||
|
|
||||||
del mcu.modules[:]
|
del mcu.modules[:]
|
||||||
mcu.reload_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":
|
elif (2 <= len(command) <= 3) and command[0] == "delay":
|
||||||
l = len(command)
|
l = len(command)
|
||||||
|
@ -233,6 +270,7 @@ def queue_processor():
|
||||||
elif l == 2:
|
elif l == 2:
|
||||||
print(f"[INFO]: DELAY_AFTER_IDLE = {DELAY_AFTER_IDLE}")
|
print(f"[INFO]: DELAY_AFTER_IDLE = {DELAY_AFTER_IDLE}")
|
||||||
updater.bot.send_message(msg.chat.id, f"[INFO]: DELAY_AFTER_IDLE = {DELAY_AFTER_IDLE}")
|
updater.bot.send_message(msg.chat.id, f"[INFO]: DELAY_AFTER_IDLE = {DELAY_AFTER_IDLE}")
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# modules are used in here
|
# modules are used in here
|
||||||
|
|
Loading…
Reference in New Issue