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:
sheldy 2022-11-02 22:40:19 +02:00 committed by GitHub
parent 45705faf12
commit b8cd06fd6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 1 deletions

View file

@ -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)