From 9fe2e80742080b6e60372c75134e069a63b1bff7 Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Sat, 7 Sep 2019 08:08:07 +0000 Subject: [PATCH] Count messages and sort by top posters --- stdplugins/who.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/stdplugins/who.py b/stdplugins/who.py index 33c81b0..3982344 100644 --- a/stdplugins/who.py +++ b/stdplugins/who.py @@ -34,8 +34,19 @@ async def _(event): @borg.on(events.NewMessage(pattern=r"\.members", outgoing=True)) async def _(event): - members = [ - get_who_string(m) async for m in borg.iter_participants(event.chat_id) - ] + members = [] + async for member in borg.iter_participants(event.chat_id): + messages = await borg.get_messages( + event.chat_id, + from_user=member, + limit=0 + ) + members.append(( + messages.total, + f"{messages.total} - {get_who_string(member)}" + )) + members = ( + m[1] for m in sorted(members, key=lambda m: m[0], reverse=True) + ) await event.edit("\n".join(members), parse_mode='html')