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

Merge pull request #1383 from coder2020official/master

Bot API 5.5
This commit is contained in:
Badiboy 2021-12-08 13:19:56 +03:00 committed by GitHub
commit 3ebefa15bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 175 additions and 6 deletions

View File

@ -1667,6 +1667,38 @@ class TeleBot:
""" """
return apihelper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title) 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]) -> 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
:return: True on success.
"""
return apihelper.ban_chat_sender_chat(self.token, chat_id, sender_chat_id)
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( def set_chat_permissions(
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool: self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool:
""" """

View File

@ -969,6 +969,18 @@ def set_chat_administrator_custom_title(token, chat_id, user_id, custom_title):
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
def ban_chat_sender_chat(token, chat_id, sender_chat_id):
method_url = 'banChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
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): def set_chat_permissions(token, chat_id, permissions):
method_url = 'setChatPermissions' method_url = 'setChatPermissions'
payload = { payload = {

View File

@ -94,7 +94,81 @@ class CancelUpdate:
pass pass
class AsyncTeleBot: class AsyncTeleBot:
""" This is AsyncTeleBot Class
Methods:
getMe
logOut
close
sendMessage
forwardMessage
copyMessage
deleteMessage
sendPhoto
sendAudio
sendDocument
sendSticker
sendVideo
sendVenue
sendAnimation
sendVideoNote
sendLocation
sendChatAction
sendDice
sendContact
sendInvoice
sendMediaGroup
getUserProfilePhotos
getUpdates
getFile
sendPoll
stopPoll
sendGame
setGameScore
getGameHighScores
editMessageText
editMessageCaption
editMessageMedia
editMessageReplyMarkup
editMessageLiveLocation
stopMessageLiveLocation
banChatMember
unbanChatMember
restrictChatMember
promoteChatMember
setChatAdministratorCustomTitle
setChatPermissions
createChatInviteLink
editChatInviteLink
revokeChatInviteLink
exportChatInviteLink
setChatStickerSet
deleteChatStickerSet
createNewStickerSet
addStickerToSet
deleteStickerFromSet
setStickerPositionInSet
uploadStickerFile
setStickerSetThumb
getStickerSet
setChatPhoto
deleteChatPhoto
setChatTitle
setChatDescription
pinChatMessage
unpinChatMessage
leaveChat
getChat
getChatAdministrators
getChatMemberCount
getChatMember
answerCallbackQuery
getMyCommands
setMyCommands
deleteMyCommands
answerInlineQuery
answerShippingQuery
answerPreCheckoutQuery
"""
def __init__(self, token: str, parse_mode: Optional[str]=None, offset=None, def __init__(self, token: str, parse_mode: Optional[str]=None, offset=None,
exception_handler=None) -> None: # TODO: ADD TYPEHINTS exception_handler=None) -> None: # TODO: ADD TYPEHINTS
@ -2135,6 +2209,37 @@ class AsyncTeleBot:
""" """
return await asyncio_helper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title) 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]) -> 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
:return: True on success.
"""
return await asyncio_helper.ban_chat_sender_chat(self.token, chat_id, sender_chat_id)
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( async def set_chat_permissions(
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool: self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool:
""" """

View File

@ -912,6 +912,17 @@ 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') return await _process_request(token, method_url, params=payload, method='post')
async def ban_chat_sender_chat(token, chat_id, sender_chat_id):
method_url = 'banChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
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): async def set_chat_permissions(token, chat_id, permissions):
method_url = 'setChatPermissions' method_url = 'setChatPermissions'
payload = { payload = {

View File

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

View File

@ -50,7 +50,7 @@ def test_json_message_with_dice():
def test_json_message_group(): def test_json_message_group():
json_string = r'{"message_id":10,"from":{"id":12345,"first_name":"g","last_name":"G","username":"GG","is_bot":true},"chat":{"id":-866,"type":"private","title":"\u4ea4"},"date":1435303157,"text":"HIHI"}' json_string = r'{"message_id":10,"from":{"id":12345,"first_name":"g","last_name":"G","username":"GG","is_bot":true},"chat":{"id":-866,"type":"private","title":"\u4ea4"},"date":1435303157,"text":"HIHI","has_protected_content":true}'
msg = types.Message.de_json(json_string) msg = types.Message.de_json(json_string)
assert msg.text == 'HIHI' assert msg.text == 'HIHI'
assert len(msg.chat.title) != 0 assert len(msg.chat.title) != 0