From 95d95701ea2b6f54df09c928e568919cd0d584a6 Mon Sep 17 00:00:00 2001 From: Lonami Date: Mon, 7 Oct 2019 16:53:10 +0200 Subject: [PATCH] Show admin rank title if available --- stdplugins/who.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/stdplugins/who.py b/stdplugins/who.py index 3982344..bc621f9 100644 --- a/stdplugins/who.py +++ b/stdplugins/who.py @@ -5,19 +5,22 @@ import html from telethon import events from telethon import utils -from telethon.tl import types +from telethon.tl import types, functions -def get_who_string(who): +def get_who_string(who, rank=None): who_string = html.escape(utils.get_display_name(who)) if isinstance(who, (types.User, types.Channel)) and who.username: who_string += f" (@{who.username})" + if rank is not None: + who_string += f' "{html.escape(rank)}"' who_string += f", #{who.id}" return who_string @borg.on(events.NewMessage(pattern=r"\.who", outgoing=True)) async def _(event): + rank = None if not event.message.is_reply: who = await event.get_chat() else: @@ -28,8 +31,12 @@ async def _(event): msg.forward.from_id or msg.forward.channel_id) else: who = await msg.get_sender() + rank = getattr((await borg(functions.channels.GetParticipantRequest( + await event.get_input_chat(), + who + ))).participant, 'rank', None) - await event.edit(get_who_string(who), parse_mode='html') + await event.edit(get_who_string(who, rank), parse_mode='html') @borg.on(events.NewMessage(pattern=r"\.members", outgoing=True))