Add link property to Bot (#1770)

* added link property to bot

link property was available in User and Chat objects but not in Bot which was inconsistent.

* added 'link' property to Bot object

Bot will always have username so it does not require hasattr check

* add tests

Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
This commit is contained in:
Ak4zh 2020-03-09 21:17:05 +00:00 committed by GitHub
parent 13a641b3d7
commit 28ded6718e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -223,6 +223,13 @@ class Bot(TelegramObject):
return self.bot.username
@property
@info
def link(self):
""":obj:`str`: Convenience property. Returns the t.me link of the bot."""
return "https://t.me/{}".format(self.username)
@property
def name(self):
""":obj:`str`: Bot's @username."""

View file

@ -87,6 +87,7 @@ class TestBot(object):
assert get_me_bot.first_name == bot.first_name
assert get_me_bot.last_name == bot.last_name
assert get_me_bot.name == bot.name
assert 'https://t.me/{}'.format(get_me_bot.username) == bot.link
@flaky(3, 1)
@pytest.mark.timeout(10)