From 2eae08aaa642d742cfc888b543501316188f2bad Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 15 Oct 2018 10:16:19 +0200 Subject: [PATCH] Add on_user_status decorator --- .../methods/decorators/on_user_status.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 pyrogram/client/methods/decorators/on_user_status.py diff --git a/pyrogram/client/methods/decorators/on_user_status.py b/pyrogram/client/methods/decorators/on_user_status.py new file mode 100644 index 00000000..81367c3e --- /dev/null +++ b/pyrogram/client/methods/decorators/on_user_status.py @@ -0,0 +1,41 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from ...ext import BaseClient + + +class OnUserStatus(BaseClient): + def on_user_status(self, 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`. + + Args: + filters (:obj:`Filters `): + Pass one or more filters to allow only a subset of UserStatus updated to be passed in your function. + + group (``int``, *optional*): + The group identifier, defaults to 0. + """ + + def decorator(func): + self.add_handler(pyrogram.UserStatusHandler(func, filters), group) + return func + + return decorator