1
0
Fork 0

More logical modules load

This commit is contained in:
Ethanell 2019-12-27 13:44:44 +01:00
parent a2b8dd76b7
commit 75d661744a
2 changed files with 15 additions and 6 deletions

View file

@ -11,7 +11,6 @@ from TelegramEDT.EDTcalendar import Calendar
from TelegramEDT.base import Base, User from TelegramEDT.base import Base, User
from TelegramEDT.lang import lang from TelegramEDT.lang import lang
from TelegramEDT.logger import logger from TelegramEDT.logger import logger
from TelegramEDT.modules import load_module, load_cmd, unload_cmd
if not isfile("token.ini"): if not isfile("token.ini"):
logger.critical("No token specified, impossible to start the bot !") logger.critical("No token specified, impossible to start the bot !")
@ -47,10 +46,8 @@ def check_id(user: types.User):
session.commit() session.commit()
dp.register_message_handler(load_cmd, commands="load")
dp.register_message_handler(unload_cmd, commands="unload")
logger.info("Start loading modules") 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) load_module(m)
logger.info("Modules loading finish") logger.info("Modules loading finish")

View file

@ -2,7 +2,7 @@ from importlib import import_module
from aiogram.types import Message from aiogram.types import Message
from TelegramEDT import ADMIN_ID, logger from TelegramEDT import ADMIN_ID, dp, logger
logger = logger.getChild("modules") logger = logger.getChild("modules")
@ -59,3 +59,15 @@ async def unload_cmd(message: Message):
msg = f"Fail to unload module {module} !" msg = f"Fail to unload module {module} !"
await message.reply(msg) 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)