diff --git a/README.md b/README.md index 2dd5394a..f9052665 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![PyPi status](https://img.shields.io/pypi/status/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram) [![Downloads](https://img.shields.io/pypi/dm/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram) [![Supported python versions](https://img.shields.io/pypi/pyversions/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram) -[![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-5.4-blue.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-5.5-blue.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) [![Documentation Status](https://img.shields.io/readthedocs/aiogram?style=flat-square)](http://docs.aiogram.dev/en/latest/?badge=latest) [![Github issues](https://img.shields.io/github/issues/aiogram/aiogram.svg?style=flat-square)](https://github.com/aiogram/aiogram/issues) [![MIT License](https://img.shields.io/pypi/l/aiogram.svg?style=flat-square)](https://opensource.org/licenses/MIT) diff --git a/aiogram/__init__.py b/aiogram/__init__.py index a9581081..5216689a 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -43,5 +43,5 @@ __all__ = ( 'utils', ) -__version__ = '2.16' -__api_version__ = '5.4' +__version__ = '2.17' +__api_version__ = '5.5' diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index b0bb790c..fca5b738 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -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 diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index 436b83a4..d5aa5d65 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -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: """ diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index a2487b59..00b7a656 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -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 diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 403ef954..fa73f2e4 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -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() diff --git a/docs/source/index.rst b/docs/source/index.rst index 1b9c752d..a4ce2354 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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