2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Only parse selected messages

This commit is contained in:
Dan 2018-03-27 15:58:04 +02:00
parent 91133812a7
commit f1e1480c5a
2 changed files with 12 additions and 7 deletions

View File

@ -730,6 +730,9 @@ class Client:
elif isinstance(message, types.MessageService):
m = utils.parse_message_service(message, users, chats)
if m is None:
continue
if isinstance(message.action, types.MessageActionPinMessage):
pm = self.get_messages(m.chat.id, [message.reply_to_msg_id])

View File

@ -43,13 +43,13 @@ def parse_user(user: types.User):
) if user else None
def parse_chat(peer: types.PeerUser or types.PeerChat or types.PeerChannel, users: dict, chats: dict):
if isinstance(peer, types.PeerUser):
return parse_user_chat(users[peer.user_id])
elif isinstance(peer, types.PeerChat):
return parse_chat_chat(chats[peer.chat_id])
def parse_chat(message: types.Message, users: dict, chats: dict):
if isinstance(message.to_id, types.PeerUser):
return parse_user_chat(users[message.from_id])
elif isinstance(message.to_id, types.PeerChat):
return parse_chat_chat(chats[message.to_id.chat_id])
else:
return parse_channel_chat(chats[peer.channel_id])
return parse_channel_chat(chats[message.to_id.channel_id])
def parse_user_chat(user: types.User):
@ -104,7 +104,7 @@ def parse_message(message: types.Message, users: dict, chats: dict):
return pyrogram.Message(
message_id=message.id,
date=message.date,
chat=parse_chat(message.to_id, users, chats),
chat=parse_chat(message, users, chats),
from_user=parse_user(users.get(message.from_id, None)),
text=message.message or None if message.media is None else None,
caption=message.message or None if message.media is not None else None,
@ -147,6 +147,8 @@ def parse_message_service(message: types.MessageService, users: dict, chats: dic
migrate_from_chat_id = action.chat_id
elif isinstance(action, types.MessageActionChatCreate):
group_chat_created = True
else:
return None
return pyrogram.Message(
message_id=message.id,