mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 00:27:09 +08:00
fix: reuse function
Signed-off-by: Frost Ming <me@frostming.com>
This commit is contained in:
parent
ea236d47a8
commit
3f2a768ede
@ -57,15 +57,12 @@ def wrap_handler(handler: T, bot: TeleBot) -> T:
|
|||||||
|
|
||||||
def load_handlers(bot: TeleBot, disable_commands: list[str]) -> None:
|
def load_handlers(bot: TeleBot, disable_commands: list[str]) -> None:
|
||||||
# import all submodules
|
# import all submodules
|
||||||
this_path = Path(__file__).parent
|
for name in list_available_commands():
|
||||||
for child in this_path.iterdir():
|
if name in disable_commands:
|
||||||
if child.name.startswith("_"):
|
|
||||||
continue
|
continue
|
||||||
if child.stem in disable_commands:
|
module = importlib.import_module(f".{name}", __package__)
|
||||||
continue
|
|
||||||
module = importlib.import_module(f".{child.stem}", __package__)
|
|
||||||
if hasattr(module, "register"):
|
if hasattr(module, "register"):
|
||||||
print(f"Loading {child.stem} handlers.")
|
print(f"Loading {name} handlers.")
|
||||||
module.register(bot)
|
module.register(bot)
|
||||||
print("Loading handlers done.")
|
print("Loading handlers done.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user