Avoid name conflicts between modules and modules list
This commit is contained in:
parent
2e9d3dd549
commit
ba67968a77
9 changed files with 27 additions and 26 deletions
|
@ -33,6 +33,8 @@ key = reply_keyboard.ReplyKeyboardMarkup()
|
||||||
for k in ["Edt", "Kfet", "Setkfet", "Setedt", "Notif", "Settomuss"]:
|
for k in ["Edt", "Kfet", "Setkfet", "Setedt", "Notif", "Settomuss"]:
|
||||||
key.add(reply_keyboard.KeyboardButton(k))
|
key.add(reply_keyboard.KeyboardButton(k))
|
||||||
|
|
||||||
|
modules_active = list()
|
||||||
|
|
||||||
|
|
||||||
def check_id(user: types.User):
|
def check_id(user: types.User):
|
||||||
with Session as session:
|
with Session as session:
|
||||||
|
@ -48,7 +50,6 @@ def check_id(user: types.User):
|
||||||
|
|
||||||
logger.info("Start loading modules")
|
logger.info("Start loading modules")
|
||||||
from TelegramEDT.modules import load_module
|
from TelegramEDT.modules import load_module
|
||||||
modules = list()
|
|
||||||
for m in ["modules", "basic", "edt", "kfet", "tomuss", "edt_notif", "tools"]:
|
for m in ["modules", "basic", "edt", "kfet", "tomuss", "edt_notif", "tools"]:
|
||||||
load_module(m)
|
load_module(m)
|
||||||
logger.info("Modules loading finish")
|
logger.info("Modules loading finish")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from aiogram import types
|
from aiogram import types
|
||||||
from aiogram.types import ParseMode
|
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.base import User
|
||||||
from TelegramEDT.lang import lang
|
from TelegramEDT.lang import lang
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@ def load():
|
||||||
logger.info(f"Load {module_name} module")
|
logger.info(f"Load {module_name} module")
|
||||||
dp.register_message_handler(start, commands="start")
|
dp.register_message_handler(start, commands="start")
|
||||||
dp.register_message_handler(help_cmd, commands="help")
|
dp.register_message_handler(help_cmd, commands="help")
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
logger.info(f"Unload {module_name} module")
|
logger.info(f"Unload {module_name} module")
|
||||||
dp.message_handlers.unregister(start)
|
dp.message_handlers.unregister(start)
|
||||||
dp.message_handlers.unregister(help_cmd)
|
dp.message_handlers.unregister(help_cmd)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
|
@ -11,7 +11,7 @@ from ics.parse import ParseError, string_to_container
|
||||||
from pyzbar.pyzbar import decode
|
from pyzbar.pyzbar import decode
|
||||||
from requests.exceptions import ConnectionError, InvalidSchema, MissingSchema
|
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.EDTcalendar import Calendar
|
||||||
from TelegramEDT.base import User
|
from TelegramEDT.base import User
|
||||||
from TelegramEDT.lang import lang
|
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,
|
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg), content_types=[ContentType.TEXT,
|
||||||
ContentType.PHOTO])
|
ContentType.PHOTO])
|
||||||
dp.register_message_handler(edt_geturl, commands="getedt")
|
dp.register_message_handler(edt_geturl, commands="getedt")
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
|
@ -156,4 +156,4 @@ def unload():
|
||||||
dp.message_handlers.unregister(edt_await)
|
dp.message_handlers.unregister(edt_await)
|
||||||
dp.message_handlers.unregister(await_cmd)
|
dp.message_handlers.unregister(await_cmd)
|
||||||
dp.message_handlers.unregister(edt_geturl)
|
dp.message_handlers.unregister(edt_geturl)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
|
@ -2,7 +2,7 @@ from aiogram import types
|
||||||
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ParseMode
|
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ParseMode
|
||||||
from aiogram.utils import markdown
|
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.base import User
|
||||||
from TelegramEDT.lang import lang
|
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_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_callback_query_handler(notif_query, posts_cb.filter(action=["toggle", "time", "cooldown"]))
|
||||||
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
|
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
|
@ -99,4 +99,4 @@ def unload():
|
||||||
dp.message_handlers.unregister(notif_cmd)
|
dp.message_handlers.unregister(notif_cmd)
|
||||||
dp.callback_query_handlers.unregister(notif_query)
|
dp.callback_query_handlers.unregister(notif_query)
|
||||||
dp.message_handlers.unregister(await_cmd)
|
dp.message_handlers.unregister(await_cmd)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from aiogram import types
|
||||||
from aiogram.types import ParseMode
|
from aiogram.types import ParseMode
|
||||||
from aiogram.utils import markdown
|
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.base import User, KFET_URL
|
||||||
from TelegramEDT.lang import lang
|
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, lambda msg: msg.text.lower() == "kfet")
|
||||||
dp.register_message_handler(kfet_set, lambda msg: msg.text.lower() == "setkfet")
|
dp.register_message_handler(kfet_set, lambda msg: msg.text.lower() == "setkfet")
|
||||||
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
|
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
|
@ -109,4 +109,4 @@ def unload():
|
||||||
dp.message_handlers.unregister(kfet)
|
dp.message_handlers.unregister(kfet)
|
||||||
dp.message_handlers.unregister(kfet_set)
|
dp.message_handlers.unregister(kfet_set)
|
||||||
dp.message_handlers.unregister(await_cmd)
|
dp.message_handlers.unregister(await_cmd)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
|
|
||||||
from TelegramEDT import modules
|
from TelegramEDT import modules_active
|
||||||
from TelegramEDT.edt_notif import notif as edt_notif
|
from TelegramEDT.edt_notif import notif as edt_notif
|
||||||
from TelegramEDT.kfet import notif as kfet_notif
|
from TelegramEDT.kfet import notif as kfet_notif
|
||||||
from TelegramEDT.tomuss import notif as tomuss_notif
|
from TelegramEDT.tomuss import notif as tomuss_notif
|
||||||
|
@ -8,10 +8,10 @@ from TelegramEDT.tomuss import notif as tomuss_notif
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
while True:
|
while True:
|
||||||
if "edt_notif" in modules:
|
if "edt_notif" in modules_active:
|
||||||
await edt_notif()
|
await edt_notif()
|
||||||
if "kfet" in modules:
|
if "kfet" in modules_active:
|
||||||
await kfet_notif()
|
await kfet_notif()
|
||||||
if "tomuss" in modules:
|
if "tomuss" in modules_active:
|
||||||
await tomuss_notif()
|
await tomuss_notif()
|
||||||
await sleep(30)
|
await sleep(30)
|
||||||
|
|
|
@ -2,7 +2,7 @@ from importlib import import_module
|
||||||
|
|
||||||
from aiogram.types import Message
|
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"
|
module_name = "modules"
|
||||||
logger = logger.getChild(module_name)
|
logger = logger.getChild(module_name)
|
||||||
|
@ -66,11 +66,11 @@ def load():
|
||||||
logger.info(f"Load {module_name} module")
|
logger.info(f"Load {module_name} module")
|
||||||
dp.register_message_handler(load_cmd, commands="load")
|
dp.register_message_handler(load_cmd, commands="load")
|
||||||
dp.register_message_handler(unload_cmd, commands="unload")
|
dp.register_message_handler(unload_cmd, commands="unload")
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
logger.info(f"Unload {module_name} module")
|
logger.info(f"Unload {module_name} module")
|
||||||
dp.message_handlers.unregister(load_cmd)
|
dp.message_handlers.unregister(load_cmd)
|
||||||
dp.message_handlers.unregister(unload_cmd)
|
dp.message_handlers.unregister(unload_cmd)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from aiogram.types import ParseMode
|
||||||
from aiogram.utils import markdown
|
from aiogram.utils import markdown
|
||||||
from feedparser import parse
|
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.base import User
|
||||||
from TelegramEDT.lang import lang
|
from TelegramEDT.lang import lang
|
||||||
|
|
||||||
|
@ -72,11 +72,11 @@ def load():
|
||||||
logger.info(f"Load {module_name} module")
|
logger.info(f"Load {module_name} module")
|
||||||
dp.register_message_handler(settomuss, lambda msg: msg.text.lower() == "settomuss")
|
dp.register_message_handler(settomuss, lambda msg: msg.text.lower() == "settomuss")
|
||||||
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
|
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
logger.info(f"Unload {module_name} module")
|
logger.info(f"Unload {module_name} module")
|
||||||
dp.message_handlers.unregister(settomuss)
|
dp.message_handlers.unregister(settomuss)
|
||||||
dp.message_handlers.unregister(await_cmd)
|
dp.message_handlers.unregister(await_cmd)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from aiogram.types import ParseMode
|
||||||
from aiogram.utils import markdown
|
from aiogram.utils import markdown
|
||||||
from aiogram.utils.exceptions import MessageIsTooLong
|
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
|
from TelegramEDT.base import User
|
||||||
|
|
||||||
module_name = "tools"
|
module_name = "tools"
|
||||||
|
@ -92,7 +92,7 @@ def load():
|
||||||
dp.register_message_handler(get_db, commands="getdb")
|
dp.register_message_handler(get_db, commands="getdb")
|
||||||
dp.register_message_handler(eval_cmd, commands="eval")
|
dp.register_message_handler(eval_cmd, commands="eval")
|
||||||
dp.register_errors_handler(errors)
|
dp.register_errors_handler(errors)
|
||||||
modules.append(module_name)
|
modules_active.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def unload():
|
def unload():
|
||||||
|
@ -102,4 +102,4 @@ def unload():
|
||||||
dp.message_handlers.unregister(get_db)
|
dp.message_handlers.unregister(get_db)
|
||||||
dp.message_handlers.unregister(eval_cmd)
|
dp.message_handlers.unregister(eval_cmd)
|
||||||
dp.errors_handlers.unregister(errors)
|
dp.errors_handlers.unregister(errors)
|
||||||
modules.remove(module_name)
|
modules_active.remove(module_name)
|
||||||
|
|
Reference in a new issue