From b056aa8d7f1f484aaffffc966a52b48094f8cfbe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 14 Apr 2019 21:04:34 +0200 Subject: [PATCH] Add the field is_member to the ChatMember type This can be used to find whether a restricted user is a member of the chat at the moment of the request. --- .../types/user_and_chats/chat_member.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py index 35911210..9ccf9314 100644 --- a/pyrogram/client/types/user_and_chats/chat_member.py +++ b/pyrogram/client/types/user_and_chats/chat_member.py @@ -36,6 +36,9 @@ class ChatMember(PyrogramType): date (``int``, *optional*): Date when the user joined, unix time. Not available for creator. + is_member (``bool``, *optional*): + Restricted only. True, if the user is a member of the chat at the moment of the request. + invited_by (:obj:`User `, *optional*): Administrators and self member only. Information about the user who invited this member. In case the user joined by himself this will be the same as "user". @@ -51,7 +54,7 @@ class ChatMember(PyrogramType): Information about the member permissions. """ - __slots__ = ["user", "status", "date", "invited_by", "promoted_by", "restricted_by", "permissions"] + __slots__ = ["user", "status", "date", "is_member", "invited_by", "promoted_by", "restricted_by", "permissions"] def __init__( self, @@ -60,6 +63,7 @@ class ChatMember(PyrogramType): user: "pyrogram.User", status: str, date: int = None, + is_member: bool = None, invited_by: "pyrogram.User" = None, promoted_by: "pyrogram.User" = None, restricted_by: "pyrogram.User" = None, @@ -70,6 +74,7 @@ class ChatMember(PyrogramType): self.user = user self.status = status self.date = date + self.is_member = is_member self.invited_by = invited_by self.promoted_by = promoted_by self.restricted_by = restricted_by @@ -121,14 +126,17 @@ class ChatMember(PyrogramType): ) if isinstance(member, types.ChannelParticipantBanned): + status = ( + "kicked" if member.banned_rights.view_messages + else "left" if member.left + else "restricted" + ) + return ChatMember( user=user, - status=( - "kicked" if member.banned_rights.view_messages - else "left" if member.left - else "restricted" - ), + status=status, date=member.date, + is_member=not member.left if status == "restricted" else None, restricted_by=pyrogram.User._parse(client, users[member.kicked_by]), permissions=pyrogram.ChatPermissions._parse(member), client=client