From f1e1480c5a0c8c98b9c37f636c2320e003ac5f0a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:58:04 +0200 Subject: [PATCH] Only parse selected messages --- pyrogram/client/client.py | 3 +++ pyrogram/client/utils.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index ebb87dd3..290a8ba9 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -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]) diff --git a/pyrogram/client/utils.py b/pyrogram/client/utils.py index 053b06f7..db755822 100644 --- a/pyrogram/client/utils.py +++ b/pyrogram/client/utils.py @@ -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,