From d92ace680534c9433994e0e7bfd4028cd855109f Mon Sep 17 00:00:00 2001 From: Oleg A Date: Thu, 5 Nov 2020 18:20:36 +0300 Subject: [PATCH] AIOG-T-75 Added the ability to pin messages in private chats (docs update) --- aiogram/bot/bot.py | 26 ++++++++++++++++++-------- aiogram/types/chat.py | 22 +++++++++++++++------- aiogram/types/message.py | 16 ++++++++++------ 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index f2c18cca..d1d9b826 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -1450,21 +1450,31 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.SET_CHAT_DESCRIPTION, payload) return result - async def pin_chat_message(self, chat_id: typing.Union[base.Integer, base.String], message_id: base.Integer, - disable_notification: typing.Union[base.Boolean, None] = None) -> base.Boolean: + async def pin_chat_message(self, + chat_id: typing.Union[base.Integer, base.String], + message_id: base.Integer, + disable_notification: typing.Optional[base.Boolean] = None, + ) -> base.Boolean: """ - Use this method to pin a message in a supergroup. - The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + Use this method to add a message to the list of pinned messages in a chat. + If the chat is not a private chat, the bot must be an administrator in the + chat for this to work and must have the 'can_pin_messages' admin right in a + supergroup or 'can_edit_messages' admin right in a channel. Returns True on + success. Source: https://core.telegram.org/bots/api#pinchatmessage - :param chat_id: Unique identifier for the target chat or username of the target supergroup + :param chat_id: Unique identifier for the target chat or username of the + target channel (in the format @channelusername) :type chat_id: :obj:`typing.Union[base.Integer, base.String]` + :param message_id: Identifier of a message to pin :type message_id: :obj:`base.Integer` - :param disable_notification: Pass True, if it is not necessary to send a notification to - all group members about the new pinned message - :type disable_notification: :obj:`typing.Union[base.Boolean, None]` + + :param disable_notification: Pass True, if it is not necessary to send a + notification to all group members about the new pinned message + :type disable_notification: :obj:`typing.Optional[base.Boolean]` + :return: Returns True on success :rtype: :obj:`base.Boolean` """ diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 30135a44..6d2b6590 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -360,19 +360,27 @@ class Chat(base.TelegramObject): return await self.bot.set_chat_administrator_custom_title(chat_id=self.id, user_id=user_id, custom_title=custom_title) - async def pin_message(self, message_id: base.Integer, disable_notification: base.Boolean = False) -> base.Boolean: + async def pin_message(self, + message_id: base.Integer, + disable_notification: typing.Optional[base.Boolean] = False, + ) -> base.Boolean: """ - Use this method to pin a message in a supergroup. - The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + Use this method to add a message to the list of pinned messages in a chat. + If the chat is not a private chat, the bot must be an administrator in the + chat for this to work and must have the 'can_pin_messages' admin right in a + supergroup or 'can_edit_messages' admin right in a channel. Returns True on + success. Source: https://core.telegram.org/bots/api#pinchatmessage :param message_id: Identifier of a message to pin :type message_id: :obj:`base.Integer` - :param disable_notification: Pass True, if it is not necessary to send a notification to - all group members about the new pinned message - :type disable_notification: :obj:`typing.Union[base.Boolean, None]` - :return: Returns True on success. + + :param disable_notification: Pass True, if it is not necessary to send a + notification to all group members about the new pinned message + :type disable_notification: :obj:`typing.Optional[base.Boolean]` + + :return: Returns True on success :rtype: :obj:`base.Boolean` """ return await self.bot.pin_chat_message(self.id, message_id, disable_notification) diff --git a/aiogram/types/message.py b/aiogram/types/message.py index c69455c2..3b0c4698 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -2098,17 +2098,21 @@ class Message(base.TelegramObject): return await self.bot.delete_message(self.chat.id, self.message_id) async def pin( - self, disable_notification: typing.Union[base.Boolean, None] = None + self, disable_notification: typing.Optional[base.Boolean] = None, ) -> base.Boolean: """ - Use this method to pin a message in a supergroup. - The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + Use this method to add a message to the list of pinned messages in a chat. + If the chat is not a private chat, the bot must be an administrator in the + chat for this to work and must have the 'can_pin_messages' admin right in a + supergroup or 'can_edit_messages' admin right in a channel. Returns True on + success. Source: https://core.telegram.org/bots/api#pinchatmessage - :param disable_notification: Pass True, if it is not necessary to send a notification to - all group members about the new pinned message - :type disable_notification: :obj:`typing.Union[base.Boolean, None]` + :param disable_notification: Pass True, if it is not necessary to send a + notification to all group members about the new pinned message + :type disable_notification: :obj:`typing.Optional[base.Boolean]` + :return: Returns True on success :rtype: :obj:`base.Boolean` """