From f621ec4aadd28ef7e61f245cae17e51599ba60d4 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Fri, 4 Nov 2022 20:11:23 +0200 Subject: [PATCH] Fixed a few stability issues and added support for dynamic module reloading --- main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 22145fe..57ffc91 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ from telegram.ext import Updater, MessageHandler, Filters +import datetime import codecs import time import json @@ -30,13 +31,13 @@ class ModuleV1: self.predefine = predefine if self.predefine: - self.predefine() + self.set_predefine() # set environmental variables def set_env(self): self.RESPONCE = "" - def predefine(self): + def set_predefine(self): try: exec(self.predefine) except Exception as e: @@ -52,6 +53,7 @@ class ModuleV1: return self.RESPONCE except Exception as e: print("[ERROR] module: module \"{}\" ({}) raised exception \"{}\"".format(self.path, self.alias, e)) + return "" # module control unit @@ -157,7 +159,21 @@ def queue_processor(): msg = message_queue[0] print("[DEBUG] queue_processor: {}".format(msg)) # debug - # modules will be used in here + # 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() + + del message_queue[0] + continue + + # modules are used in here for mod in mcu.modules: if mod.enabled: if mod.version == 1: