mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Add more descriptive errors for get_input_peer (#93)
This commit is contained in:
parent
7eaa393271
commit
e60c70c1a7
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user