Allow passing raw
This commit is contained in:
parent
cffafa8c61
commit
66cd896a99
@ -84,7 +84,7 @@ class ChatMember(PyrogramType):
|
||||
can_delete_messages: bool = None, can_invite_users: bool = None, can_restrict_members: bool = None,
|
||||
can_pin_messages: bool = None, can_promote_members: bool = None, can_send_messages: bool = None,
|
||||
can_send_media_messages: bool = None, can_send_other_messages: bool = None,
|
||||
can_add_web_page_previews: bool = None, client=None):
|
||||
can_add_web_page_previews: bool = None, client, raw):
|
||||
self.user = user
|
||||
self.status = status
|
||||
self.until_date = until_date
|
||||
@ -102,18 +102,19 @@ class ChatMember(PyrogramType):
|
||||
self.can_send_other_messages = can_send_other_messages
|
||||
self.can_add_web_page_previews = can_add_web_page_previews
|
||||
|
||||
self.client = client
|
||||
self._client = client
|
||||
self._raw = raw
|
||||
|
||||
@staticmethod
|
||||
def parse(client, member, user) -> "ChatMember":
|
||||
if isinstance(member, (types.ChannelParticipant, types.ChannelParticipantSelf, types.ChatParticipant)):
|
||||
return ChatMember(user=user, status="member", client=client)
|
||||
return ChatMember(user=user, status="member", client=client, raw=member)
|
||||
|
||||
if isinstance(member, (types.ChannelParticipantCreator, types.ChatParticipantCreator)):
|
||||
return ChatMember(user=user, status="creator", client=client)
|
||||
return ChatMember(user=user, status="creator", client=client, raw=member)
|
||||
|
||||
if isinstance(member, types.ChatParticipantAdmin):
|
||||
return ChatMember(user=user, status="administrator", client=client)
|
||||
return ChatMember(user=user, status="administrator", client=client, raw=member)
|
||||
|
||||
if isinstance(member, types.ChannelParticipantAdmin):
|
||||
rights = member.admin_rights
|
||||
@ -130,7 +131,7 @@ class ChatMember(PyrogramType):
|
||||
can_restrict_members=rights.ban_users,
|
||||
can_pin_messages=rights.pin_messages,
|
||||
can_promote_members=rights.add_admins,
|
||||
client=client
|
||||
client=client, raw=member
|
||||
)
|
||||
|
||||
if isinstance(member, types.ChannelParticipantBanned):
|
||||
@ -140,7 +141,7 @@ class ChatMember(PyrogramType):
|
||||
user=user,
|
||||
status="kicked" if rights.view_messages else "restricted",
|
||||
until_date=0 if rights.until_date == (1 << 31) - 1 else rights.until_date,
|
||||
client=client
|
||||
client=client, raw=member
|
||||
)
|
||||
|
||||
if chat_member.status == "restricted":
|
||||
|
@ -17,8 +17,9 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from .chat_member import ChatMember
|
||||
from .user import User
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ..user_and_chats import ChatMember, User
|
||||
|
||||
|
||||
class ChatMembers(PyrogramType):
|
||||
@ -32,14 +33,18 @@ class ChatMembers(PyrogramType):
|
||||
Requested chat members.
|
||||
"""
|
||||
|
||||
def __init__(self, *, total_count: int, chat_members: list, client=None):
|
||||
def __init__(self, *, total_count: int, chat_members: list, client, raw):
|
||||
self.total_count = total_count
|
||||
self.chat_members = chat_members
|
||||
|
||||
self.client = client
|
||||
self._client = client
|
||||
self._raw = raw
|
||||
|
||||
@staticmethod
|
||||
def parse(client, members, users: dict):
|
||||
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
|
||||
@ -47,8 +52,6 @@ class ChatMembers(PyrogramType):
|
||||
members = members.full_chat.participants.participants
|
||||
total_count = len(members)
|
||||
|
||||
chat_members = []
|
||||
|
||||
for member in members:
|
||||
user = User.parse(client, users[member.user_id])
|
||||
chat_members.append(ChatMember.parse(client, member, user))
|
||||
@ -56,5 +59,5 @@ class ChatMembers(PyrogramType):
|
||||
return ChatMembers(
|
||||
total_count=total_count,
|
||||
chat_members=chat_members,
|
||||
client=client
|
||||
client=client, raw=members
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user