mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Bot API 5.5 (#768)
* chore: bump version 5.5 * feat: add banChatSenderChat and unbanChatSenderChat Added the methods banChatSenderChat and unbanChatSenderChat for banning and unbanning channel chats in supergroups and channels. * feat: add has_private_forwards Added the field has_private_forwards to the class Chat for private chats, which can be used to check the possibility of mentioning the user by their ID. * feat: add has_protected_content Added the field has_protected_content to the classes Chat and Message. * feat: add is_automatic_forward Added the field is_automatic_forward to the class Message. * feat: add shortcuts Added Chat.ban_sender_chat() and Chat.unban_sender_chat() shortcuts. * docs: add new methods Source
This commit is contained in:
parent
5bcbcedeba
commit
910e4d7784
7 changed files with 91 additions and 5 deletions
|
|
@ -6,7 +6,7 @@
|
|||
[](https://pypi.python.org/pypi/aiogram)
|
||||
[](https://pypi.python.org/pypi/aiogram)
|
||||
[](https://pypi.python.org/pypi/aiogram)
|
||||
[](https://core.telegram.org/bots/api)
|
||||
[](https://core.telegram.org/bots/api)
|
||||
[](http://docs.aiogram.dev/en/latest/?badge=latest)
|
||||
[](https://github.com/aiogram/aiogram/issues)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
|
|
|||
|
|
@ -43,5 +43,5 @@ __all__ = (
|
|||
'utils',
|
||||
)
|
||||
|
||||
__version__ = '2.16'
|
||||
__api_version__ = '5.4'
|
||||
__version__ = '2.17'
|
||||
__api_version__ = '5.5'
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ class Methods(Helper):
|
|||
"""
|
||||
Helper for Telegram API Methods listed on https://core.telegram.org/bots/api
|
||||
|
||||
List is updated to Bot API 5.4
|
||||
List is updated to Bot API 5.5
|
||||
"""
|
||||
mode = HelperMode.lowerCamelCase
|
||||
|
||||
|
|
@ -230,6 +230,8 @@ class Methods(Helper):
|
|||
RESTRICT_CHAT_MEMBER = Item() # restrictChatMember
|
||||
PROMOTE_CHAT_MEMBER = Item() # promoteChatMember
|
||||
SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE = Item() # setChatAdministratorCustomTitle
|
||||
BAN_CHAT_SENDER_CHAT = Item() # banChatSenderChat
|
||||
UNBAN_CHAT_SENDER_CHAT = Item() # unbanChatSenderChat
|
||||
SET_CHAT_PERMISSIONS = Item() # setChatPermissions
|
||||
EXPORT_CHAT_INVITE_LINK = Item() # exportChatInviteLink
|
||||
CREATE_CHAT_INVITE_LINK = Item() # createChatInviteLink
|
||||
|
|
|
|||
|
|
@ -1814,6 +1814,62 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
|
||||
return await self.request(api.Methods.SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE, payload)
|
||||
|
||||
async def ban_chat_sender_chat(
|
||||
self,
|
||||
chat_id: typing.Union[base.Integer, base.String],
|
||||
sender_chat_id: base.Integer,
|
||||
until_date: typing.Union[
|
||||
base.Integer, datetime.datetime, datetime.timedelta, None
|
||||
] = None,
|
||||
):
|
||||
"""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.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#banchatsenderchat
|
||||
|
||||
: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.
|
||||
"""
|
||||
until_date = prepare_arg(until_date)
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.BAN_CHAT_SENDER_CHAT, payload)
|
||||
|
||||
async def unban_chat_sender_chat(
|
||||
self,
|
||||
chat_id: typing.Union[base.Integer, base.String],
|
||||
sender_chat_id: base.Integer,
|
||||
):
|
||||
"""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.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#unbanchatsenderchat
|
||||
|
||||
: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
|
||||
"""
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.UNBAN_CHAT_SENDER_CHAT, payload)
|
||||
|
||||
async def set_chat_permissions(self, chat_id: typing.Union[base.Integer, base.String],
|
||||
permissions: types.ChatPermissions) -> base.Boolean:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -30,12 +30,14 @@ class Chat(base.TelegramObject):
|
|||
all_members_are_administrators: base.Boolean = fields.Field()
|
||||
photo: ChatPhoto = fields.Field(base=ChatPhoto)
|
||||
bio: base.String = fields.Field()
|
||||
has_private_forwards: base.Boolean = fields.Field()
|
||||
description: base.String = fields.Field()
|
||||
invite_link: base.String = fields.Field()
|
||||
pinned_message: 'Message' = fields.Field(base='Message')
|
||||
permissions: ChatPermissions = fields.Field(base=ChatPermissions)
|
||||
slow_mode_delay: base.Integer = fields.Field()
|
||||
message_auto_delete_time: base.Integer = fields.Field()
|
||||
has_protected_content: base.Boolean = fields.Field()
|
||||
sticker_set_name: base.String = fields.Field()
|
||||
can_set_sticker_set: base.Boolean = fields.Field()
|
||||
linked_chat_id: base.Integer = fields.Field()
|
||||
|
|
@ -621,6 +623,30 @@ class Chat(base.TelegramObject):
|
|||
message_id=message_id,
|
||||
)
|
||||
|
||||
async def ban_sender_chat(
|
||||
self,
|
||||
sender_chat_id: base.Integer,
|
||||
until_date: typing.Union[
|
||||
base.Integer, datetime.datetime, datetime.timedelta, None
|
||||
] = None,
|
||||
):
|
||||
"""Shortcut for banChatSenderChat method."""
|
||||
return await self.bot.ban_chat_sender_chat(
|
||||
chat_id=self.id,
|
||||
sender_chat_id=sender_chat_id,
|
||||
until_date=until_date,
|
||||
)
|
||||
|
||||
async def unban_sender_chat(
|
||||
self,
|
||||
sender_chat_id: base.Integer,
|
||||
):
|
||||
"""Shortcut for unbanChatSenderChat method."""
|
||||
return await self.bot.unban_chat_sender_chat(
|
||||
chat_id=self.id,
|
||||
sender_chat_id=sender_chat_id,
|
||||
)
|
||||
|
||||
def __int__(self):
|
||||
return self.id
|
||||
|
||||
|
|
|
|||
|
|
@ -58,9 +58,11 @@ class Message(base.TelegramObject):
|
|||
forward_from_message_id: base.Integer = fields.Field()
|
||||
forward_signature: base.String = fields.Field()
|
||||
forward_date: datetime.datetime = fields.DateTimeField()
|
||||
is_automatic_forward: base.Boolean = fields.Field()
|
||||
reply_to_message: Message = fields.Field(base="Message")
|
||||
via_bot: User = fields.Field(base=User)
|
||||
edit_date: datetime.datetime = fields.DateTimeField()
|
||||
has_protected_content: base.Boolean = fields.Field()
|
||||
media_group_id: base.String = fields.Field()
|
||||
author_signature: base.String = fields.Field()
|
||||
forward_sender_name: base.String = fields.Field()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Welcome to aiogram's documentation!
|
|||
:target: https://pypi.python.org/pypi/aiogram
|
||||
:alt: Supported python versions
|
||||
|
||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.4-blue.svg?style=flat-square&logo=telegram
|
||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.5-blue.svg?style=flat-square&logo=telegram
|
||||
:target: https://core.telegram.org/bots/api
|
||||
:alt: Telegram Bot API
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue