What I want to accomplish is to calculate the ranking of the most active users in a group. My approach to it was to first iterate through all message history in a group, get the user name, assign the message to it and then sort it in python from highest (most often sent from a given user) to lowest, but I have no idea how to make it programmatically and I've been stuck in this code:
async def calculate_ranking(event):
@client.on(events.NewMessage)
async def calculate_ranking(event):
messages = {}
if "!ranking" in event.raw_text:
chat_id = event.chat_id
async for message in client.iter_messages(chat_id, reverse=True):
author = message.sender.username
messages[author] += 1
print(messages)
I have no idea on how to assign a message to a user so the output would be as for example:
- user1: 12 messages
- user2: 10 messages