Add message.link attribute/property (#442)

* Add message.link attribute

Adds the functionality to access the message link.
Either as `t.me/c/` or `t.me/username` format.

* Change message.link logic

Property now has a returned type, list is a tuple and
we use `utils.get_channel_id` to not rely on str.replace

* Update message.py

- Prepend https:// like official clients do
- Use .format()

Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
This commit is contained in:
ColinShark 2020-07-27 15:30:49 +02:00 committed by GitHub
parent d3a34f1084
commit c5b7a365af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -251,6 +251,9 @@ class Message(Object, Update):
Messages sent from yourself to other chats are outgoing (*outgoing* is True).
An exception is made for your own personal chat; messages sent there will be incoming.
link (``str``):
A link to the message, only for groups and channels.
matches (List of regex Matches, *optional*):
A list containing all `Match Objects <https://docs.python.org/3/library/re.html#match-objects>`_ that match
the text of this message. Only applicable when using :obj:`Filters.regex <pyrogram.Filters.regex>`.
@ -670,6 +673,13 @@ class Message(Object, Update):
return parsed_message
@property
def link(self) -> str:
if self.chat.type in ("group", "supergroup", "channel") and self.chat.username:
return "https://t.me/{}/{}".format(self.chat.username, self.message_id)
else:
return "https://t.me/c/{}/{}".format(utils.get_channel_id(self.chat.id), self.message_id)
def reply_text(
self,
text: str,