Finish update to layer 98

This commit is contained in:
Lonami Exo 2019-04-22 19:02:15 +02:00
parent 013525797a
commit bb23bc0fd2
3 changed files with 25 additions and 28 deletions

View File

@ -180,7 +180,7 @@ class DownloadMethods(UserMethods):
Downloads the given input location to a file. Downloads the given input location to a file.
Args: Args:
input_location (:tl:`FileLocation` | :tl:`InputFileLocation`): input_location (:tl:`InputFileLocation`):
The file location from which the file will be downloaded. The file location from which the file will be downloaded.
See `telethon.utils.get_input_location` source for a complete See `telethon.utils.get_input_location` source for a complete
list of supported types. list of supported types.

View File

@ -420,13 +420,6 @@ def get_input_media(
if isinstance(media, types.MessageMediaGame): if isinstance(media, types.MessageMediaGame):
return types.InputMediaGame(id=media.game.id) return types.InputMediaGame(id=media.game.id)
if isinstance(media, (types.ChatPhoto, types.UserProfilePhoto)):
if isinstance(media.photo_big, types.FileLocationUnavailable):
media = media.photo_small
else:
media = media.photo_big
return get_input_media(media, is_photo=True)
if isinstance(media, types.MessageMediaContact): if isinstance(media, types.MessageMediaContact):
return types.InputMediaContact( return types.InputMediaContact(
phone_number=media.phone_number, phone_number=media.phone_number,
@ -451,7 +444,8 @@ def get_input_media(
if isinstance(media, ( if isinstance(media, (
types.MessageMediaEmpty, types.MessageMediaUnsupported, types.MessageMediaEmpty, types.MessageMediaUnsupported,
types.ChatPhotoEmpty, types.UserProfilePhotoEmpty, types.ChatPhotoEmpty, types.UserProfilePhotoEmpty,
types.FileLocationUnavailable)): types.ChatPhoto, types.UserProfilePhoto,
types.FileLocationToBeDeprecated)):
return types.InputMediaEmpty() return types.InputMediaEmpty()
if isinstance(media, types.Message): if isinstance(media, types.Message):
@ -644,13 +638,6 @@ def get_input_location(location):
)) ))
if isinstance(location, types.FileLocationToBeDeprecated): if isinstance(location, types.FileLocationToBeDeprecated):
return (None, types.InputFileLocation(
volume_id=location.volume_id,
local_id=location.local_id,
secret=0,
file_reference=b''
))
elif isinstance(location, types.FileLocationUnavailable):
raise TypeError('Unavailable location cannot be used as input') raise TypeError('Unavailable location cannot be used as input')
_raise_cast_fail(location, 'InputFileLocation') _raise_cast_fail(location, 'InputFileLocation')
@ -991,15 +978,24 @@ def resolve_bot_file_id(file_id):
# Thumbnails (small) always have ID 0; otherwise size 'x' # Thumbnails (small) always have ID 0; otherwise size 'x'
photo_size = 's' if media_id or access_hash else 'x' photo_size = 's' if media_id or access_hash else 'x'
return types.Photo(id=media_id, access_hash=access_hash, sizes=[ return types.Photo(
types.PhotoSize(photo_size, location=types.FileLocation( id=media_id,
dc_id=dc_id, access_hash=access_hash,
volume_id=volume_id, file_reference=b'',
secret=secret, date=None,
local_id=local_id, sizes=[types.PhotoSize(
file_reference=b'' type=photo_size,
), w=0, h=0, size=0) location=types.FileLocationToBeDeprecated(
], file_reference=b'', date=None) volume_id=volume_id,
local_id=local_id
),
w=0,
h=0,
size=0
)],
dc_id=dc_id,
has_stickers=None
)
def pack_bot_file_id(file): def pack_bot_file_id(file):
@ -1038,13 +1034,13 @@ def pack_bot_file_id(file):
size = next((x for x in reversed(file.sizes) if isinstance( size = next((x for x in reversed(file.sizes) if isinstance(
x, (types.PhotoSize, types.PhotoCachedSize))), None) x, (types.PhotoSize, types.PhotoCachedSize))), None)
if not size or not isinstance(size.location, types.FileLocation): if not size:
return None return None
size = size.location size = size.location
return _encode_telegram_base64(_rle_encode(struct.pack( return _encode_telegram_base64(_rle_encode(struct.pack(
'<iiqqqqib', 2, size.dc_id, file.id, file.access_hash, '<iiqqqqib', 2, file.dc_id, file.id, file.access_hash,
size.volume_id, size.secret, size.local_id, 2 size.volume_id, 0, size.local_id, 2 # 0 = old `secret`
))) )))
else: else:
return None return None

View File

@ -251,6 +251,7 @@ USER_BOT_REQUIRED,400,This method can only be called by a bot
USER_CHANNELS_TOO_MUCH,403,One of the users you tried to add is already in too many channels/supergroups USER_CHANNELS_TOO_MUCH,403,One of the users you tried to add is already in too many channels/supergroups
USER_CREATOR,400,"You can't leave this channel, because you're its creator" USER_CREATOR,400,"You can't leave this channel, because you're its creator"
USER_DEACTIVATED,401,The user has been deleted/deactivated USER_DEACTIVATED,401,The user has been deleted/deactivated
USER_DEACTIVATED_BAN,401,The user has been deleted/deactivated
USER_ID_INVALID,400,"Invalid object ID for a user. Make sure to pass the right types, for instance making sure that the request is designed for users or otherwise look for a different one more suited" USER_ID_INVALID,400,"Invalid object ID for a user. Make sure to pass the right types, for instance making sure that the request is designed for users or otherwise look for a different one more suited"
USER_INVALID,400,The given user was invalid USER_INVALID,400,The given user was invalid
USER_IS_BLOCKED,400 403,User is blocked USER_IS_BLOCKED,400 403,User is blocked

1 name codes description
251 USER_CHANNELS_TOO_MUCH 403 One of the users you tried to add is already in too many channels/supergroups
252 USER_CREATOR 400 You can't leave this channel, because you're its creator
253 USER_DEACTIVATED 401 The user has been deleted/deactivated
254 USER_DEACTIVATED_BAN 401 The user has been deleted/deactivated
255 USER_ID_INVALID 400 Invalid object ID for a user. Make sure to pass the right types, for instance making sure that the request is designed for users or otherwise look for a different one more suited
256 USER_INVALID 400 The given user was invalid
257 USER_IS_BLOCKED 400 403 User is blocked