From 0a4d54fca44cda198914501e4bc929396fa6d2ac Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 11 Dec 2020 16:55:49 +0100 Subject: [PATCH] Update to layer 122 Closes #1645. --- telethon/client/chats.py | 23 ++++++--- telethon/tl/custom/adminlogevent.py | 61 +++++++++++++++++++++++ telethon/utils.py | 11 ++++ telethon_generator/data/api.tl | 51 ++++++++++++++++--- telethon_generator/generators/tlobject.py | 1 + 5 files changed, 135 insertions(+), 12 deletions(-) diff --git a/telethon/client/chats.py b/telethon/client/chats.py index 64cbe52b..4ccae265 100644 --- a/telethon/client/chats.py +++ b/telethon/client/chats.py @@ -221,15 +221,17 @@ class _AdminLogIter(RequestIter): async def _init( self, entity, admins, search, min_id, max_id, join, leave, invite, restrict, unrestrict, ban, unban, - promote, demote, info, settings, pinned, edit, delete + promote, demote, info, settings, pinned, edit, delete, + group_call ): if any((join, leave, invite, restrict, unrestrict, ban, unban, - promote, demote, info, settings, pinned, edit, delete)): + promote, demote, info, settings, pinned, edit, delete, + group_call)): events_filter = types.ChannelAdminLogEventsFilter( join=join, leave=leave, invite=invite, ban=restrict, unban=unrestrict, kick=ban, unkick=unban, promote=promote, demote=demote, info=info, settings=settings, pinned=pinned, - edit=edit, delete=delete + edit=edit, delete=delete, group_call=group_call ) else: events_filter = None @@ -495,7 +497,8 @@ class ChatMethods: settings: bool = None, pinned: bool = None, edit: bool = None, - delete: bool = None) -> _AdminLogIter: + delete: bool = None, + group_call: bool = None) -> _AdminLogIter: """ Iterator over the admin log for the specified channel. @@ -582,6 +585,9 @@ class ChatMethods: delete (`bool`): If `True`, events of message deletions will be returned. + group_call (`bool`): + If `True`, events related to group calls will be returned. + Yields Instances of `AdminLogEvent `. @@ -613,7 +619,8 @@ class ChatMethods: settings=settings, pinned=pinned, edit=edit, - delete=delete + delete=delete, + group_call=group_call ) async def get_admin_log( @@ -811,6 +818,7 @@ class ChatMethods: invite_users: bool = None, pin_messages: bool = None, add_admins: bool = None, + manage_call: bool = True, anonymous: bool = None, is_admin: bool = None, title: str = None) -> types.Updates: @@ -855,6 +863,9 @@ class ChatMethods: add_admins (`bool`, optional): Whether the user will be able to add admins. + manage_call (`bool`, optional): + Whether the user will be able to manage group calls. + anonymous (`bool`, optional): Whether the user will remain anonymous when sending messages. The sender of the anonymous messages becomes the group itself. @@ -907,7 +918,7 @@ class ChatMethods: perm_names = ( 'change_info', 'post_messages', 'edit_messages', 'delete_messages', 'ban_users', 'invite_users', 'pin_messages', 'add_admins', - 'anonymous', + 'anonymous', 'manage_call', ) ty = helpers._entity_type(entity) diff --git a/telethon/tl/custom/adminlogevent.py b/telethon/tl/custom/adminlogevent.py index a1744017..0a299171 100644 --- a/telethon/tl/custom/adminlogevent.py +++ b/telethon/tl/custom/adminlogevent.py @@ -91,6 +91,8 @@ class AdminLogEvent: return ori.message elif isinstance(ori, types.ChannelAdminLogEventActionDefaultBannedRights): return ori.prev_banned_rights + elif isinstance(ori, types.ChannelAdminLogEventActionDiscardGroupCall): + return ori.call @property def new(self): @@ -125,6 +127,15 @@ class AdminLogEvent: return ori.new_banned_rights elif isinstance(ori, types.ChannelAdminLogEventActionStopPoll): return ori.message + elif isinstance(ori, types.ChannelAdminLogEventActionStartGroupCall): + return ori.call + elif isinstance(ori, ( + types.ChannelAdminLogEventActionParticipantMute, + types.ChannelAdminLogEventActionParticipantUnmute, + )): + return ori.participant + elif isinstance(ori, types.ChannelAdminLogEventActionToggleGroupCallSetting): + return ori.join_muted @property def changed_about(self): @@ -327,6 +338,56 @@ class AdminLogEvent: return isinstance(self.original.action, types.ChannelAdminLogEventActionStopPoll) + @property + def started_group_call(self): + """ + Whether a group call was started or not. + + If `True`, `new` will be present as :tl:`InputGroupCall`. + """ + return isinstance(self.original.action, + types.ChannelAdminLogEventActionStartGroupCall) + + @property + def discarded_group_call(self): + """ + Whether a group call was started or not. + + If `True`, `old` will be present as :tl:`InputGroupCall`. + """ + return isinstance(self.original.action, + types.ChannelAdminLogEventActionDiscardGroupCall) + + @property + def user_muted(self): + """ + Whether a participant was muted in the ongoing group call or not. + + If `True`, `new` will be present as :tl:`GroupCallParticipant`. + """ + return isinstance(self.original.action, + types.ChannelAdminLogEventActionParticipantMute) + + @property + def user_unmutted(self): + """ + Whether a participant was unmuted from the ongoing group call or not. + + If `True`, `new` will be present as :tl:`GroupCallParticipant`. + """ + return isinstance(self.original.action, + types.ChannelAdminLogEventActionParticipantUnmute) + + @property + def changed_call_settings(self): + """ + Whether the group call settings were changed or not. + + If `True`, `new` will be `True` if new users are muted on join. + """ + return isinstance(self.original.action, + types.ChannelAdminLogEventActionToggleGroupCallSetting) + def __str__(self): return str(self.original) diff --git a/telethon/utils.py b/telethon/utils.py index 866a4972..636dd93d 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -564,6 +564,17 @@ def get_input_message(message): _raise_cast_fail(message, 'InputMedia') +def get_input_group_call(call): + """Similar to :meth:`get_input_peer`, but for input calls.""" + try: + if call.SUBCLASS_OF_ID == 0x58611ab1: # crc32(b'InputGroupCall') + return call + elif call.SUBCLASS_OF_ID == 0x20b4f320: # crc32(b'GroupCall') + return types.InputGroupCall(id=call.id, access_hash=call.access_hash) + except AttributeError: + _raise_cast_fail(call, 'InputGroupCall') + + def _get_entity_pair(entity_id, entities, cache, get_input_peer=get_input_peer): """ diff --git a/telethon_generator/data/api.tl b/telethon_generator/data/api.tl index 06f21cc2..4c7722f4 100644 --- a/telethon_generator/data/api.tl +++ b/telethon_generator/data/api.tl @@ -124,11 +124,11 @@ userStatusLastMonth#77ebc742 = UserStatus; chatEmpty#9ba2d800 id:int = Chat; chat#3bda1bde flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat; chatForbidden#7328bdb id:int title:string = Chat; -channel#d31a961e flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat; +channel#d31a961e flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?Vector admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat; channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat; chatFull#1b7c9db3 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int = ChatFull; -channelFull#f0e6672a flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int = ChatFull; +channelFull#ef3a6acd flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall = ChatFull; chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant; chatParticipantCreator#da13538a user_id:int = ChatParticipant; @@ -182,6 +182,8 @@ messageActionSecureValuesSentMe#1b287353 values:Vector credentials: messageActionSecureValuesSent#d95c6154 types:Vector = MessageAction; messageActionContactSignUp#f3f25f76 = MessageAction; messageActionGeoProximityReached#98e0d697 from_id:Peer to_id:Peer distance:int = MessageAction; +messageActionGroupCall#7a0d7f42 flags:# call:InputGroupCall duration:flags.0?int = MessageAction; +messageActionInviteToGroupCall#76b9f11a call:InputGroupCall users:Vector = MessageAction; dialog#2c171f72 flags:# pinned:flags.2?true unread_mark:flags.3?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int = Dialog; dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog; @@ -194,6 +196,7 @@ photoSize#77bfb61b type:string location:FileLocation w:int h:int size:int = Phot photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize; photoStrippedSize#e0b0bc2e type:string bytes:bytes = PhotoSize; photoSizeProgressive#5aa86a51 type:string location:FileLocation w:int h:int sizes:Vector = PhotoSize; +photoPathSize#d8214d41 type:string bytes:bytes = PhotoSize; geoPointEmpty#1117dd5f = GeoPoint; geoPoint#b2a2f663 flags:# long:double lat:double access_hash:long accuracy_radius:flags.0?int = GeoPoint; @@ -312,7 +315,7 @@ updateNewStickerSet#688a30aa stickerset:messages.StickerSet = Update; updateStickerSetsOrder#bb2d201 flags:# masks:flags.0?true order:Vector = Update; updateStickerSets#43ae3dec = Update; updateSavedGifs#9375341e = Update; -updateBotInlineQuery#54826690 flags:# query_id:long user_id:int query:string geo:flags.0?GeoPoint offset:string = Update; +updateBotInlineQuery#3f2038db flags:# query_id:long user_id:int query:string geo:flags.0?GeoPoint peer_type:flags.1?InlineQueryPeerType offset:string = Update; updateBotInlineSend#e48f964 flags:# user_id:int query:string geo:flags.0?GeoPoint id:string msg_id:flags.1?InputBotInlineMessageID = Update; updateEditChannelMessage#1b3f4df7 message:Message pts:int pts_count:int = Update; updateBotCallbackQuery#e73547e1 flags:# query_id:long user_id:int peer:Peer msg_id:int chat_instance:long data:flags.0?bytes game_short_name:flags.1?string = Update; @@ -362,6 +365,8 @@ updatePeerBlocked#246a4b22 peer_id:Peer blocked:Bool = Update; updateChannelUserTyping#ff2abe9f flags:# channel_id:int top_msg_id:flags.0?int user_id:int action:SendMessageAction = Update; updatePinnedMessages#ed85eab5 flags:# pinned:flags.0?true peer:Peer messages:Vector pts:int pts_count:int = Update; updatePinnedChannelMessages#8588878b flags:# pinned:flags.0?true channel_id:int messages:Vector pts:int pts_count:int = Update; +updateGroupCallParticipants#f2ebdb4e call:InputGroupCall participants:Vector version:int = Update; +updateGroupCall#5724806e channel_id:int call:GroupCall = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -448,6 +453,7 @@ sendMessageChooseContactAction#628cbc6f = SendMessageAction; sendMessageGamePlayAction#dd6a8f48 = SendMessageAction; sendMessageRecordRoundAction#88f27fbc = SendMessageAction; sendMessageUploadRoundAction#243e1c66 progress:int = SendMessageAction; +speakingInGroupCallAction#d92c2285 = SendMessageAction; contacts.found#b3134d9d my_results:Vector results:Vector chats:Vector users:Vector = contacts.Found; @@ -873,12 +879,17 @@ channelAdminLogEventActionStopPoll#8f079643 message:Message = ChannelAdminLogEve channelAdminLogEventActionChangeLinkedChat#a26f881b prev_value:int new_value:int = ChannelAdminLogEventAction; channelAdminLogEventActionChangeLocation#e6b76ae prev_value:ChannelLocation new_value:ChannelLocation = ChannelAdminLogEventAction; channelAdminLogEventActionToggleSlowMode#53909779 prev_value:int new_value:int = ChannelAdminLogEventAction; +channelAdminLogEventActionStartGroupCall#23209745 call:InputGroupCall = ChannelAdminLogEventAction; +channelAdminLogEventActionDiscardGroupCall#db9f9140 call:InputGroupCall = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantMute#f92424d2 participant:GroupCallParticipant = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantUnmute#e64429c0 participant:GroupCallParticipant = ChannelAdminLogEventAction; +channelAdminLogEventActionToggleGroupCallSetting#56d6a247 join_muted:Bool = ChannelAdminLogEventAction; channelAdminLogEvent#3b5a3e40 id:long date:int user_id:int action:ChannelAdminLogEventAction = ChannelAdminLogEvent; channels.adminLogResults#ed8af74d events:Vector chats:Vector users:Vector = channels.AdminLogResults; -channelAdminLogEventsFilter#ea107ae4 flags:# join:flags.0?true leave:flags.1?true invite:flags.2?true ban:flags.3?true unban:flags.4?true kick:flags.5?true unkick:flags.6?true promote:flags.7?true demote:flags.8?true info:flags.9?true settings:flags.10?true pinned:flags.11?true edit:flags.12?true delete:flags.13?true = ChannelAdminLogEventsFilter; +channelAdminLogEventsFilter#ea107ae4 flags:# join:flags.0?true leave:flags.1?true invite:flags.2?true ban:flags.3?true unban:flags.4?true kick:flags.5?true unkick:flags.6?true promote:flags.7?true demote:flags.8?true info:flags.9?true settings:flags.10?true pinned:flags.11?true edit:flags.12?true delete:flags.13?true group_call:flags.14?true = ChannelAdminLogEventsFilter; popularContact#5ce14175 client_id:long importers:int = PopularContact; @@ -902,6 +913,7 @@ account.webAuthorizations#ed56c9fc authorizations:Vector users inputMessageID#a676a322 id:int = InputMessage; inputMessageReplyTo#bad88395 id:int = InputMessage; inputMessagePinned#86872538 = InputMessage; +inputMessageCallbackQuery#acfa1a7e id:int query_id:long = InputMessage; inputDialogPeer#fcaafeb7 peer:InputPeer = InputDialogPeer; inputDialogPeerFolder#64600527 folder_id:int = InputDialogPeer; @@ -1035,7 +1047,7 @@ chatOnlines#f041e250 onlines:int = ChatOnlines; statsURL#47a971e0 url:string = StatsURL; -chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true anonymous:flags.10?true = ChatAdminRights; +chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true anonymous:flags.10?true manage_call:flags.11?true = ChatAdminRights; chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true until_date:int = ChatBannedRights; @@ -1177,6 +1189,23 @@ peerBlocked#e8fd8014 peer_id:Peer date:int = PeerBlocked; stats.messageStats#8999f295 views_graph:StatsGraph = stats.MessageStats; +groupCallDiscarded#7780bcb4 id:long access_hash:long duration:int = GroupCall; +groupCall#55903081 flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true id:long access_hash:long participants_count:int params:flags.0?DataJSON version:int = GroupCall; + +inputGroupCall#d8aa840f id:long access_hash:long = InputGroupCall; + +groupCallParticipant#56b087c9 flags:# muted:flags.0?true left:flags.1?true can_self_unmute:flags.2?true user_id:int date:int active_date:flags.3?int source:int = GroupCallParticipant; + +phone.groupCall#66ab0bfc call:GroupCall participants:Vector participants_next_offset:string users:Vector = phone.GroupCall; + +phone.groupParticipants#9cfeb92d count:int participants:Vector next_offset:string users:Vector version:int = phone.GroupParticipants; + +inlineQueryPeerTypeSameBotPM#3081ed9d = InlineQueryPeerType; +inlineQueryPeerTypePM#833c0fac = InlineQueryPeerType; +inlineQueryPeerTypeChat#d766c50a = InlineQueryPeerType; +inlineQueryPeerTypeMegagroup#5ec4be43 = InlineQueryPeerType; +inlineQueryPeerTypeBroadcast#6334ee9a = InlineQueryPeerType; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1531,6 +1560,16 @@ phone.discardCall#b2cbc1c0 flags:# video:flags.0?true peer:InputPhoneCall durati phone.setCallRating#59ead627 flags:# user_initiative:flags.0?true peer:InputPhoneCall rating:int comment:string = Updates; phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool; phone.sendSignalingData#ff7a9383 peer:InputPhoneCall data:bytes = Bool; +phone.createGroupCall#e428fa02 channel:InputChannel random_id:int = Updates; +phone.joinGroupCall#5f9c8e62 flags:# muted:flags.0?true call:InputGroupCall params:DataJSON = Updates; +phone.leaveGroupCall#500377f9 call:InputGroupCall source:int = Updates; +phone.editGroupCallMember#63146ae4 flags:# muted:flags.0?true call:InputGroupCall user_id:InputUser = Updates; +phone.inviteToGroupCall#7b393160 call:InputGroupCall users:Vector = Updates; +phone.discardGroupCall#7a777135 call:InputGroupCall = Updates; +phone.toggleGroupCallSettings#74bbb43d flags:# call:InputGroupCall join_muted:flags.0?Bool = Updates; +phone.getGroupCall#c7cb017 call:InputGroupCall = phone.GroupCall; +phone.getGroupParticipants#c9f1d285 call:InputGroupCall ids:Vector sources:Vector offset:string limit:int = phone.GroupParticipants; +phone.checkGroupCall#b74a7bea call:InputGroupCall source:int = Bool; langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference; langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector = Vector; @@ -1547,4 +1586,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 120 +// LAYER 122 diff --git a/telethon_generator/generators/tlobject.py b/telethon_generator/generators/tlobject.py index 9ef23861..e18be176 100644 --- a/telethon_generator/generators/tlobject.py +++ b/telethon_generator/generators/tlobject.py @@ -28,6 +28,7 @@ AUTO_CASTS = { 'InputMessage': 'utils.get_input_message({})', 'InputDocument': 'utils.get_input_document({})', 'InputChatPhoto': 'utils.get_input_chat_photo({})', + 'InputGroupCall': 'utils.get_input_group_call({})', } NAMED_AUTO_CASTS = {