Skip to content

Commit 7d917f4

Browse files
committed
Add approve/decline_chat_join_request
1 parent 29b4615 commit 7d917f4

File tree

4 files changed

+120
-4
lines changed

4 files changed

+120
-4
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ def get_title_list(s: str) -> list:
253253
get_chat_admin_invite_links_count
254254
get_chat_admins_with_invite_links
255255
delete_chat_admin_invite_links
256+
approve_chat_join_request
257+
decline_chat_join_request
256258
""",
257259
contacts="""
258260
Contacts

pyrogram/methods/invite_links/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919

20+
from .approve_chat_join_request import ApproveChatJoinRequest
2021
from .create_chat_invite_link import CreateChatInviteLink
22+
from .decline_chat_join_request import DeclineChatJoinRequest
2123
from .delete_chat_admin_invite_links import DeleteChatAdminInviteLinks
2224
from .delete_chat_invite_link import DeleteChatInviteLink
2325
from .edit_chat_invite_link import EditChatInviteLink
2426
from .export_chat_invite_link import ExportChatInviteLink
27+
from .get_chat_admin_invite_links import GetChatAdminInviteLinks
28+
from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount
2529
from .get_chat_admins_with_invite_links import GetChatAdminsWithInviteLinks
2630
from .get_chat_invite_link import GetChatInviteLink
2731
from .get_chat_invite_link_members import GetChatInviteLinkMembers
2832
from .get_chat_invite_link_members_count import GetChatInviteLinkMembersCount
29-
from .get_chat_admin_invite_links import GetChatAdminInviteLinks
30-
from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount
3133
from .revoke_chat_invite_link import RevokeChatInviteLink
3234

3335

@@ -43,6 +45,8 @@ class InviteLinks(
4345
DeleteChatAdminInviteLinks,
4446
GetChatAdminInviteLinksCount,
4547
GetChatAdminsWithInviteLinks,
46-
GetChatInviteLink
48+
GetChatInviteLink,
49+
ApproveChatJoinRequest,
50+
DeclineChatJoinRequest
4751
):
48-
pass
52+
pass
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2021 Dan <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 import raw
22+
from pyrogram.scaffold import Scaffold
23+
24+
25+
class ApproveChatJoinRequest(Scaffold):
26+
async def approve_chat_join_request(
27+
self,
28+
chat_id: Union[int, str],
29+
user_id: int,
30+
) -> bool:
31+
"""Approve a chat join request.
32+
33+
The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator
34+
right.
35+
36+
Parameters:
37+
chat_id (``int`` | ``str``):
38+
Unique identifier for the target chat or username of the target channel/supergroup
39+
(in the format @username).
40+
41+
user_id (``int``):
42+
Unique identifier of the target user.
43+
44+
Returns:
45+
``bool``: True on success.
46+
"""
47+
await self.send(
48+
raw.functions.messages.HideChatJoinRequest(
49+
peer=await self.resolve_peer(chat_id),
50+
user_id=await self.resolve_peer(user_id),
51+
approved=True
52+
)
53+
)
54+
55+
return True
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2021 Dan <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 import raw
22+
from pyrogram.scaffold import Scaffold
23+
24+
25+
class DeclineChatJoinRequest(Scaffold):
26+
async def decline_chat_join_request(
27+
self,
28+
chat_id: Union[int, str],
29+
user_id: int,
30+
) -> bool:
31+
"""Decline a chat join request.
32+
33+
The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator
34+
right.
35+
36+
Parameters:
37+
chat_id (``int`` | ``str``):
38+
Unique identifier for the target chat or username of the target channel/supergroup
39+
(in the format @username).
40+
41+
user_id (``int``):
42+
Unique identifier of the target user.
43+
44+
Returns:
45+
``bool``: True on success.
46+
"""
47+
await self.send(
48+
raw.functions.messages.HideChatJoinRequest(
49+
peer=await self.resolve_peer(chat_id),
50+
user_id=await self.resolve_peer(user_id),
51+
approved=False
52+
)
53+
)
54+
55+
return True

0 commit comments

Comments
 (0)