From b423730dcbd59d650362ade56457e156805b1c2b Mon Sep 17 00:00:00 2001 From: Sam <100821827+01101sam@users.noreply.github.com> Date: Sun, 13 Nov 2022 21:18:42 +0800 Subject: [PATCH] Fix on_disconnect decorator not working (#1134) * Fix on_disconnect decorator not working * Remove useless if else statment in on_raw_update --- pyrogram/methods/decorators/on_disconnect.py | 5 +++++ pyrogram/methods/decorators/on_raw_update.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/methods/decorators/on_disconnect.py b/pyrogram/methods/decorators/on_disconnect.py index ae54800f..26aa62f8 100644 --- a/pyrogram/methods/decorators/on_disconnect.py +++ b/pyrogram/methods/decorators/on_disconnect.py @@ -32,6 +32,11 @@ class OnDisconnect: def decorator(func: Callable) -> Callable: if isinstance(self, pyrogram.Client): self.add_handler(pyrogram.handlers.DisconnectHandler(func)) + else: + if not hasattr(func, "handlers"): + func.handlers = [] + + func.handlers.append((pyrogram.handlers.DisconnectHandler(func), 0)) return func diff --git a/pyrogram/methods/decorators/on_raw_update.py b/pyrogram/methods/decorators/on_raw_update.py index dffc50b9..644bc8a5 100644 --- a/pyrogram/methods/decorators/on_raw_update.py +++ b/pyrogram/methods/decorators/on_raw_update.py @@ -46,7 +46,7 @@ class OnRawUpdate: func.handlers.append( ( pyrogram.handlers.RawUpdateHandler(func), - group if self is None else group + group ) )