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

Make delete_messages return False when it fails to delete

This is because there will be no exception raised, because Telegram
is not sending any RPCError when you try to delete a message you don't
have rights on to.
This commit is contained in:
Dan 2019-04-14 22:34:05 +02:00
parent 605b5f1b0f
commit 57be97566d
2 changed files with 8 additions and 8 deletions

View File

@ -48,7 +48,7 @@ class DeleteMessages(BaseClient):
Defaults to True. Defaults to True.
Returns: Returns:
True on success. True on success, False otherwise.
Raises: Raises:
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error. :class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
@ -57,18 +57,20 @@ class DeleteMessages(BaseClient):
message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids] message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids]
if isinstance(peer, types.InputPeerChannel): if isinstance(peer, types.InputPeerChannel):
self.send( r = self.send(
functions.channels.DeleteMessages( functions.channels.DeleteMessages(
channel=peer, channel=peer,
id=message_ids id=message_ids
) )
) )
else: else:
self.send( r = self.send(
functions.messages.DeleteMessages( functions.messages.DeleteMessages(
id=message_ids, id=message_ids,
revoke=revoke or None revoke=revoke or None
) )
) )
return True # Deleting messages you don't have right onto, won't raise any error.
# Check for pts_count, which is 0 in case deletes fail.
return bool(r.pts_count)

View File

@ -2729,19 +2729,17 @@ class Message(PyrogramType, Update):
Defaults to True. Defaults to True.
Returns: Returns:
True on success. True on success, False otherwise.
Raises: Raises:
:class:`RPCError <pyrogram.RPCError>` :class:`RPCError <pyrogram.RPCError>`
""" """
self._client.delete_messages( return self._client.delete_messages(
chat_id=self.chat.id, chat_id=self.chat.id,
message_ids=self.message_id, message_ids=self.message_id,
revoke=revoke revoke=revoke
) )
return True
def click(self, x: int or str, y: int = None, quote: bool = None): def click(self, x: int or str, y: int = None, quote: bool = None):
"""Bound method *click* of :obj:`Message <pyrogram.Message>`. """Bound method *click* of :obj:`Message <pyrogram.Message>`.