mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 01:54:53 +00:00
Get mention in private chats.
This commit is contained in:
parent
c8349112d0
commit
62417da6a7
1 changed files with 15 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from aiogram.utils.markdown import hlink, link
|
||||
from .base import Deserializable
|
||||
from .chat_photo import ChatPhoto
|
||||
from ..utils.helper import Helper, HelperMode, Item
|
||||
|
|
@ -65,6 +66,20 @@ class Chat(Deserializable):
|
|||
return self.full_name
|
||||
return None
|
||||
|
||||
@property
|
||||
def user_url(self):
|
||||
if self.type != ChatType.PRIVATE:
|
||||
raise TypeError('This property available only in private chats.')
|
||||
|
||||
return f"tg://user?id={self.id}"
|
||||
|
||||
def get_mention(self, name=None, as_html=False):
|
||||
if name is None:
|
||||
name = self.mention
|
||||
if as_html:
|
||||
return hlink(name, self.user_url)
|
||||
return link(name, self.user_url)
|
||||
|
||||
async def set_photo(self, photo):
|
||||
return await self.bot.set_chat_photo(self.id, photo)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue