From c8604e8e2c59f542625edcf645563297f4096d5b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 12:58:11 +0200 Subject: [PATCH] Update on_user_status decorator --- .../client/methods/decorators/on_user_status.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/decorators/on_user_status.py b/pyrogram/client/methods/decorators/on_user_status.py index 81367c3e..b49e63a8 100644 --- a/pyrogram/client/methods/decorators/on_user_status.py +++ b/pyrogram/client/methods/decorators/on_user_status.py @@ -17,11 +17,12 @@ # along with Pyrogram. If not, see . import pyrogram +from pyrogram.client.filters.filter import Filter from ...ext import BaseClient class OnUserStatus(BaseClient): - def on_user_status(self, filters=None, group: int = 0): + def on_user_status(self=None, filters=None, group: int = 0): """Use this decorator to automatically register a function for handling user status updates. This does the same thing as :meth:`add_handler` using the :class:`UserStatusHandler`. @@ -35,7 +36,14 @@ class OnUserStatus(BaseClient): """ def decorator(func): - self.add_handler(pyrogram.UserStatusHandler(func, filters), group) - return func + handler = pyrogram.UserStatusHandler(func, filters) + + if isinstance(self, Filter): + return pyrogram.UserStatusHandler(func, self), group if filters is None else filters + + if self is not None: + self.add_handler(handler, group) + + return handler, group return decorator