fix: reuse function

Signed-off-by: Frost Ming <me@frostming.com>
This commit is contained in:
Frost Ming 2023-12-16 18:23:22 +08:00
parent ea236d47a8
commit 3f2a768ede
No known key found for this signature in database
GPG Key ID: 5BFA9CB4DDA943BF

View File

@ -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.")