mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
add method for get user mention (#1049)
* add new method * Create 1049.feature.rst * update test_user * after black and isort using * after black and isort using * adding new tests * fix test * update tests * update test * using create_tg_link function instead of new func * Update user.py * Update aiogram/types/user.py Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>
This commit is contained in:
parent
45705faf12
commit
b8cd06fd6f
3 changed files with 52 additions and 1 deletions
|
|
@ -2,13 +2,14 @@ from __future__ import annotations
|
|||
|
||||
from typing import Optional
|
||||
|
||||
from ..utils.link import create_tg_link
|
||||
from ..utils import markdown
|
||||
from .base import TelegramObject
|
||||
|
||||
|
||||
class User(TelegramObject):
|
||||
"""
|
||||
This object represents a Telegram user or bot.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#user
|
||||
"""
|
||||
|
||||
|
|
@ -40,3 +41,17 @@ class User(TelegramObject):
|
|||
if self.last_name:
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
return self.first_name
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return create_tg_link("user", id=self.id)
|
||||
|
||||
def mention_markdown(self, name: Optional[str] = None) -> str:
|
||||
if name is None:
|
||||
name = self.full_name
|
||||
return markdown.link(name, self.url)
|
||||
|
||||
def mention_html(self, name: Optional[str] = None) -> str:
|
||||
if name is None:
|
||||
name = self.full_name
|
||||
return markdown.hlink(name, self.url)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue