Skip to content

Commit d48cef9

Browse files
committed
Add ChatJoiner and get_chat_join_requests
Rename get_chat_invite_link_{members -> joiners} Rename get_chat_invite_link_{members -> joiners}_count
1 parent f6f6141 commit d48cef9

File tree

7 files changed

+196
-22
lines changed

7 files changed

+196
-22
lines changed

compiler/docs/compiler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,17 @@ def get_title_list(s: str) -> list:
256256
edit_chat_invite_link
257257
revoke_chat_invite_link
258258
delete_chat_invite_link
259-
get_chat_invite_link_members
260-
get_chat_invite_link_members_count
259+
get_chat_invite_link_joiners
260+
get_chat_invite_link_joiners_count
261261
get_chat_admin_invite_links
262262
get_chat_admin_invite_links_count
263263
get_chat_admins_with_invite_links
264+
get_chat_join_requests
264265
delete_chat_admin_invite_links
265266
approve_chat_join_request
267+
approve_all_chat_join_requests
266268
decline_chat_join_request
269+
decline_all_chat_join_requests
267270
""",
268271
contacts="""
269272
Contacts
@@ -370,6 +373,7 @@ def get_title_list(s: str) -> list:
370373
ChatEventFilter
371374
ChatMemberUpdated
372375
ChatJoinRequest
376+
ChatJoiner
373377
Dialog
374378
Restriction
375379
""",

pyrogram/methods/invite_links/__init__.py

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

1919

20+
from .approve_all_chat_join_requests import ApproveAllChatJoinRequests
2021
from .approve_chat_join_request import ApproveChatJoinRequest
2122
from .create_chat_invite_link import CreateChatInviteLink
23+
from .decline_all_chat_join_requests import DeclineAllChatJoinRequests
2224
from .decline_chat_join_request import DeclineChatJoinRequest
2325
from .delete_chat_admin_invite_links import DeleteChatAdminInviteLinks
2426
from .delete_chat_invite_link import DeleteChatInviteLink
@@ -28,8 +30,9 @@
2830
from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount
2931
from .get_chat_admins_with_invite_links import GetChatAdminsWithInviteLinks
3032
from .get_chat_invite_link import GetChatInviteLink
31-
from .get_chat_invite_link_members import GetChatInviteLinkMembers
32-
from .get_chat_invite_link_members_count import GetChatInviteLinkMembersCount
33+
from .get_chat_invite_link_joiners import GetChatInviteLinkJoiners
34+
from .get_chat_invite_link_joiners_count import GetChatInviteLinkJoinersCount
35+
from .get_chat_join_requests import GetChatJoinRequests
3336
from .revoke_chat_invite_link import RevokeChatInviteLink
3437

3538

@@ -38,15 +41,18 @@ class InviteLinks(
3841
DeleteChatInviteLink,
3942
EditChatInviteLink,
4043
CreateChatInviteLink,
41-
GetChatInviteLinkMembers,
42-
GetChatInviteLinkMembersCount,
44+
GetChatInviteLinkJoiners,
45+
GetChatInviteLinkJoinersCount,
4346
GetChatAdminInviteLinks,
4447
ExportChatInviteLink,
4548
DeleteChatAdminInviteLinks,
4649
GetChatAdminInviteLinksCount,
4750
GetChatAdminsWithInviteLinks,
4851
GetChatInviteLink,
4952
ApproveChatJoinRequest,
50-
DeclineChatJoinRequest
53+
DeclineChatJoinRequest,
54+
ApproveAllChatJoinRequests,
55+
DeclineAllChatJoinRequests,
56+
GetChatJoinRequests
5157
):
5258
pass

pyrogram/methods/invite_links/get_chat_invite_link_members.py renamed to pyrogram/methods/invite_links/get_chat_invite_link_joiners.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
from pyrogram import types
2424

2525

26-
class GetChatInviteLinkMembers:
27-
async def get_chat_invite_link_members(
26+
class GetChatInviteLinkJoiners:
27+
async def get_chat_invite_link_joiners(
2828
self: "pyrogram.Client",
2929
chat_id: Union[int, str],
3030
invite_link: str,
3131
limit: int = 0
32-
) -> Optional[AsyncGenerator["types.ChatMember", None]]:
32+
) -> Optional[AsyncGenerator["types.ChatJoiner", None]]:
3333
"""Get the members who joined the chat with the invite link.
3434
3535
Parameters:
@@ -45,10 +45,10 @@ async def get_chat_invite_link_members(
4545
By default, no limit is applied and all invite links are returned.
4646
4747
Returns:
48-
``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects.
48+
``Generator``: A generator yielding :obj:`~pyrogram.types.ChatJoiner` objects.
4949
5050
Yields:
51-
:obj:`~pyrogram.types.ChatMember` objects.
51+
:obj:`~pyrogram.types.ChatJoiner` objects.
5252
"""
5353
current = 0
5454
total = abs(limit) or (1 << 31) - 1
@@ -77,13 +77,7 @@ async def get_chat_invite_link_members(
7777
offset_user = await self.resolve_peer(r.importers[-1].user_id)
7878

7979
for i in r.importers:
80-
user = types.User._parse(self, users[i.user_id])
81-
82-
yield types.ChatMember(
83-
user=user,
84-
status="member",
85-
joined_date=i.date
86-
)
80+
yield types.ChatJoiner._parse(self, i, users)
8781

8882
current += 1
8983

pyrogram/methods/invite_links/get_chat_invite_link_members_count.py renamed to pyrogram/methods/invite_links/get_chat_invite_link_joiners_count.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from pyrogram import raw
2323

2424

25-
class GetChatInviteLinkMembersCount:
26-
async def get_chat_invite_link_members_count(
25+
class GetChatInviteLinkJoinersCount:
26+
async def get_chat_invite_link_joiners_count(
2727
self: "pyrogram.Client",
2828
chat_id: Union[int, str],
2929
invite_link: str
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present 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, Optional, AsyncGenerator
20+
21+
import pyrogram
22+
from pyrogram import raw
23+
from pyrogram import types
24+
25+
26+
class GetChatJoinRequests:
27+
async def get_chat_join_requests(
28+
self: "pyrogram.Client",
29+
chat_id: Union[int, str],
30+
limit: int = 0,
31+
query: str = ""
32+
) -> Optional[AsyncGenerator["types.ChatJoiner", None]]:
33+
"""Get the pending join requests of a chat.
34+
35+
Parameters:
36+
chat_id (``int`` | ``str``):
37+
Unique identifier for the target chat or username of the target channel/supergroup
38+
(in the format @username).
39+
40+
limit (``int``, *optional*):
41+
Limits the number of invite links to be retrieved.
42+
By default, no limit is applied and all invite links are returned.
43+
44+
query (``str``, *optional*):
45+
Query to search for a user.
46+
47+
Returns:
48+
``Generator``: A generator yielding :obj:`~pyrogram.types.ChatJoiner` objects.
49+
50+
Yields:
51+
:obj:`~pyrogram.types.ChatJoiner` objects.
52+
"""
53+
current = 0
54+
total = abs(limit) or (1 << 31) - 1
55+
limit = min(100, total)
56+
57+
offset_date = 0
58+
offset_user = raw.types.InputUserEmpty()
59+
60+
while True:
61+
r = await self.invoke(
62+
raw.functions.messages.GetChatInviteImporters(
63+
peer=await self.resolve_peer(chat_id),
64+
limit=limit,
65+
offset_date=offset_date,
66+
offset_user=offset_user,
67+
requested=True,
68+
q=query
69+
)
70+
)
71+
72+
if not r.importers:
73+
break
74+
75+
users = {i.id: i for i in r.users}
76+
77+
offset_date = r.importers[-1].date
78+
offset_user = await self.resolve_peer(r.importers[-1].user_id)
79+
80+
for i in r.importers:
81+
yield types.ChatJoiner._parse(self, i, users)
82+
83+
current += 1
84+
85+
if current >= total:
86+
return

pyrogram/types/user_and_chats/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .chat_event_filter import ChatEventFilter
2323
from .chat_invite_link import ChatInviteLink
2424
from .chat_join_request import ChatJoinRequest
25+
from .chat_joiner import ChatJoiner
2526
from .chat_member import ChatMember
2627
from .chat_member_updated import ChatMemberUpdated
2728
from .chat_permissions import ChatPermissions
@@ -57,5 +58,6 @@
5758
"ChatMemberUpdated",
5859
"VoiceChatScheduled",
5960
"ChatJoinRequest",
60-
"ChatPrivileges"
61+
"ChatPrivileges",
62+
"ChatJoiner"
6163
]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present 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 datetime import datetime
20+
from typing import Dict
21+
22+
import pyrogram
23+
from pyrogram import raw, types, utils
24+
from ..object import Object
25+
26+
27+
class ChatJoiner(Object):
28+
"""Contains information about a joiner member of a chat.
29+
30+
Parameters:
31+
user (:obj:`~pyrogram.types.User`):
32+
Information about the user.
33+
34+
date (:py:obj:`~datetime.datetime`):
35+
Date when the user joined.
36+
37+
bio (``str``, *optional*):
38+
Bio of the user.
39+
40+
pending (``bool``, *optional*):
41+
True in case the chat joiner has a pending request.
42+
43+
approved_by (:obj:`~pyrogram.types.User`, *optional*):
44+
Administrator who approved this chat joiner.
45+
"""
46+
47+
def __init__(
48+
self,
49+
*,
50+
client: "pyrogram.Client",
51+
user: "types.User",
52+
date: datetime = None,
53+
bio: str = None,
54+
pending: bool = None,
55+
approved_by: "types.User" = None,
56+
):
57+
super().__init__(client)
58+
59+
self.user = user
60+
self.date = date
61+
self.bio = bio
62+
self.pending = pending
63+
self.approved_by = approved_by
64+
65+
@staticmethod
66+
def _parse(
67+
client: "pyrogram.Client",
68+
joiner: "raw.base.ChatInviteImporter",
69+
users: Dict[int, "raw.base.User"],
70+
) -> "ChatJoiner":
71+
return ChatJoiner(
72+
user=types.User._parse(client, users[joiner.user_id]),
73+
date=utils.timestamp_to_datetime(joiner.date),
74+
pending=joiner.requested,
75+
bio=joiner.about,
76+
approved_by=(
77+
types.User._parse(client, users[joiner.approved_by])
78+
if joiner.approved_by
79+
else None
80+
),
81+
client=client
82+
)

0 commit comments

Comments
 (0)