Fix reply_to_peer wrongly be set to the target chat_id

This commit is contained in:
KurimuzonAkuma 2023-11-10 10:20:38 +03:00
parent 2bbe5af50b
commit ecf5eb8586
20 changed files with 122 additions and 23 deletions

View File

@ -32,6 +32,7 @@ class SendGame:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
protect_content: bool = None,
reply_markup: Union[
"types.InlineKeyboardMarkup",
@ -64,6 +65,9 @@ class SendGame:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
protect_content (``bool``, *optional*):
Protects the contents of the sent message from forwarding and saving.
@ -92,6 +96,7 @@ class SendGame:
silent=disable_notification or None,
reply_to=utils.get_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,
message_thread_id=message_thread_id
),
random_id=self.rnd_id(),

View File

@ -32,6 +32,7 @@ class SendInlineBotResult:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None
@ -64,6 +65,9 @@ class SendInlineBotResult:
reply_to_message_id (``bool``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
quote_text (``str``):
Text of the quote to be sent.
@ -93,6 +97,7 @@ class SendInlineBotResult:
silent=disable_notification or None,
reply_to=utils.get_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,
message_thread_id=message_thread_id,
quote_text=quote_text,
quote_entities=quote_entities

View File

@ -17,10 +17,10 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from typing import Union, List
from typing import Union, List, Optional
import pyrogram
from pyrogram import types, utils, raw
from pyrogram import types, utils, raw, enums
class CopyMediaGroup:
@ -33,6 +33,11 @@ class CopyMediaGroup:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
schedule_date: datetime = None,
invert_media: bool = None,
) -> List["types.Message"]:
@ -74,6 +79,22 @@ class CopyMediaGroup:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
quote_text (``str``):
Text of the quote to be sent.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the message will be automatically sent.
@ -94,6 +115,7 @@ class CopyMediaGroup:
await app.copy_media_group(to_chat, from_chat, 123,
captions=["caption 1", None, ""])
"""
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()
media_group = await self.get_media_group(from_chat_id, message_id)
multi_media = []
@ -128,7 +150,14 @@ class CopyMediaGroup:
peer=await self.resolve_peer(chat_id),
multi_media=multi_media,
silent=disable_notification or None,
reply_to=utils.get_reply_to(reply_to_message_id, message_thread_id),
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
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,
),
schedule_date=utils.datetime_to_timestamp(schedule_date),
invert_media=invert_media
),

View File

@ -48,6 +48,7 @@ class SendAnimation:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -126,6 +127,9 @@ class SendAnimation:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -253,7 +257,7 @@ class SendAnimation:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -46,6 +46,7 @@ class SendAudio:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -119,6 +120,9 @@ class SendAudio:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -240,7 +244,7 @@ class SendAudio:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -35,6 +35,7 @@ class SendCachedMedia:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -133,7 +134,7 @@ class SendCachedMedia:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -37,6 +37,7 @@ class SendContact:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
@ -82,6 +83,9 @@ class SendContact:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
quote_text (``str``):
Text of the quote to be sent.
@ -126,6 +130,7 @@ class SendContact:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
quote_text=quote_text,
quote_entities=quote_entities,
),

View File

@ -32,6 +32,7 @@ class SendDice:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
@ -73,6 +74,9 @@ class SendDice:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -122,7 +126,7 @@ class SendDice:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -44,6 +44,7 @@ class SendDocument:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -111,6 +112,9 @@ class SendDocument:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -218,7 +222,7 @@ class SendDocument:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -33,6 +33,7 @@ class SendLocation:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
@ -72,6 +73,9 @@ class SendLocation:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
quote_text (``str``):
Text of the quote to be sent.
@ -116,6 +120,7 @@ class SendLocation:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
quote_text=quote_text,
quote_entities=quote_entities,
),

View File

@ -46,6 +46,7 @@ class SendMediaGroup:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
@ -78,6 +79,9 @@ class SendMediaGroup:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -428,7 +432,7 @@ class SendMediaGroup:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -34,8 +34,8 @@ class SendMessage:
disable_web_page_preview: bool = None,
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_chat_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -79,12 +79,12 @@ class SendMessage:
Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, the ID of the original chat.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -143,12 +143,10 @@ class SendMessage:
"""
message, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values()
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()
peer = await self.resolve_peer(chat_id)
if reply_to_chat_id:
peer = await self.resolve_peer(reply_to_chat_id)
r = await self.invoke(
raw.functions.messages.SendMessage(
peer=peer,
@ -157,7 +155,7 @@ class SendMessage:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -42,6 +42,7 @@ class SendPhoto:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -102,6 +103,9 @@ class SendPhoto:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -202,7 +206,7 @@ class SendPhoto:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -44,6 +44,7 @@ class SendPoll:
protect_content: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
@ -125,6 +126,9 @@ class SendPoll:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
quote_text (``str``):
Text of the quote to be sent.
@ -153,6 +157,7 @@ class SendPoll:
solution, solution_entities = (await utils.parse_text_entities(
self, explanation, explanation_parse_mode, explanation_entities
)).values()
quote_text, quote_entities = (await utils.parse_text_entities(self, quote_text, parse_mode, quote_entities)).values()
r = await self.invoke(
@ -182,6 +187,7 @@ class SendPoll:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
quote_text=quote_text,
quote_entities=quote_entities,
),

View File

@ -39,6 +39,7 @@ class SendSticker:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
@ -82,6 +83,9 @@ class SendSticker:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -183,7 +187,7 @@ class SendSticker:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -37,6 +37,7 @@ class SendVenue:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
@ -89,6 +90,9 @@ class SendVenue:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
quote_text (``str``):
Text of the quote to be sent.
@ -140,6 +144,7 @@ class SendVenue:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=await self.resolve_peer(reply_to_chat_id) if reply_to_chat_id else None,
quote_text=quote_text,
quote_entities=quote_entities,
),

View File

@ -49,6 +49,7 @@ class SendVideo:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -132,6 +133,9 @@ class SendVideo:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -259,7 +263,7 @@ class SendVideo:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -41,6 +41,7 @@ class SendVideoNote:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
@ -96,6 +97,9 @@ class SendVideoNote:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -207,7 +211,7 @@ class SendVideoNote:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -42,6 +42,7 @@ class SendVoice:
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,
@ -97,6 +98,9 @@ class SendVoice:
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message
reply_to_chat_id (``int``, *optional*):
If the message is a reply, ID of the original chat.
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
@ -201,7 +205,7 @@ class SendVoice:
reply_to=utils.get_reply_to(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_peer=peer,
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,

View File

@ -3517,7 +3517,7 @@ class Message(Object, Update):
caption_entities: List["types.MessageEntity"] = None,
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_chat_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_message_id: int = None,
quote_text: str = None,
quote_entities: List["types.MessageEntity"] = None,