From c72bbcf9e129fe42415ef33d508a5f5679f92668 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 17 Mar 2021 18:12:34 +0100 Subject: [PATCH] Fix ChatMemberUpdated args being parsed when they don't exist --- .../user_and_chats/chat_member_updated.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pyrogram/types/user_and_chats/chat_member_updated.py b/pyrogram/types/user_and_chats/chat_member_updated.py index 5794069f..31cec664 100644 --- a/pyrogram/types/user_and_chats/chat_member_updated.py +++ b/pyrogram/types/user_and_chats/chat_member_updated.py @@ -38,10 +38,10 @@ class ChatMemberUpdated(Object, Update): date (``int``): Date the change was done in Unix time. - old_chat_member (:obj:`~pyrogram.types.ChatMember`): + old_chat_member (:obj:`~pyrogram.types.ChatMember`, *optional*): Previous information about the chat member. - new_chat_member (:obj:`~pyrogram.types.ChatMember`): + new_chat_member (:obj:`~pyrogram.types.ChatMember`, *optional*): New information about the chat member. invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*): @@ -76,14 +76,26 @@ class ChatMemberUpdated(Object, Update): chats: Dict[int, "raw.types.Chat"] ) -> "ChatMemberUpdated": chat_id = getattr(update, "chat_id", None) or getattr(update, "channel_id") - invite_link = types.ChatInviteLink._parse(client, update.invite, users) if update.invite else None + + old_chat_member = None + new_chat_member = None + invite_link = None + + if update.prev_participant: + old_chat_member = types.ChatMember._parse(client, update.prev_participant, users) + + if update.new_participant: + new_chat_member = types.ChatMember._parse(client, update.new_participant, users) + + if update.invite: + invite_link = types.ChatInviteLink._parse(client, update.invite, users) return ChatMemberUpdated( chat=types.Chat._parse_chat(client, chats[chat_id]), from_user=types.User._parse(client, users[update.actor_id]), date=update.date, - old_chat_member=types.ChatMember._parse(client, update.prev_participant, users), - new_chat_member=types.ChatMember._parse(client, update.new_participant, users), + old_chat_member=old_chat_member, + new_chat_member=new_chat_member, invite_link=invite_link, client=client )