mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-17 04:39:55 +01:00
fixing message.link (#1741)
* fixing message.link * improving if clause
This commit is contained in:
parent
a397e6c3c6
commit
423794f473
2 changed files with 7 additions and 11 deletions
|
@ -339,18 +339,13 @@ class Message(TelegramObject):
|
|||
@property
|
||||
def link(self):
|
||||
""":obj:`str`: Convenience property. If the chat of the message is not
|
||||
a private chat, returns a t.me link of the message."""
|
||||
if self.chat.type != Chat.PRIVATE:
|
||||
a private chat or normal group, returns a t.me link of the message."""
|
||||
if self.chat.type not in [Chat.PRIVATE, Chat.GROUP]:
|
||||
if self.chat.username:
|
||||
to_link = self.chat.username
|
||||
else:
|
||||
if self.chat.type != Chat.GROUP:
|
||||
# Get rid of leading -100 for supergroups
|
||||
id_to_link = str(self.chat.id)[4:]
|
||||
else:
|
||||
# Get rid of leading minus for regular groups
|
||||
id_to_link = str(self.chat.id)[1:]
|
||||
to_link = "c/{}".format(id_to_link)
|
||||
# Get rid of leading -100 for supergroups
|
||||
to_link = "c/{}".format(str(self.chat.id)[4:])
|
||||
return "https://t.me/{}/{}".format(to_link, self.message_id)
|
||||
return None
|
||||
|
||||
|
|
|
@ -311,8 +311,7 @@ class TestMessage(object):
|
|||
message.message_id)
|
||||
|
||||
@pytest.mark.parametrize('type, id', argvalues=[
|
||||
(Chat.CHANNEL, -1003), (Chat.SUPERGROUP, -1003), (Chat.GROUP, -3)
|
||||
])
|
||||
(Chat.CHANNEL, -1003), (Chat.SUPERGROUP, -1003)])
|
||||
def test_link_with_id(self, message, type, id):
|
||||
message.chat.username = None
|
||||
message.chat.id = id
|
||||
|
@ -328,6 +327,8 @@ class TestMessage(object):
|
|||
message.chat.id = id
|
||||
message.chat.username = username
|
||||
assert message.link is None
|
||||
message.chat.type = Chat.GROUP
|
||||
assert message.link is None
|
||||
|
||||
def test_effective_attachment(self, message_params):
|
||||
for i in ('audio', 'game', 'document', 'animation', 'photo', 'sticker', 'video', 'voice',
|
||||
|
|
Loading…
Add table
Reference in a new issue