Skip to content

Commit d2e7f4d

Browse files
committed
Add 2.1 new method.
1 parent ddd3664 commit d2e7f4d

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

telebot/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,26 @@ def get_user_profile_photos(self, user_id, offset=None, limit=None):
285285
result = apihelper.get_user_profile_photos(self.token, user_id, offset, limit)
286286
return types.UserProfilePhotos.de_json(result)
287287

288+
def get_chat(self, chat_id):
289+
result = apihelper.get_chat(self.token, chat_id)
290+
return types.Chat.de_json(result)
291+
292+
def leave_chat(self, chat_id):
293+
result = apihelper.leave_chat(self.token, chat_id)
294+
return result
295+
296+
def get_chat_administrators(self, chat_id):
297+
result = apihelper.get_chat_administrators(self.token, chat_id)
298+
return [[types.ChatMember.de_json(y) for y in x] for x in result]
299+
300+
def get_chat_members_count(self, chat_id):
301+
result = apihelper.get_chat_members_count(self.token, chat_id)
302+
return result
303+
304+
def get_chat_member(self, chat_id, user_id):
305+
result = apihelper.get_chat_member(self.token, chat_id,user_id)
306+
return types.ChatMember.de_json(result)
307+
288308
def send_message(self, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None,
289309
parse_mode=None, disable_notification=None):
290310
"""

telebot/apihelper.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,36 @@ def get_user_profile_photos(token, user_id, offset=None, limit=None):
149149
return _make_request(token, method_url, params=payload)
150150

151151

152+
def get_chat(token, chat_id):
153+
method_url = r'getChat'
154+
payload = {'chat_id': chat_id}
155+
return _make_request(token, method_url, params=payload)
156+
157+
158+
def leave_chat(token, chat_id):
159+
method_url = r'leaveChat'
160+
payload = {'chat_id': chat_id}
161+
return _make_request(token, method_url, params=payload)
162+
163+
164+
def get_chat_administrators(token, chat_id):
165+
method_url = r'getChatAdministrators'
166+
payload = {'chat_id': chat_id}
167+
return _make_request(token, method_url, params=payload)
168+
169+
170+
def get_chat_members_count(token, chat_id):
171+
method_url = r'getChatMembersCount'
172+
payload = {'chat_id': chat_id}
173+
return _make_request(token, method_url, params=payload)
174+
175+
176+
def get_chat_member(token, chat_id, user_id):
177+
method_url = r'getChatMember'
178+
payload = {'chat_id': chat_id, 'user_id': user_id}
179+
return _make_request(token, method_url, params=payload)
180+
181+
152182
def forward_message(token, chat_id, from_chat_id, message_id, disable_notification=None):
153183
method_url = r'forwardMessage'
154184
payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id}

telebot/types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,19 @@ def __init__(self, id, from_user, data, message=None, inline_message_id=None):
721721
self.inline_message_id = inline_message_id
722722

723723

724+
class ChatMember(JsonDeserializable):
725+
@classmethod
726+
def de_json(cls, json_type):
727+
obj = cls.check_json(json_type)
728+
user = User.de_json(obj['user'])
729+
status = obj['status']
730+
return cls(id, user, status)
731+
732+
def __init__(self, user, status):
733+
self.user = user
734+
self.status = status
735+
736+
724737
# InlineQuery
725738

726739
class InlineQuery(JsonDeserializable):

0 commit comments

Comments
 (0)