Create new client.pin_message method

This commit is contained in:
Lonami Exo 2019-05-30 17:15:50 +02:00
parent 9ea686ab14
commit 5832ab2f31
4 changed files with 54 additions and 0 deletions

View File

@ -63,6 +63,7 @@ Messages
forward_messages
iter_messages
get_messages
pin_message
send_read_acknowledge
Uploads

View File

@ -76,6 +76,7 @@ Methods
delete
get_reply_message
click
pin
download_media
get_entities_text
get_buttons

View File

@ -1121,6 +1121,49 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
return False
async def pin_message(
self: 'TelegramClient',
entity: 'hints.EntityLike',
message: 'typing.Optional[hints.MessageIDLike]',
*,
notify: bool = False
):
"""
Pins or unpins a message in a chat.
The default behaviour is to *not* notify members, unlike the
official applications.
See also `Message.pin() <telethon.tl.custom.message.Message.pin>`.
Arguments
entity (`entity`):
The chat where the message should be pinned.
message (`int` | `Message <telethon.tl.custom.message.Message>`):
The message or the message ID to pin. If it's
``None``, the message will be unpinned instead.
notify (`bool`, optional):
Whether the pin should notify people or not.
Example
.. code-block:: python
# Send and pin a message to annoy everyone
message = client.send_message(chat, 'Pinotifying is fun!')
client.pin_message(chat, message, notify=True)
"""
if not message:
message = 0
entity = await self.get_input_entity(entity)
await self(functions.messages.UpdatePinnedMessageRequest(
peer=entity,
id=message,
silent=not notify
))
# endregion
# endregion

View File

@ -854,6 +854,15 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
else:
return await self._buttons[i][j].click()
async def pin(self, *, notify=False):
"""
Pins the message. Shorthand for
`telethon.client.messages.MessageMethods.pin_message`
with both ``entity`` and ``message`` already set.
"""
await self._client.pin_message(
await self.get_input_chat(), self.id, notify=notify)
# endregion Public Methods
# region Private Methods