2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Remove ChatMembers type

This commit is contained in:
Dan 2019-06-08 13:49:01 +02:00
parent 2e05c81a5c
commit 2db2ca3283
7 changed files with 38 additions and 100 deletions

View File

@ -30,7 +30,6 @@ Users & Chats
- :class:`ChatPreview` - :class:`ChatPreview`
- :class:`ChatPhoto` - :class:`ChatPhoto`
- :class:`ChatMember` - :class:`ChatMember`
- :class:`ChatMembers`
- :class:`ChatPermissions` - :class:`ChatPermissions`
- :class:`Dialog` - :class:`Dialog`
- :class:`Dialogs` - :class:`Dialogs`
@ -123,7 +122,6 @@ Details
.. autoclass:: ChatPreview() .. autoclass:: ChatPreview()
.. autoclass:: ChatPhoto() .. autoclass:: ChatPhoto()
.. autoclass:: ChatMember() .. autoclass:: ChatMember()
.. autoclass:: ChatMembers()
.. autoclass:: ChatPermissions() .. autoclass:: ChatPermissions()
.. autoclass:: Dialog() .. autoclass:: Dialog()
.. autoclass:: Dialogs() .. autoclass:: Dialogs()

View File

@ -51,13 +51,18 @@ class GetChatMember(BaseClient):
user = self.resolve_peer(user_id) user = self.resolve_peer(user_id)
if isinstance(chat, types.InputPeerChat): if isinstance(chat, types.InputPeerChat):
full_chat = self.send( r = self.send(
functions.messages.GetFullChat( functions.messages.GetFullChat(
chat_id=chat.chat_id 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 isinstance(user, types.InputPeerSelf):
if member.user.is_self: if member.user.is_self:
return member return member

View File

@ -18,7 +18,7 @@
import logging import logging
import time import time
from typing import Union from typing import Union, List
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
@ -45,7 +45,7 @@ class GetChatMembers(BaseClient):
limit: int = 200, limit: int = 200,
query: str = "", query: str = "",
filter: str = Filters.ALL filter: str = Filters.ALL
) -> "pyrogram.ChatMembers": ) -> List["pyrogram.ChatMember"]:
"""Get a chunk of the members list of a chat. """Get a chunk of the members list of a chat.
You can get up to 200 chat members at once. You can get up to 200 chat members at once.
@ -59,15 +59,16 @@ class GetChatMembers(BaseClient):
offset (``int``, *optional*): offset (``int``, *optional*):
Sequential number of the first member to be returned. 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*): limit (``int``, *optional*):
Limits the number of members to be retrieved. 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. Defaults to 200, which is also the maximum server limit allowed per method call.
query (``str``, *optional*): query (``str``, *optional*):
Query string to filter members based on their display names and usernames. 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 (``str``, *optional*):
Filter used to select the kind of members you want to retrieve. Only applicable for supergroups 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, *"bots"* - bots only,
*"recent"* - recent members only, *"recent"* - recent members only,
*"administrators"* - chat administrators only. *"administrators"* - chat administrators only.
Only applicable to supergroups and channels.
Defaults to *"all"*. 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 .. [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. .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only.
Returns: 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: Raises:
RPCError: In case of a Telegram RPC error. RPCError: In case of a Telegram RPC error.
@ -95,14 +97,16 @@ class GetChatMembers(BaseClient):
peer = self.resolve_peer(chat_id) peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChat): if isinstance(peer, types.InputPeerChat):
return pyrogram.ChatMembers._parse( r = self.send(
self, functions.messages.GetFullChat(
self.send( chat_id=peer.chat_id
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): elif isinstance(peer, types.InputPeerChannel):
filter = filter.lower() filter = filter.lower()
@ -123,18 +127,20 @@ class GetChatMembers(BaseClient):
while True: while True:
try: try:
return pyrogram.ChatMembers._parse( r = self.send(
self, functions.channels.GetParticipants(
self.send( channel=peer,
functions.channels.GetParticipants( filter=filter,
channel=peer, offset=offset,
filter=filter, limit=limit,
offset=offset, hash=0
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: except FloodWait as e:
log.warning("Sleeping for {}s".format(e.x)) log.warning("Sleeping for {}s".format(e.x))
time.sleep(e.x) time.sleep(e.x)

View File

@ -106,7 +106,7 @@ class IterChatMembers(BaseClient):
limit=limit, limit=limit,
query=q, query=q,
filter=filter filter=filter
).chat_members )
if not chat_members: if not chat_members:
break break

View File

@ -20,6 +20,8 @@ from .keyboards import *
from .inline_mode import * from .inline_mode import *
from .input_media import * from .input_media import *
from .input_message_content import * from .input_message_content import *
from .list import List
from .messages_and_media import * from .messages_and_media import *
from .object import Object
from .update import * from .update import *
from .user_and_chats import * from .user_and_chats import *

View File

@ -18,7 +18,6 @@
from .chat import Chat from .chat import Chat
from .chat_member import ChatMember from .chat_member import ChatMember
from .chat_members import ChatMembers
from .chat_permissions import ChatPermissions from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto from .chat_photo import ChatPhoto
from .chat_preview import ChatPreview from .chat_preview import ChatPreview
@ -28,6 +27,5 @@ from .user import User
from .user_status import UserStatus from .user_status import UserStatus
__all__ = [ __all__ = [
"Chat", "ChatMember", "ChatMembers", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", "Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", "UserStatus"
"UserStatus"
] ]

View File

@ -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
)