mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #834 from tohabyuraev/master
Bot API 4.5 partial support (in regards to chat).
This commit is contained in:
commit
aacc494a55
@ -547,9 +547,11 @@ class TeleBot:
|
|||||||
|
|
||||||
def get_chat_administrators(self, chat_id):
|
def get_chat_administrators(self, chat_id):
|
||||||
"""
|
"""
|
||||||
Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects
|
Use this method to get a list of administrators in a chat.
|
||||||
that contains information about all chat administrators except other bots.
|
On success, returns an Array of ChatMember objects that contains
|
||||||
:param chat_id:
|
information about all chat administrators except other bots.
|
||||||
|
:param chat_id: Unique identifier for the target chat or username
|
||||||
|
of the target supergroup or channel (in the format @channelusername)
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
result = apihelper.get_chat_administrators(self.token, chat_id)
|
result = apihelper.get_chat_administrators(self.token, chat_id)
|
||||||
@ -985,6 +987,33 @@ class TeleBot:
|
|||||||
can_edit_messages, can_delete_messages, can_invite_users,
|
can_edit_messages, can_delete_messages, can_invite_users,
|
||||||
can_restrict_members, can_pin_messages, can_promote_members)
|
can_restrict_members, can_pin_messages, can_promote_members)
|
||||||
|
|
||||||
|
def set_chat_administrator_custom_title(self, chat_id, user_id, custom_title):
|
||||||
|
"""
|
||||||
|
Use this method to set a custom title for an administrator
|
||||||
|
in a supergroup promoted by the bot.
|
||||||
|
Returns True on success.
|
||||||
|
:param chat_id: Unique identifier for the target chat or username of the target supergroup
|
||||||
|
(in the format @supergroupusername)
|
||||||
|
:param user_id: Unique identifier of the target user
|
||||||
|
:param custom_title: New custom title for the administrator;
|
||||||
|
0-16 characters, emoji are not allowed
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return apihelper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title)
|
||||||
|
|
||||||
|
|
||||||
|
def set_chat_permissions(self, chat_id, permissions):
|
||||||
|
"""
|
||||||
|
Use this method to set default chat permissions for all members.
|
||||||
|
The bot must be an administrator in the group or a supergroup for this to work
|
||||||
|
and must have the can_restrict_members admin rights.
|
||||||
|
:param chat_id: Unique identifier for the target chat or username of the target supergroup
|
||||||
|
(in the format @supergroupusername)
|
||||||
|
:param permissions: New default chat permissions
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return apihelper.set_chat_permissions(self.token, chat_id, permissions)
|
||||||
|
|
||||||
def export_chat_invite_link(self, chat_id):
|
def export_chat_invite_link(self, chat_id):
|
||||||
"""
|
"""
|
||||||
Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator
|
Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator
|
||||||
|
@ -586,7 +586,6 @@ def restrict_chat_member(token, chat_id, user_id, until_date=None, can_send_mess
|
|||||||
payload['can_add_web_page_previews'] = can_add_web_page_previews
|
payload['can_add_web_page_previews'] = can_add_web_page_previews
|
||||||
if can_invite_users:
|
if can_invite_users:
|
||||||
payload['can_invite_users'] = can_invite_users
|
payload['can_invite_users'] = can_invite_users
|
||||||
|
|
||||||
return _make_request(token, method_url, params=payload, method='post')
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
@ -614,6 +613,21 @@ def promote_chat_member(token, chat_id, user_id, can_change_info=None, can_post_
|
|||||||
return _make_request(token, method_url, params=payload, method='post')
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def set_chat_administrator_custom_title(token, chat_id, user_id, custom_title):
|
||||||
|
method_url = 'setChatAdministratorCustomTitle'
|
||||||
|
payload = {
|
||||||
|
'chat_id': chat_id, 'user_id': user_id, 'custom_title': custom_title}
|
||||||
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def set_chat_permissions(token, chat_id, permissions):
|
||||||
|
method_url = 'setChatPermissions'
|
||||||
|
payload = {
|
||||||
|
'chat_id': chat_id,
|
||||||
|
'permissions': _convert_list_json_serializable(permissions)}
|
||||||
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
def export_chat_invite_link(token, chat_id):
|
def export_chat_invite_link(token, chat_id):
|
||||||
method_url = 'exportChatInviteLink'
|
method_url = 'exportChatInviteLink'
|
||||||
payload = {'chat_id': chat_id}
|
payload = {'chat_id': chat_id}
|
||||||
|
166
telebot/types.py
166
telebot/types.py
@ -183,7 +183,8 @@ class GroupChat(JsonDeserializable):
|
|||||||
class Chat(JsonDeserializable):
|
class Chat(JsonDeserializable):
|
||||||
@classmethod
|
@classmethod
|
||||||
def de_json(cls, json_string):
|
def de_json(cls, json_string):
|
||||||
if (json_string is None): return None
|
if json_string is None:
|
||||||
|
return None
|
||||||
obj = cls.check_json(json_string)
|
obj = cls.check_json(json_string)
|
||||||
id = obj['id']
|
id = obj['id']
|
||||||
type = obj['type']
|
type = obj['type']
|
||||||
@ -196,25 +197,34 @@ class Chat(JsonDeserializable):
|
|||||||
description = obj.get('description')
|
description = obj.get('description')
|
||||||
invite_link = obj.get('invite_link')
|
invite_link = obj.get('invite_link')
|
||||||
pinned_message = Message.de_json(obj.get('pinned_message'))
|
pinned_message = Message.de_json(obj.get('pinned_message'))
|
||||||
|
permissions = ChatPermissions.de_json(obj.get('permissions'))
|
||||||
|
slow_mode_delay = obj.get('slow_mode_delay')
|
||||||
sticker_set_name = obj.get('sticker_set_name')
|
sticker_set_name = obj.get('sticker_set_name')
|
||||||
can_set_sticker_set = obj.get('can_set_sticker_set')
|
can_set_sticker_set = obj.get('can_set_sticker_set')
|
||||||
return cls(id, type, title, username, first_name, last_name, all_members_are_administrators,
|
return cls(
|
||||||
photo, description, invite_link, pinned_message, sticker_set_name, can_set_sticker_set)
|
id, type, title, username, first_name, last_name,
|
||||||
|
all_members_are_administrators, photo, description, invite_link,
|
||||||
|
pinned_message, permissions, slow_mode_delay, sticker_set_name,
|
||||||
|
can_set_sticker_set)
|
||||||
|
|
||||||
def __init__(self, id, type, title=None, username=None, first_name=None, last_name=None,
|
def __init__(self, id, type, title=None, username=None, first_name=None,
|
||||||
all_members_are_administrators=None, photo=None, description=None, invite_link=None,
|
last_name=None, all_members_are_administrators=None,
|
||||||
pinned_message=None, sticker_set_name=None, can_set_sticker_set=None):
|
photo=None, description=None, invite_link=None,
|
||||||
self.type = type
|
pinned_message=None, permissions=None, slow_mode_delay=None,
|
||||||
self.last_name = last_name
|
sticker_set_name=None, can_set_sticker_set=None):
|
||||||
self.first_name = first_name
|
|
||||||
self.username = username
|
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.type = type
|
||||||
self.title = title
|
self.title = title
|
||||||
|
self.username = username
|
||||||
|
self.first_name = first_name
|
||||||
|
self.last_name = last_name
|
||||||
self.all_members_are_administrators = all_members_are_administrators
|
self.all_members_are_administrators = all_members_are_administrators
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
self.description = description
|
self.description = description
|
||||||
self.invite_link = invite_link
|
self.invite_link = invite_link
|
||||||
self.pinned_message = pinned_message
|
self.pinned_message = pinned_message
|
||||||
|
self.permissions = permissions
|
||||||
|
self.slow_mode_delay = slow_mode_delay
|
||||||
self.sticker_set_name = sticker_set_name
|
self.sticker_set_name = sticker_set_name
|
||||||
self.can_set_sticker_set = can_set_sticker_set
|
self.can_set_sticker_set = can_set_sticker_set
|
||||||
|
|
||||||
@ -855,17 +865,27 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
|
|||||||
|
|
||||||
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
||||||
def __init__(self, row_width=3):
|
def __init__(self, row_width=3):
|
||||||
|
"""
|
||||||
|
This object represents an inline keyboard that appears
|
||||||
|
right next to the message it belongs to.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
self.row_width = row_width
|
self.row_width = row_width
|
||||||
self.keyboard = []
|
self.keyboard = []
|
||||||
|
|
||||||
def add(self, *args):
|
def add(self, *args):
|
||||||
"""
|
"""
|
||||||
This function adds strings to the keyboard, while not exceeding row_width.
|
This method adds buttons to the keyboard without exceeding row_width.
|
||||||
E.g. ReplyKeyboardMarkup#add("A", "B", "C") yields the json result {keyboard: [["A"], ["B"], ["C"]]}
|
|
||||||
|
E.g. InlineKeyboardMarkup#add("A", "B", "C") yields the json result:
|
||||||
|
{keyboard: [["A"], ["B"], ["C"]]}
|
||||||
when row_width is set to 1.
|
when row_width is set to 1.
|
||||||
When row_width is set to 2, the following is the result of this function: {keyboard: [["A", "B"], ["C"]]}
|
When row_width is set to 2, the result:
|
||||||
See https://core.telegram.org/bots/api#replykeyboardmarkup
|
{keyboard: [["A", "B"], ["C"]]}
|
||||||
:param args: KeyboardButton to append to the keyboard
|
See https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
||||||
|
|
||||||
|
:param args: Array of InlineKeyboardButton to append to the keyboard
|
||||||
"""
|
"""
|
||||||
i = 1
|
i = 1
|
||||||
row = []
|
row = []
|
||||||
@ -880,26 +900,28 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
|||||||
|
|
||||||
def row(self, *args):
|
def row(self, *args):
|
||||||
"""
|
"""
|
||||||
Adds a list of KeyboardButton to the keyboard. This function does not consider row_width.
|
Adds a list of InlineKeyboardButton to the keyboard.
|
||||||
ReplyKeyboardMarkup#row("A")#row("B", "C")#to_json() outputs '{keyboard: [["A"], ["B", "C"]]}'
|
This metod does not consider row_width.
|
||||||
|
|
||||||
|
InlineKeyboardMarkup.row("A").row("B", "C").to_json() outputs:
|
||||||
|
'{keyboard: [["A"], ["B", "C"]]}'
|
||||||
See https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
See https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
||||||
:param args: strings
|
|
||||||
|
:param args: Array of InlineKeyboardButton to append to the keyboard
|
||||||
:return: self, to allow function chaining.
|
:return: self, to allow function chaining.
|
||||||
"""
|
"""
|
||||||
btn_array = []
|
button_array = [button.to_dict() for button in args]
|
||||||
for button in args:
|
self.keyboard.append(button_array)
|
||||||
btn_array.append(button.to_dict())
|
|
||||||
self.keyboard.append(btn_array)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
"""
|
"""
|
||||||
Converts this object to its json representation following the Telegram API guidelines described here:
|
Converts this object to its json representation
|
||||||
|
following the Telegram API guidelines described here:
|
||||||
https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
json_dict = {'inline_keyboard': self.keyboard}
|
return json.dumps(self.to_dict())
|
||||||
return json.dumps(json_dict)
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
json_dict = {'inline_keyboard': self.keyboard}
|
json_dict = {'inline_keyboard': self.keyboard}
|
||||||
@ -1003,50 +1025,118 @@ class ChatPhoto(JsonDeserializable):
|
|||||||
class ChatMember(JsonDeserializable):
|
class ChatMember(JsonDeserializable):
|
||||||
@classmethod
|
@classmethod
|
||||||
def de_json(cls, json_string):
|
def de_json(cls, json_string):
|
||||||
if (json_string is None):
|
if json_string is None:
|
||||||
return None
|
return None
|
||||||
obj = cls.check_json(json_string)
|
obj = cls.check_json(json_string)
|
||||||
user = User.de_json(obj['user'])
|
user = User.de_json(obj['user'])
|
||||||
status = obj['status']
|
status = obj['status']
|
||||||
|
custom_title = obj.get('custom_title')
|
||||||
until_date = obj.get('until_date')
|
until_date = obj.get('until_date')
|
||||||
can_be_edited = obj.get('can_be_edited')
|
can_be_edited = obj.get('can_be_edited')
|
||||||
can_change_info = obj.get('can_change_info')
|
|
||||||
can_post_messages = obj.get('can_post_messages')
|
can_post_messages = obj.get('can_post_messages')
|
||||||
can_edit_messages = obj.get('can_edit_messages')
|
can_edit_messages = obj.get('can_edit_messages')
|
||||||
can_delete_messages = obj.get('can_delete_messages')
|
can_delete_messages = obj.get('can_delete_messages')
|
||||||
can_invite_users = obj.get('can_invite_users')
|
|
||||||
can_restrict_members = obj.get('can_restrict_members')
|
can_restrict_members = obj.get('can_restrict_members')
|
||||||
can_pin_messages = obj.get('can_pin_messages')
|
|
||||||
can_promote_members = obj.get('can_promote_members')
|
can_promote_members = obj.get('can_promote_members')
|
||||||
|
can_change_info = obj.get('can_change_info')
|
||||||
|
can_invite_users = obj.get('can_invite_users')
|
||||||
|
can_pin_messages = obj.get('can_pin_messages')
|
||||||
|
is_member = obj.get('is_member')
|
||||||
can_send_messages = obj.get('can_send_messages')
|
can_send_messages = obj.get('can_send_messages')
|
||||||
can_send_media_messages = obj.get('can_send_media_messages')
|
can_send_media_messages = obj.get('can_send_media_messages')
|
||||||
|
can_send_polls = obj.get('can_send_polls')
|
||||||
can_send_other_messages = obj.get('can_send_other_messages')
|
can_send_other_messages = obj.get('can_send_other_messages')
|
||||||
can_add_web_page_previews = obj.get('can_add_web_page_previews')
|
can_add_web_page_previews = obj.get('can_add_web_page_previews')
|
||||||
return cls(user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
|
return cls(
|
||||||
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
|
user, status, custom_title, until_date, can_be_edited, can_post_messages,
|
||||||
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews)
|
can_edit_messages, can_delete_messages, can_restrict_members,
|
||||||
|
can_promote_members, can_change_info, can_invite_users, can_pin_messages,
|
||||||
|
is_member, can_send_messages, can_send_media_messages, can_send_polls,
|
||||||
|
can_send_other_messages, can_add_web_page_previews)
|
||||||
|
|
||||||
def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
|
def __init__(self, user, status, custom_title=None, until_date=None, can_be_edited=None,
|
||||||
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
|
can_post_messages=None, can_edit_messages=None, can_delete_messages=None,
|
||||||
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews):
|
can_restrict_members=None, can_promote_members=None, can_change_info=None,
|
||||||
|
can_invite_users=None, can_pin_messages=None, is_member=None,
|
||||||
|
can_send_messages=None, can_send_media_messages=None, can_send_polls=None,
|
||||||
|
can_send_other_messages=None, can_add_web_page_previews=None):
|
||||||
self.user = user
|
self.user = user
|
||||||
self.status = status
|
self.status = status
|
||||||
|
self.custom_title = custom_title
|
||||||
self.until_date = until_date
|
self.until_date = until_date
|
||||||
self.can_be_edited = can_be_edited
|
self.can_be_edited = can_be_edited
|
||||||
self.can_change_info = can_change_info
|
|
||||||
self.can_post_messages = can_post_messages
|
self.can_post_messages = can_post_messages
|
||||||
self.can_edit_messages = can_edit_messages
|
self.can_edit_messages = can_edit_messages
|
||||||
self.can_delete_messages = can_delete_messages
|
self.can_delete_messages = can_delete_messages
|
||||||
self.can_invite_users = can_invite_users
|
|
||||||
self.can_restrict_members = can_restrict_members
|
self.can_restrict_members = can_restrict_members
|
||||||
self.can_pin_messages = can_pin_messages
|
|
||||||
self.can_promote_members = can_promote_members
|
self.can_promote_members = can_promote_members
|
||||||
|
self.can_change_info = can_change_info
|
||||||
|
self.can_invite_users = can_invite_users
|
||||||
|
self.can_pin_messages = can_pin_messages
|
||||||
|
self.is_member = is_member
|
||||||
self.can_send_messages = can_send_messages
|
self.can_send_messages = can_send_messages
|
||||||
self.can_send_media_messages = can_send_media_messages
|
self.can_send_media_messages = can_send_media_messages
|
||||||
|
self.can_send_polls = can_send_polls
|
||||||
self.can_send_other_messages = can_send_other_messages
|
self.can_send_other_messages = can_send_other_messages
|
||||||
self.can_add_web_page_previews = can_add_web_page_previews
|
self.can_add_web_page_previews = can_add_web_page_previews
|
||||||
|
|
||||||
|
|
||||||
|
class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
|
||||||
|
def __init__(self, can_send_messages=None, can_send_media_messages=None,
|
||||||
|
can_send_polls=None, can_send_other_messages=None,
|
||||||
|
can_add_web_page_previews=None, can_change_info=None,
|
||||||
|
can_invite_users=None, can_pin_messages=None):
|
||||||
|
self.can_send_messages = can_send_messages
|
||||||
|
self.can_send_media_messages = can_send_media_messages
|
||||||
|
self.can_send_polls = can_send_polls
|
||||||
|
self.can_send_other_messages = can_send_other_messages
|
||||||
|
self.can_add_web_page_previews = can_add_web_page_previews
|
||||||
|
self.can_change_info = can_change_info
|
||||||
|
self.can_invite_users = can_invite_users
|
||||||
|
self.can_pin_messages = can_pin_messages
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
if json_string is None:
|
||||||
|
return json_string
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
can_send_messages = obj.get('can_send_messages')
|
||||||
|
can_send_media_messages = obj.get('can_send_media_messages')
|
||||||
|
can_send_polls = obj.get('can_send_polls')
|
||||||
|
can_send_other_messages = obj.get('can_send_other_messages')
|
||||||
|
can_add_web_page_previews = obj.get('can_add_web_page_previews')
|
||||||
|
can_change_info = obj.get('can_change_info')
|
||||||
|
can_invite_users = obj.get('can_invite_users')
|
||||||
|
can_pin_messages = obj.get('can_pin_messages')
|
||||||
|
return cls(
|
||||||
|
can_send_messages, can_send_media_messages, can_send_polls,
|
||||||
|
can_send_other_messages, can_add_web_page_previews,
|
||||||
|
can_change_info, can_invite_users, can_pin_messages)
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
json_dict = dict()
|
||||||
|
if self.can_send_messages is not None:
|
||||||
|
json_dict['can_send_messages'] = self.can_send_messages
|
||||||
|
if self.can_send_media_messages is not None:
|
||||||
|
json_dict['can_send_media_messages'] = self.can_send_media_messages
|
||||||
|
if self.can_send_polls is not None:
|
||||||
|
json_dict['can_send_polls'] = self.can_send_polls
|
||||||
|
if self.can_send_other_messages is not None:
|
||||||
|
json_dict['can_send_other_messages'] = self.can_send_other_messages
|
||||||
|
if self.can_add_web_page_previews is not None:
|
||||||
|
json_dict['can_add_web_page_previews'] = self.can_add_web_page_previews
|
||||||
|
if self.can_change_info is not None:
|
||||||
|
json_dict['can_change_info'] = self.can_change_info
|
||||||
|
if self.can_invite_users is not None:
|
||||||
|
json_dict['can_invite_users'] = self.can_invite_users
|
||||||
|
if self.can_pin_messages is not None:
|
||||||
|
json_dict['can_pin_messages'] = self.can_pin_messages
|
||||||
|
return json_dict
|
||||||
|
|
||||||
|
|
||||||
class BotCommand(JsonSerializable):
|
class BotCommand(JsonSerializable):
|
||||||
def __init__(self, command, description):
|
def __init__(self, command, description):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user