From 3f2a768ede286c44c95284b395148f5f7fb408fb Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sat, 16 Dec 2023 18:23:22 +0800 Subject: [PATCH] fix: reuse function Signed-off-by: Frost Ming --- handlers/__init__.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/handlers/__init__.py b/handlers/__init__.py index b9ba4a3..6ab54c7 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -57,15 +57,12 @@ def wrap_handler(handler: T, bot: TeleBot) -> T: def load_handlers(bot: TeleBot, disable_commands: list[str]) -> None: # import all submodules - this_path = Path(__file__).parent - for child in this_path.iterdir(): - if child.name.startswith("_"): + for name in list_available_commands(): + if name in disable_commands: continue - if child.stem in disable_commands: - continue - module = importlib.import_module(f".{child.stem}", __package__) + module = importlib.import_module(f".{name}", __package__) if hasattr(module, "register"): - print(f"Loading {child.stem} handlers.") + print(f"Loading {name} handlers.") module.register(bot) print("Loading handlers done.")