From fafa3b513168c4b3ace7528a7fc6207f4776d66d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 10 Nov 2018 15:15:58 +0100 Subject: [PATCH 1/2] Fix some decorators not working when used in plugins --- pyrogram/client/methods/decorators/on_callback_query.py | 2 +- pyrogram/client/methods/decorators/on_deleted_messages.py | 2 +- pyrogram/client/methods/decorators/on_disconnect.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/decorators/on_callback_query.py b/pyrogram/client/methods/decorators/on_callback_query.py index 8413515d..a79cbd10 100644 --- a/pyrogram/client/methods/decorators/on_callback_query.py +++ b/pyrogram/client/methods/decorators/on_callback_query.py @@ -22,7 +22,7 @@ from ...ext import BaseClient class OnCallbackQuery(BaseClient): - def on_callback_query(self, filters=None, group: int = 0): + def on_callback_query(self=None, filters=None, group: int = 0): """Use this decorator to automatically register a function for handling callback queries. This does the same thing as :meth:`add_handler` using the :class:`CallbackQueryHandler`. diff --git a/pyrogram/client/methods/decorators/on_deleted_messages.py b/pyrogram/client/methods/decorators/on_deleted_messages.py index e4b2bc97..347deaf9 100644 --- a/pyrogram/client/methods/decorators/on_deleted_messages.py +++ b/pyrogram/client/methods/decorators/on_deleted_messages.py @@ -22,7 +22,7 @@ from ...ext import BaseClient class OnDeletedMessages(BaseClient): - def on_deleted_messages(self, filters=None, group: int = 0): + def on_deleted_messages(self=None, filters=None, group: int = 0): """Use this decorator to automatically register a function for handling deleted messages. This does the same thing as :meth:`add_handler` using the :class:`DeletedMessagesHandler`. diff --git a/pyrogram/client/methods/decorators/on_disconnect.py b/pyrogram/client/methods/decorators/on_disconnect.py index a639471b..e2288619 100644 --- a/pyrogram/client/methods/decorators/on_disconnect.py +++ b/pyrogram/client/methods/decorators/on_disconnect.py @@ -21,7 +21,7 @@ from ...ext import BaseClient class OnDisconnect(BaseClient): - def on_disconnect(self): + def on_disconnect(self=None): """Use this decorator to automatically register a function for handling disconnections. This does the same thing as :meth:`add_handler` using the :class:`DisconnectHandler`. From 2e164993693fe70c36c7cf41b22b95ecd22738ce Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 10 Nov 2018 15:21:52 +0100 Subject: [PATCH 2/2] Allow decorators to be stacked E.g: app1.on_message(...) app2.on_message(...) app3.on_message(...) def on_message(client, message): ... --- pyrogram/client/methods/decorators/on_callback_query.py | 3 +++ pyrogram/client/methods/decorators/on_deleted_messages.py | 3 +++ pyrogram/client/methods/decorators/on_message.py | 3 +++ pyrogram/client/methods/decorators/on_raw_update.py | 3 +++ pyrogram/client/methods/decorators/on_user_status.py | 3 +++ 5 files changed, 15 insertions(+) diff --git a/pyrogram/client/methods/decorators/on_callback_query.py b/pyrogram/client/methods/decorators/on_callback_query.py index a79cbd10..a7079236 100644 --- a/pyrogram/client/methods/decorators/on_callback_query.py +++ b/pyrogram/client/methods/decorators/on_callback_query.py @@ -37,6 +37,9 @@ class OnCallbackQuery(BaseClient): """ def decorator(func): + if isinstance(func, tuple): + func = func[0].callback + handler = pyrogram.CallbackQueryHandler(func, filters) if isinstance(self, Filter): diff --git a/pyrogram/client/methods/decorators/on_deleted_messages.py b/pyrogram/client/methods/decorators/on_deleted_messages.py index 347deaf9..2fd8f298 100644 --- a/pyrogram/client/methods/decorators/on_deleted_messages.py +++ b/pyrogram/client/methods/decorators/on_deleted_messages.py @@ -37,6 +37,9 @@ class OnDeletedMessages(BaseClient): """ def decorator(func): + if isinstance(func, tuple): + func = func[0].callback + handler = pyrogram.DeletedMessagesHandler(func, filters) if isinstance(self, Filter): diff --git a/pyrogram/client/methods/decorators/on_message.py b/pyrogram/client/methods/decorators/on_message.py index 7a0d54a0..690f8368 100644 --- a/pyrogram/client/methods/decorators/on_message.py +++ b/pyrogram/client/methods/decorators/on_message.py @@ -37,6 +37,9 @@ class OnMessage(BaseClient): """ def decorator(func): + if isinstance(func, tuple): + func = func[0].callback + handler = pyrogram.MessageHandler(func, filters) if isinstance(self, Filter): diff --git a/pyrogram/client/methods/decorators/on_raw_update.py b/pyrogram/client/methods/decorators/on_raw_update.py index 7675a4f0..1391482f 100644 --- a/pyrogram/client/methods/decorators/on_raw_update.py +++ b/pyrogram/client/methods/decorators/on_raw_update.py @@ -32,6 +32,9 @@ class OnRawUpdate(BaseClient): """ def decorator(func): + if isinstance(func, tuple): + func = func[0].callback + handler = pyrogram.RawUpdateHandler(func) if isinstance(self, int): diff --git a/pyrogram/client/methods/decorators/on_user_status.py b/pyrogram/client/methods/decorators/on_user_status.py index b49e63a8..5aa6f783 100644 --- a/pyrogram/client/methods/decorators/on_user_status.py +++ b/pyrogram/client/methods/decorators/on_user_status.py @@ -36,6 +36,9 @@ class OnUserStatus(BaseClient): """ def decorator(func): + if isinstance(func, tuple): + func = func[0].callback + handler = pyrogram.UserStatusHandler(func, filters) if isinstance(self, Filter):