Skip to content

Commit 96b3997

Browse files
committed
Allow on_callback_query to be used as a static decorator
1 parent 6fdb90e commit 96b3997

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pyrogram/client/methods/decorators/on_callback_query.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import pyrogram
20+
from pyrogram.client.filters.filter import Filter
2021
from ...ext import BaseClient
2122

2223

@@ -36,7 +37,14 @@ def on_callback_query(self, filters=None, group: int = 0):
3637
"""
3738

3839
def decorator(func):
39-
self.add_handler(pyrogram.CallbackQueryHandler(func, filters), group)
40-
return func
40+
handler = pyrogram.CallbackQueryHandler(func, filters)
41+
42+
if isinstance(self, Filter):
43+
return pyrogram.CallbackQueryHandler(func, self), group if filters is None else filters
44+
45+
if self is not None:
46+
self.add_handler(handler, group)
47+
48+
return handler, group
4149

4250
return decorator

0 commit comments

Comments
 (0)