From 73a1fee28af6218be38077b4f33ccd223b2d7f20 Mon Sep 17 00:00:00 2001 From: Jonathan <49692607+jonatan1609@users.noreply.github.com> Date: Thu, 18 Mar 2021 12:34:36 +0200 Subject: [PATCH] Fix stackable plugin decorators with include/exclude directives (#643) * combination of decorators with plugins has solved * fixing last pr: allow stackable plugin decorators even in exclude and include as well. * counting plugins has fixed * fix indentation * Update client.py * Update client.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/client.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 2820de18..5f80182d 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -724,7 +724,7 @@ class Client(Methods, Scaffold): log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format( self.session_name, type(handler).__name__, name, group, module_path)) - count += 1 + count += 1 except Exception: pass else: @@ -749,15 +749,14 @@ class Client(Methods, Scaffold): for name in handlers: # noinspection PyBroadException try: - handler, group = getattr(module, name).handler + for handler, group in getattr(module, name).handlers: + if isinstance(handler, Handler) and isinstance(group, int): + self.add_handler(handler, group) - if isinstance(handler, Handler) and isinstance(group, int): - self.add_handler(handler, group) + log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format( + self.session_name, type(handler).__name__, name, group, module_path)) - log.info('[{}] [LOAD] {}("{}") in group {} from "{}"'.format( - self.session_name, type(handler).__name__, name, group, module_path)) - - count += 1 + count += 1 except Exception: if warn_non_existent_functions: log.warning('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"'.format( @@ -785,15 +784,14 @@ class Client(Methods, Scaffold): for name in handlers: # noinspection PyBroadException try: - handler, group = getattr(module, name).handler + for handler, group in getattr(module, name).handlers: + if isinstance(handler, Handler) and isinstance(group, int): + self.remove_handler(handler, group) - if isinstance(handler, Handler) and isinstance(group, int): - self.remove_handler(handler, group) + log.info('[{}] [UNLOAD] {}("{}") from group {} in "{}"'.format( + self.session_name, type(handler).__name__, name, group, module_path)) - log.info('[{}] [UNLOAD] {}("{}") from group {} in "{}"'.format( - self.session_name, type(handler).__name__, name, group, module_path)) - - count -= 1 + count -= 1 except Exception: if warn_non_existent_functions: log.warning('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"'.format(