|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <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 | +from typing import Dict, Optional |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import raw, types, utils |
| 23 | + |
| 24 | +from ..object import Object |
| 25 | + |
| 26 | + |
| 27 | +class PaidReactor(Object): |
| 28 | + """Contains information about a user that added paid reactions. |
| 29 | +
|
| 30 | + Parameters: |
| 31 | + sender (:obj:`~pyrogram.types.Chat`, *optional*): |
| 32 | + Identifier of the user or chat that added the reactions. |
| 33 | + May be None for anonymous reactors that aren't the current user |
| 34 | +
|
| 35 | + star_count (``int``, *optional*): |
| 36 | + True, if the reactions are tags and Telegram Premium users can filter messages by them. |
| 37 | +
|
| 38 | + is_top (``bool``, *optional*): |
| 39 | + True, if the reactor is one of the most active reactors. |
| 40 | + May be False if the reactor is the current user. |
| 41 | +
|
| 42 | + is_me (``bool``, *optional*): |
| 43 | + True, if the paid reaction was added by the current user. |
| 44 | +
|
| 45 | + is_anonymous (``bool``, *optional*): |
| 46 | + True, if the reactor is anonymous. |
| 47 | + """ |
| 48 | + |
| 49 | + def __init__( |
| 50 | + self, |
| 51 | + *, |
| 52 | + sender: Optional["types.Chat"] = None, |
| 53 | + star_count: Optional[int] = None, |
| 54 | + is_top: Optional[bool] = None, |
| 55 | + is_me: Optional[bool] = None, |
| 56 | + is_anonymous: Optional[bool] = None, |
| 57 | + ): |
| 58 | + super().__init__() |
| 59 | + |
| 60 | + self.sender = sender |
| 61 | + self.star_count = star_count |
| 62 | + self.is_top = is_top |
| 63 | + self.is_me = is_me |
| 64 | + self.is_anonymous = is_anonymous |
| 65 | + |
| 66 | + @staticmethod |
| 67 | + def _parse( |
| 68 | + client: "pyrogram.Client", |
| 69 | + paid_reactor: Optional["raw.base.MessageReactor"], |
| 70 | + users: Dict[int, "raw.base.User"], |
| 71 | + chats: Dict[int, "raw.base.Chat"], |
| 72 | + ) -> Optional["PaidReactor"]: |
| 73 | + if not paid_reactor: |
| 74 | + return None |
| 75 | + |
| 76 | + chat = chats.get(utils.get_raw_peer_id(paid_reactor.peer_id)) or users.get( |
| 77 | + utils.get_raw_peer_id(paid_reactor.peer_id) |
| 78 | + ) |
| 79 | + |
| 80 | + return PaidReactor( |
| 81 | + sender=types.Chat._parse_chat(client, chat), |
| 82 | + star_count=paid_reactor.count, |
| 83 | + is_top=paid_reactor.top, |
| 84 | + is_me=paid_reactor.my, |
| 85 | + is_anonymous=paid_reactor.anonymous, |
| 86 | + ) |
0 commit comments