From 3328979f28732dfe1d92b677354bd588f267b77b Mon Sep 17 00:00:00 2001 From: Oleg A Date: Thu, 5 Nov 2020 18:45:10 +0300 Subject: [PATCH] AIOG-T-77 Added the method unpinAllChatMessages, which can be used to unpin all pinned messages in a chat. --- aiogram/bot/api.py | 1 + aiogram/bot/bot.py | 23 +++++++++++++++++++++++ aiogram/types/chat.py | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index a4379334..ba4bd2b1 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -200,6 +200,7 @@ class Methods(Helper): SET_CHAT_DESCRIPTION = Item() # setChatDescription PIN_CHAT_MESSAGE = Item() # pinChatMessage UNPIN_CHAT_MESSAGE = Item() # unpinChatMessage + UNPIN_ALL_CHAT_MESSAGES = Item() # unpinAllChatMessages LEAVE_CHAT = Item() # leaveChat GET_CHAT = Item() # getChat GET_CHAT_ADMINISTRATORS = Item() # getChatAdministrators diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index fda35703..9ccf0c5f 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -1512,6 +1512,29 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.UNPIN_CHAT_MESSAGE, payload) return result + async def unpin_all_chat_messages(self, + chat_id: typing.Union[base.Integer, base.String], + ) -> base.Boolean: + """ + Use this method to clear 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#unpinallchatmessages + + :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]` + + :return: Returns True on success + :rtype: :obj:`base.Boolean` + """ + payload = generate_payload(**locals()) + + result = await self.request(api.Methods.UNPIN_ALL_CHAT_MESSAGES, payload) + return result + async def leave_chat(self, chat_id: typing.Union[base.Integer, base.String]) -> base.Boolean: """ Use this method for your bot to leave a group, supergroup or channel. diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 0380fbed..901e2052 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -409,6 +409,22 @@ class Chat(base.TelegramObject): message_id=message_id, ) + async def unpin_all_messages(self): + """ + Use this method to clear 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#unpinallchatmessages + + :return: Returns True on success + :rtype: :obj:`base.Boolean` + """ + return await self.bot.unpin_all_chat_messages( + chat_id=self.id, + ) + async def leave(self) -> base.Boolean: """ Use this method for your bot to leave a group, supergroup or channel.