From 6496a87029a6b0987d3825b8a22d08474fc92aa9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 3 Sep 2022 13:46:37 +0200 Subject: [PATCH] Add message_reactions.py --- pyrogram/types/messages_and_media/__init__.py | 3 +- pyrogram/types/messages_and_media/message.py | 3 +- .../messages_and_media/message_reactions.py | 56 +++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 pyrogram/types/messages_and_media/message_reactions.py diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 3a18b2a5..54dfd560 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -38,9 +38,10 @@ from .video_note import VideoNote from .voice import Voice from .web_app_data import WebAppData from .web_page import WebPage +from .message_reactions import MessageReactions __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", - "Reaction", "WebAppData" + "Reaction", "WebAppData", "MessageReactions" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 146e37c4..40386af0 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -742,8 +742,7 @@ class Message(Object, Update): from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None - reactions = [types.Reaction(emoji=r.reaction, count=r.count, chosen=r.chosen) - for r in message.reactions.results] if message.reactions else None + reactions = types.MessageReactions._parse(client, message.reactions) parsed_message = Message( id=message.id, diff --git a/pyrogram/types/messages_and_media/message_reactions.py b/pyrogram/types/messages_and_media/message_reactions.py new file mode 100644 index 00000000..8f057cf5 --- /dev/null +++ b/pyrogram/types/messages_and_media/message_reactions.py @@ -0,0 +1,56 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +from typing import Optional, List + +import pyrogram +from pyrogram import raw, types +from ..object import Object + + +class MessageReactions(Object): + """Contains information about a message reactions. + + Parameters: + reactions (List of :obj:`~pyrogram.types.Reaction`): + Reactions list. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + reactions: Optional[List["types.Reaction"]] = None, + ): + super().__init__(client) + + self.reactions = reactions + + @staticmethod + def _parse( + client: "pyrogram.Client", + message_reactions: Optional["raw.base.MessageReactions"] = None + ) -> Optional["MessageReactions"]: + if not message_reactions: + return None + + return MessageReactions( + client=client, + reactions=[types.Reaction._parse_count(client, reaction) + for reaction in message_reactions.results] + )