@@ -93,6 +93,22 @@ class Chat(BaseObject, mixins.ChatMixin):
9393 }
9494 _check_equality_ = "id"
9595
96+ def _to_user (self ):
97+ """Convert this Chat object to an User object"""
98+ if self .type != "private" :
99+ raise TypeError ("This method works only on private chats!" )
100+
101+ # Be sure to cache the instance
102+ if not hasattr (self , "_cache_user" ):
103+ self ._cache_user = User ({
104+ "id" : self .id ,
105+ "first_name" : self .first_name ,
106+ "last_name" : self .last_name ,
107+ "username" : self .username ,
108+ }, self ._api )
109+
110+ return self ._cache_user
111+
96112 @property
97113 def name (self ):
98114 """Get the full name of the chat"""
@@ -107,6 +123,27 @@ def name(self):
107123
108124 return result
109125
126+ @property
127+ def admins (self ):
128+ """Get a list of the admins of the chat"""
129+ # If this is a private chat, return the current user since Telegram
130+ # doesn't support `getChatAdministrators` for private chats
131+ if self .type == "private" :
132+ return [self ._to_user ()]
133+ elif self .type == "channel" :
134+ raise TypeError ("Not available on channels" )
135+
136+ # Be sure to cache the list of the admins
137+ if not hasattr (self , "_cache_admins" ):
138+ members = self ._api .call ("getChatAdministrators" ,
139+ {"chat_id" : self .id },
140+ expect = multiple (ChatMember ))
141+ self ._cache_admins = tuple (member .user for member in members )
142+
143+ # The list of admins is saved as a tuple, so it's not mutable, but it's
144+ # returned as a list (the tuple thing is an implementation detail)
145+ return list (self ._cache_admins )
146+
110147 def leave (self ):
111148 """Leave this chat"""
112149 if self .type not in ("group" , "supergroup" ):
@@ -122,6 +159,19 @@ def leave(self):
122159 raise
123160
124161
162+ class ChatMember (BaseObject ):
163+ """Telegram API representation of a chat member
164+
165+ https://core.telegram.org/bots/api#chatmember
166+ """
167+
168+ required = {
169+ "user" : User ,
170+ "status" : str ,
171+ }
172+ _check_equality_ = "user"
173+
174+
125175class UserProfilePhotos (BaseObject ):
126176 """Telegram API representation of an user's profile photos
127177
0 commit comments