Add convenience methods to block and unblock Users · dotlambda/pyrogram@1fd31ca · GitHub
Skip to content

Commit 1fd31ca

Browse files
author
ColinShark
committed
Add convenience methods to block and unblock Users
1 parent 10de006 commit 1fd31ca

3 files changed

Lines changed: 95 additions & 1 deletion

File tree

pyrogram/client/methods/users/__init__.py

Lines changed: 5 additions & 1 deletion
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
import pyrogram
22+
from pyrogram.api import functions, types
23+
from ...ext import BaseClient
24+
25+
26+
class BlockUser(BaseClient):
27+
def block_user(
28+
self,
29+
user_id: Union[int, str]
30+
) -> bool:
31+
"""Block a user.
32+
33+
Returns:
34+
``bool``: True on success
35+
36+
Raises:
37+
RPCError: In case of Telegram RPC Error.
38+
"""
39+
return bool(
40+
self.send(
41+
functions.contact.Block(
42+
id=self.resolve_peer(user_id)
43+
)
44+
)
45+
)
Lines changed: 45 additions & 0 deletions

0 commit comments

Comments
 (0)