mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-23 10:28:00 +00:00
Add ChatJoiner and get_chat_join_requests
Rename get_chat_invite_link_{members -> joiners} Rename get_chat_invite_link_{members -> joiners}_count
This commit is contained in:
parent
f6f6141b19
commit
d48cef9a26
@ -256,14 +256,17 @@ def pyrogram_api():
|
|||||||
edit_chat_invite_link
|
edit_chat_invite_link
|
||||||
revoke_chat_invite_link
|
revoke_chat_invite_link
|
||||||
delete_chat_invite_link
|
delete_chat_invite_link
|
||||||
get_chat_invite_link_members
|
get_chat_invite_link_joiners
|
||||||
get_chat_invite_link_members_count
|
get_chat_invite_link_joiners_count
|
||||||
get_chat_admin_invite_links
|
get_chat_admin_invite_links
|
||||||
get_chat_admin_invite_links_count
|
get_chat_admin_invite_links_count
|
||||||
get_chat_admins_with_invite_links
|
get_chat_admins_with_invite_links
|
||||||
|
get_chat_join_requests
|
||||||
delete_chat_admin_invite_links
|
delete_chat_admin_invite_links
|
||||||
approve_chat_join_request
|
approve_chat_join_request
|
||||||
|
approve_all_chat_join_requests
|
||||||
decline_chat_join_request
|
decline_chat_join_request
|
||||||
|
decline_all_chat_join_requests
|
||||||
""",
|
""",
|
||||||
contacts="""
|
contacts="""
|
||||||
Contacts
|
Contacts
|
||||||
@ -370,6 +373,7 @@ def pyrogram_api():
|
|||||||
ChatEventFilter
|
ChatEventFilter
|
||||||
ChatMemberUpdated
|
ChatMemberUpdated
|
||||||
ChatJoinRequest
|
ChatJoinRequest
|
||||||
|
ChatJoiner
|
||||||
Dialog
|
Dialog
|
||||||
Restriction
|
Restriction
|
||||||
""",
|
""",
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from .approve_all_chat_join_requests import ApproveAllChatJoinRequests
|
||||||
from .approve_chat_join_request import ApproveChatJoinRequest
|
from .approve_chat_join_request import ApproveChatJoinRequest
|
||||||
from .create_chat_invite_link import CreateChatInviteLink
|
from .create_chat_invite_link import CreateChatInviteLink
|
||||||
|
from .decline_all_chat_join_requests import DeclineAllChatJoinRequests
|
||||||
from .decline_chat_join_request import DeclineChatJoinRequest
|
from .decline_chat_join_request import DeclineChatJoinRequest
|
||||||
from .delete_chat_admin_invite_links import DeleteChatAdminInviteLinks
|
from .delete_chat_admin_invite_links import DeleteChatAdminInviteLinks
|
||||||
from .delete_chat_invite_link import DeleteChatInviteLink
|
from .delete_chat_invite_link import DeleteChatInviteLink
|
||||||
@ -28,8 +30,9 @@ from .get_chat_admin_invite_links import GetChatAdminInviteLinks
|
|||||||
from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount
|
from .get_chat_admin_invite_links_count import GetChatAdminInviteLinksCount
|
||||||
from .get_chat_admins_with_invite_links import GetChatAdminsWithInviteLinks
|
from .get_chat_admins_with_invite_links import GetChatAdminsWithInviteLinks
|
||||||
from .get_chat_invite_link import GetChatInviteLink
|
from .get_chat_invite_link import GetChatInviteLink
|
||||||
from .get_chat_invite_link_members import GetChatInviteLinkMembers
|
from .get_chat_invite_link_joiners import GetChatInviteLinkJoiners
|
||||||
from .get_chat_invite_link_members_count import GetChatInviteLinkMembersCount
|
from .get_chat_invite_link_joiners_count import GetChatInviteLinkJoinersCount
|
||||||
|
from .get_chat_join_requests import GetChatJoinRequests
|
||||||
from .revoke_chat_invite_link import RevokeChatInviteLink
|
from .revoke_chat_invite_link import RevokeChatInviteLink
|
||||||
|
|
||||||
|
|
||||||
@ -38,8 +41,8 @@ class InviteLinks(
|
|||||||
DeleteChatInviteLink,
|
DeleteChatInviteLink,
|
||||||
EditChatInviteLink,
|
EditChatInviteLink,
|
||||||
CreateChatInviteLink,
|
CreateChatInviteLink,
|
||||||
GetChatInviteLinkMembers,
|
GetChatInviteLinkJoiners,
|
||||||
GetChatInviteLinkMembersCount,
|
GetChatInviteLinkJoinersCount,
|
||||||
GetChatAdminInviteLinks,
|
GetChatAdminInviteLinks,
|
||||||
ExportChatInviteLink,
|
ExportChatInviteLink,
|
||||||
DeleteChatAdminInviteLinks,
|
DeleteChatAdminInviteLinks,
|
||||||
@ -47,6 +50,9 @@ class InviteLinks(
|
|||||||
GetChatAdminsWithInviteLinks,
|
GetChatAdminsWithInviteLinks,
|
||||||
GetChatInviteLink,
|
GetChatInviteLink,
|
||||||
ApproveChatJoinRequest,
|
ApproveChatJoinRequest,
|
||||||
DeclineChatJoinRequest
|
DeclineChatJoinRequest,
|
||||||
|
ApproveAllChatJoinRequests,
|
||||||
|
DeclineAllChatJoinRequests,
|
||||||
|
GetChatJoinRequests
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
@ -23,13 +23,13 @@ from pyrogram import raw
|
|||||||
from pyrogram import types
|
from pyrogram import types
|
||||||
|
|
||||||
|
|
||||||
class GetChatInviteLinkMembers:
|
class GetChatInviteLinkJoiners:
|
||||||
async def get_chat_invite_link_members(
|
async def get_chat_invite_link_joiners(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
invite_link: str,
|
invite_link: str,
|
||||||
limit: int = 0
|
limit: int = 0
|
||||||
) -> Optional[AsyncGenerator["types.ChatMember", None]]:
|
) -> Optional[AsyncGenerator["types.ChatJoiner", None]]:
|
||||||
"""Get the members who joined the chat with the invite link.
|
"""Get the members who joined the chat with the invite link.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
@ -45,10 +45,10 @@ class GetChatInviteLinkMembers:
|
|||||||
By default, no limit is applied and all invite links are returned.
|
By default, no limit is applied and all invite links are returned.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
``Generator``: A generator yielding :obj:`~pyrogram.types.ChatMember` objects.
|
``Generator``: A generator yielding :obj:`~pyrogram.types.ChatJoiner` objects.
|
||||||
|
|
||||||
Yields:
|
Yields:
|
||||||
:obj:`~pyrogram.types.ChatMember` objects.
|
:obj:`~pyrogram.types.ChatJoiner` objects.
|
||||||
"""
|
"""
|
||||||
current = 0
|
current = 0
|
||||||
total = abs(limit) or (1 << 31) - 1
|
total = abs(limit) or (1 << 31) - 1
|
||||||
@ -77,13 +77,7 @@ class GetChatInviteLinkMembers:
|
|||||||
offset_user = await self.resolve_peer(r.importers[-1].user_id)
|
offset_user = await self.resolve_peer(r.importers[-1].user_id)
|
||||||
|
|
||||||
for i in r.importers:
|
for i in r.importers:
|
||||||
user = types.User._parse(self, users[i.user_id])
|
yield types.ChatJoiner._parse(self, i, users)
|
||||||
|
|
||||||
yield types.ChatMember(
|
|
||||||
user=user,
|
|
||||||
status="member",
|
|
||||||
joined_date=i.date
|
|
||||||
)
|
|
||||||
|
|
||||||
current += 1
|
current += 1
|
||||||
|
|
@ -22,8 +22,8 @@ import pyrogram
|
|||||||
from pyrogram import raw
|
from pyrogram import raw
|
||||||
|
|
||||||
|
|
||||||
class GetChatInviteLinkMembersCount:
|
class GetChatInviteLinkJoinersCount:
|
||||||
async def get_chat_invite_link_members_count(
|
async def get_chat_invite_link_joiners_count(
|
||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
invite_link: str
|
invite_link: str
|
86
pyrogram/methods/invite_links/get_chat_join_requests.py
Normal file
86
pyrogram/methods/invite_links/get_chat_join_requests.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
# 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, AsyncGenerator
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
from pyrogram import types
|
||||||
|
|
||||||
|
|
||||||
|
class GetChatJoinRequests:
|
||||||
|
async def get_chat_join_requests(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
chat_id: Union[int, str],
|
||||||
|
limit: int = 0,
|
||||||
|
query: str = ""
|
||||||
|
) -> Optional[AsyncGenerator["types.ChatJoiner", None]]:
|
||||||
|
"""Get the pending join requests of a chat.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier for the target chat or username of the target channel/supergroup
|
||||||
|
(in the format @username).
|
||||||
|
|
||||||
|
limit (``int``, *optional*):
|
||||||
|
Limits the number of invite links to be retrieved.
|
||||||
|
By default, no limit is applied and all invite links are returned.
|
||||||
|
|
||||||
|
query (``str``, *optional*):
|
||||||
|
Query to search for a user.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``Generator``: A generator yielding :obj:`~pyrogram.types.ChatJoiner` objects.
|
||||||
|
|
||||||
|
Yields:
|
||||||
|
:obj:`~pyrogram.types.ChatJoiner` objects.
|
||||||
|
"""
|
||||||
|
current = 0
|
||||||
|
total = abs(limit) or (1 << 31) - 1
|
||||||
|
limit = min(100, total)
|
||||||
|
|
||||||
|
offset_date = 0
|
||||||
|
offset_user = raw.types.InputUserEmpty()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.messages.GetChatInviteImporters(
|
||||||
|
peer=await self.resolve_peer(chat_id),
|
||||||
|
limit=limit,
|
||||||
|
offset_date=offset_date,
|
||||||
|
offset_user=offset_user,
|
||||||
|
requested=True,
|
||||||
|
q=query
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not r.importers:
|
||||||
|
break
|
||||||
|
|
||||||
|
users = {i.id: i for i in r.users}
|
||||||
|
|
||||||
|
offset_date = r.importers[-1].date
|
||||||
|
offset_user = await self.resolve_peer(r.importers[-1].user_id)
|
||||||
|
|
||||||
|
for i in r.importers:
|
||||||
|
yield types.ChatJoiner._parse(self, i, users)
|
||||||
|
|
||||||
|
current += 1
|
||||||
|
|
||||||
|
if current >= total:
|
||||||
|
return
|
@ -22,6 +22,7 @@ from .chat_event import ChatEvent
|
|||||||
from .chat_event_filter import ChatEventFilter
|
from .chat_event_filter import ChatEventFilter
|
||||||
from .chat_invite_link import ChatInviteLink
|
from .chat_invite_link import ChatInviteLink
|
||||||
from .chat_join_request import ChatJoinRequest
|
from .chat_join_request import ChatJoinRequest
|
||||||
|
from .chat_joiner import ChatJoiner
|
||||||
from .chat_member import ChatMember
|
from .chat_member import ChatMember
|
||||||
from .chat_member_updated import ChatMemberUpdated
|
from .chat_member_updated import ChatMemberUpdated
|
||||||
from .chat_permissions import ChatPermissions
|
from .chat_permissions import ChatPermissions
|
||||||
@ -57,5 +58,6 @@ __all__ = [
|
|||||||
"ChatMemberUpdated",
|
"ChatMemberUpdated",
|
||||||
"VoiceChatScheduled",
|
"VoiceChatScheduled",
|
||||||
"ChatJoinRequest",
|
"ChatJoinRequest",
|
||||||
"ChatPrivileges"
|
"ChatPrivileges",
|
||||||
|
"ChatJoiner"
|
||||||
]
|
]
|
||||||
|
82
pyrogram/types/user_and_chats/chat_joiner.py
Normal file
82
pyrogram/types/user_and_chats/chat_joiner.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
# 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 datetime import datetime
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, types, utils
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class ChatJoiner(Object):
|
||||||
|
"""Contains information about a joiner member of a chat.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
user (:obj:`~pyrogram.types.User`):
|
||||||
|
Information about the user.
|
||||||
|
|
||||||
|
date (:py:obj:`~datetime.datetime`):
|
||||||
|
Date when the user joined.
|
||||||
|
|
||||||
|
bio (``str``, *optional*):
|
||||||
|
Bio of the user.
|
||||||
|
|
||||||
|
pending (``bool``, *optional*):
|
||||||
|
True in case the chat joiner has a pending request.
|
||||||
|
|
||||||
|
approved_by (:obj:`~pyrogram.types.User`, *optional*):
|
||||||
|
Administrator who approved this chat joiner.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
client: "pyrogram.Client",
|
||||||
|
user: "types.User",
|
||||||
|
date: datetime = None,
|
||||||
|
bio: str = None,
|
||||||
|
pending: bool = None,
|
||||||
|
approved_by: "types.User" = None,
|
||||||
|
):
|
||||||
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.user = user
|
||||||
|
self.date = date
|
||||||
|
self.bio = bio
|
||||||
|
self.pending = pending
|
||||||
|
self.approved_by = approved_by
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse(
|
||||||
|
client: "pyrogram.Client",
|
||||||
|
joiner: "raw.base.ChatInviteImporter",
|
||||||
|
users: Dict[int, "raw.base.User"],
|
||||||
|
) -> "ChatJoiner":
|
||||||
|
return ChatJoiner(
|
||||||
|
user=types.User._parse(client, users[joiner.user_id]),
|
||||||
|
date=utils.timestamp_to_datetime(joiner.date),
|
||||||
|
pending=joiner.requested,
|
||||||
|
bio=joiner.about,
|
||||||
|
approved_by=(
|
||||||
|
types.User._parse(client, users[joiner.approved_by])
|
||||||
|
if joiner.approved_by
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
client=client
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user