mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: Add reply_to_story field to Message
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
fa5539a16d
commit
db6cae4ae1
2 changed files with 53 additions and 13 deletions
|
|
@ -124,6 +124,9 @@ class Message(Object, Update):
|
|||
For replies, the original message. Note that the Message object in this field will not contain
|
||||
further reply_to_message fields even if it itself is a reply.
|
||||
|
||||
reply_to_story (:obj:`~pyrogram.types.Story`, *optional*):
|
||||
For replies, the original story.
|
||||
|
||||
mentioned (``bool``, *optional*):
|
||||
The message contains a mention.
|
||||
|
||||
|
|
@ -378,6 +381,7 @@ class Message(Object, Update):
|
|||
reply_to_story_user_id: int = None,
|
||||
reply_to_top_message_id: int = None,
|
||||
reply_to_message: "Message" = None,
|
||||
reply_to_story: "types.Story" = None,
|
||||
mentioned: bool = None,
|
||||
empty: bool = None,
|
||||
service: "enums.MessageServiceType" = None,
|
||||
|
|
@ -470,6 +474,7 @@ class Message(Object, Update):
|
|||
self.reply_to_story_user_id = reply_to_story_user_id
|
||||
self.reply_to_top_message_id = reply_to_top_message_id
|
||||
self.reply_to_message = reply_to_message
|
||||
self.reply_to_story = reply_to_story
|
||||
self.mentioned = mentioned
|
||||
self.empty = empty
|
||||
self.service = service
|
||||
|
|
@ -1003,20 +1008,31 @@ class Message(Object, Update):
|
|||
parsed_message.reply_to_story_user_id = message.reply_to.user_id
|
||||
|
||||
if replies:
|
||||
try:
|
||||
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
|
||||
reply_to_message = client.message_cache[key]
|
||||
if parsed_message.reply_to_message_id:
|
||||
try:
|
||||
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
|
||||
reply_to_message = client.message_cache[key]
|
||||
|
||||
if not reply_to_message:
|
||||
reply_to_message = await client.get_messages(
|
||||
parsed_message.chat.id,
|
||||
reply_to_message_ids=message.id,
|
||||
replies=replies - 1
|
||||
if not reply_to_message:
|
||||
reply_to_message = await client.get_messages(
|
||||
parsed_message.chat.id,
|
||||
reply_to_message_ids=message.id,
|
||||
replies=replies - 1
|
||||
)
|
||||
if reply_to_message and not reply_to_message.forum_topic_created:
|
||||
parsed_message.reply_to_message = reply_to_message
|
||||
except MessageIdsEmpty:
|
||||
pass
|
||||
elif parsed_message.reply_to_story_id:
|
||||
try:
|
||||
reply_to_story = await client.get_stories(
|
||||
parsed_message.reply_to_story_user_id,
|
||||
parsed_message.reply_to_story_id
|
||||
)
|
||||
if reply_to_message and not reply_to_message.forum_topic_created:
|
||||
parsed_message.reply_to_message = reply_to_message
|
||||
except MessageIdsEmpty:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
parsed_message.reply_to_story = reply_to_story
|
||||
|
||||
if not parsed_message.poll: # Do not cache poll messages
|
||||
client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message
|
||||
|
|
|
|||
|
|
@ -108,7 +108,13 @@ async def parse_messages(
|
|||
messages_with_replies = {
|
||||
i.id: i.reply_to.reply_to_msg_id
|
||||
for i in messages.messages
|
||||
if not isinstance(i, raw.types.MessageEmpty) and i.reply_to
|
||||
if not isinstance(i, raw.types.MessageEmpty) and i.reply_to and isinstance(i.reply_to, raw.types.MessageReplyHeader)
|
||||
}
|
||||
|
||||
message_reply_to_story = {
|
||||
i.id: {'user_id': i.reply_to.user_id, 'story_id': i.reply_to.story_id}
|
||||
for i in messages.messages
|
||||
if not isinstance(i, raw.types.MessageEmpty) and i.reply_to and isinstance(i.reply_to, raw.types.MessageReplyStoryHeader)
|
||||
}
|
||||
|
||||
if messages_with_replies:
|
||||
|
|
@ -134,6 +140,24 @@ async def parse_messages(
|
|||
if reply.id == reply_id:
|
||||
if not reply.forum_topic_created:
|
||||
message.reply_to_message = reply
|
||||
if message_reply_to_story:
|
||||
for m in parsed_messages:
|
||||
if m.chat:
|
||||
chat_id = m.chat.id
|
||||
break
|
||||
else:
|
||||
chat_id = 0
|
||||
|
||||
reply_messages = {}
|
||||
for msg_id in message_reply_to_story.keys():
|
||||
reply_messages[msg_id] = await client.get_stories(
|
||||
message_reply_to_story[msg_id]['user_id'],
|
||||
message_reply_to_story[msg_id]['story_id']
|
||||
)
|
||||
|
||||
for message in parsed_messages:
|
||||
if message.id in reply_messages:
|
||||
message.reply_to_story = reply_messages[message.id]
|
||||
|
||||
return types.List(parsed_messages)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue