From 75d661744a98b4e110fba5bfc840d91fe0590882 Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 27 Dec 2019 13:44:44 +0100 Subject: [PATCH] More logical modules load --- TelegramEDT/__init__.py | 7 ++----- TelegramEDT/modules.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/TelegramEDT/__init__.py b/TelegramEDT/__init__.py index da742b2..c1ea75a 100644 --- a/TelegramEDT/__init__.py +++ b/TelegramEDT/__init__.py @@ -11,7 +11,6 @@ from TelegramEDT.EDTcalendar import Calendar from TelegramEDT.base import Base, User from TelegramEDT.lang import lang from TelegramEDT.logger import logger -from TelegramEDT.modules import load_module, load_cmd, unload_cmd if not isfile("token.ini"): logger.critical("No token specified, impossible to start the bot !") @@ -47,10 +46,8 @@ def check_id(user: types.User): session.commit() -dp.register_message_handler(load_cmd, commands="load") -dp.register_message_handler(unload_cmd, commands="unload") - logger.info("Start loading modules") -for m in ["basic", "edt", "kfet", "tomuss", "notif", "tools"]: +from TelegramEDT.modules import load_module +for m in ["modules", "basic", "edt", "kfet", "tomuss", "notif", "tools"]: load_module(m) logger.info("Modules loading finish") diff --git a/TelegramEDT/modules.py b/TelegramEDT/modules.py index 9351ac1..a5ec952 100644 --- a/TelegramEDT/modules.py +++ b/TelegramEDT/modules.py @@ -2,7 +2,7 @@ from importlib import import_module from aiogram.types import Message -from TelegramEDT import ADMIN_ID, logger +from TelegramEDT import ADMIN_ID, dp, logger logger = logger.getChild("modules") @@ -59,3 +59,15 @@ async def unload_cmd(message: Message): msg = f"Fail to unload module {module} !" await message.reply(msg) + + +def load(): + logger.info("Load modules module") + dp.register_message_handler(load_cmd, commands="load") + dp.register_message_handler(unload_cmd, commands="unload") + + +def unload(): + logger.info("Unload tools module") + dp.message_handlers.unregister(load_cmd) + dp.message_handlers.unregister(unload_cmd)