mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Add convenience methods to block and unblock Users
This commit is contained in:
parent
10de006cc5
commit
1fd31cac1e
@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from .block_user import BlockUser
|
||||||
from .delete_profile_photos import DeleteProfilePhotos
|
from .delete_profile_photos import DeleteProfilePhotos
|
||||||
from .get_me import GetMe
|
from .get_me import GetMe
|
||||||
from .get_profile_photos import GetProfilePhotos
|
from .get_profile_photos import GetProfilePhotos
|
||||||
@ -24,10 +25,12 @@ from .get_user_dc import GetUserDC
|
|||||||
from .get_users import GetUsers
|
from .get_users import GetUsers
|
||||||
from .iter_profile_photos import IterProfilePhotos
|
from .iter_profile_photos import IterProfilePhotos
|
||||||
from .set_profile_photo import SetProfilePhoto
|
from .set_profile_photo import SetProfilePhoto
|
||||||
|
from .unblock_user import UnblockUser
|
||||||
from .update_username import UpdateUsername
|
from .update_username import UpdateUsername
|
||||||
|
|
||||||
|
|
||||||
class Users(
|
class Users(
|
||||||
|
BlockUser,
|
||||||
GetProfilePhotos,
|
GetProfilePhotos,
|
||||||
SetProfilePhoto,
|
SetProfilePhoto,
|
||||||
DeleteProfilePhotos,
|
DeleteProfilePhotos,
|
||||||
@ -36,6 +39,7 @@ class Users(
|
|||||||
UpdateUsername,
|
UpdateUsername,
|
||||||
GetProfilePhotosCount,
|
GetProfilePhotosCount,
|
||||||
GetUserDC,
|
GetUserDC,
|
||||||
IterProfilePhotos
|
IterProfilePhotos,
|
||||||
|
UnblockUser
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
45
pyrogram/client/methods/users/block_user.py
Normal file
45
pyrogram/client/methods/users/block_user.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram.api import functions, types
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class BlockUser(BaseClient):
|
||||||
|
def block_user(
|
||||||
|
self,
|
||||||
|
user_id: Union[int, str]
|
||||||
|
) -> bool:
|
||||||
|
"""Block a user.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: True on success
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
RPCError: In case of Telegram RPC Error.
|
||||||
|
"""
|
||||||
|
return bool(
|
||||||
|
self.send(
|
||||||
|
functions.contact.Block(
|
||||||
|
id=self.resolve_peer(user_id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
45
pyrogram/client/methods/users/unblock_user.py
Normal file
45
pyrogram/client/methods/users/unblock_user.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram.api import functions, types
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class UnblockUser(BaseClient):
|
||||||
|
def unblock_user(
|
||||||
|
self,
|
||||||
|
user_id: Union[int, str]
|
||||||
|
) -> bool:
|
||||||
|
"""Unblock a user.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: True on success
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
RPCError: In case of Telegram RPC Error.
|
||||||
|
"""
|
||||||
|
return bool(
|
||||||
|
self.send(
|
||||||
|
functions.contact.Unblock(
|
||||||
|
id=self.resolve_peer(user_id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user