-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathset_chat_guard_bot.py
More file actions
83 lines (66 loc) · 2.88 KB
/
Copy pathset_chat_guard_bot.py
File metadata and controls
83 lines (66 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <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, Optional
import pyrogram
from pyrogram import raw
class SetChatGuardBot:
async def set_chat_guard_bot(
self: "pyrogram.Client",
chat_id: Union[int, str],
bot: Optional[Union[int, str]] = None,
apply_to_invites: bool = False
) -> bool:
"""Set or remove a guard bot for a channel or supergroup.
The guard bot screens join requests before approval.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
bot (``int`` | ``str`` | ``None``):
Unique identifier (int) or username (str) of the bot to set as guard.
Pass ``None`` to remove the guard bot (disables join request screening).
apply_to_invites (``bool``, *optional*):
Pass True to also apply guard bot screening to invite link joins.
Defaults to False.
Returns:
``bool``: True on success.
Example:
.. code-block:: python
# Set a guard bot
await app.set_chat_guard_bot(chat_id, "@myguardbot")
# Set guard bot and apply to invite links too
await app.set_chat_guard_bot(chat_id, "@myguardbot", apply_to_invites=True)
# Remove guard bot
await app.set_chat_guard_bot(chat_id, None)
"""
guard_bot = None
if bot is not None:
peer = await self.resolve_peer(bot)
if isinstance(peer, raw.types.InputPeerUser):
guard_bot = raw.types.InputUser(user_id=peer.user_id, access_hash=peer.access_hash)
else:
guard_bot = peer
await self.invoke(
raw.functions.channels.ToggleJoinRequest(
channel=await self.resolve_peer(chat_id),
enabled=guard_bot is not None,
guard_bot=guard_bot,
apply_to_invites=apply_to_invites
)
)
return True