Handle more cases on .get_display_name

This commit is contained in:
feodoran 2017-06-16 09:11:49 +02:00 committed by Lonami
parent 86d45cc276
commit 13199f737e

View File

@ -15,9 +15,14 @@ def get_display_name(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""" Returns None if it was not found"""
if isinstance(entity, User): if isinstance(entity, User):
if entity.last_name is not None: if entity.last_name and entity.first_name:
return '{} {}'.format(entity.first_name, entity.last_name) return '{} {}'.format(entity.first_name, entity.last_name)
return entity.first_name elif entity.first_name:
return entity.first_name
elif entity.last_name:
return entity.last_name
else:
return '(No name)'
if isinstance(entity, Chat) or isinstance(entity, Channel): if isinstance(entity, Chat) or isinstance(entity, Channel):
return entity.title return entity.title