Бот для капчи в чатах
db.py
@@ -66,7 +66,8 @@
    "type TEXT, "
    "added_at INTEGER, "
    "updated_at INTEGER, "
    "active INTEGER DEFAULT 1)",
    "active INTEGER DEFAULT 1, "
    "msgs INTEGER DEFAULT 0)",
    "CREATE TABLE IF NOT EXISTS usr_fails ("
    "user_id INTEGER, "
    "chat_id INTEGER, "
@@ -211,6 +212,8 @@
            await db.execute("ALTER TABLE reports ADD COLUMN target_msg_id INTEGER DEFAULT 0")
        if not await col_exists(db, "reports", "target_text"):
            await db.execute("ALTER TABLE reports ADD COLUMN target_text TEXT DEFAULT ''")
    if await tbl_exists(db, "chats") and not await col_exists(db, "chats", "msgs"):
        await db.execute("ALTER TABLE chats ADD COLUMN msgs INTEGER DEFAULT 0")
async def init_db() -> None:
@@ -229,10 +232,11 @@
async def upsert_chat(chat_id: int, title: Optional[str], ctype: Optional[str], ts: int) -> None:
    async with db_conn() as db:
        await db.execute(
            "INSERT INTO chats (chat_id, title, type, added_at, updated_at, active) "
            "VALUES (?, ?, ?, ?, ?, 1) "
            "INSERT INTO chats (chat_id, title, type, added_at, updated_at, active, msgs) "
            "VALUES (?, ?, ?, ?, ?, 1, 1) "
            "ON CONFLICT(chat_id) DO UPDATE SET "
            "title=excluded.title, type=excluded.type, updated_at=excluded.updated_at, active=1",
            "title=excluded.title, type=excluded.type, updated_at=excluded.updated_at, "
            "active=1, msgs=msgs+1",
            (chat_id, title, ctype, ts, ts),
        )
        await db.commit()