mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: fix MESSAGE_IDS_EMPTY error on get_scheduled_messages method
Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
57feed8b45
commit
99e6005cf1
2 changed files with 67 additions and 54 deletions
|
|
@ -78,6 +78,6 @@ class GetScheduledMessages:
|
||||||
|
|
||||||
r = await self.invoke(rpc, sleep_threshold=-1)
|
r = await self.invoke(rpc, sleep_threshold=-1)
|
||||||
|
|
||||||
messages = await utils.parse_messages(self, r)
|
messages = await utils.parse_messages(self, r, is_scheduled=True)
|
||||||
|
|
||||||
return messages if is_iterable else messages[0] if messages else None
|
return messages if is_iterable else messages[0] if messages else None
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,8 @@ async def parse_messages(
|
||||||
client,
|
client,
|
||||||
messages: "raw.types.messages.Messages",
|
messages: "raw.types.messages.Messages",
|
||||||
replies: int = 1,
|
replies: int = 1,
|
||||||
business_connection_id: str = None
|
business_connection_id: str = None,
|
||||||
|
is_scheduled: bool = False
|
||||||
) -> List["types.Message"]:
|
) -> List["types.Message"]:
|
||||||
users = {i.id: i for i in messages.users}
|
users = {i.id: i for i in messages.users}
|
||||||
chats = {i.id: i for i in messages.chats}
|
chats = {i.id: i for i in messages.chats}
|
||||||
|
|
@ -120,64 +121,76 @@ async def parse_messages(
|
||||||
parsed_messages.append(await types.Message._parse(client, message, users, chats, topics, replies=0, business_connection_id=business_connection_id))
|
parsed_messages.append(await types.Message._parse(client, message, users, chats, topics, replies=0, business_connection_id=business_connection_id))
|
||||||
|
|
||||||
if replies:
|
if replies:
|
||||||
messages_with_replies = {
|
if not is_scheduled:
|
||||||
i.id: i.reply_to.reply_to_msg_id
|
messages_with_replies = {
|
||||||
for i in messages.messages
|
i.id: i.reply_to.reply_to_msg_id
|
||||||
if (
|
for i in messages.messages
|
||||||
not isinstance(i, raw.types.MessageEmpty)
|
if (
|
||||||
and i.reply_to
|
not isinstance(i, raw.types.MessageEmpty)
|
||||||
and isinstance(i.reply_to, raw.types.MessageReplyHeader)
|
and i.reply_to
|
||||||
and i.reply_to.reply_to_msg_id is not None
|
and isinstance(i.reply_to, raw.types.MessageReplyHeader)
|
||||||
)
|
and i.reply_to.reply_to_msg_id is not None
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
message_reply_to_story = {
|
message_reply_to_story = {
|
||||||
i.id: {'user_id': i.reply_to.user_id, 'story_id': i.reply_to.story_id}
|
i.id: {'user_id': i.reply_to.user_id, 'story_id': i.reply_to.story_id}
|
||||||
for i in messages.messages
|
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 not isinstance(i, raw.types.MessageEmpty) and i.reply_to and isinstance(i.reply_to, raw.types.MessageReplyStoryHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
if messages_with_replies:
|
if messages_with_replies:
|
||||||
# We need a chat id, but some messages might be empty (no chat attribute available)
|
# We need a chat id, but some messages might be empty (no chat attribute available)
|
||||||
# Scan until we find a message with a chat available (there must be one, because we are fetching replies)
|
# Scan until we find a message with a chat available (there must be one, because we are fetching replies)
|
||||||
for m in parsed_messages:
|
for m in parsed_messages:
|
||||||
if m.chat:
|
if m.chat:
|
||||||
chat_id = m.chat.id
|
chat_id = m.chat.id
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
chat_id = 0
|
chat_id = 0
|
||||||
|
|
||||||
reply_messages = await client.get_messages(
|
reply_messages = await client.get_messages(
|
||||||
chat_id,
|
chat_id,
|
||||||
reply_to_message_ids=messages_with_replies.keys(),
|
reply_to_message_ids=messages_with_replies.keys(),
|
||||||
replies=replies - 1
|
replies=replies - 1
|
||||||
)
|
|
||||||
|
|
||||||
for message in parsed_messages:
|
|
||||||
reply_id = messages_with_replies.get(message.id, None)
|
|
||||||
|
|
||||||
for reply in reply_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:
|
||||||
|
reply_id = messages_with_replies.get(message.id, None)
|
||||||
|
|
||||||
|
for reply in reply_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]
|
||||||
|
else:
|
||||||
for message in parsed_messages:
|
for message in parsed_messages:
|
||||||
if message.id in reply_messages:
|
if (
|
||||||
message.reply_to_story = reply_messages[message.id]
|
message.reply_to_message_id
|
||||||
|
and not message.external_reply
|
||||||
|
):
|
||||||
|
message.reply_to_message = await client.get_messages(
|
||||||
|
message.chat.id,
|
||||||
|
message_ids=message.reply_to_message_id,
|
||||||
|
replies=replies - 1
|
||||||
|
)
|
||||||
|
|
||||||
return types.List(parsed_messages)
|
return types.List(parsed_messages)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue