mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-03 09:49:21 +01:00
Add Chat.effective_name
Convenience Property (#3485)
This commit is contained in:
parent
f9cbddd10a
commit
d48fa71ec5
2 changed files with 25 additions and 1 deletions
|
@ -388,10 +388,24 @@ class Chat(TelegramObject):
|
|||
|
||||
self._freeze()
|
||||
|
||||
@property
|
||||
def effective_name(self) -> Optional[str]:
|
||||
"""
|
||||
:obj:`str`: Convenience property. Gives :attr:`title` if not :obj:`None`,
|
||||
else :attr:`full_name` if not :obj:`None`.
|
||||
|
||||
.. versionadded:: 20.1
|
||||
"""
|
||||
if self.title is not None:
|
||||
return self.title
|
||||
if self.full_name is not None:
|
||||
return self.full_name
|
||||
return None
|
||||
|
||||
@property
|
||||
def full_name(self) -> Optional[str]:
|
||||
"""
|
||||
:obj:`str`: Convenience property. If :attr:`first_name` is not :obj:`None` gives,
|
||||
:obj:`str`: Convenience property. If :attr:`first_name` is not :obj:`None`, gives
|
||||
:attr:`first_name` followed by (if available) :attr:`last_name`.
|
||||
|
||||
Note:
|
||||
|
|
|
@ -212,6 +212,16 @@ class TestChat:
|
|||
)
|
||||
assert chat.full_name is None
|
||||
|
||||
def test_effective_name(self):
|
||||
chat = Chat(id=1, type=Chat.PRIVATE, first_name="first\u2022name")
|
||||
assert chat.effective_name == "first\u2022name"
|
||||
chat = Chat(id=1, type=Chat.GROUP, title="group")
|
||||
assert chat.effective_name == "group"
|
||||
chat = Chat(id=1, type=Chat.GROUP, first_name="first\u2022name", title="group")
|
||||
assert chat.effective_name == "group"
|
||||
chat = Chat(id=1, type=Chat.GROUP)
|
||||
assert chat.effective_name is None
|
||||
|
||||
async def test_send_action(self, monkeypatch, chat):
|
||||
async def make_assertion(*_, **kwargs):
|
||||
id_ = kwargs["chat_id"] == chat.id
|
||||
|
|
Loading…
Reference in a new issue