Skip to content

Commit

Permalink
Pyrofork: Add support to reply message in another chat
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <[email protected]>
  • Loading branch information
wulan17 committed Nov 25, 2023
1 parent 5c54499 commit fced8aa
Show file tree
Hide file tree
Showing 19 changed files with 438 additions and 34 deletions.
15 changes: 14 additions & 1 deletion pyrogram/methods/messages/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def send_animation(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -129,6 +130,10 @@ async def send_animation(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -191,8 +196,16 @@ async def progress(current, total):
file = None

reply_to = None
reply_to_chat = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def send_audio(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -122,6 +123,10 @@ async def send_audio(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -186,7 +191,14 @@ async def progress(current, total):

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_cached_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async def send_cached_media(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -94,6 +95,10 @@ async def send_cached_media(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand All @@ -119,7 +124,14 @@ async def send_cached_media(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def send_contact(
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -79,6 +80,10 @@ async def send_contact(
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand All @@ -104,7 +109,14 @@ async def send_contact(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)

r = await self.invoke(
raw.functions.messages.SendMedia(
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def send_dice(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -75,6 +76,10 @@ async def send_dice(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -107,7 +112,14 @@ async def send_dice(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def send_document(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -114,6 +115,10 @@ async def send_document(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -173,7 +178,14 @@ async def progress(current, total):

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def send_location(
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -68,6 +69,10 @@ async def send_location(
Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message
Expand Down Expand Up @@ -96,7 +101,14 @@ async def send_location(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)

r = await self.invoke(
raw.functions.messages.SendMedia(
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def send_media_group(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -80,6 +81,10 @@ async def send_media_group(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -111,7 +116,14 @@ async def send_media_group(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
15 changes: 14 additions & 1 deletion pyrogram/methods/messages/send_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async def send_message(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -84,6 +85,10 @@ async def send_message(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -139,8 +144,16 @@ async def send_message(
message, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values()

reply_to = None
reply_to_chat = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async def send_photo(
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_story_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
protect_content: bool = None,
Expand Down Expand Up @@ -105,6 +106,10 @@ async def send_photo(
reply_to_story_id (``int``, *optional*):
Unique identifier for the target story.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand Down Expand Up @@ -164,7 +169,14 @@ async def send_photo(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)
if reply_to_story_id:
user_id = await self.resolve_peer(chat_id)
reply_to = types.InputReplyToStory(user_id=user_id, story_id=reply_to_story_id)
Expand Down
14 changes: 13 additions & 1 deletion pyrogram/methods/messages/send_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def send_poll(
protect_content: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: int = None,
quote_text: str = None,
schedule_date: datetime = None,
reply_markup: Union[
Expand Down Expand Up @@ -124,6 +125,10 @@ async def send_poll(
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
reply_to_chat_id (``int``, *optional*):
Unique identifier for the origin chat.
for reply to message from another chat.
quote_text (``str``, *optional*):
Text to quote.
for reply_to_message only.
Expand All @@ -146,7 +151,14 @@ async def send_poll(

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to = types.InputReplyToMessage(reply_to_message_id=reply_to_message_id, message_thread_id=message_thread_id, quote_text=quote_text)
if reply_to_chat_id is not None:
reply_to_chat = await self.resolve_peer(reply_to_chat_id)
reply_to = types.InputReplyToMessage(
reply_to_message_id=reply_to_message_id,
message_thread_id=message_thread_id,
reply_to_chat=reply_to_chat,
quote_text=quote_text
)

solution, solution_entities = (await utils.parse_text_entities(
self, explanation, explanation_parse_mode, explanation_entities
Expand Down
Loading

0 comments on commit fced8aa

Please sign in to comment.