Merge pull request #229 from uburuntu/private-chat-links

Private chat links
This commit is contained in:
Alex Root Junior 2020-02-22 23:21:50 +02:00 committed by GitHub
commit 8686482e2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View file

@ -230,12 +230,19 @@ class Message(base.TelegramObject):
:return: str
"""
if self.chat.type not in [ChatType.SUPER_GROUP, ChatType.CHANNEL]:
if ChatType.is_private(self.chat):
raise TypeError('Invalid chat type!')
elif not self.chat.username:
raise TypeError('This chat does not have @username')
return f"https://t.me/{self.chat.username}/{self.message_id}"
url = 'https://t.me/'
if self.chat.username:
# Generates public link
url += f'{self.chat.username}/'
else:
# Generates private link available for chat members
url += f'c/{self.chat.shifted_id}/'
url += f'{self.message_id}'
return url
def link(self, text, as_html=True) -> str:
"""