feat: add xm,cai ranking
This commit is contained in:
parent
aca87ce3a0
commit
e4f70dd729
2 changed files with 34 additions and 0 deletions
|
@ -39,6 +39,8 @@ class MessageStatsMiddleware(BaseMiddleware):
|
|||
name = event.from_user.full_name
|
||||
self.stats[chat_id]['users'][user_id] = {
|
||||
'message_count': 0,
|
||||
'xm_count': 0,
|
||||
'wocai_count': 0,
|
||||
'username': event.from_user.username if event.from_user else 'Unknown',
|
||||
'name': name
|
||||
}
|
||||
|
@ -46,6 +48,16 @@ class MessageStatsMiddleware(BaseMiddleware):
|
|||
# 更新统计
|
||||
self.stats[chat_id]['total_messages'] += 1
|
||||
self.stats[chat_id]['users'][user_id]['message_count'] += 1
|
||||
# 羡慕、我菜统计
|
||||
if event.text and any(keyword in event.text.lower() for keyword in ['xm','xmsl','羡慕','羡慕死了']):
|
||||
if not self.stats[chat_id]['users'][user_id]['xm_count']:
|
||||
self.stats[chat_id]['users'][user_id]['xm_count'] = 0
|
||||
self.stats[chat_id]['users'][user_id]['xm_count'] += 1
|
||||
if event.text and '我菜' in event.text:
|
||||
if not self.stats[chat_id]['users'][user_id]['wocai_count']:
|
||||
self.stats[chat_id]['users'][user_id]['xm_count'] = 0
|
||||
self.stats[chat_id]['users'][user_id]['wocai_count'] += 1
|
||||
# 保存统计数据
|
||||
self.save_stats()
|
||||
|
||||
return await handler(event, data)
|
||||
|
|
|
@ -28,6 +28,16 @@ async def handle_stats_command(message: Message):
|
|||
key=lambda x: x[1]['message_count'],
|
||||
reverse=True
|
||||
)
|
||||
sorted_most_xm_users = sorted(
|
||||
stats['users'].items(),
|
||||
key=lambda x: x[1]['xm_count'],
|
||||
reverse=True
|
||||
)
|
||||
sorted_most_wocai_users = sorted(
|
||||
stats['users'].items(),
|
||||
key=lambda x: x[1]['wocai_count'],
|
||||
reverse=True
|
||||
)
|
||||
|
||||
# 构建统计消息
|
||||
text = f"📊 群组统计\n\n"
|
||||
|
@ -38,5 +48,17 @@ async def handle_stats_command(message: Message):
|
|||
for i, (user_id, user_data) in enumerate(sorted_users[:10], 1):
|
||||
name = user_data['name'] or user_data['username'] or str(user_id)
|
||||
text += f"{i}. {name}: {user_data['message_count']} 条\n"
|
||||
if sorted_most_xm_users:
|
||||
text += "\n💬 羡慕统计:\n"
|
||||
for user_id, user_data in sorted_most_xm_users:
|
||||
if user_data['xm_count'] > 0:
|
||||
name = user_data['name'] or user_data['username'] or str(user_id)
|
||||
text += f"{name}: {user_data['xm_count']} 次羡慕\n"
|
||||
if sorted_most_wocai_users:
|
||||
text += "\n🥬 卖菜统计:\n"
|
||||
for user_id, user_data in sorted_most_wocai_users:
|
||||
if user_data['wocai_count'] > 0:
|
||||
name = user_data['name'] or user_data['username'] or str(user_id)
|
||||
text += f"{name}: {user_data['wocai_count']} 次卖菜\n"
|
||||
|
||||
await message.reply(text)
|
Loading…
Add table
Add a link
Reference in a new issue