Update some methods

This commit is contained in:
KurimuzonAkuma 2023-10-18 15:11:01 +03:00
parent e27e782e50
commit 35ebe8ea9d
4 changed files with 59 additions and 31 deletions

View File

@ -26,8 +26,9 @@ class SendReaction:
async def send_reaction( async def send_reaction(
self: "pyrogram.Client", self: "pyrogram.Client",
chat_id: Union[int, str], chat_id: Union[int, str],
message_id: int, message_id: int = None,
emoji: str = "", story_id: int = None,
emoji: Union[int, str] = None,
big: bool = False big: bool = False
) -> bool: ) -> bool:
"""Send a reaction to a message. """Send a reaction to a message.
@ -41,7 +42,10 @@ class SendReaction:
message_id (``int``): message_id (``int``):
Identifier of the message. Identifier of the message.
emoji (``str``, *optional*): story_id (``int``):
Identifier of the story.
emoji (``int`` | ``str``, *optional*):
Reaction emoji. Reaction emoji.
Pass "" as emoji (default) to retract the reaction. Pass "" as emoji (default) to retract the reaction.
@ -61,13 +65,25 @@ class SendReaction:
# Retract a reaction # Retract a reaction
await app.send_reaction(chat_id, message_id) await app.send_reaction(chat_id, message_id)
""" """
await self.invoke( if isinstance(emoji, int):
raw.functions.messages.SendReaction( emoji = [raw.types.ReactionCustomEmoji(document_id=emoji)]
else:
emoji = [raw.types.ReactionEmoji(emoticon=emoji)] if emoji else None
if story_id:
rpc = raw.functions.stories.SendReaction(
peer=await self.resolve_peer(chat_id),
story_id=story_id,
reaction=emoji,
)
else:
rpc = raw.functions.messages.SendReaction(
peer=await self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
msg_id=message_id, msg_id=message_id,
reaction=[raw.types.ReactionEmoji(emoticon=emoji)] if emoji else None, reaction=emoji,
big=big big=big
) )
)
await self.invoke(rpc)
return True return True

View File

@ -47,21 +47,22 @@ class GetStoriesArchive:
offset_id (``int``, *optional*): offset_id (``int``, *optional*):
Identifier of the first story to be returned. Identifier of the first story to be returned.
Returns: Yields:
``Generator``: On success, a generator yielding :obj:`~pyrogram.types.Story` objects is returned. :obj:`~pyrogram.types.Story` objects.
Example: Example:
.. code-block:: python .. code-block:: python
# Get story archive # Get stories archive
async for story in app.get_stories_archive(chat_id): async for story in app.get_stories_archive(chat_id):
print(story) print(story)
Raises:
ValueError: In case of invalid arguments.
""" """
peer = await self.resolve_peer(chat_id) current = 0
total = abs(limit) or (1 << 31)
limit = min(100, total)
while True:
peer = await self.resolve_peer(chat_id)
r = await self.invoke( r = await self.invoke(
raw.functions.stories.GetStoriesArchive( raw.functions.stories.GetStoriesArchive(
peer=peer, peer=peer,
@ -70,6 +71,12 @@ class GetStoriesArchive:
) )
) )
if not r.stories:
return
last = r.stories[-1]
offset_id = last.id
for story in r.stories: for story in r.stories:
yield await types.Story._parse( yield await types.Story._parse(
self, self,
@ -78,3 +85,8 @@ class GetStoriesArchive:
{i.id: i for i in r.chats}, {i.id: i for i in r.chats},
peer peer
) )
current += 1
if current >= total:
return

View File

@ -28,7 +28,7 @@ class PinStories:
self: "pyrogram.Client", self: "pyrogram.Client",
chat_id: Union[int, str], chat_id: Union[int, str],
stories_ids: Union[int, Iterable[int]], stories_ids: Union[int, Iterable[int]],
pinned: bool, pinned: bool = False,
) -> List[int]: ) -> List[int]:
"""Toggle stories pinned. """Toggle stories pinned.

View File

@ -3598,7 +3598,7 @@ class Message(Object, Update):
else: else:
await self.reply(button, quote=quote) await self.reply(button, quote=quote)
async def react(self, emoji: str = "", big: bool = False) -> bool: async def react(self, emoji: Union[int, str] = None, big: bool = False) -> bool:
"""Bound method *react* of :obj:`~pyrogram.types.Message`. """Bound method *react* of :obj:`~pyrogram.types.Message`.
Use as a shortcut for: Use as a shortcut for: