Remove ChatMembers type
This commit is contained in:
parent
2e05c81a5c
commit
2db2ca3283
@ -30,7 +30,6 @@ Users & Chats
|
||||
- :class:`ChatPreview`
|
||||
- :class:`ChatPhoto`
|
||||
- :class:`ChatMember`
|
||||
- :class:`ChatMembers`
|
||||
- :class:`ChatPermissions`
|
||||
- :class:`Dialog`
|
||||
- :class:`Dialogs`
|
||||
@ -123,7 +122,6 @@ Details
|
||||
.. autoclass:: ChatPreview()
|
||||
.. autoclass:: ChatPhoto()
|
||||
.. autoclass:: ChatMember()
|
||||
.. autoclass:: ChatMembers()
|
||||
.. autoclass:: ChatPermissions()
|
||||
.. autoclass:: Dialog()
|
||||
.. autoclass:: Dialogs()
|
||||
|
@ -51,13 +51,18 @@ class GetChatMember(BaseClient):
|
||||
user = self.resolve_peer(user_id)
|
||||
|
||||
if isinstance(chat, types.InputPeerChat):
|
||||
full_chat = self.send(
|
||||
r = self.send(
|
||||
functions.messages.GetFullChat(
|
||||
chat_id=chat.chat_id
|
||||
)
|
||||
)
|
||||
|
||||
for member in pyrogram.ChatMembers._parse(self, full_chat).chat_members:
|
||||
members = r.full_chat.participants.participants
|
||||
users = {i.id: i for i in r.users}
|
||||
|
||||
for member in members:
|
||||
member = pyrogram.ChatMember._parse(self, member, users)
|
||||
|
||||
if isinstance(user, types.InputPeerSelf):
|
||||
if member.user.is_self:
|
||||
return member
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
import logging
|
||||
import time
|
||||
from typing import Union
|
||||
from typing import Union, List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import functions, types
|
||||
@ -45,7 +45,7 @@ class GetChatMembers(BaseClient):
|
||||
limit: int = 200,
|
||||
query: str = "",
|
||||
filter: str = Filters.ALL
|
||||
) -> "pyrogram.ChatMembers":
|
||||
) -> List["pyrogram.ChatMember"]:
|
||||
"""Get a chunk of the members list of a chat.
|
||||
|
||||
You can get up to 200 chat members at once.
|
||||
@ -59,15 +59,16 @@ class GetChatMembers(BaseClient):
|
||||
|
||||
offset (``int``, *optional*):
|
||||
Sequential number of the first member to be returned.
|
||||
Defaults to 0 [1]_.
|
||||
Only applicable to supergroups and channels. Defaults to 0 [1]_.
|
||||
|
||||
limit (``int``, *optional*):
|
||||
Limits the number of members to be retrieved.
|
||||
Only applicable to supergroups and channels.
|
||||
Defaults to 200, which is also the maximum server limit allowed per method call.
|
||||
|
||||
query (``str``, *optional*):
|
||||
Query string to filter members based on their display names and usernames.
|
||||
Defaults to "" (empty string) [2]_.
|
||||
Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_.
|
||||
|
||||
filter (``str``, *optional*):
|
||||
Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
|
||||
@ -78,6 +79,7 @@ class GetChatMembers(BaseClient):
|
||||
*"bots"* - bots only,
|
||||
*"recent"* - recent members only,
|
||||
*"administrators"* - chat administrators only.
|
||||
Only applicable to supergroups and channels.
|
||||
Defaults to *"all"*.
|
||||
|
||||
.. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
|
||||
@ -86,7 +88,7 @@ class GetChatMembers(BaseClient):
|
||||
.. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only.
|
||||
|
||||
Returns:
|
||||
:obj:`ChatMembers`: On success, an object containing a list of chat members is returned.
|
||||
List of :obj:`ChatMember`: On success, a list of chat members is returned.
|
||||
|
||||
Raises:
|
||||
RPCError: In case of a Telegram RPC error.
|
||||
@ -95,14 +97,16 @@ class GetChatMembers(BaseClient):
|
||||
peer = self.resolve_peer(chat_id)
|
||||
|
||||
if isinstance(peer, types.InputPeerChat):
|
||||
return pyrogram.ChatMembers._parse(
|
||||
self,
|
||||
self.send(
|
||||
functions.messages.GetFullChat(
|
||||
chat_id=peer.chat_id
|
||||
)
|
||||
r = self.send(
|
||||
functions.messages.GetFullChat(
|
||||
chat_id=peer.chat_id
|
||||
)
|
||||
)
|
||||
|
||||
members = r.full_chat.participants.participants
|
||||
users = {i.id: i for i in r.users}
|
||||
|
||||
return pyrogram.List(pyrogram.ChatMember._parse(self, member, users) for member in members)
|
||||
elif isinstance(peer, types.InputPeerChannel):
|
||||
filter = filter.lower()
|
||||
|
||||
@ -123,18 +127,20 @@ class GetChatMembers(BaseClient):
|
||||
|
||||
while True:
|
||||
try:
|
||||
return pyrogram.ChatMembers._parse(
|
||||
self,
|
||||
self.send(
|
||||
functions.channels.GetParticipants(
|
||||
channel=peer,
|
||||
filter=filter,
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
hash=0
|
||||
)
|
||||
r = self.send(
|
||||
functions.channels.GetParticipants(
|
||||
channel=peer,
|
||||
filter=filter,
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
hash=0
|
||||
)
|
||||
)
|
||||
|
||||
members = r.participants
|
||||
users = {i.id: i for i in r.users}
|
||||
|
||||
return pyrogram.List(pyrogram.ChatMember._parse(self, member, users) for member in members)
|
||||
except FloodWait as e:
|
||||
log.warning("Sleeping for {}s".format(e.x))
|
||||
time.sleep(e.x)
|
||||
|
@ -106,7 +106,7 @@ class IterChatMembers(BaseClient):
|
||||
limit=limit,
|
||||
query=q,
|
||||
filter=filter
|
||||
).chat_members
|
||||
)
|
||||
|
||||
if not chat_members:
|
||||
break
|
||||
|
@ -20,6 +20,8 @@ from .keyboards import *
|
||||
from .inline_mode import *
|
||||
from .input_media import *
|
||||
from .input_message_content import *
|
||||
from .list import List
|
||||
from .messages_and_media import *
|
||||
from .object import Object
|
||||
from .update import *
|
||||
from .user_and_chats import *
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
from .chat import Chat
|
||||
from .chat_member import ChatMember
|
||||
from .chat_members import ChatMembers
|
||||
from .chat_permissions import ChatPermissions
|
||||
from .chat_photo import ChatPhoto
|
||||
from .chat_preview import ChatPreview
|
||||
@ -28,6 +27,5 @@ from .user import User
|
||||
from .user_status import UserStatus
|
||||
|
||||
__all__ = [
|
||||
"Chat", "ChatMember", "ChatMembers", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User",
|
||||
"UserStatus"
|
||||
"Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", "UserStatus"
|
||||
]
|
||||
|
@ -1,71 +0,0 @@
|
||||
# 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 List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .chat_member import ChatMember
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class ChatMembers(Object):
|
||||
"""Contains information about the members list of a chat.
|
||||
|
||||
Parameters:
|
||||
total_count (``int``):
|
||||
Total number of members the chat has.
|
||||
|
||||
chat_members (List of :obj:`ChatMember <pyrogram.ChatMember>`):
|
||||
Requested chat members.
|
||||
"""
|
||||
|
||||
__slots__ = ["total_count", "chat_members"]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
total_count: int,
|
||||
chat_members: List[ChatMember]
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.total_count = total_count
|
||||
self.chat_members = chat_members
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, members):
|
||||
users = {i.id: i for i in members.users}
|
||||
chat_members = []
|
||||
|
||||
if isinstance(members, types.channels.ChannelParticipants):
|
||||
total_count = members.count
|
||||
members = members.participants
|
||||
else:
|
||||
members = members.full_chat.participants.participants
|
||||
total_count = len(members)
|
||||
|
||||
for member in members:
|
||||
chat_members.append(ChatMember._parse(client, member, users))
|
||||
|
||||
return ChatMembers(
|
||||
total_count=total_count,
|
||||
chat_members=chat_members,
|
||||
client=client
|
||||
)
|
Loading…
Reference in New Issue
Block a user