2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Rework delete_messages

This commit is contained in:
Dan 2018-04-29 18:13:50 +02:00
parent b8996b1147
commit 34d7f3372f

View File

@ -2624,8 +2624,8 @@ class Client:
def delete_messages(self, def delete_messages(self,
chat_id: int or str, chat_id: int or str,
message_ids: list, message_ids: list or int,
revoke: bool = None): revoke: bool = True):
"""Use this method to delete messages, including service messages, with the following limitations: """Use this method to delete messages, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago. - A message can only be deleted if it was sent less than 48 hours ago.
@ -2641,37 +2641,41 @@ class Client:
For a contact that exists in your Telegram address book you can use his phone number (str). For a contact that exists in your Telegram address book you can use his phone number (str).
For a private channel/supergroup you can use its *t.me/joinchat/* link. For a private channel/supergroup you can use its *t.me/joinchat/* link.
message_ids (``list``): message_ids (``list`` | ``int``):
List of identifiers of the messages to delete. A list of Message identifiers to delete or a single message id.
revoke (``bool``, optional): revoke (``bool``, optional):
Deletes messages on both parts. Deletes messages on both parts.
This is only for private cloud chats and normal groups, messages on This is only for private cloud chats and normal groups, messages on
channels and supergroups are always revoked (i.e.: deleted for everyone). channels and supergroups are always revoked (i.e.: deleted for everyone).
Defaults to True.
Returns:
True on success.
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
peer = self.resolve_peer(chat_id) peer = self.resolve_peer(chat_id)
message_ids = message_ids if isinstance(message_ids, list) else [message_ids]
if isinstance(peer, types.InputPeerChannel): if isinstance(peer, types.InputPeerChannel):
return self.send( self.send(
functions.channels.DeleteMessages( functions.channels.DeleteMessages(
channel=peer, channel=peer,
id=message_ids id=message_ids
) )
) )
else: else:
# TODO: Maybe "revoke" is superfluous. self.send(
# If I want to delete a message, chances are I want it to
# be deleted even from the other side
return self.send(
functions.messages.DeleteMessages( functions.messages.DeleteMessages(
id=message_ids, id=message_ids,
revoke=revoke or None revoke=revoke or None
) )
) )
return True
# TODO: Improvements for the new API # TODO: Improvements for the new API
def save_file(self, def save_file(self,
path: str, path: str,