Статистика разделена на две команды.
This commit is contained in:
parent
2333e05f28
commit
f98ef98b3b
1 changed files with 16 additions and 4 deletions
20
bot.py
20
bot.py
|
|
@ -5,7 +5,7 @@ from vkbottle import GroupTypes, GroupEventType
|
||||||
from vkbottle.bot import Bot, Message
|
from vkbottle.bot import Bot, Message
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from config import db_load, db_save, db_print
|
from config import db_load, db_save
|
||||||
|
|
||||||
db_load()
|
db_load()
|
||||||
db_save()
|
db_save()
|
||||||
|
|
@ -53,8 +53,8 @@ async def stats_handler(message: Message):
|
||||||
await message.answer('Готова к работе!')
|
await message.answer('Готова к работе!')
|
||||||
|
|
||||||
|
|
||||||
@bot.on.chat_message(text="!статистика")
|
@bot.on.chat_message(text="!сегодня")
|
||||||
async def stats_handler(message: Message):
|
async def stats_today_handler(message: Message):
|
||||||
chat_id = str(message.peer_id)
|
chat_id = str(message.peer_id)
|
||||||
|
|
||||||
chat_users = []
|
chat_users = []
|
||||||
|
|
@ -72,8 +72,20 @@ async def stats_handler(message: Message):
|
||||||
response += '{}. {} {} - {}\n'.format(i + 1, info.first_name, info.last_name, top[i]['messages_today'])
|
response += '{}. {} {} - {}\n'.format(i + 1, info.first_name, info.last_name, top[i]['messages_today'])
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
|
await message.answer(response)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.on.chat_message(text="!месяц")
|
||||||
|
async def stats_month_handler(message: Message):
|
||||||
|
chat_id = str(message.peer_id)
|
||||||
|
|
||||||
|
chat_users = []
|
||||||
|
for user_id in config.DB['chats'][chat_id]['users'].keys():
|
||||||
|
flat_user = {**{'id': user_id}, **config.DB['chats'][chat_id]['users'][user_id]}
|
||||||
|
chat_users.append(flat_user)
|
||||||
|
|
||||||
top = sorted(chat_users, key=lambda item: item['messages_month'], reverse=True)
|
top = sorted(chat_users, key=lambda item: item['messages_month'], reverse=True)
|
||||||
response += '\n* Статистика за месяц:\n'
|
response = '\n* Статистика за месяц:\n'
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(top):
|
while i < len(top):
|
||||||
if top[i]['messages_month'] == 0:
|
if top[i]['messages_month'] == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue