mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-20 12:06:37 +00:00
Support omitting the entity on client.edit_message
This commit is contained in:
parent
03bebfb600
commit
b0dda777fe
@ -877,20 +877,26 @@ class TelegramClient(TelegramBareClient):
|
|||||||
result = [id_to_message[random_to_id[rnd]] for rnd in req.random_id]
|
result = [id_to_message[random_to_id[rnd]] for rnd in req.random_id]
|
||||||
return result[0] if single else result
|
return result[0] if single else result
|
||||||
|
|
||||||
def edit_message(self, entity, message_id, message=None, parse_mode='md',
|
def edit_message(self, entity, message=None, text=None, parse_mode='md',
|
||||||
link_preview=True):
|
link_preview=True):
|
||||||
"""
|
"""
|
||||||
Edits the given message ID (to change its contents or disable preview).
|
Edits the given message ID (to change its contents or disable preview).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
entity (`entity`):
|
entity (`entity` | :tl:`Message`):
|
||||||
From which chat to edit the message.
|
From which chat to edit the message. This can also be
|
||||||
|
the message to be edited, and the entity will be inferred
|
||||||
|
from it, so the next parameter will be assumed to be the
|
||||||
|
message text.
|
||||||
|
|
||||||
message_id (`str`):
|
message (`int` | :tl:`Message` | `str`):
|
||||||
The ID of the message (or ``Message`` itself) to be edited.
|
The ID of the message (or :tl:`Message` itself) to be edited.
|
||||||
|
If the `entity` was a :tl:`Message`, then this message will be
|
||||||
|
treated as the new text.
|
||||||
|
|
||||||
message (`str`, optional):
|
text (`str`, optional):
|
||||||
The new text of the message.
|
The new text of the message. Does nothing if the `entity`
|
||||||
|
was a :tl:`Message`.
|
||||||
|
|
||||||
parse_mode (`str`, optional):
|
parse_mode (`str`, optional):
|
||||||
Can be 'md' or 'markdown' for markdown-like parsing (default),
|
Can be 'md' or 'markdown' for markdown-like parsing (default),
|
||||||
@ -901,6 +907,17 @@ class TelegramClient(TelegramBareClient):
|
|||||||
link_preview (`bool`, optional):
|
link_preview (`bool`, optional):
|
||||||
Should the link preview be shown?
|
Should the link preview be shown?
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
>>> client = TelegramClient(...).start()
|
||||||
|
>>> message = client.send_message('username', 'hello')
|
||||||
|
>>>
|
||||||
|
>>> client.edit_message('username', message, 'hello!')
|
||||||
|
>>> # or
|
||||||
|
>>> client.edit_message('username', message.id, 'Hello')
|
||||||
|
>>> # or
|
||||||
|
>>> client.edit_message(message, 'Hello!')
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
``MessageAuthorRequiredError`` if you're not the author of the
|
``MessageAuthorRequiredError`` if you're not the author of the
|
||||||
message but try editing it anyway.
|
message but try editing it anyway.
|
||||||
@ -911,11 +928,16 @@ class TelegramClient(TelegramBareClient):
|
|||||||
Returns:
|
Returns:
|
||||||
The edited :tl:`Message`.
|
The edited :tl:`Message`.
|
||||||
"""
|
"""
|
||||||
message, msg_entities = self._parse_message_text(message, parse_mode)
|
if isinstance(entity, Message):
|
||||||
|
text = message # Shift the parameters to the right
|
||||||
|
message = entity
|
||||||
|
entity = entity.to_id
|
||||||
|
|
||||||
|
text, msg_entities = self._parse_message_text(text, parse_mode)
|
||||||
request = EditMessageRequest(
|
request = EditMessageRequest(
|
||||||
peer=self.get_input_entity(entity),
|
peer=self.get_input_entity(entity),
|
||||||
id=self._get_message_id(message_id),
|
id=self._get_message_id(message),
|
||||||
message=message,
|
message=text,
|
||||||
no_webpage=not link_preview,
|
no_webpage=not link_preview,
|
||||||
entities=msg_entities
|
entities=msg_entities
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user