1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added use_independent_chat_permissions to setchatpermissions

This commit is contained in:
coder2020official 2023-02-04 20:04:07 +04:00
parent d0d03d0c09
commit d1348606e3
4 changed files with 25 additions and 7 deletions

View File

@ -3138,7 +3138,8 @@ class TeleBot:
return apihelper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id) return apihelper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id)
def set_chat_permissions( def set_chat_permissions(
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool: self, chat_id: Union[int, str], permissions: types.ChatPermissions,
use_independent_chat_permissions: Optional[bool]=None) -> bool:
""" """
Use this method to set default chat permissions for all members. 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 The bot must be an administrator in the group or a supergroup for this to work
@ -3153,10 +3154,16 @@ class TeleBot:
:param permissions: New default chat permissions :param permissions: New default chat permissions
:type permissions: :class:`telebot.types..ChatPermissions` :type permissions: :class:`telebot.types..ChatPermissions`
:param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise,
the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages,
can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
:type use_independent_chat_permissions: :obj:`bool`
:return: True on success :return: True on success
:rtype: :obj:`bool` :rtype: :obj:`bool`
""" """
return apihelper.set_chat_permissions(self.token, chat_id, permissions) return apihelper.set_chat_permissions(self.token, chat_id, permissions, use_independent_chat_permissions)
def create_chat_invite_link( def create_chat_invite_link(
self, chat_id: Union[int, str], self, chat_id: Union[int, str],

View File

@ -993,7 +993,7 @@ def restrict_chat_member(
permissions['can_pin_messages'] = can_pin_messages 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) permissions_json = json.dumps(permissions)
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json} payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json}
if until_date is not None: if until_date is not None:
@ -1059,12 +1059,14 @@ def unban_chat_sender_chat(token, chat_id, sender_chat_id):
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
def set_chat_permissions(token, chat_id, permissions): def set_chat_permissions(token, chat_id, permissions, use_independent_chat_permissions=None):
method_url = 'setChatPermissions' method_url = 'setChatPermissions'
payload = { payload = {
'chat_id': chat_id, 'chat_id': chat_id,
'permissions': permissions.to_json() 'permissions': permissions.to_json()
} }
if use_independent_chat_permissions is not None:
payload['use_independent_chat_permissions'] = use_independent_chat_permissions
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')

View File

@ -3998,7 +3998,8 @@ class AsyncTeleBot:
return await asyncio_helper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id) return await asyncio_helper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id)
async def set_chat_permissions( async def set_chat_permissions(
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool: self, chat_id: Union[int, str], permissions: types.ChatPermissions,
use_independent_chat_permissions: Optional[bool]=None) -> bool:
""" """
Use this method to set default chat permissions for all members. 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 The bot must be an administrator in the group or a supergroup for this to work
@ -4013,10 +4014,16 @@ class AsyncTeleBot:
:param permissions: New default chat permissions :param permissions: New default chat permissions
:type permissions: :class:`telebot.types..ChatPermissions` :type permissions: :class:`telebot.types..ChatPermissions`
:param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise,
the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages,
can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
:type use_independent_chat_permissions: :obj:`bool`
:return: True on success :return: True on success
:rtype: :obj:`bool` :rtype: :obj:`bool`
""" """
return await asyncio_helper.set_chat_permissions(self.token, chat_id, permissions) return await asyncio_helper.set_chat_permissions(self.token, chat_id, permissions, use_independent_chat_permissions)
async def create_chat_invite_link( async def create_chat_invite_link(
self, chat_id: Union[int, str], self, chat_id: Union[int, str],

View File

@ -1049,12 +1049,14 @@ async def unban_chat_sender_chat(token, chat_id, sender_chat_id):
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id} payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
return await _process_request(token, method_url, params=payload, method='post') return await _process_request(token, method_url, params=payload, method='post')
async def set_chat_permissions(token, chat_id, permissions): async def set_chat_permissions(token, chat_id, permissions, use_independent_chat_permissions=None):
method_url = 'setChatPermissions' method_url = 'setChatPermissions'
payload = { payload = {
'chat_id': chat_id, 'chat_id': chat_id,
'permissions': permissions.to_json() 'permissions': permissions.to_json()
} }
if use_independent_chat_permissions is not None:
payload['use_independent_chat_permissions'] = use_independent_chat_permissions
return await _process_request(token, method_url, params=payload, method='post') return await _process_request(token, method_url, params=payload, method='post')