Skip to content

Commit c5cc85f

Browse files
kalmengrdelivrance
andcommitted
Add method delete_user_history (pyrogram#282)
* Add method delete_all_user_messages * Update delete_all_user_messages.py * Rename delete_all_user_messages.py to delete_user_history.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
1 parent cf76945 commit c5cc85f

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Union
20+
21+
from pyrogram.api import functions, types
22+
from pyrogram.client.ext import BaseClient
23+
24+
25+
class DeleteUserHistory(BaseClient):
26+
def delete_user_history(
27+
self,
28+
chat_id: Union[int, str],
29+
user_id: Union[int, str],
30+
) -> bool:
31+
"""Delete all messages sent by a certain user in a supergroup.
32+
33+
Parameters:
34+
chat_id (``int`` | ``str``):
35+
Unique identifier (int) or username (str) of the target chat.
36+
37+
user_id (``int`` | ``str``):
38+
Unique identifier (int) or username (str) of the user whose messages will be deleted.
39+
40+
Returns:
41+
``bool``: True on success, False otherwise.
42+
"""
43+
44+
r = self.send(
45+
functions.channels.DeleteUserHistory(
46+
channel=self.resolve_peer(chat_id),
47+
user_id=self.resolve_peer(user_id)
48+
)
49+
)
50+
51+
# Deleting messages you don't have right onto won't raise any error.
52+
# Check for pts_count, which is 0 in case deletes fail.
53+
return bool(r.pts_count)

0 commit comments

Comments
 (0)