mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-04 22:34:52 +00:00
Enable custom format for User mentions
Examples:
- format(user, "mention")
- "{:mention}".format(user)
- f"{user:mention}"
This commit is contained in:
parent
a790431274
commit
6c80064f2c
1 changed files with 8 additions and 0 deletions
|
|
@ -16,6 +16,8 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import html
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .chat_photo import ChatPhoto
|
from .chat_photo import ChatPhoto
|
||||||
|
|
@ -134,6 +136,12 @@ class User(Object):
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
self.restriction_reason = restriction_reason
|
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
|
@staticmethod
|
||||||
def _parse(client, user: types.User) -> "User" or None:
|
def _parse(client, user: types.User) -> "User" or None:
|
||||||
if user is None:
|
if user is None:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue