Skip to content

Commit

Permalink
Add ability to react by specifying story_id
Browse files Browse the repository at this point in the history
Stole code from Pyrogram-Fork
  • Loading branch information
SpEcHiDe committed Jan 23, 2024
1 parent 899520c commit f6ad4fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pyrogram/methods/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
from .send_message import SendMessage
from .send_photo import SendPhoto
from .send_poll import SendPoll
from .set_message_reaction import SetMessageReaction
from .set_message_reaction import (
SetMessageReaction
)
from .send_sticker import SendSticker
from .send_venue import SendVenue
from .send_video import SendVideo
Expand Down
31 changes: 28 additions & 3 deletions pyrogram/methods/messages/set_message_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def set_message_reaction(
self: "pyrogram.Client",
chat_id: Union[int, str],
message_id: int = None,
story_id: int = None,
reaction: List["types.ReactionType"] = [],
is_big: bool = False,
add_to_recent: bool = True
Expand All @@ -40,14 +41,19 @@ async def set_message_reaction(
.. include:: /_includes/usable-by/users-bots.rst
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
message_id (``int``):
message_id (``int``, *optional*):
Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.
reaction (List of :obj:`~pyrogram.types.ReactionType` *optional*):
story_id (``int``, *optional*):
Identifier of the story.
reaction (List of :obj:`~pyrogram.types.ReactionType`, *optional*):
New list of reaction types to set on the message.
Pass None as emoji (default) to retract the reaction.
Expand Down Expand Up @@ -90,5 +96,24 @@ async def set_message_reaction(
for i in r.updates:
if isinstance(i, raw.types.UpdateMessageReactions):
return types.MessageReactions._parse(self, i.reactions)

elif story_id is not None:
r = await self.invoke(
raw.functions.stories.SendReaction(
peer=await self.resolve_peer(chat_id),
story_id=story_id,
reaction=(
[
r.write(self)
for r in reaction
] if reaction else [
raw.types.ReactionEmpty()
]
)[0],
add_to_recent=add_to_recent
)
)
# TODO
return r
else:
raise ValueError("You need to pass one of message_id!")
raise ValueError("You need to pass one of message_id OR story_id!")
6 changes: 5 additions & 1 deletion pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3546,7 +3546,11 @@ async def react(
is_big (``bool``, *optional*):
Pass True to set the reaction with a big animation.
Defaults to False.
add_to_recent (``bool``, *optional*):
Pass True if the reaction should appear in the recently used reactions.
This option is applicable only for users.
Defaults to True.
Returns:
On success, :obj:`~pyrogram.types.MessageReactions`: is returned.
Expand Down

0 comments on commit f6ad4fd

Please sign in to comment.