Skip to content

Commit

Permalink
Pyrofork: Update some methods to layer 160
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Jul 22, 2023
1 parent 5368a50 commit 30c9088
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 20 deletions.
16 changes: 15 additions & 1 deletion pyrogram/methods/bots/send_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ async def send_game(
await app.send_game(chat_id, "gamename")
"""
reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
Expand All @@ -89,7 +103,7 @@ async def send_game(
),
message="",
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
noforwards=protect_content,
reply_markup=await reply_markup.write(self) if reply_markup else None
Expand Down
21 changes: 20 additions & 1 deletion pyrogram/methods/bots/send_inline_bot_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ async def send_inline_bot_result(
Sends the message silently.
Users will receive a notification with no sound.
message_thread_id (``int``, *optional*):
Unique identifier of a message thread to which the message belongs.
for supergroups only
reply_to_message_id (``bool``, *optional*):
If the message is a reply, ID of the original message.
Expand All @@ -64,13 +68,28 @@ async def send_inline_bot_result(
await app.send_inline_bot_result(chat_id, query_id, result_id)
"""

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

return await self.invoke(
raw.functions.messages.SendInlineBotResult(
peer=await self.resolve_peer(chat_id),
query_id=query_id,
id=result_id,
random_id=self.rnd_id(),
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id
reply_to=reply_to
)
)
21 changes: 20 additions & 1 deletion pyrogram/methods/messages/copy_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def copy_media_group(
message_id: int,
captions: Union[List[str], str] = None,
disable_notification: bool = None,
message_thread_id: int = None,
reply_to_message_id: int = None,
schedule_date: datetime = None,
) -> List["types.Message"]:
Expand Down Expand Up @@ -65,6 +66,10 @@ async def copy_media_group(
Sends the message silently.
Users will receive a notification with no sound.
message_thread_id (``int``, *optional*):
Unique identifier for the target message thread (topic) of the forum.
for forum supergroups only.
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.
Expand All @@ -89,6 +94,20 @@ async def copy_media_group(
media_group = await self.get_media_group(from_chat_id, message_id)
multi_media = []

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

for i, message in enumerate(media_group):
if message.photo:
file_id = message.photo.file_id
Expand Down Expand Up @@ -119,7 +138,7 @@ async def copy_media_group(
peer=await self.resolve_peer(chat_id),
multi_media=multi_media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
reply_to=reply_to,
schedule_date=utils.datetime_to_timestamp(schedule_date)
),
sleep_threshold=60
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/copy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,27 @@ async def copy_message(
"""
message: types.Message = await self.get_messages(from_chat_id, message_id)

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

return await message.copy(
chat_id=chat_id,
caption=caption,
parse_mode=parse_mode,
caption_entities=caption_entities,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
schedule_date=schedule_date,
protect_content=protect_content,
reply_markup=reply_markup
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ async def progress(current, total):
"""
file = None

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

try:
if isinstance(animation, str):
if os.path.isfile(animation):
Expand Down Expand Up @@ -235,7 +249,7 @@ async def progress(current, total):
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/send_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ async def progress(current, total):
"""
file = None

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

try:
if isinstance(audio, str):
if os.path.isfile(audio):
Expand Down Expand Up @@ -222,7 +236,7 @@ async def progress(current, total):
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/send_cached_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,26 @@ async def send_cached_media(
await app.send_cached_media("me", file_id)
"""

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
media=utils.get_input_media_from_file_id(file_id),
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
17 changes: 16 additions & 1 deletion pyrogram/methods/messages/send_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ async def send_contact(
await app.send_contact("me", "+1-123-456-7890", "Name")
"""

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
Expand All @@ -106,7 +121,7 @@ async def send_contact(
),
message="",
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/send_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,26 @@ async def send_dice(
await app.send_dice(chat_id, "🏀")
"""

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaDice(emoticon=emoji),
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/send_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ async def progress(current, total):
"""
file = None

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

try:
if isinstance(document, str):
if os.path.isfile(document):
Expand Down Expand Up @@ -200,7 +214,7 @@ async def progress(current, total):
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
17 changes: 16 additions & 1 deletion pyrogram/methods/messages/send_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ async def send_location(
app.send_location("me", latitude, longitude)
"""

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
Expand All @@ -98,7 +113,7 @@ async def send_location(
),
message="",
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
16 changes: 15 additions & 1 deletion pyrogram/methods/messages/send_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ async def send_media_group(
"""
multi_media = []

reply_to = None
if reply_to_message_id or message_thread_id:
reply_to_msg_id = None
top_msg_id = None
if message_thread_id:
if not reply_to_message_id:
reply_to_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
top_msg_id = message_thread_id
else:
reply_to_msg_id = reply_to_message_id
reply_to = raw.types.InputReplyToMessage(reply_to_msg_id=reply_to_msg_id, top_msg_id=top_msg_id)

for i in media:
if isinstance(i, types.InputMediaPhoto):
if isinstance(i.media, str):
Expand Down Expand Up @@ -412,7 +426,7 @@ async def send_media_group(
peer=await self.resolve_peer(chat_id),
multi_media=multi_media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id or message_thread_id,
reply_to=reply_to,
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content
),
Expand Down
Loading

0 comments on commit 30c9088

Please sign in to comment.