mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Add top_reactors field to class MessageReactions
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
3061115d57
commit
ecfa97f115
6 changed files with 104 additions and 5 deletions
|
|
@ -520,6 +520,7 @@ def pyrogram_api():
|
|||
VideoChatMembersInvited
|
||||
WebAppData
|
||||
MessageReactions
|
||||
MessageReactor
|
||||
ChatReactions
|
||||
ForumTopicCreated
|
||||
ForumTopicEdited
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ class SendPaidReaction:
|
|||
private=anonymous
|
||||
)
|
||||
)
|
||||
users = {i.id: i for i in r.users}
|
||||
|
||||
for i in r.updates:
|
||||
if isinstance(i, raw.types.UpdateMessageReactions):
|
||||
return types.MessageReactions._parse(self, i.reactions)
|
||||
return types.MessageReactions._parse(self, i.reactions, users)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ from .web_page_preview import WebPagePreview
|
|||
from .message_reactions import MessageReactions
|
||||
from .message_reaction_updated import MessageReactionUpdated
|
||||
from .message_reaction_count_updated import MessageReactionCountUpdated
|
||||
from .message_reactor import MessageReactor
|
||||
from .message_story import MessageStory
|
||||
from .story import Story
|
||||
from .story_deleted import StoryDeleted
|
||||
|
|
@ -66,5 +67,5 @@ from .exported_story_link import ExportedStoryLink
|
|||
__all__ = [
|
||||
"Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "LabeledPrice", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||
"Reaction", "WebAppData", "MessageReactions", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||
"Reaction", "WebAppData", "MessageReactions", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageReactor", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1100,7 +1100,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.MessageReactions._parse(client, message.reactions)
|
||||
reactions = types.MessageReactions._parse(client, message.reactions, users)
|
||||
|
||||
if message.via_business_bot_id:
|
||||
sender_business_bot = types.User._parse(client, users.get(message.via_business_bot_id, None))
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Optional, List
|
||||
from typing import Optional, List, Dict
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types
|
||||
|
|
@ -30,6 +30,9 @@ class MessageReactions(Object):
|
|||
Parameters:
|
||||
reactions (List of :obj:`~pyrogram.types.Reaction`):
|
||||
Reactions list.
|
||||
|
||||
top_reactors (List of :obj:`~pyrogram.types.MessageReactor`):
|
||||
Top reactors.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
|
@ -37,15 +40,18 @@ class MessageReactions(Object):
|
|||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
reactions: Optional[List["types.Reaction"]] = None,
|
||||
top_reactors: Optional[List["types.MessageReactor"]] = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.reactions = reactions
|
||||
self.top_reactors = top_reactors
|
||||
|
||||
@staticmethod
|
||||
def _parse(
|
||||
client: "pyrogram.Client",
|
||||
message_reactions: Optional["raw.base.MessageReactions"] = None
|
||||
message_reactions: Optional["raw.base.MessageReactions"] = None,
|
||||
users: Optional[Dict[int, "raw.types.User"]] = None
|
||||
) -> Optional["MessageReactions"]:
|
||||
if not message_reactions:
|
||||
return None
|
||||
|
|
@ -55,5 +61,9 @@ class MessageReactions(Object):
|
|||
reactions=[
|
||||
types.Reaction._parse_count(client, reaction)
|
||||
for reaction in message_reactions.results
|
||||
],
|
||||
top_reactors=[
|
||||
types.MessageReactor._parse(client, reactor, users)
|
||||
for reactor in message_reactions.top_reactors
|
||||
]
|
||||
)
|
||||
|
|
|
|||
85
pyrogram/types/messages_and_media/message_reactor.py
Normal file
85
pyrogram/types/messages_and_media/message_reactor.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrofork.
|
||||
#
|
||||
# Pyrofork 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.
|
||||
#
|
||||
# Pyrofork 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 Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Optional, Dict
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class MessageReactor(Object):
|
||||
"""Contains information about a message reactor.
|
||||
|
||||
Parameters:
|
||||
amount (``int``):
|
||||
Stars amount.
|
||||
|
||||
is_top (``bool``, *optional*):
|
||||
True, if reactor is top.
|
||||
|
||||
is_my (``bool``, *optional*):
|
||||
True, if the reaction is mine.
|
||||
|
||||
is_anonymous (``bool``, *optional*):
|
||||
True, if reactor is anonymous.
|
||||
|
||||
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
||||
Information about the reactor.
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
amount: int,
|
||||
is_top: bool = None,
|
||||
is_my: bool = None,
|
||||
is_anonymous: bool = None,
|
||||
from_user: "types.User" = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.amount = amount
|
||||
self.is_top = is_top
|
||||
self.is_my = is_my
|
||||
self.is_anonymous = is_anonymous
|
||||
self.from_user = from_user
|
||||
|
||||
@staticmethod
|
||||
def _parse(
|
||||
client: "pyrogram.Client",
|
||||
message_reactor: Optional["raw.base.MessageReactor"] = None,
|
||||
users: Dict[int, "raw.types.User"] = None
|
||||
) -> Optional["MessageReactor"]:
|
||||
if not message_reactor:
|
||||
return None
|
||||
|
||||
is_anonymous = message_reactor.anonymous
|
||||
from_user = None
|
||||
if not is_anonymous:
|
||||
from_user = types.User._parse(client, users.get(message_reactor.peer_id.user_id))
|
||||
|
||||
return MessageReactor(
|
||||
client=client,
|
||||
amount=message_reactor.count,
|
||||
is_top=message_reactor.top,
|
||||
is_my=message_reactor.my,
|
||||
is_anonymous=is_anonymous,
|
||||
from_user=from_user
|
||||
)
|
||||
Loading…
Reference in a new issue