Skip to content

Commit 2eae08a

Browse files
committed
Add on_user_status decorator
1 parent ff9be53 commit 2eae08a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import pyrogram
20+
from ...ext import BaseClient
21+
22+
23+
class OnUserStatus(BaseClient):
24+
def on_user_status(self, filters=None, group: int = 0):
25+
"""Use this decorator to automatically register a function for handling
26+
user status updates. This does the same thing as :meth:`add_handler` using the
27+
:class:`UserStatusHandler`.
28+
29+
Args:
30+
filters (:obj:`Filters <pyrogram.Filters>`):
31+
Pass one or more filters to allow only a subset of UserStatus updated to be passed in your function.
32+
33+
group (``int``, *optional*):
34+
The group identifier, defaults to 0.
35+
"""
36+
37+
def decorator(func):
38+
self.add_handler(pyrogram.UserStatusHandler(func, filters), group)
39+
return func
40+
41+
return decorator

0 commit comments

Comments
 (0)