2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Enable custom format for User mentions

Examples:
  - format(user, "mention")
  - "{:mention}".format(user)
  - f"{user:mention}"
This commit is contained in:
Dan 2019-06-30 21:10:28 +02:00
parent a790431274
commit 6c80064f2c

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import html
import pyrogram
from pyrogram.api import types
from .chat_photo import ChatPhoto
@ -134,6 +136,12 @@ class User(Object):
self.photo = photo
self.restriction_reason = restriction_reason
def __format__(self, format_spec):
if format_spec == "mention":
return '<a href="tg://user?id={0}">{1}</a>'.format(self.id, html.escape(self.first_name))
return html.escape(str(self))
@staticmethod
def _parse(client, user: types.User) -> "User" or None:
if user is None: