From e20d9117582036a9db95049fb8c6897a118c1420 Mon Sep 17 00:00:00 2001 From: ColinTheShark Date: Tue, 21 Jul 2020 02:46:36 +0200 Subject: [PATCH 1/3] Add message.link attribute Adds the functionality to access the message link. Either as `t.me/c/` or `t.me/username` format. --- pyrogram/client/types/messages_and_media/message.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 476067152d1..a02682ec6f1 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -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 `_ that match the text of this message. Only applicable when using :obj:`Filters.regex `. @@ -325,6 +328,7 @@ def __init__( views: int = None, via_bot: User = None, outgoing: bool = None, + link: str = None, matches: List[Match] = None, command: List[str] = None, reply_markup: Union[ @@ -390,6 +394,7 @@ def __init__( self.views = views self.via_bot = via_bot self.outgoing = outgoing + self.link = link self.matches = matches self.command = command self.reply_markup = reply_markup @@ -670,6 +675,14 @@ def _parse(client, message: types.Message or types.MessageService or types.Messa return parsed_message + @property + def link(self): + if self.chat.type in ["group", "supergroup", "channel"] and self.chat.username: + return "t.me/" + self.chat.username + "/" + str(self.message_id) + else: + return "t.me/c/" + str(self.chat.id).replace("-100", "") + "/" + str(self.message_id) + + def reply_text( self, text: str, From a83d7dd7afecebf18e1a386d45cf92388e21b429 Mon Sep 17 00:00:00 2001 From: ColinTheShark Date: Tue, 21 Jul 2020 16:39:57 +0200 Subject: [PATCH 2/3] 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 --- pyrogram/client/types/messages_and_media/message.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index a02682ec6f1..f3877fd0f16 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -328,7 +328,6 @@ def __init__( views: int = None, via_bot: User = None, outgoing: bool = None, - link: str = None, matches: List[Match] = None, command: List[str] = None, reply_markup: Union[ @@ -394,7 +393,6 @@ def __init__( self.views = views self.via_bot = via_bot self.outgoing = outgoing - self.link = link self.matches = matches self.command = command self.reply_markup = reply_markup @@ -676,11 +674,11 @@ def _parse(client, message: types.Message or types.MessageService or types.Messa return parsed_message @property - def link(self): - if self.chat.type in ["group", "supergroup", "channel"] and self.chat.username: + def link(self) -> str: + if self.chat.type in ("group", "supergroup", "channel") and self.chat.username: return "t.me/" + self.chat.username + "/" + str(self.message_id) else: - return "t.me/c/" + str(self.chat.id).replace("-100", "") + "/" + str(self.message_id) + return "t.me/c/" + str(utils.get_channel_id(self.chat.id)) + "/" + str(self.message_id) def reply_text( From b4ba3754924934d2c02a231a563e7dbeae0801e6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 27 Jul 2020 15:29:51 +0200 Subject: [PATCH 3/3] Update message.py - Prepend https:// like official clients do - Use .format() --- pyrogram/client/types/messages_and_media/message.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index f3877fd0f16..f2f6abab7ab 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -676,10 +676,9 @@ def _parse(client, message: types.Message or types.MessageService or types.Messa @property def link(self) -> str: if self.chat.type in ("group", "supergroup", "channel") and self.chat.username: - return "t.me/" + self.chat.username + "/" + str(self.message_id) + return "https://t.me/{}/{}".format(self.chat.username, self.message_id) else: - return "t.me/c/" + str(utils.get_channel_id(self.chat.id)) + "/" + str(self.message_id) - + return "https://t.me/c/{}/{}".format(utils.get_channel_id(self.chat.id), self.message_id) def reply_text( self,