From b1dc0315a137242c66aca62300c935392028275e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Mar 2021 16:32:10 +0100 Subject: [PATCH] Update API schema to Layer 126 --- compiler/api/source/main_api.tl | 14 +++++++------- pyrogram/methods/chats/get_chat_member.py | 7 ++++--- pyrogram/methods/chats/get_chat_members.py | 5 +++-- pyrogram/methods/chats/kick_chat_member.py | 2 +- pyrogram/methods/chats/unban_chat_member.py | 2 +- pyrogram/types/user_and_chats/chat_event.py | 10 +++++----- pyrogram/types/user_and_chats/chat_member.py | 10 ++++++++-- .../types/user_and_chats/chat_member_updated.py | 4 ++-- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 9d1ef451..c7bea223 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -598,8 +598,8 @@ channelParticipant#15ebac1d user_id:int date:int = ChannelParticipant; channelParticipantSelf#a3289a6d user_id:int inviter_id:int date:int = ChannelParticipant; channelParticipantCreator#447dca4b flags:# user_id:int admin_rights:ChatAdminRights rank:flags.0?string = ChannelParticipant; channelParticipantAdmin#ccbebbaf flags:# can_edit:flags.0?true self:flags.1?true user_id:int inviter_id:flags.1?int promoted_by:int date:int admin_rights:ChatAdminRights rank:flags.2?string = ChannelParticipant; -channelParticipantBanned#1c0facaf flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant; -channelParticipantLeft#c3c6796b user_id:int = ChannelParticipant; +channelParticipantBanned#50a1dfd6 flags:# left:flags.0?true peer:Peer kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant; +channelParticipantLeft#1b03f006 peer:Peer = ChannelParticipant; channelParticipantsRecent#de3f3c79 = ChannelParticipantsFilter; channelParticipantsAdmins#b4608969 = ChannelParticipantsFilter; @@ -610,10 +610,10 @@ channelParticipantsSearch#656ac4b q:string = ChannelParticipantsFilter; channelParticipantsContacts#bb6ae88d q:string = ChannelParticipantsFilter; channelParticipantsMentions#e04b5ceb flags:# q:flags.0?string top_msg_id:flags.1?int = ChannelParticipantsFilter; -channels.channelParticipants#f56ee2a8 count:int participants:Vector users:Vector = channels.ChannelParticipants; +channels.channelParticipants#9ab0feaf count:int participants:Vector chats:Vector users:Vector = channels.ChannelParticipants; channels.channelParticipantsNotModified#f0173fe9 = channels.ChannelParticipants; -channels.channelParticipant#d0d9b163 participant:ChannelParticipant users:Vector = channels.ChannelParticipant; +channels.channelParticipant#dfb80317 participant:ChannelParticipant chats:Vector users:Vector = channels.ChannelParticipant; help.termsOfService#780a0310 flags:# popup:flags.0?true id:DataJSON text:string entities:Vector min_age_confirm:flags.1?int = help.TermsOfService; @@ -1535,7 +1535,7 @@ channels.deleteUserHistory#d10dd71b channel:InputChannel user_id:InputUser = mes channels.reportSpam#fe087810 channel:InputChannel user_id:InputUser id:Vector = Bool; channels.getMessages#ad8c9a23 channel:InputChannel id:Vector = messages.Messages; channels.getParticipants#123e05e9 channel:InputChannel filter:ChannelParticipantsFilter offset:int limit:int hash:int = channels.ChannelParticipants; -channels.getParticipant#546dd7a6 channel:InputChannel user_id:InputUser = channels.ChannelParticipant; +channels.getParticipant#a0ab6cc6 channel:InputChannel participant:InputPeer = channels.ChannelParticipant; channels.getChannels#a7f6bbb id:Vector = messages.Chats; channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull; channels.createChannel#3d5fb10f flags:# broadcast:flags.0?true megagroup:flags.1?true for_import:flags.3?true title:string about:string geo_point:flags.2?InputGeoPoint address:flags.2?string = Updates; @@ -1551,7 +1551,7 @@ channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; channels.exportMessageLink#e63fadeb flags:# grouped:flags.0?true thread:flags.1?true channel:InputChannel id:int = ExportedMessageLink; channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.getAdminedPublicChannels#f8b036af flags:# by_location:flags.0?true check_limit:flags.1?true = messages.Chats; -channels.editBanned#72796912 channel:InputChannel user_id:InputUser banned_rights:ChatBannedRights = Updates; +channels.editBanned#96e6cd81 channel:InputChannel participant:InputPeer banned_rights:ChatBannedRights = Updates; channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector max_id:long min_id:long limit:int = channels.AdminLogResults; channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = Bool; channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; @@ -1623,4 +1623,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 125 \ No newline at end of file +// LAYER 126 \ No newline at end of file diff --git a/pyrogram/methods/chats/get_chat_member.py b/pyrogram/methods/chats/get_chat_member.py index 7f649a21..74aff5da 100644 --- a/pyrogram/methods/chats/get_chat_member.py +++ b/pyrogram/methods/chats/get_chat_member.py @@ -64,7 +64,7 @@ class GetChatMember(Scaffold): users = {i.id: i for i in r.users} for member in members: - member = types.ChatMember._parse(self, member, users) + member = types.ChatMember._parse(self, member, users, {}) if isinstance(user, raw.types.InputPeerSelf): if member.user.is_self: @@ -78,12 +78,13 @@ class GetChatMember(Scaffold): r = await self.send( raw.functions.channels.GetParticipant( channel=chat, - user_id=user + participant=user ) ) users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} - return types.ChatMember._parse(self, r.participant, users) + return types.ChatMember._parse(self, r.participant, users, chats) else: raise ValueError(f'The chat_id "{chat_id}" belongs to a user') diff --git a/pyrogram/methods/chats/get_chat_members.py b/pyrogram/methods/chats/get_chat_members.py index a27478fd..1f891b46 100644 --- a/pyrogram/methods/chats/get_chat_members.py +++ b/pyrogram/methods/chats/get_chat_members.py @@ -115,7 +115,7 @@ class GetChatMembers(Scaffold): members = r.full_chat.participants.participants users = {i.id: i for i in r.users} - return types.List(types.ChatMember._parse(self, member, users) for member in members) + return types.List(types.ChatMember._parse(self, member, users, {}) for member in members) elif isinstance(peer, raw.types.InputPeerChannel): filter = filter.lower() @@ -147,7 +147,8 @@ class GetChatMembers(Scaffold): members = r.participants users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} - return types.List(types.ChatMember._parse(self, member, users) for member in members) + return types.List(types.ChatMember._parse(self, member, users, chats) for member in members) else: raise ValueError(f'The chat_id "{chat_id}" belongs to a user') diff --git a/pyrogram/methods/chats/kick_chat_member.py b/pyrogram/methods/chats/kick_chat_member.py index 50c98219..495eac94 100644 --- a/pyrogram/methods/chats/kick_chat_member.py +++ b/pyrogram/methods/chats/kick_chat_member.py @@ -75,7 +75,7 @@ class KickChatMember(Scaffold): r = await self.send( raw.functions.channels.EditBanned( channel=chat_peer, - user_id=user_peer, + participant=user_peer, banned_rights=raw.types.ChatBannedRights( until_date=until_date, view_messages=True, diff --git a/pyrogram/methods/chats/unban_chat_member.py b/pyrogram/methods/chats/unban_chat_member.py index ce004577..44c19286 100644 --- a/pyrogram/methods/chats/unban_chat_member.py +++ b/pyrogram/methods/chats/unban_chat_member.py @@ -52,7 +52,7 @@ class UnbanChatMember(Scaffold): await self.send( raw.functions.channels.EditBanned( channel=await self.resolve_peer(chat_id), - user_id=await self.resolve_peer(user_id), + participant=await self.resolve_peer(user_id), banned_rights=raw.types.ChatBannedRights( until_date=0 ) diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py index 7b97a31c..3d0bbe19 100644 --- a/pyrogram/types/user_and_chats/chat_event.py +++ b/pyrogram/types/user_and_chats/chat_event.py @@ -475,17 +475,17 @@ class ChatEvent(Object): action = ChatEventAction.MESSAGE_EDITED.value elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantInvite): - invited_member = types.ChatMember._parse(client, action.participant, users) + invited_member = types.ChatMember._parse(client, action.participant, users, chats) action = ChatEventAction.MEMBER_INVITED.value elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleAdmin): - old_admin_rights = types.ChatMember._parse(client, action.prev_participant, users) - new_admin_rights = types.ChatMember._parse(client, action.new_participant, users) + old_admin_rights = types.ChatMember._parse(client, action.prev_participant, users, chats) + new_admin_rights = types.ChatMember._parse(client, action.new_participant, users, chats) action = ChatEventAction.ADMIN_RIGHTS_CHANGED.value elif isinstance(action, raw.types.ChannelAdminLogEventActionParticipantToggleBan): - old_member_permissions = types.ChatMember._parse(client, action.prev_participant, users) - new_member_permissions = types.ChatMember._parse(client, action.new_participant, users) + old_member_permissions = types.ChatMember._parse(client, action.prev_participant, users, chats) + new_member_permissions = types.ChatMember._parse(client, action.new_participant, users, chats) action = ChatEventAction.MEMBER_PERMISSIONS_CHANGED.value elif isinstance(action, raw.types.ChannelAdminLogEventActionStopPoll): diff --git a/pyrogram/types/user_and_chats/chat_member.py b/pyrogram/types/user_and_chats/chat_member.py index 7853042a..d33bcfc5 100644 --- a/pyrogram/types/user_and_chats/chat_member.py +++ b/pyrogram/types/user_and_chats/chat_member.py @@ -212,8 +212,14 @@ class ChatMember(Object): self.can_send_polls = can_send_polls @staticmethod - def _parse(client, member, users) -> "ChatMember": - user = types.User._parse(client, users[member.user_id]) + def _parse(client, member, users, chats) -> "ChatMember": + if not isinstance(member, (raw.types.ChannelParticipantBanned, raw.types.ChannelParticipantLeft)): + user = types.User._parse(client, users[member.user_id]) + else: + if isinstance(member.peer, raw.types.PeerUser): + user = types.User._parse(client, users[member.peer.user_id]) + else: + user = None invited_by = ( types.User._parse(client, users[member.inviter_id]) diff --git a/pyrogram/types/user_and_chats/chat_member_updated.py b/pyrogram/types/user_and_chats/chat_member_updated.py index 31cec664..a8d7abca 100644 --- a/pyrogram/types/user_and_chats/chat_member_updated.py +++ b/pyrogram/types/user_and_chats/chat_member_updated.py @@ -82,10 +82,10 @@ class ChatMemberUpdated(Object, Update): invite_link = None if update.prev_participant: - old_chat_member = types.ChatMember._parse(client, update.prev_participant, users) + old_chat_member = types.ChatMember._parse(client, update.prev_participant, users, chats) if update.new_participant: - new_chat_member = types.ChatMember._parse(client, update.new_participant, users) + new_chat_member = types.ChatMember._parse(client, update.new_participant, users, chats) if update.invite: invite_link = types.ChatInviteLink._parse(client, update.invite, users)