Make edit_message parameters more consistent

This commit is contained in:
Lonami Exo 2021-09-18 16:54:54 +02:00
parent 4321b97e98
commit 0b54fa7a25
4 changed files with 24 additions and 15 deletions

View File

@ -417,8 +417,8 @@ perform a separate request with no filter to fetch the total without filter (thi
library used to do).
Using message.edit will now raise an error if the message cannot be edited
--------------------------------------------------------------------------
Changes to editing messages
---------------------------
Before, calling ``message.edit()`` would completely ignore your attempt to edit a message if the
message had a forward header or was not outgoing. This is no longer the case. It is now the user's
@ -427,6 +427,23 @@ responsibility to check for this.
However, most likely, you were already doing the right thing (or else you would've experienced a
"why is this not being edited", which you would most likely consider a bug rather than a feature).
When using ``client.edit_message``, you now must always specify the chat and the message (or
message identifier). This should be less "magic". As an example, if you were doing this before:
.. code-block:: python
await client.edit_message(message, 'new text')
You now have to do the following:
.. code-block:: python
await client.edit_message(message.input_chat, message.id, 'new text')
# or
await message.edit('new text')
Signing in no longer sends the code
-----------------------------------

View File

@ -570,14 +570,6 @@ async def edit_message(
supports_streaming: bool = False,
schedule: 'hints.DateLike' = None
) -> '_tl.Message':
if isinstance(entity, _tl.InputBotInlineMessageID):
text = text or message
message = entity
elif isinstance(entity, _tl.Message):
text = message # Shift the parameters to the right
message = entity
entity = entity.peer_id
if formatting_entities is None:
text, formatting_entities = await self._parse_message_text(text, parse_mode)
file_handle, media, image = await self._file_to_media(file,
@ -586,9 +578,9 @@ async def edit_message(
attributes=attributes,
force_document=force_document)
if isinstance(entity, _tl.InputBotInlineMessageID):
if isinstance(message, _tl.InputBotInlineMessageID):
request = _tl.fn.messages.EditInlineBotMessage(
id=entity,
id=message,
message=text,
no_webpage=not link_preview,
entities=formatting_entities,

View File

@ -2397,7 +2397,7 @@ class TelegramClient:
async def edit_message(
self: 'TelegramClient',
entity: 'typing.Union[hints.EntityLike, _tl.Message]',
message: 'hints.MessageLike' = None,
message: 'hints.MessageLike',
text: str = None,
*,
parse_mode: str = (),
@ -2519,7 +2519,7 @@ class TelegramClient:
# or
await client.edit_message(chat, message.id, 'hello!!')
# or
await client.edit_message(message, 'hello!!!')
await message.edit('hello!!!')
"""
return await messages.edit_message(**locals())

View File

@ -314,7 +314,7 @@ class CallbackQuery(EventBuilder):
self._client.loop.create_task(self.answer())
if isinstance(self.query.msg_id, _tl.InputBotInlineMessageID):
return await self._client.edit_message(
self.query.msg_id, *args, **kwargs
None, self.query.msg_id, *args, **kwargs
)
else:
return await self._client.edit_message(