Боты не добавляются в БД.

This commit is contained in:
Kirill Kirilenko 2025-08-20 16:29:59 +03:00
parent ed82166bdc
commit 2333e05f28

11
bot.py
View file

@ -7,7 +7,6 @@ from vkbottle.bot import Bot, Message
import config
from config import db_load, db_save, db_print
db_load()
db_save()
bot = Bot(config.DB['api_token'])
@ -39,6 +38,8 @@ async def stats_handler(message: Message):
chat_members = await bot.api.messages.get_conversation_members(peer_id=message.peer_id, extended=False)
for member in chat_members.items:
if member.member_id < 0:
continue
member_id = str(member.member_id)
if member_id not in config.DB['chats'][chat_id]['users']:
config.DB['chats'][chat_id]['users'][member_id] = {
@ -90,7 +91,8 @@ async def silent_handler(message: Message):
chat_users = []
for user_id in config.DB['chats'][chat_id]['users'].keys():
flat_user = {**{'id': user_id}, **{'last_message': config.DB['chats'][chat_id]['users'][user_id]['last_message']}}
flat_user = {**{'id': user_id},
**{'last_message': config.DB['chats'][chat_id]['users'][user_id]['last_message']}}
chat_users.append(flat_user)
top = sorted(chat_users, key=lambda item: item['last_message'])
@ -100,6 +102,8 @@ async def silent_handler(message: Message):
for i in range(0, len(top)):
if top[i]['last_message'] == 0:
info = await get_user_info(top[i]['id'])
if info is None:
continue
response += '{}. {} {} - никогда\n'.format(i + 1, info.first_name, info.last_name)
else:
days_silent = round((now - top[i]['last_message']) / 3600 / 24)
@ -113,6 +117,9 @@ async def silent_handler(message: Message):
@bot.on.chat_message()
async def any_message_handler(message: Message):
if message.from_id < 0:
return
chat_id = str(message.peer_id)
user_id = str(message.from_id)
if chat_id not in config.DB['chats']: