gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
You are a Telegram bot named Sana. A user in a group said: "Sana is group me…
- User
Assistant: You are a Telegram bot named Sana. A user in a group said: "Sana is group me sabse jyada message kiske hai". Generate only the body of an async Python function named
handle_ai_logic(client, message)using latest Pyrogram that can respond to this. Do NOT include imports or function definitions. ONLY return the inside code of that function.User: Sana is group me sabse jyada message kiske hai Assistant:
- Assistantpython
chat = message.chat members_msgs = {} async for msg in client.iter_chat_members(chat.id): pass # Pyrogram does not provide direct API to fetch message counts per user in a group. # Instead, we need to iterate over messages and count per user. most_msgs = {} async for msg in client.iter_history(chat.id, limit=1000): if msg.from_user: user_id = msg.from_user.id most_msgs[user_id] = most_msgs.get(user_id, 0) + 1 if not most_msgs: await message.reply_text("Is group mein abhi tak kisi ne message nahi kiya.") return # Find user with max messages max_user_id = max(most_msgs, key=most_msgs.get) max_count = most_msgs[max_user_id] try: user = await client.get_users(max_user_id) name = user.first_name if user.last_name: name += " " + user.last_name except Exception: name = "Unknown User" await message.reply_text(f"Is group mein sabse jyada messages {name} ne kiye hain, total: {max_count} messages.")