From 7e0a47e4986f1f90e77c0b217b639884ade796e8 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Wed, 3 May 2023 21:44:46 +0300 Subject: [PATCH] main.py: fix v2 modules reloading --- main.py | 7 +++++++ module-testing.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/main.py b/main.py index a19ca50..ee96b64 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import sys import os import threading import importlib +import imp # global variables STOP_REQUESTED = False @@ -172,6 +173,12 @@ def queue_processor(): if len(command) >= 2 and command[0] == "module": if command[1] == "reload": print("[INFO] Module reloading triggered by a command") + + # properly reload all v2 modules + for mod in mcu.modules: + if mod.version == 2: + imp.reload(mod.obj) + del mcu.modules[:] mcu.reload_modules() diff --git a/module-testing.py b/module-testing.py index d56fe94..d333df9 100644 --- a/module-testing.py +++ b/module-testing.py @@ -6,6 +6,7 @@ import sys import os import threading import importlib +import imp from telegram import Message, Chat @@ -175,6 +176,12 @@ def queue_processor(): if len(command) >= 2 and command[0] == "module": if command[1] == "reload": print("[INFO] Module reloading triggered by a command") + + # properly reload all v2 modules + for mod in mcu.modules: + if mod.version == 2: + imp.reload(mod.obj) + del mcu.modules[:] mcu.reload_modules()