From 6c80064f2c239309c50b9e44db0ee1d6fa08be51 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sun, 30 Jun 2019 21:10:28 +0200
Subject: [PATCH] Enable custom format for User mentions
Examples:
- format(user, "mention")
- "{:mention}".format(user)
- f"{user:mention}"
---
pyrogram/client/types/user_and_chats/user.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/pyrogram/client/types/user_and_chats/user.py b/pyrogram/client/types/user_and_chats/user.py
index f47e8c42..248c4c0a 100644
--- a/pyrogram/client/types/user_and_chats/user.py
+++ b/pyrogram/client/types/user_and_chats/user.py
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+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 '{1}'.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: