Бот для капчи в чатах
track.py
@@ -7,13 +7,20 @@
@dp.message.middleware()
async def track_msg(handler, event: types.Message, data: dict):
    # Фиксируем чаты, где присутствует бот, для веб-панели.
    # Фиксируем чаты и пользователей, чтобы панель и /aperm могли их находить.
    chat = event.chat
    ts = now_ts()
    if chat and chat.type in ("group", "supergroup", "channel"):
        try:
            await db.upsert_chat(chat.id, chat.title, chat.type, now_ts())
            await db.upsert_chat(chat.id, chat.title, chat.type, ts)
        except Exception as e:
            logger.warning("upsert_chat failed chat=%s: %s", chat.id, e)
    u = event.from_user
    if u is not None and not u.is_bot:
        try:
            await db.upsert_user(u.id, u.username, u.first_name, u.last_name, ts)
        except Exception as e:
            logger.warning("upsert_user failed user=%s: %s", u.id, e)
    return await handler(event, data)