AIOG-T-76 Added the parameter message_id to the method unpinChatMessage to allow unpinning of the specific pinned message

This commit is contained in:
Oleg A 2020-11-05 18:37:20 +03:00
parent d92ace6805
commit aef6fd2c52
3 changed files with 50 additions and 9 deletions

View file

@ -1483,15 +1483,27 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.PIN_CHAT_MESSAGE, payload) result = await self.request(api.Methods.PIN_CHAT_MESSAGE, payload)
return result return result
async def unpin_chat_message(self, chat_id: typing.Union[base.Integer, base.String]) -> base.Boolean: async def unpin_chat_message(self,
chat_id: typing.Union[base.Integer, base.String],
message_id: typing.Optional[base.Integer] = None,
) -> base.Boolean:
""" """
Use this method to unpin a message in a supergroup chat. Use this method to remove a message from the list of pinned messages in a
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 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#unpinchatmessage Source: https://core.telegram.org/bots/api#unpinchatmessage
: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]` :type chat_id: :obj:`typing.Union[base.Integer, base.String]`
:param message_id: Identifier of a message to unpin. If not specified, the
most recent pinned message (by sending date) will be unpinned.
:type message_id: :obj:`typing.Optional[base.Integer]`
:return: Returns True on success :return: Returns True on success
:rtype: :obj:`base.Boolean` :rtype: :obj:`base.Boolean`
""" """

View file

@ -385,17 +385,29 @@ class Chat(base.TelegramObject):
""" """
return await self.bot.pin_chat_message(self.id, message_id, disable_notification) return await self.bot.pin_chat_message(self.id, message_id, disable_notification)
async def unpin_message(self) -> base.Boolean: async def unpin_message(self,
message_id: typing.Optional[base.Integer] = None,
) -> base.Boolean:
""" """
Use this method to unpin a message in a supergroup chat. Use this method to remove a message from the list of pinned messages in a
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 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#unpinchatmessage Source: https://core.telegram.org/bots/api#unpinchatmessage
:return: Returns True on success. :param message_id: Identifier of a message to unpin. If not specified, the
most recent pinned message (by sending date) will be unpinned.
:type message_id: :obj:`typing.Optional[base.Integer]`
:return: Returns True on success
:rtype: :obj:`base.Boolean` :rtype: :obj:`base.Boolean`
""" """
return await self.bot.unpin_chat_message(self.id) return await self.bot.unpin_chat_message(
chat_id=self.id,
message_id=message_id,
)
async def leave(self) -> base.Boolean: async def leave(self) -> base.Boolean:
""" """

View file

@ -2118,6 +2118,23 @@ class Message(base.TelegramObject):
""" """
return await self.chat.pin_message(self.message_id, disable_notification) return await self.chat.pin_message(self.message_id, disable_notification)
async def unpin(self) -> base.Boolean:
"""
Use this method to remove a message from 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#unpinchatmessage
:return: Returns True on success
:rtype: :obj:`base.Boolean`
"""
return await self.chat.unpin_message(
message_id=self.message_id,
)
async def send_copy( async def send_copy(
self: Message, self: Message,
chat_id: typing.Union[str, int], chat_id: typing.Union[str, int],