Add Convenience Property Message.id (#3077)

This commit is contained in:
dglitxh 2022-06-01 19:29:46 +00:00 committed by GitHub
parent 67869693a7
commit 42955ecddf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View file

@ -105,8 +105,10 @@ The following wonderful people contributed directly or indirectly to this projec
- `Vorobjev Simon <https://github.com/simonvorobjev>`_
- `Wagner Macedo <https://github.com/wagnerluis1982>`_
- `wjt <https://github.com/wjt>`_
- `Yaw Danso <https://github.com/dglitxh>`_
- `zeroone2numeral2 <https://github.com/zeroone2numeral2>`_
- `zeshuaro <https://github.com/zeshuaro>`_
- `zpavloudis <https://github.com/zpavloudis>`_
Please add yourself here alphabetically when you submit your first pull request.

View file

@ -572,6 +572,15 @@ class Message(TelegramObject):
""":obj:`int`: Shortcut for :attr:`telegram.Chat.id` for :attr:`chat`."""
return self.chat.id
@property
def id(self) -> int: # pylint: disable=invalid-name
"""
:obj:`int`: Shortcut for :attr:`message_id`.
.. versionadded:: 20.0
"""
return self.message_id
@property
def link(self) -> Optional[str]:
""":obj:`str`: Convenience property. If the chat of the message is not

View file

@ -664,6 +664,9 @@ class TestMessage:
def test_chat_id(self, message):
assert message.chat_id == message.chat.id
def test_id(self, message):
assert message.message_id == message.id
@pytest.mark.parametrize("type_", argvalues=[Chat.SUPERGROUP, Chat.CHANNEL])
def test_link_with_username(self, message, type_):
message.chat.username = "username"