diff --git a/TelegramEDT/__init__.py b/TelegramEDT/__init__.py index 42d6fb5..b51708e 100644 --- a/TelegramEDT/__init__.py +++ b/TelegramEDT/__init__.py @@ -33,6 +33,8 @@ key = reply_keyboard.ReplyKeyboardMarkup() for k in ["Edt", "Kfet", "Setkfet", "Setedt", "Notif", "Settomuss"]: key.add(reply_keyboard.KeyboardButton(k)) +modules_active = list() + def check_id(user: types.User): with Session as session: @@ -48,7 +50,6 @@ def check_id(user: types.User): logger.info("Start loading modules") from TelegramEDT.modules import load_module -modules = list() for m in ["modules", "basic", "edt", "kfet", "tomuss", "edt_notif", "tools"]: load_module(m) logger.info("Modules loading finish") diff --git a/TelegramEDT/basic.py b/TelegramEDT/basic.py index 274bac5..4d592b4 100644 --- a/TelegramEDT/basic.py +++ b/TelegramEDT/basic.py @@ -1,7 +1,7 @@ from aiogram import types from aiogram.types import ParseMode -from TelegramEDT import dp, key, logger, Session, check_id, modules +from TelegramEDT import dp, key, logger, Session, check_id, modules_active from TelegramEDT.base import User from TelegramEDT.lang import lang @@ -35,11 +35,11 @@ def load(): logger.info(f"Load {module_name} module") dp.register_message_handler(start, commands="start") dp.register_message_handler(help_cmd, commands="help") - modules.append(module_name) + modules_active.append(module_name) def unload(): logger.info(f"Unload {module_name} module") dp.message_handlers.unregister(start) dp.message_handlers.unregister(help_cmd) - modules.remove(module_name) + modules_active.remove(module_name) diff --git a/TelegramEDT/edt.py b/TelegramEDT/edt.py index e3b2a54..ada57a0 100644 --- a/TelegramEDT/edt.py +++ b/TelegramEDT/edt.py @@ -11,7 +11,7 @@ from ics.parse import ParseError, string_to_container from pyzbar.pyzbar import decode from requests.exceptions import ConnectionError, InvalidSchema, MissingSchema -from TelegramEDT import API_TOKEN, TIMES, bot, dp, key, logger, Session, check_id, posts_cb, modules +from TelegramEDT import API_TOKEN, TIMES, bot, dp, key, logger, Session, check_id, posts_cb, modules_active from TelegramEDT.EDTcalendar import Calendar from TelegramEDT.base import User from TelegramEDT.lang import lang @@ -145,7 +145,7 @@ def load(): dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg), content_types=[ContentType.TEXT, ContentType.PHOTO]) dp.register_message_handler(edt_geturl, commands="getedt") - modules.append(module_name) + modules_active.append(module_name) def unload(): @@ -156,4 +156,4 @@ def unload(): dp.message_handlers.unregister(edt_await) dp.message_handlers.unregister(await_cmd) dp.message_handlers.unregister(edt_geturl) - modules.remove(module_name) + modules_active.remove(module_name) diff --git a/TelegramEDT/edt_notif.py b/TelegramEDT/edt_notif.py index 3e1d6d0..9ac3746 100644 --- a/TelegramEDT/edt_notif.py +++ b/TelegramEDT/edt_notif.py @@ -2,7 +2,7 @@ from aiogram import types from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ParseMode from aiogram.utils import markdown -from TelegramEDT import bot, dp, logger, posts_cb, Session, check_id, key, modules +from TelegramEDT import bot, dp, logger, posts_cb, Session, check_id, key, modules_active from TelegramEDT.base import User from TelegramEDT.lang import lang @@ -91,7 +91,7 @@ def load(): dp.register_message_handler(notif_cmd, lambda msg: msg.text.lower() == "notif") dp.register_callback_query_handler(notif_query, posts_cb.filter(action=["toggle", "time", "cooldown"])) dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg)) - modules.append(module_name) + modules_active.append(module_name) def unload(): @@ -99,4 +99,4 @@ def unload(): dp.message_handlers.unregister(notif_cmd) dp.callback_query_handlers.unregister(notif_query) dp.message_handlers.unregister(await_cmd) - modules.remove(module_name) + modules_active.remove(module_name) diff --git a/TelegramEDT/kfet.py b/TelegramEDT/kfet.py index e9522db..0b40704 100644 --- a/TelegramEDT/kfet.py +++ b/TelegramEDT/kfet.py @@ -5,7 +5,7 @@ from aiogram import types from aiogram.types import ParseMode from aiogram.utils import markdown -from TelegramEDT import dp, key, logger, Session, check_id, modules, bot +from TelegramEDT import dp, key, logger, Session, check_id, modules_active, bot from TelegramEDT.base import User, KFET_URL from TelegramEDT.lang import lang @@ -101,7 +101,7 @@ def load(): dp.register_message_handler(kfet, lambda msg: msg.text.lower() == "kfet") dp.register_message_handler(kfet_set, lambda msg: msg.text.lower() == "setkfet") dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg)) - modules.append(module_name) + modules_active.append(module_name) def unload(): @@ -109,4 +109,4 @@ def unload(): dp.message_handlers.unregister(kfet) dp.message_handlers.unregister(kfet_set) dp.message_handlers.unregister(await_cmd) - modules.remove(module_name) + modules_active.remove(module_name) diff --git a/TelegramEDT/loop.py b/TelegramEDT/loop.py index 59798a0..3dd1787 100644 --- a/TelegramEDT/loop.py +++ b/TelegramEDT/loop.py @@ -1,6 +1,6 @@ from asyncio import sleep -from TelegramEDT import modules +from TelegramEDT import modules_active from TelegramEDT.edt_notif import notif as edt_notif from TelegramEDT.kfet import notif as kfet_notif from TelegramEDT.tomuss import notif as tomuss_notif @@ -8,10 +8,10 @@ from TelegramEDT.tomuss import notif as tomuss_notif async def main(): while True: - if "edt_notif" in modules: + if "edt_notif" in modules_active: await edt_notif() - if "kfet" in modules: + if "kfet" in modules_active: await kfet_notif() - if "tomuss" in modules: + if "tomuss" in modules_active: await tomuss_notif() await sleep(30) diff --git a/TelegramEDT/modules.py b/TelegramEDT/modules.py index 7c5dad4..2b6426e 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, dp, logger, modules +from TelegramEDT import ADMIN_ID, dp, logger, modules_active module_name = "modules" logger = logger.getChild(module_name) @@ -66,11 +66,11 @@ def load(): logger.info(f"Load {module_name} module") dp.register_message_handler(load_cmd, commands="load") dp.register_message_handler(unload_cmd, commands="unload") - modules.append(module_name) + modules_active.append(module_name) def unload(): logger.info(f"Unload {module_name} module") dp.message_handlers.unregister(load_cmd) dp.message_handlers.unregister(unload_cmd) - modules.remove(module_name) + modules_active.remove(module_name) diff --git a/TelegramEDT/tomuss.py b/TelegramEDT/tomuss.py index ff1e601..51a890b 100644 --- a/TelegramEDT/tomuss.py +++ b/TelegramEDT/tomuss.py @@ -3,7 +3,7 @@ from aiogram.types import ParseMode from aiogram.utils import markdown from feedparser import parse -from TelegramEDT import dp, key, logger, Session, check_id, modules, bot +from TelegramEDT import dp, key, logger, Session, check_id, modules_active, bot from TelegramEDT.base import User from TelegramEDT.lang import lang @@ -72,11 +72,11 @@ def load(): logger.info(f"Load {module_name} module") dp.register_message_handler(settomuss, lambda msg: msg.text.lower() == "settomuss") dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg)) - modules.append(module_name) + modules_active.append(module_name) def unload(): logger.info(f"Unload {module_name} module") dp.message_handlers.unregister(settomuss) dp.message_handlers.unregister(await_cmd) - modules.remove(module_name) + modules_active.remove(module_name) diff --git a/TelegramEDT/tools.py b/TelegramEDT/tools.py index bbae2bb..0c964fa 100644 --- a/TelegramEDT/tools.py +++ b/TelegramEDT/tools.py @@ -3,7 +3,7 @@ from aiogram.types import ParseMode from aiogram.utils import markdown from aiogram.utils.exceptions import MessageIsTooLong -from TelegramEDT import ADMIN_ID, bot, dp, key, logger, Session, check_id, modules +from TelegramEDT import ADMIN_ID, bot, dp, key, logger, Session, check_id, modules_active from TelegramEDT.base import User module_name = "tools" @@ -92,7 +92,7 @@ def load(): dp.register_message_handler(get_db, commands="getdb") dp.register_message_handler(eval_cmd, commands="eval") dp.register_errors_handler(errors) - modules.append(module_name) + modules_active.append(module_name) def unload(): @@ -102,4 +102,4 @@ def unload(): dp.message_handlers.unregister(get_db) dp.message_handlers.unregister(eval_cmd) dp.errors_handlers.unregister(errors) - modules.remove(module_name) + modules_active.remove(module_name)