mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Fix can_send_media_messages param, added warnings
This commit is contained in:
parent
2094120ec7
commit
a9b878107c
@ -2918,6 +2918,7 @@ class TeleBot:
|
|||||||
can_change_info: Optional[bool]=None,
|
can_change_info: Optional[bool]=None,
|
||||||
can_invite_users: Optional[bool]=None,
|
can_invite_users: Optional[bool]=None,
|
||||||
can_pin_messages: Optional[bool]=None,
|
can_pin_messages: Optional[bool]=None,
|
||||||
|
permissions: Optional[types.ChatPermissions]=None,
|
||||||
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
||||||
"""
|
"""
|
||||||
Use this method to restrict a user in a supergroup.
|
Use this method to restrict a user in a supergroup.
|
||||||
@ -2926,6 +2927,10 @@ class TeleBot:
|
|||||||
|
|
||||||
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
|
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
Please pass `telebot.types.ChatPermissions` object to `permissions` parameter instead of
|
||||||
|
passing all boolean parameters. Those boolean parameters won't be supported soon, so please take it into consideration.
|
||||||
|
|
||||||
:param chat_id: Unique identifier for the target group or username of the target supergroup
|
:param chat_id: Unique identifier for the target group or username of the target supergroup
|
||||||
or channel (in the format @channelusername)
|
or channel (in the format @channelusername)
|
||||||
:type chat_id: :obj:`int` or :obj:`str`
|
:type chat_id: :obj:`int` or :obj:`str`
|
||||||
@ -2972,15 +2977,31 @@ class TeleBot:
|
|||||||
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
||||||
:type use_independent_chat_permissions: :obj:`bool`
|
:type use_independent_chat_permissions: :obj:`bool`
|
||||||
|
|
||||||
|
:param permissions: Pass ChatPermissions object to set all permissions at once. Use this param instead of
|
||||||
|
passing all boolean parameters.
|
||||||
|
:type permissions: :class:`telebot.types.ChatPermissions`
|
||||||
|
|
||||||
:return: True on success
|
:return: True on success
|
||||||
:rtype: :obj:`bool`
|
:rtype: :obj:`bool`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if permissions is None:
|
||||||
|
permissions = types.ChatPermissions(
|
||||||
|
can_send_messages=can_send_messages,
|
||||||
|
can_send_media_messages=can_send_media_messages,
|
||||||
|
can_send_polls=can_send_polls,
|
||||||
|
can_send_other_messages=can_send_other_messages,
|
||||||
|
can_add_web_page_previews=can_add_web_page_previews,
|
||||||
|
can_change_info=can_change_info,
|
||||||
|
can_invite_users=can_invite_users,
|
||||||
|
can_pin_messages=can_pin_messages
|
||||||
|
)
|
||||||
|
logger.warning(
|
||||||
|
'Please pass `telebot.types.ChatPermissions` object to `permissions` parameter instead of '
|
||||||
|
'passing all boolean parameters. Those boolean parameters won\'t be supported soon, so please take it into consideration.'
|
||||||
|
)
|
||||||
return apihelper.restrict_chat_member(
|
return apihelper.restrict_chat_member(
|
||||||
self.token, chat_id, user_id, until_date,
|
self.token, chat_id, user_id, permissions, until_date, use_independent_chat_permissions)
|
||||||
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, use_independent_chat_permissions)
|
|
||||||
|
|
||||||
def promote_chat_member(
|
def promote_chat_member(
|
||||||
self, chat_id: Union[int, str], user_id: int,
|
self, chat_id: Union[int, str], user_id: int,
|
||||||
|
@ -968,39 +968,19 @@ def unban_chat_member(token, chat_id, user_id, only_if_banned):
|
|||||||
|
|
||||||
|
|
||||||
def restrict_chat_member(
|
def restrict_chat_member(
|
||||||
token, chat_id, user_id, until_date=None,
|
token, chat_id, user_id, permissions, until_date=None,
|
||||||
can_send_messages=None, can_send_media_messages=None,
|
use_independent_chat_permissions=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, use_independent_chat_permissions=None):
|
|
||||||
method_url = 'restrictChatMember'
|
method_url = 'restrictChatMember'
|
||||||
permissions = {}
|
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions.to_json()}
|
||||||
if can_send_messages is not None:
|
|
||||||
permissions['can_send_messages'] = can_send_messages
|
|
||||||
if can_send_media_messages is not None:
|
|
||||||
permissions['can_send_media_messages'] = can_send_media_messages
|
|
||||||
if can_send_polls is not None:
|
|
||||||
permissions['can_send_polls'] = can_send_polls
|
|
||||||
if can_send_other_messages is not None:
|
|
||||||
permissions['can_send_other_messages'] = can_send_other_messages
|
|
||||||
if can_add_web_page_previews is not None:
|
|
||||||
permissions['can_add_web_page_previews'] = can_add_web_page_previews
|
|
||||||
if can_change_info is not None:
|
|
||||||
permissions['can_change_info'] = can_change_info
|
|
||||||
if can_invite_users is not None:
|
|
||||||
permissions['can_invite_users'] = can_invite_users
|
|
||||||
if can_pin_messages is not None:
|
|
||||||
permissions['can_pin_messages'] = can_pin_messages
|
|
||||||
if use_independent_chat_permissions is not None:
|
if use_independent_chat_permissions is not None:
|
||||||
permissions['use_independent_chat_permissions'] = use_independent_chat_permissions
|
permissions['use_independent_chat_permissions'] = use_independent_chat_permissions
|
||||||
|
|
||||||
permissions_json = json.dumps(permissions)
|
|
||||||
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json}
|
|
||||||
if until_date is not None:
|
if until_date is not None:
|
||||||
if isinstance(until_date, datetime):
|
if isinstance(until_date, datetime):
|
||||||
payload['until_date'] = until_date.timestamp()
|
payload['until_date'] = until_date.timestamp()
|
||||||
else:
|
else:
|
||||||
payload['until_date'] = until_date
|
payload['until_date'] = until_date
|
||||||
|
|
||||||
return _make_request(token, method_url, params=payload, method='post')
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
@ -3776,6 +3776,7 @@ class AsyncTeleBot:
|
|||||||
can_change_info: Optional[bool]=None,
|
can_change_info: Optional[bool]=None,
|
||||||
can_invite_users: Optional[bool]=None,
|
can_invite_users: Optional[bool]=None,
|
||||||
can_pin_messages: Optional[bool]=None,
|
can_pin_messages: Optional[bool]=None,
|
||||||
|
permissions: Optional[types.ChatPermissions]=None,
|
||||||
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
||||||
"""
|
"""
|
||||||
Use this method to restrict a user in a supergroup.
|
Use this method to restrict a user in a supergroup.
|
||||||
@ -3784,6 +3785,10 @@ class AsyncTeleBot:
|
|||||||
|
|
||||||
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
|
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
Please pass `telebot.types.ChatPermissions` object to `permissions` parameter instead of
|
||||||
|
passing all boolean parameters. Those boolean parameters won't be supported soon, so please take it into consideration.
|
||||||
|
|
||||||
:param chat_id: Unique identifier for the target group or username of the target supergroup
|
:param chat_id: Unique identifier for the target group or username of the target supergroup
|
||||||
or channel (in the format @channelusername)
|
or channel (in the format @channelusername)
|
||||||
:type chat_id: :obj:`int` or :obj:`str`
|
:type chat_id: :obj:`int` or :obj:`str`
|
||||||
@ -3830,15 +3835,30 @@ class AsyncTeleBot:
|
|||||||
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
||||||
:type use_independent_chat_permissions: :obj:`bool`
|
:type use_independent_chat_permissions: :obj:`bool`
|
||||||
|
|
||||||
|
:param permissions: Pass ChatPermissions object to set all permissions at once. Use this parameter instead of
|
||||||
|
passing all boolean parameters to avoid backward compatibility problems in future.
|
||||||
|
:type permissions: :obj:`types.ChatPermissions`
|
||||||
|
|
||||||
:return: True on success
|
:return: True on success
|
||||||
:rtype: :obj:`bool`
|
:rtype: :obj:`bool`
|
||||||
"""
|
"""
|
||||||
|
if permissions is None:
|
||||||
|
permissions = types.ChatPermissions(
|
||||||
|
can_send_messages=can_send_messages,
|
||||||
|
can_send_media_messages=can_send_media_messages,
|
||||||
|
can_send_polls=can_send_polls,
|
||||||
|
can_send_other_messages=can_send_other_messages,
|
||||||
|
can_add_web_page_previews=can_add_web_page_previews,
|
||||||
|
can_change_info=can_change_info,
|
||||||
|
can_invite_users=can_invite_users,
|
||||||
|
can_pin_messages=can_pin_messages
|
||||||
|
)
|
||||||
|
logger.warning(
|
||||||
|
'Please pass `telebot.types.ChatPermissions` object to `permissions` parameter instead of '
|
||||||
|
'passing all boolean parameters. Those boolean parameters won\'t be supported soon, so please take it into consideration.'
|
||||||
|
)
|
||||||
return await asyncio_helper.restrict_chat_member(
|
return await asyncio_helper.restrict_chat_member(
|
||||||
self.token, chat_id, user_id, until_date,
|
self.token, chat_id, user_id, permissions, until_date, use_independent_chat_permissions)
|
||||||
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, use_independent_chat_permissions)
|
|
||||||
|
|
||||||
async def promote_chat_member(
|
async def promote_chat_member(
|
||||||
self, chat_id: Union[int, str], user_id: int,
|
self, chat_id: Union[int, str], user_id: int,
|
||||||
|
@ -960,34 +960,13 @@ async def unban_chat_member(token, chat_id, user_id, only_if_banned):
|
|||||||
|
|
||||||
|
|
||||||
async def restrict_chat_member(
|
async def restrict_chat_member(
|
||||||
token, chat_id, user_id, until_date=None,
|
token, chat_id, user_id, permissions, until_date=None,
|
||||||
can_send_messages=None, can_send_media_messages=None,
|
use_independent_chat_permissions=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, use_independent_chat_permissions=None):
|
|
||||||
method_url = 'restrictChatMember'
|
method_url = 'restrictChatMember'
|
||||||
permissions = {}
|
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions.to_json()}
|
||||||
if can_send_messages is not None:
|
|
||||||
permissions['can_send_messages'] = can_send_messages
|
|
||||||
if can_send_media_messages is not None:
|
|
||||||
permissions['can_send_media_messages'] = can_send_media_messages
|
|
||||||
if can_send_polls is not None:
|
|
||||||
permissions['can_send_polls'] = can_send_polls
|
|
||||||
if can_send_other_messages is not None:
|
|
||||||
permissions['can_send_other_messages'] = can_send_other_messages
|
|
||||||
if can_add_web_page_previews is not None:
|
|
||||||
permissions['can_add_web_page_previews'] = can_add_web_page_previews
|
|
||||||
if can_change_info is not None:
|
|
||||||
permissions['can_change_info'] = can_change_info
|
|
||||||
if can_invite_users is not None:
|
|
||||||
permissions['can_invite_users'] = can_invite_users
|
|
||||||
if can_pin_messages is not None:
|
|
||||||
permissions['can_pin_messages'] = can_pin_messages
|
|
||||||
if use_independent_chat_permissions is not None:
|
if use_independent_chat_permissions is not None:
|
||||||
permissions['use_independent_chat_permissions'] = use_independent_chat_permissions
|
permissions['use_independent_chat_permissions'] = use_independent_chat_permissions
|
||||||
|
|
||||||
permissions_json = json.dumps(permissions)
|
|
||||||
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json}
|
|
||||||
if until_date is not None:
|
if until_date is not None:
|
||||||
if isinstance(until_date, datetime):
|
if isinstance(until_date, datetime):
|
||||||
payload['until_date'] = until_date.timestamp()
|
payload['until_date'] = until_date.timestamp()
|
||||||
|
@ -2418,6 +2418,8 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
|
|||||||
json_dict['web_app'] = self.web_app.to_dict()
|
json_dict['web_app'] = self.web_app.to_dict()
|
||||||
if self.request_user is not None:
|
if self.request_user is not None:
|
||||||
json_dict['request_user'] = self.request_user.to_dict()
|
json_dict['request_user'] = self.request_user.to_dict()
|
||||||
|
if self.request_chat is not None:
|
||||||
|
json_dict['request_chat'] = self.request_chat.to_dict()
|
||||||
return json_dict
|
return json_dict
|
||||||
|
|
||||||
|
|
||||||
@ -3124,6 +3126,10 @@ class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
|
|||||||
value of can_pin_messages
|
value of can_pin_messages
|
||||||
:type can_manage_topics: :obj:`bool`
|
:type can_manage_topics: :obj:`bool`
|
||||||
|
|
||||||
|
:param can_send_media_messages: deprecated. True, if the user is allowed to send audios, documents, photos, videos,
|
||||||
|
video notes and voice notes
|
||||||
|
:type can_send_media_messages: :obj:`bool`
|
||||||
|
|
||||||
:return: Instance of the class
|
:return: Instance of the class
|
||||||
:rtype: :class:`telebot.types.ChatPermissions`
|
:rtype: :class:`telebot.types.ChatPermissions`
|
||||||
"""
|
"""
|
||||||
@ -3133,7 +3139,7 @@ class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
|
|||||||
obj = cls.check_json(json_string, dict_copy=False)
|
obj = cls.check_json(json_string, dict_copy=False)
|
||||||
return cls(**obj)
|
return cls(**obj)
|
||||||
|
|
||||||
def __init__(self, can_send_messages=None, can_send_audios=None,
|
def __init__(self, can_send_messages=None, can_send_media_messages=None,can_send_audios=None,
|
||||||
can_send_documents=None, can_send_photos=None,
|
can_send_documents=None, can_send_photos=None,
|
||||||
can_send_videos=None, can_send_video_notes=None,
|
can_send_videos=None, can_send_video_notes=None,
|
||||||
can_send_voice_notes=None, can_send_polls=None, can_send_other_messages=None,
|
can_send_voice_notes=None, can_send_polls=None, can_send_other_messages=None,
|
||||||
@ -3156,6 +3162,14 @@ class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
|
|||||||
self.can_send_video_notes: bool = can_send_video_notes
|
self.can_send_video_notes: bool = can_send_video_notes
|
||||||
self.can_send_voice_notes: bool = can_send_voice_notes
|
self.can_send_voice_notes: bool = can_send_voice_notes
|
||||||
|
|
||||||
|
if can_send_media_messages is not None:
|
||||||
|
self.can_send_audios = can_send_media_messages
|
||||||
|
self.can_send_documents = can_send_media_messages
|
||||||
|
self.can_send_photos = can_send_media_messages
|
||||||
|
self.can_send_videos = can_send_media_messages
|
||||||
|
self.can_send_video_notes = can_send_media_messages
|
||||||
|
self.can_send_voice_notes = can_send_media_messages
|
||||||
|
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return json.dumps(self.to_dict())
|
return json.dumps(self.to_dict())
|
||||||
|
Loading…
Reference in New Issue
Block a user