1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00
This commit is contained in:
_run 2021-12-07 22:17:51 +05:00
parent fbf34f5953
commit 038be81db3
5 changed files with 109 additions and 4 deletions

View File

@ -1667,6 +1667,41 @@ class TeleBot:
"""
return apihelper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title)
def ban_chat_sender_chat(self, chat_id: Union[int, str], sender_chat_id: Union[int, str],
until_date:Optional[Union[int, datetime]]=None) -> bool:
"""
Use this method to ban a channel chat in a supergroup or a channel.
The owner of the chat will not be able to send messages and join live
streams on behalf of the chat, unless it is unbanned first.
The bot must be an administrator in the supergroup or channel
for this to work and must have the appropriate administrator rights.
Returns True on success.
:params:
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:param sender_chat_id: Unique identifier of the target sender chat
:param until_date: Date when the sender chat will be unbanned, unix time. If the chat is banned for more than 366 days
or less than 30 seconds from the current time they are considered to be banned forever.
:return: True on success.
"""
return apihelper.ban_chat_sender_chat(self.token, chat_id, sender_chat_id, until_date)
def unban_chat_sender_chat(self, chat_id: Union[int, str], sender_chat_id: Union[int, str]) -> bool:
"""
Use this method to unban a previously banned channel chat in a supergroup or channel.
The bot must be an administrator for this to work and must have the appropriate
administrator rights.
Returns True on success.
:params:
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:param sender_chat_id: Unique identifier of the target sender chat
:return: True on success.
"""
return apihelper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id)
def set_chat_permissions(
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool:
"""

View File

@ -969,6 +969,20 @@ def set_chat_administrator_custom_title(token, chat_id, user_id, custom_title):
return _make_request(token, method_url, params=payload, method='post')
def ban_chat_sender_chat(token, chat_id, sender_chat_id, until_date=None):
method_url = 'banChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
if until_date:
payload['until_date'] = until_date
return _make_request(token, method_url, params=payload, method='post')
def unban_chat_sender_chat(token, chat_id, sender_chat_id):
method_url = 'unbanChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
return _make_request(token, method_url, params=payload, method='post')
def set_chat_permissions(token, chat_id, permissions):
method_url = 'setChatPermissions'
payload = {

View File

@ -2135,6 +2135,40 @@ class AsyncTeleBot:
"""
return await asyncio_helper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title)
async def ban_chat_sender_chat(self, chat_id: Union[int, str], sender_chat_id: Union[int, str],
until_date:Optional[Union[int, datetime]]=None) -> bool:
"""
Use this method to ban a channel chat in a supergroup or a channel.
The owner of the chat will not be able to send messages and join live
streams on behalf of the chat, unless it is unbanned first.
The bot must be an administrator in the supergroup or channel
for this to work and must have the appropriate administrator rights.
Returns True on success.
:params:
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:param sender_chat_id: Unique identifier of the target sender chat
:param until_date: Date when the sender chat will be unbanned, unix time. If the chat is banned for more than 366 days
or less than 30 seconds from the current time they are considered to be banned forever.
:return: True on success.
"""
return await asyncio_helper.ban_chat_sender_chat(self.token, chat_id, sender_chat_id, until_date)
async def unban_chat_sender_chat(self, chat_id: Union[int, str], sender_chat_id: Union[int, str]) -> bool:
"""
Use this method to unban a previously banned channel chat in a supergroup or channel.
The bot must be an administrator for this to work and must have the appropriate
administrator rights.
Returns True on success.
:params:
:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:param sender_chat_id: Unique identifier of the target sender chat
:return: True on success.
"""
return await asyncio_helper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id)
async def set_chat_permissions(
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool:
"""

View File

@ -912,6 +912,19 @@ async def set_chat_administrator_custom_title(token, chat_id, user_id, custom_ti
return await _process_request(token, method_url, params=payload, method='post')
async def ban_chat_sender_chat(token, chat_id, sender_chat_id, until_date=None):
method_url = 'banChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
if until_date:
payload['until_date'] = until_date
return await _process_request(token, method_url, params=payload, method='post')
async def unban_chat_sender_chat(token, chat_id, sender_chat_id):
method_url = 'unbanChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
return await _process_request(token, method_url, params=payload, method='post')
async def set_chat_permissions(token, chat_id, permissions):
method_url = 'setChatPermissions'
payload = {

View File

@ -274,10 +274,11 @@ class Chat(JsonDeserializable):
return cls(**obj)
def __init__(self, id, type, title=None, username=None, first_name=None,
last_name=None, photo=None, bio=None, description=None, invite_link=None,
pinned_message=None, permissions=None, slow_mode_delay=None,
message_auto_delete_time=None, sticker_set_name=None, can_set_sticker_set=None,
linked_chat_id=None, location=None, **kwargs):
last_name=None, photo=None, bio=None, has_private_forwards=None,
description=None, invite_link=None, pinned_message=None,
permissions=None, slow_mode_delay=None,
message_auto_delete_time=None, has_protected_content=None, sticker_set_name=None,
can_set_sticker_set=None, linked_chat_id=None, location=None, **kwargs):
self.id: int = id
self.type: str = type
self.title: str = title
@ -286,12 +287,14 @@ class Chat(JsonDeserializable):
self.last_name: str = last_name
self.photo: ChatPhoto = photo
self.bio: str = bio
self.has_private_forwards: bool = has_private_forwards
self.description: str = description
self.invite_link: str = invite_link
self.pinned_message: Message = pinned_message
self.permissions: ChatPermissions = permissions
self.slow_mode_delay: int = slow_mode_delay
self.message_auto_delete_time: int = message_auto_delete_time
self.has_protected_content: bool = has_protected_content
self.sticker_set_name: str = sticker_set_name
self.can_set_sticker_set: bool = can_set_sticker_set
self.linked_chat_id: int = linked_chat_id
@ -334,12 +337,16 @@ class Message(JsonDeserializable):
opts['forward_sender_name'] = obj.get('forward_sender_name')
if 'forward_date' in obj:
opts['forward_date'] = obj.get('forward_date')
if 'is_automatic_forward' in obj:
opts['is_automatic_forward'] = obj.get('is_automatic_forward')
if 'reply_to_message' in obj:
opts['reply_to_message'] = Message.de_json(obj['reply_to_message'])
if 'via_bot' in obj:
opts['via_bot'] = User.de_json(obj['via_bot'])
if 'edit_date' in obj:
opts['edit_date'] = obj.get('edit_date')
if 'has_protected_content' in obj:
opts['has_protected_content'] = obj.get('has_protected_content')
if 'media_group_id' in obj:
opts['media_group_id'] = obj.get('media_group_id')
if 'author_signature' in obj:
@ -503,9 +510,11 @@ class Message(JsonDeserializable):
self.forward_signature: Optional[str] = None
self.forward_sender_name: Optional[str] = None
self.forward_date: Optional[int] = None
self.is_automatic_forward: Optional[bool] = None
self.reply_to_message: Optional[Message] = None
self.via_bot: Optional[User] = None
self.edit_date: Optional[int] = None
self.has_protected_content: Optional[bool] = None
self.media_group_id: Optional[str] = None
self.author_signature: Optional[str] = None
self.text: Optional[str] = None