Add more descriptive errors for get_input_peer (#93)

This commit is contained in:
Lonami Exo 2017-05-23 09:45:48 +02:00
parent 7eaa393271
commit e60c70c1a7

View File

@ -21,6 +21,8 @@ def get_display_name(entity):
if isinstance(entity, Chat) or isinstance(entity, Channel): if isinstance(entity, Chat) or isinstance(entity, Channel):
return entity.title return entity.title
return '(unknown)'
# For some reason, .webp (stickers' format) is not registered # For some reason, .webp (stickers' format) is not registered
add_type('image/webp', '.webp') add_type('image/webp', '.webp')
@ -43,7 +45,7 @@ def get_extension(media):
def get_input_peer(entity): def get_input_peer(entity):
"""Gets the input peer for the given "entity" (user, chat or channel). """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 if (isinstance(entity, InputPeerUser) or
isinstance(entity, InputPeerChat) or isinstance(entity, InputPeerChat) or
isinstance(entity, InputPeerChannel)): isinstance(entity, InputPeerChannel)):
@ -56,6 +58,9 @@ def get_input_peer(entity):
if isinstance(entity, Channel): if isinstance(entity, Channel):
return InputPeerChannel(entity.id, entity.access_hash) 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): def find_user_or_chat(peer, users, chats):
"""Finds the corresponding user or chat given a peer. """Finds the corresponding user or chat given a peer.