Source code for pyrogram.types.messages_and_media.reaction
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.
from __future__ import annotations
import pyrogram
from pyrogram import raw
from ..object import Object
[docs]
class Reaction(Object):
"""Contains information about a reaction.
Parameters:
emoji (``str``, *optional*):
Reaction emoji.
custom_emoji_id (``str``, *optional*):
Custom emoji id.
count (``int``, *optional*):
Reaction count.
chosen_order (``int``, *optional*):
Chosen reaction order.
Available for chosen reactions.
is_paid (``bool``, *optional*):
True, if reaction is paid.
"""
def __init__(
self,
*,
client: pyrogram.Client | None = None,
emoji: str | None = None,
custom_emoji_id: str | None = None,
count: int | None = None,
chosen_order: int | None = None,
is_paid: bool | None = None,
):
super().__init__(client)
self.emoji = emoji
self.custom_emoji_id = custom_emoji_id
self.count = count
self.chosen_order = chosen_order
self.is_paid = is_paid
@staticmethod
def _parse(client: pyrogram.Client, reaction: raw.base.Reaction) -> Reaction:
if isinstance(reaction, raw.types.ReactionEmoji):
return Reaction(client=client, emoji=reaction.emoticon)
if isinstance(reaction, raw.types.ReactionCustomEmoji):
return Reaction(client=client, custom_emoji_id=str(reaction.document_id))
if isinstance(reaction, raw.types.ReactionPaid):
return Reaction(client=client, is_paid=True)
@staticmethod
def _parse_count(client: pyrogram.Client, reaction_count: raw.base.ReactionCount) -> Reaction:
reaction = Reaction._parse(client, reaction_count.reaction)
reaction.count = reaction_count.count
reaction.chosen_order = reaction_count.chosen_order
return reaction