Skip to content

Commit ecb1fe1

Browse files
Add missing attributes in MessageReactions type
1 parent f11adfb commit ecb1fe1

5 files changed

Lines changed: 129 additions & 6 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ def get_title_list(s: str) -> list:
702702
PaidMediaInfo
703703
PaidMediaPreview
704704
PaidMessagesRefunded
705+
PaidReactor
705706
PaidMessagesPriceChanged
706707
DirectMessagePriceChanged
707708
DirectMessagesTopic

pyrogram/types/messages_and_media/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from .paid_media_preview import PaidMediaPreview
6868
from .paid_messages_price_changed import PaidMessagesPriceChanged
6969
from .paid_messages_refunded import PaidMessagesRefunded
70+
from .paid_reactor import PaidReactor
7071
from .payment_form import PaymentForm
7172
from .photo import Photo
7273
from .poll import Poll
@@ -152,6 +153,7 @@
152153
"PaidMediaPreview",
153154
"PaidMessagesPriceChanged",
154155
"PaidMessagesRefunded",
156+
"PaidReactor",
155157
"PaymentForm",
156158
"Photo",
157159
"Poll",

pyrogram/types/messages_and_media/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ async def _parse_service(
11241124
paid_messages_refunded=paid_messages_refunded,
11251125
paid_messages_price_changed=paid_messages_price_changed,
11261126
direct_message_price_changed=direct_message_price_changed,
1127-
reactions=types.MessageReactions._parse(client, message.reactions),
1127+
reactions=types.MessageReactions._parse(client, message.reactions, users, chats),
11281128
business_connection_id=business_connection_id,
11291129
raw=message,
11301130
client=client
@@ -1356,7 +1356,7 @@ async def _parse_message(
13561356
else:
13571357
reply_markup = None
13581358

1359-
reactions = types.MessageReactions._parse(client, message.reactions)
1359+
reactions = types.MessageReactions._parse(client, message.reactions, users, chats)
13601360

13611361
parsed_message = Message(
13621362
id=message.id,

pyrogram/types/messages_and_media/message_reactions.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Optional, List
19+
from typing import Dict, List, Optional
2020

2121
import pyrogram
2222
from pyrogram import raw, types
23+
2324
from ..object import Object
2425

2526

@@ -29,28 +30,61 @@ class MessageReactions(Object):
2930
Parameters:
3031
reactions (List of :obj:`~pyrogram.types.Reaction`):
3132
Reactions list.
33+
34+
are_tags (``bool``, *optional*):
35+
True, if the reactions are tags and Telegram Premium users can filter messages by them.
36+
37+
paid_reactors (List of :obj:`~pyrogram.types.PaidReactor`, *optional*):
38+
Information about top users that added the paid reaction.
39+
40+
can_get_added_reactions (``bool``, *optional*):
41+
True, if the list of added reactions is available using :meth:`~pyrogram.Client.get_message_added_reactions`.
3242
"""
3343

44+
# TODO: Add get_message_added_reactions method
45+
3446
def __init__(
3547
self,
3648
*,
3749
client: "pyrogram.Client" = None,
3850
reactions: Optional[List["types.Reaction"]] = None,
51+
are_tags: Optional[bool] = None,
52+
paid_reactors: Optional[List["types.PaidReactor"]] = None,
53+
can_get_added_reactions: Optional[bool] = None,
3954
):
4055
super().__init__(client)
4156

4257
self.reactions = reactions
58+
self.are_tags = are_tags
59+
self.paid_reactors = paid_reactors
60+
self.can_get_added_reactions = can_get_added_reactions
4361

4462
@staticmethod
4563
def _parse(
4664
client: "pyrogram.Client",
47-
message_reactions: Optional["raw.base.MessageReactions"] = None
65+
message_reactions: Optional["raw.base.MessageReactions"],
66+
users: Dict[int, "types.User"],
67+
chats: Dict[int, "types.Chat"],
4868
) -> Optional["MessageReactions"]:
4969
if not message_reactions:
5070
return None
5171

5272
return MessageReactions(
5373
client=client,
54-
reactions=[types.Reaction._parse_count(client, reaction)
55-
for reaction in message_reactions.results]
74+
reactions=types.List(
75+
[
76+
types.Reaction._parse_count(client, reaction)
77+
for reaction in message_reactions.results
78+
]
79+
),
80+
are_tags=message_reactions.reactions_as_tags,
81+
paid_reactors=types.List(
82+
[
83+
types.PaidReactor._parse(client, paid_reactor, users, chats)
84+
for paid_reactor in message_reactions.top_reactors
85+
]
86+
)
87+
if message_reactions.top_reactors
88+
else None,
89+
can_get_added_reactions=message_reactions.can_see_list,
5690
)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Dict, Optional
20+
21+
import pyrogram
22+
from pyrogram import raw, types, utils
23+
24+
from ..object import Object
25+
26+
27+
class PaidReactor(Object):
28+
"""Contains information about a user that added paid reactions.
29+
30+
Parameters:
31+
sender (:obj:`~pyrogram.types.Chat`, *optional*):
32+
Identifier of the user or chat that added the reactions.
33+
May be None for anonymous reactors that aren't the current user
34+
35+
star_count (``int``, *optional*):
36+
True, if the reactions are tags and Telegram Premium users can filter messages by them.
37+
38+
is_top (``bool``, *optional*):
39+
True, if the reactor is one of the most active reactors.
40+
May be False if the reactor is the current user.
41+
42+
is_me (``bool``, *optional*):
43+
True, if the paid reaction was added by the current user.
44+
45+
is_anonymous (``bool``, *optional*):
46+
True, if the reactor is anonymous.
47+
"""
48+
49+
def __init__(
50+
self,
51+
*,
52+
sender: Optional["types.Chat"] = None,
53+
star_count: Optional[int] = None,
54+
is_top: Optional[bool] = None,
55+
is_me: Optional[bool] = None,
56+
is_anonymous: Optional[bool] = None,
57+
):
58+
super().__init__()
59+
60+
self.sender = sender
61+
self.star_count = star_count
62+
self.is_top = is_top
63+
self.is_me = is_me
64+
self.is_anonymous = is_anonymous
65+
66+
@staticmethod
67+
def _parse(
68+
client: "pyrogram.Client",
69+
paid_reactor: Optional["raw.base.MessageReactor"],
70+
users: Dict[int, "raw.base.User"],
71+
chats: Dict[int, "raw.base.Chat"],
72+
) -> Optional["PaidReactor"]:
73+
if not paid_reactor:
74+
return None
75+
76+
chat = chats.get(utils.get_raw_peer_id(paid_reactor.peer_id)) or users.get(
77+
utils.get_raw_peer_id(paid_reactor.peer_id)
78+
)
79+
80+
return PaidReactor(
81+
sender=types.Chat._parse_chat(client, chat),
82+
star_count=paid_reactor.count,
83+
is_top=paid_reactor.top,
84+
is_me=paid_reactor.my,
85+
is_anonymous=paid_reactor.anonymous,
86+
)

0 commit comments

Comments
 (0)