From 978c5874e210d34a260f26f7746c2a138456e927 Mon Sep 17 00:00:00 2001 From: New-dev0 Date: Thu, 10 Jun 2021 17:40:28 +0530 Subject: [PATCH] hmm ? --- .../quick-references/objects-reference.rst | 2 - telethon/client/chats.py | 6 +- telethon/client/downloads.py | 9 +- telethon/client/uploads.py | 4 - telethon/tl/custom/inlinebuilder.py | 4 + telethon/utils.py | 166 +----------------- 6 files changed, 10 insertions(+), 181 deletions(-) diff --git a/readthedocs/quick-references/objects-reference.rst b/readthedocs/quick-references/objects-reference.rst index 51ed4607..b7ee3282 100644 --- a/readthedocs/quick-references/objects-reference.rst +++ b/readthedocs/quick-references/objects-reference.rst @@ -348,6 +348,4 @@ library a lot easier. Only the interesting ones will be listed here. get_inner_text get_peer_id resolve_id - pack_bot_file_id - resolve_bot_file_id resolve_invite_link diff --git a/telethon/client/chats.py b/telethon/client/chats.py index cc4ecec3..f898bdab 100644 --- a/telethon/client/chats.py +++ b/telethon/client/chats.py @@ -1108,7 +1108,7 @@ class ChatMethods: return await self(functions.channels.EditBannedRequest( channel=entity, - user_id=user, + participant=user, banned_rights=rights )) @@ -1165,14 +1165,14 @@ class ChatMethods: else: resp = await self(functions.channels.EditBannedRequest( channel=entity, - user_id=user, + participant=user, banned_rights=types.ChatBannedRights( until_date=None, view_messages=True) )) await asyncio.sleep(0.5) await self(functions.channels.EditBannedRequest( channel=entity, - user_id=user, + participant=user, banned_rights=types.ChatBannedRights(until_date=None) )) else: diff --git a/telethon/client/downloads.py b/telethon/client/downloads.py index 9f9f893a..f52f61ca 100644 --- a/telethon/client/downloads.py +++ b/telethon/client/downloads.py @@ -269,13 +269,11 @@ class DownloadMethods: photo = entity.photo - if isinstance(photo, (types.UserProfilePhoto, types.ChatPhoto)): + if isinstance(photo, (types.UserProfilePhoto, types.)): dc_id = photo.dc_id - which = photo.photo_big if download_big else photo.photo_small loc = types.InputPeerPhotoFileLocation( peer=await self.get_input_entity(entity), - local_id=which.local_id, - volume_id=which.volume_id, + photo_id=photo.photo_id, big=download_big ) else: @@ -397,9 +395,6 @@ class DownloadMethods: date = datetime.datetime.now() media = message - if isinstance(media, str): - media = utils.resolve_bot_file_id(media) - if isinstance(media, types.MessageMediaWebPage): if isinstance(media.webpage, types.WebPage): media = media.webpage.document or media.webpage.photo diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index 544b7087..c5d170e5 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -699,10 +699,6 @@ class UploadMethods: media = types.InputMediaPhotoExternal(file) else: media = types.InputMediaDocumentExternal(file) - else: - bot_file = utils.resolve_bot_file_id(file) - if bot_file: - media = utils.get_input_media(bot_file) if media: pass # Already have media, don't check the rest diff --git a/telethon/tl/custom/inlinebuilder.py b/telethon/tl/custom/inlinebuilder.py index 949f0b63..32f0bff7 100644 --- a/telethon/tl/custom/inlinebuilder.py +++ b/telethon/tl/custom/inlinebuilder.py @@ -256,6 +256,10 @@ class InlineBuilder: It will be automatically set if ``mime_type`` is specified, and default to ``'file'`` if no matching mime type is found. + attributes (`list`, optional): + Optional attributes that override the inferred ones, like + :tl:`DocumentAttributeFilename` and so on. + include_media (`bool`, optional): Whether the document file used to display the result should be included in the message itself or not. By default, the document diff --git a/telethon/utils.py b/telethon/utils.py index bcccbca7..0dbb9afd 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -518,8 +518,7 @@ def get_input_media( if isinstance(media, ( types.MessageMediaEmpty, types.MessageMediaUnsupported, types.ChatPhotoEmpty, types.UserProfilePhotoEmpty, - types.ChatPhoto, types.UserProfilePhoto, - types.FileLocationToBeDeprecated)): + types.ChatPhoto, types.UserProfilePhoto)): return types.InputMediaEmpty() if isinstance(media, types.Message): @@ -823,9 +822,6 @@ def _get_file_info(location): thumb_size=location.sizes[-1].type ), _photo_size_byte_count(location.sizes[-1])) - if isinstance(location, types.FileLocationToBeDeprecated): - raise TypeError('Unavailable location cannot be used as input') - _raise_cast_fail(location, 'InputFileLocation') @@ -859,8 +855,6 @@ def is_image(file): match = re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE) if match: return True - else: - return isinstance(resolve_bot_file_id(file), types.Photo) def is_gif(file): @@ -1119,164 +1113,6 @@ def _encode_telegram_base64(string): return None # not valid base64, not valid ascii, not a string -def resolve_bot_file_id(file_id): - """ - Given a Bot API-style `file_id `, - returns the media it represents. If the `file_id ` - is not valid, `None` is returned instead. - - Note that the `file_id ` does not have information - such as image dimensions or file size, so these will be zero if present. - - For thumbnails, the photo ID and hash will always be zero. - """ - data = _rle_decode(_decode_telegram_base64(file_id)) - if not data: - return None - - # This isn't officially documented anywhere, but - # we assume the last byte is some kind of "version". - data, version = data[:-1], data[-1] - if version not in (2, 4): - return None - - if (version == 2 and len(data) == 24) or (version == 4 and len(data) == 25): - if version == 2: - file_type, dc_id, media_id, access_hash = struct.unpack('