Skip to content

Commit

Permalink
pyrofork: Add top_reactors field to class MessageReactions
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Aug 18, 2024
1 parent 84d8949 commit b5a7b49
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 6 deletions.
1 change: 1 addition & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def get_title_list(s: str) -> list:
VideoChatMembersInvited
WebAppData
MessageReactions
MessageReactor
ChatReactions
ForumTopicCreated
ForumTopicEdited
Expand Down
6 changes: 4 additions & 2 deletions pyrogram/methods/messages/send_paid_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ async def send_paid_reaction(
await app.send_paid_reaction(chat_id, message_id=message_id, amount=5)
"""
r = await self.invoke(
raw.functions.messages.SendReaction(
raw.functions.messages.SendPaidReaction(
peer=await self.resolve_peer(chat_id),
msg_id=message_id,
count=amount,
random_id=self.rnd_id(),
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)
3 changes: 2 additions & 1 deletion pyrogram/types/messages_and_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
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
Expand All @@ -66,5 +67,5 @@
__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"
]
2 changes: 1 addition & 1 deletion pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ async def _parse(
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))
Expand Down
14 changes: 12 additions & 2 deletions pyrogram/types/messages_and_media/message_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,22 +30,28 @@ 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__(
self,
*,
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
Expand All @@ -55,5 +61,9 @@ def _parse(
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 changes: 85 additions & 0 deletions pyrogram/types/messages_and_media/message_reactor.py
Original file line number Diff line number Diff line change
@@ -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.
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,
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.user = 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
user = None
if not is_anonymous:
user = types.User._parse(users.get(message_reactor.user_id))

return MessageReactor(
client=client,
amount=message_reactor.count,
is_top=message_reactor.top,
is_my=message_reactor.my,
is_anonymous=is_anonymous,
user=user
)

0 comments on commit b5a7b49

Please sign in to comment.