2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Update reaction.py

This commit is contained in:
Dan 2022-09-03 13:42:16 +02:00
parent 1fb04b7616
commit fe7fcf3448

View File

@ -16,7 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Optional
import pyrogram import pyrogram
from pyrogram import raw
from ..object import Object from ..object import Object
@ -24,26 +27,53 @@ class Reaction(Object):
"""Contains information about a reaction. """Contains information about a reaction.
Parameters: Parameters:
emoji (``str``): emoji (``str``, *optional*):
Reaction emoji. Reaction emoji.
count (``int``): custom_emoji_id (``int``, *optional*):
Reaction count. Custom emoji id.
chosen (``bool``): count (``int``, *optional*):
Whether this is the chosen reaction. Reaction count.
""" """
def __init__( def __init__(
self, self,
*, *,
client: "pyrogram.Client" = None, client: "pyrogram.Client" = None,
emoji: str, emoji: Optional[str] = None,
count: int, custom_emoji_id: Optional[int] = None,
chosen: bool count: Optional[int] = None
): ):
super().__init__(client) super().__init__(client)
self.emoji = emoji self.emoji = emoji
self.custom_emoji_id = custom_emoji_id
self.count = count self.count = count
self.chosen = chosen
@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=reaction.document_id
)
@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
return reaction