diff --git a/telethon/utils/tl_utils.py b/telethon/utils/tl_utils.py index 476e4599..71a640fb 100644 --- a/telethon/utils/tl_utils.py +++ b/telethon/utils/tl_utils.py @@ -21,6 +21,8 @@ def get_display_name(entity): if isinstance(entity, Chat) or isinstance(entity, Channel): return entity.title + return '(unknown)' + # For some reason, .webp (stickers' format) is not registered add_type('image/webp', '.webp') @@ -43,7 +45,7 @@ def get_extension(media): def get_input_peer(entity): """Gets the input peer for the given "entity" (user, chat or channel). - Returns None if it was not found""" + A ValueError is rose if the given entity isn't a supported type.""" if (isinstance(entity, InputPeerUser) or isinstance(entity, InputPeerChat) or isinstance(entity, InputPeerChannel)): @@ -56,6 +58,9 @@ def get_input_peer(entity): if isinstance(entity, Channel): return InputPeerChannel(entity.id, entity.access_hash) + raise ValueError('Cannot cast {} to any kind of InputPeer.' + .format(type(entity).__name__)) + def find_user_or_chat(peer, users, chats): """Finds the corresponding user or chat given a peer.