diff --git a/AUTHORS.rst b/AUTHORS.rst index 6db6cabcd..bd53c1823 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -23,6 +23,7 @@ The following wonderful people contributed directly or indirectly to this projec - `d-qoi `_ - `daimajia `_ - `Daniel Reed `_ +- `Ehsan Online `_ - `Eli Gao `_ - `Emilio Molinari `_ - `ErgoZ Riftbit Vaper `_ diff --git a/telegram/message.py b/telegram/message.py index 09b07d41c..9ed3d7746 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -943,7 +943,9 @@ class Message(TelegramObject): if entity.type == MessageEntity.TEXT_LINK: insert = '{}'.format(entity.url, text) - elif (entity.type == MessageEntity.URL) and urled: + elif entity.type == MessageEntity.TEXT_MENTION and entity.user: + insert = '{}'.format(entity.user.id, text) + elif entity.type == MessageEntity.URL and urled: insert = '{0}'.format(text) elif entity.type == MessageEntity.BOLD: insert = '' + text + '' @@ -1040,7 +1042,9 @@ class Message(TelegramObject): if entity.type == MessageEntity.TEXT_LINK: insert = '[{}]({})'.format(text, entity.url) - elif (entity.type == MessageEntity.URL) and urled: + elif entity.type == MessageEntity.TEXT_MENTION and entity.user: + insert = '[{}](tg://user?id={})'.format(text, entity.user.id) + elif entity.type == MessageEntity.URL and urled: insert = '[{0}]({0})'.format(text) elif entity.type == MessageEntity.BOLD: insert = '*' + text + '*' diff --git a/tests/test_message.py b/tests/test_message.py index 125f7be91..202897758 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -114,9 +114,11 @@ class TestMessage(object): {'length': 7, 'offset': 16, 'type': 'italic'}, {'length': 4, 'offset': 25, 'type': 'code'}, {'length': 5, 'offset': 31, 'type': 'text_link', 'url': 'http://github.com/'}, - {'length': 3, 'offset': 41, 'type': 'pre'}, - {'length': 17, 'offset': 46, 'type': 'url'}] - test_text = 'Test for bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') text_html = self.test_message.text_html assert text_html == test_html_string @@ -185,14 +188,16 @@ class TestMessage(object): def test_text_html_urled(self): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') text_html = self.test_message.text_html_urled assert text_html == test_html_string def test_text_markdown_simple(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. http://google.com') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + 'http://google.com') text_markdown = self.test_message.text_markdown assert text_markdown == test_md_string @@ -202,8 +207,9 @@ class TestMessage(object): assert message.text_markdown is None def test_text_markdown_urled(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. [http://google.com](http://google.com)') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + '[http://google.com](http://google.com)') text_markdown = self.test_message.text_markdown_urled assert text_markdown == test_md_string @@ -225,8 +231,9 @@ class TestMessage(object): def test_caption_html_simple(self): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') caption_html = self.test_message.caption_html assert caption_html == test_html_string @@ -237,14 +244,16 @@ class TestMessage(object): def test_caption_html_urled(self): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') caption_html = self.test_message.caption_html_urled assert caption_html == test_html_string def test_caption_markdown_simple(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. http://google.com') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + 'http://google.com') caption_markdown = self.test_message.caption_markdown assert caption_markdown == test_md_string @@ -254,8 +263,9 @@ class TestMessage(object): assert message.caption_markdown is None def test_caption_markdown_urled(self): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. [http://google.com](http://google.com)') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + '[http://google.com](http://google.com)') caption_markdown = self.test_message.caption_markdown_urled assert caption_markdown == test_md_string @@ -326,8 +336,9 @@ class TestMessage(object): assert message.reply_text('test', reply_to_message_id=message.message_id, quote=True) def test_reply_markdown(self, monkeypatch, message): - test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/) and ' - '```pre```. http://google.com') + test_md_string = ('Test for <*bold*, _ita\_lic_, `code`, [links](http://github.com/), ' + '[text-mention](tg://user?id=123456789) and ```pre```. ' + 'http://google.com') def test(*args, **kwargs): cid = args[1] == message.chat_id @@ -351,8 +362,9 @@ class TestMessage(object): def test_reply_html(self, monkeypatch, message): test_html_string = ('Test for <bold, ita_lic, code, ' - 'links and
pre
. ' - 'http://google.com') + 'links, ' + 'text-mention and ' + '
pre
. http://google.com') def test(*args, **kwargs): cid = args[1] == message.chat_id diff --git a/tests/test_parsemode.py b/tests/test_parsemode.py index 0f7b155c6..c015f6fda 100644 --- a/tests/test_parsemode.py +++ b/tests/test_parsemode.py @@ -23,9 +23,10 @@ from telegram import ParseMode class TestParseMode(object): - markdown_text = '*bold* _italic_ [link](http://google.com).' - html_text = 'bold italic link.' - formatted_text_formatted = u'bold italic link.' + markdown_text = '*bold* _italic_ [link](http://google.com) [name](tg://user?id=123456789).' + html_text = ('bold italic link ' + 'name.') + formatted_text_formatted = u'bold italic link name.' @flaky(3, 1) @pytest.mark.timeout(10)