From d7428880e116691ec11e0d1b28600a3d82ba7df2 Mon Sep 17 00:00:00 2001 From: hikariatama Date: Wed, 4 May 2022 17:32:07 +0000 Subject: [PATCH] Fix commands parsing --- hikka/loader.py | 13 +++++++------ hikka/main.py | 4 +++- hikka/modules/hikka_security.py | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/hikka/loader.py b/hikka/loader.py index 43a2da1..8657df1 100755 --- a/hikka/loader.py +++ b/hikka/loader.py @@ -245,17 +245,16 @@ def get_commands(mod): """Introspect the module to get its commands""" # https://stackoverflow.com/a/34452/5509575 return { - method_name.rstrip("cmd"): getattr(mod, method_name) + method_name.rsplit("cmd", maxsplit=1)[0]: getattr(mod, method_name) for method_name in dir(mod) - if callable(getattr(mod, method_name)) - and method_name.endswith("cmd") + if callable(getattr(mod, method_name)) and method_name.endswith("cmd") } def get_inline_handlers(mod): """Introspect the module to get its inline handlers""" return { - method_name.rstrip("_inline_handler"): getattr(mod, method_name) + method_name.rsplit("_inline_handler", maxsplit=1)[0]: getattr(mod, method_name) for method_name in dir(mod) if callable(getattr(mod, method_name)) and method_name.endswith("_inline_handler") @@ -265,7 +264,9 @@ def get_inline_handlers(mod): def get_callback_handlers(mod): """Introspect the module to get its callback handlers""" return { - method_name.rstrip("_callback_handler"): getattr(mod, method_name) + method_name.rsplit("_callback_handler", maxsplit=1)[0]: getattr( + mod, method_name + ) for method_name in dir(mod) if callable(getattr(mod, method_name)) and method_name.endswith("_callback_handler") @@ -328,7 +329,7 @@ class Modules: def _register_modules(self, modules: list, origin: str = ""): for mod in modules: try: - module_name = f"{__package__}.{MODULES_NAME}.{os.path.basename(mod).rstrip('.py')}" # fmt: skip + module_name = f"{__package__}.{MODULES_NAME}.{os.path.basename(mod).rsplit('.py', maxsplit=1)[0]}" # fmt: skip logging.debug(module_name) with open(mod, "r") as file: spec = ModuleSpec( diff --git a/hikka/main.py b/hikka/main.py index 6c3c5dc..b1c3fd0 100755 --- a/hikka/main.py +++ b/hikka/main.py @@ -283,7 +283,9 @@ class Hikka: phones = { phone.split(":", maxsplit=1)[0]: phone for phone in map( - lambda f: f.lstrip("hikka-").rstrip(".session"), + lambda f: f.split("hikka-", maxsplit=1)[1].rsplit( + ".session", maxsplit=1 + )[0], filter( lambda f: f.startswith("hikka-") and f.endswith(".session"), os.listdir( diff --git a/hikka/modules/hikka_security.py b/hikka/modules/hikka_security.py index f02c5ed..89464d6 100755 --- a/hikka/modules/hikka_security.py +++ b/hikka/modules/hikka_security.py @@ -117,7 +117,7 @@ class HikkaSecurityMod(loader.Module): "confirm": "👑 Подтвердить", "self": "🚫 Нельзя управлять своими правами!", "warning": ( - "⚠️ Ты действительно хочешь добавить {} " + '⚠️ Ты действительно хочешь добавить {} ' "в группу {}!\nЭто действие может передать частичный или" " полный доступ к юзерботу этому пользователю!" ), @@ -227,7 +227,7 @@ class HikkaSecurityMod(loader.Module): "text": f"{('🚫' if not level else '✅')} {self.strings[group]}", "callback": self.inline__switch_perm, "args": ( - command.__name__.rstrip("cmd"), + command.__name__.rsplit("cmd", maxsplit=1)[0], group, not level, is_inline, @@ -244,7 +244,7 @@ class HikkaSecurityMod(loader.Module): "text": f"{('🚫' if not level else '✅')} {self.strings[group]}", "callback": self.inline__switch_perm, "args": ( - command.__name__.rstrip("_inline_handler"), + command.__name__.rsplit("_inline_handler", maxsplit=1)[0], group, not level, is_inline,