Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit fe7fcf3

Browse files
committed
Update reaction.py
1 parent 1fb04b7 commit fe7fcf3

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

pyrogram/types/messages_and_media/reaction.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,64 @@
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
20+
1921
import pyrogram
22+
from pyrogram import raw
2023
from ..object import Object
2124

2225

2326
class Reaction(Object):
2427
"""Contains information about a reaction.
2528
2629
Parameters:
27-
emoji (``str``):
30+
emoji (``str``, *optional*):
2831
Reaction emoji.
2932
30-
count (``int``):
31-
Reaction count.
33+
custom_emoji_id (``int``, *optional*):
34+
Custom emoji id.
3235
33-
chosen (``bool``):
34-
Whether this is the chosen reaction.
36+
count (``int``, *optional*):
37+
Reaction count.
3538
"""
3639

3740
def __init__(
3841
self,
3942
*,
4043
client: "pyrogram.Client" = None,
41-
emoji: str,
42-
count: int,
43-
chosen: bool
44+
emoji: Optional[str] = None,
45+
custom_emoji_id: Optional[int] = None,
46+
count: Optional[int] = None
4447
):
4548
super().__init__(client)
4649

4750
self.emoji = emoji
51+
self.custom_emoji_id = custom_emoji_id
4852
self.count = count
49-
self.chosen = chosen
53+
54+
@staticmethod
55+
def _parse(
56+
client: "pyrogram.Client",
57+
reaction: "raw.base.Reaction"
58+
) -> "Reaction":
59+
if isinstance(reaction, raw.types.ReactionEmoji):
60+
return Reaction(
61+
client=client,
62+
emoji=reaction.emoticon
63+
)
64+
65+
if isinstance(reaction, raw.types.ReactionCustomEmoji):
66+
return Reaction(
67+
client=client,
68+
custom_emoji_id=reaction.document_id
69+
)
70+
71+
@staticmethod
72+
def _parse_count(
73+
client: "pyrogram.Client",
74+
reaction_count: "raw.base.ReactionCount"
75+
) -> "Reaction":
76+
reaction = Reaction._parse(client, reaction_count.reaction)
77+
reaction.count = reaction_count.count
78+
79+
return reaction

0 commit comments

Comments
 (0)