Merge pull request #110 from peerids/main

fix(pyrogram.utils.get_reply_to): function parameters
This commit is contained in:
Yasir Aris M 2025-01-29 08:19:06 +07:00 committed by GitHub
commit 03c2f5ff8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 25 deletions

View file

@ -102,6 +102,17 @@ class SendInlineBotResult:
""" """
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values() quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()
reply_to = await utils.get_reply_to(
client=self,
reply_to_message_id=reply_to_message_id,
reply_to_chat_id=reply_to_chat_id,
reply_to_story_id=reply_to_story_id,
message_thread_id=message_thread_id,
quote_text=quote_text,
quote_entities=quote_entities,
quote_offset=quote_offset,
parse_mode=parse_mode,
)
r = await self.invoke( r = await self.invoke(
raw.functions.messages.SendInlineBotResult( raw.functions.messages.SendInlineBotResult(
peer=await self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
@ -109,15 +120,7 @@ class SendInlineBotResult:
id=result_id, id=result_id,
random_id=self.rnd_id(), random_id=self.rnd_id(),
silent=disable_notification or None, silent=disable_notification or None,
reply_to=utils.get_reply_to( reply_to=reply_to,
reply_to_message_id=reply_to_message_id,
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
reply_to_story_id=reply_to_story_id,
message_thread_id=message_thread_id,
quote_text=quote_text,
quote_entities=quote_entities,
quote_offset=quote_offset,
),
schedule_date=utils.datetime_to_timestamp(schedule_date), schedule_date=utils.datetime_to_timestamp(schedule_date),
) )
) )

View file

@ -34,6 +34,7 @@ class CopyMediaGroup:
has_spoilers: Union[List[bool], bool] = None, has_spoilers: Union[List[bool], bool] = None,
disable_notification: bool = None, disable_notification: bool = None,
message_thread_id: int = None, message_thread_id: int = None,
send_as: Union[int, str] = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None, reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None, reply_to_story_id: int = None,
@ -44,6 +45,8 @@ class CopyMediaGroup:
schedule_date: datetime = None, schedule_date: datetime = None,
invert_media: bool = None, invert_media: bool = None,
protect_content: bool = None, protect_content: bool = None,
allow_paid_broadcast: bool = None,
message_effect_id: int = None,
) -> List["types.Message"]: ) -> List["types.Message"]:
"""Copy a media group by providing one of the message ids. """Copy a media group by providing one of the message ids.
@ -74,6 +77,9 @@ class CopyMediaGroup:
If a list of ``string`` passed, each element becomes caption for each media element. If a list of ``string`` passed, each element becomes caption for each media element.
You can pass ``None`` in list to keep the original caption (see examples below). You can pass ``None`` in list to keep the original caption (see examples below).
has_spoilers (``bool``, *optional*):
Pass True if the photo needs to be covered with a spoiler animation.
disable_notification (``bool``, *optional*): disable_notification (``bool``, *optional*):
Sends the message silently. Sends the message silently.
Users will receive a notification with no sound. Users will receive a notification with no sound.
@ -82,6 +88,10 @@ class CopyMediaGroup:
Unique identifier for the target message thread (topic) of the forum. Unique identifier for the target message thread (topic) of the forum.
For supergroups only. For supergroups only.
send_as (``int`` | ``str``):
Unique identifier (int) or username (str) of the chat or channel to send the message as.
You can use this to send the message on behalf of a chat or channel where you have appropriate permissions.
reply_to_message_id (``int``, *optional*): reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message. If the message is a reply, ID of the original message.
@ -113,6 +123,12 @@ class CopyMediaGroup:
protect_content (``bool``, *optional*): protect_content (``bool``, *optional*):
Protects the contents of the sent message from forwarding and saving Protects the contents of the sent message from forwarding and saving
allow_paid_broadcast (``bool``, *optional*):
Pass True to allow the message to ignore regular broadcast limits for a small fee; for bots only
message_effect_id (``int`` ``64-bit``, *optional*):
Unique identifier of the message effect to be added to the message; for private chats only.
Returns: Returns:
List of :obj:`~pyrogram.types.Message`: On success, a list of copied messages is returned. List of :obj:`~pyrogram.types.Message`: On success, a list of copied messages is returned.
@ -169,23 +185,29 @@ class CopyMediaGroup:
) )
) )
reply_to = await utils.get_reply_to(
client=self,
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat_id=reply_to_chat_id,
reply_to_story_id=reply_to_story_id,
quote_text=quote_text,
quote_entities=quote_entities,
quote_offset=quote_offset,
)
r = await self.invoke( r = await self.invoke(
raw.functions.messages.SendMultiMedia( raw.functions.messages.SendMultiMedia(
peer=await self.resolve_peer(chat_id), peer=await self.resolve_peer(chat_id),
multi_media=multi_media, multi_media=multi_media,
silent=disable_notification or None, silent=disable_notification or None,
reply_to=utils.get_reply_to( reply_to=reply_to,
reply_to_message_id=reply_to_message_id, send_as=await self.resolve_peer(send_as) if send_as else None,
message_thread_id=message_thread_id,
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
reply_to_story_id=reply_to_story_id,
quote_text=quote_text,
quote_entities=quote_entities,
quote_offset=quote_offset,
),
schedule_date=utils.datetime_to_timestamp(schedule_date), schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content, noforwards=protect_content,
invert_media=invert_media invert_media=invert_media,
allow_paid_floodskip=allow_paid_broadcast,
effect=message_effect_id,
), ),
sleep_threshold=60 sleep_threshold=60
) )

View file

@ -55,7 +55,8 @@ class InputReplyToMessage(Object):
"raw.types.InputPeerUser" "raw.types.InputPeerUser"
] = None, ] = None,
quote_text: str = None, quote_text: str = None,
quote_entities: List["raw.base.MessageEntity"] = None quote_entities: List["raw.base.MessageEntity"] = None,
quote_offset: int = None,
): ):
super().__init__() super().__init__()
@ -64,6 +65,7 @@ class InputReplyToMessage(Object):
self.reply_to_chat = reply_to_chat self.reply_to_chat = reply_to_chat
self.quote_text = quote_text self.quote_text = quote_text
self.quote_entities = quote_entities self.quote_entities = quote_entities
self.quote_offset = quote_offset
def write(self): def write(self):
reply_to_msg_id = None reply_to_msg_id = None
@ -82,6 +84,7 @@ class InputReplyToMessage(Object):
top_msg_id=top_msg_id, top_msg_id=top_msg_id,
reply_to_peer_id=self.reply_to_chat, reply_to_peer_id=self.reply_to_chat,
quote_text=self.quote_text, quote_text=self.quote_text,
quote_entities=self.quote_entities quote_entities=self.quote_entities,
quote_offset=self.quote_offset,
).write() ).write()
return None return None

View file

@ -54,7 +54,8 @@ async def ainput(prompt: str = "", *, hide: bool = False):
def get_input_media_from_file_id( def get_input_media_from_file_id(
file_id: str, file_id: str,
expected_file_type: FileType = None, expected_file_type: FileType = None,
ttl_seconds: int = None ttl_seconds: int = None,
has_spoiler: bool = None
) -> Union["raw.types.InputMediaPhoto", "raw.types.InputMediaDocument"]: ) -> Union["raw.types.InputMediaPhoto", "raw.types.InputMediaDocument"]:
try: try:
decoded = FileId.decode(file_id) decoded = FileId.decode(file_id)
@ -79,6 +80,7 @@ def get_input_media_from_file_id(
access_hash=decoded.access_hash, access_hash=decoded.access_hash,
file_reference=decoded.file_reference file_reference=decoded.file_reference
), ),
spoiler=has_spoiler,
ttl_seconds=ttl_seconds ttl_seconds=ttl_seconds
) )
@ -89,6 +91,7 @@ def get_input_media_from_file_id(
access_hash=decoded.access_hash, access_hash=decoded.access_hash,
file_reference=decoded.file_reference file_reference=decoded.file_reference
), ),
spoiler=has_spoiler,
ttl_seconds=ttl_seconds ttl_seconds=ttl_seconds
) )
@ -502,7 +505,8 @@ async def get_reply_to(
reply_to_chat_id: Union[int,str] = None, reply_to_chat_id: Union[int,str] = None,
quote_text: str = None, quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None, quote_entities: List["types.MessageEntity"] = None,
parse_mode: "enums.ParseMode" = None quote_offset: int = None,
parse_mode: "enums.ParseMode" = None,
): ):
reply_to = None reply_to = None
reply_to_chat = None reply_to_chat = None
@ -515,7 +519,8 @@ async def get_reply_to(
message_thread_id=message_thread_id, message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat, reply_to_chat=reply_to_chat,
quote_text=text, quote_text=text,
quote_entities=entities quote_entities=entities,
quote_offset=quote_offset,
) )
if reply_to_story_id: if reply_to_story_id:
peer = await client.resolve_peer(chat_id) peer = await client.resolve_peer(chat_id)