diff --git a/bot.py b/bot.py index a3b215a..dfd5191 100644 --- a/bot.py +++ b/bot.py @@ -5,7 +5,7 @@ from vkbottle import GroupTypes, GroupEventType from vkbottle.bot import Bot, Message import config -from config import db_load, db_save, db_print +from config import db_load, db_save db_load() db_save() @@ -53,8 +53,8 @@ async def stats_handler(message: Message): await message.answer('Готова к работе!') -@bot.on.chat_message(text="!статистика") -async def stats_handler(message: Message): +@bot.on.chat_message(text="!сегодня") +async def stats_today_handler(message: Message): chat_id = str(message.peer_id) 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']) 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) - response += '\n* Статистика за месяц:\n' + response = '\n* Статистика за месяц:\n' i = 0 while i < len(top): if top[i]['messages_month'] == 0: