From 3df4807fb942519f8a228a111e429df6601b8584 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 2 Jan 2021 12:24:32 +0100 Subject: [PATCH] Fix ChatAction.user_left was considered as user_kicked Closes #1660. --- telethon/events/chataction.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/telethon/events/chataction.py b/telethon/events/chataction.py index 6427f85a..dfd361e0 100644 --- a/telethon/events/chataction.py +++ b/telethon/events/chataction.py @@ -54,20 +54,9 @@ class ChatAction(EventBuilder): kicked_by=True, users=update.user_id) - elif isinstance(update, types.UpdateChannel): - # We rely on the fact that update._entities is set by _process_update - # This update only has the channel ID, and Telegram *should* have sent - # the entity in the Updates.chats list. If it did, check Channel.left - # to determine what happened. - peer = types.PeerChannel(update.channel_id) - channel = update._entities.get(utils.get_peer_id(peer)) - if channel is not None: - if isinstance(channel, types.ChannelForbidden) or channel.left: - return cls.Event(peer, - kicked_by=True) - else: - return cls.Event(peer, - added_by=True) + # UpdateChannel is sent if we leave a channel, and the update._entities + # set by _process_update would let us make some guesses. However it's + # better not to rely on this. Rely only in MessageActionChatDeleteUser. elif (isinstance(update, ( types.UpdateNewMessage, types.UpdateNewChannelMessage)) @@ -86,7 +75,7 @@ class ChatAction(EventBuilder): users=action.users) elif isinstance(action, types.MessageActionChatDeleteUser): return cls.Event(msg, - kicked_by=msg.from_id or True, + kicked_by=utils.get_peer_id(msg.from_id) if msg.from_id else True, users=action.user_id) elif isinstance(action, types.MessageActionChatCreate): return cls.Event(msg,