From c3b75e7400eab11e7bd312d9c7e7c57972cfe209 Mon Sep 17 00:00:00 2001
From: Roman Sergienko <romasergienko@outlook.com>
Date: Sat, 10 Oct 2026 14:53:46 +0000
Subject: [PATCH] feat: команда /version из хэша коммита, значки в мобильной навигации, версия в сайдбаре
---
db.py | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/db.py b/db.py
index d5f649e..37b7192 100644
--- a/db.py
+++ b/db.py
@@ -405,6 +405,36 @@
}
+async def stats_scoped(ids, ts: int) -> dict:
+ # Статистика только по доступным пользователю чатам (для дашборда).
+ result = {"chats": len(ids), "warns": 0, "mutes": 0, "bans": 0, "logs": 0}
+ ids = list(ids)
+ if not ids:
+ return result
+ ph = ",".join("?" for _ in ids)
+ async with db_conn() as db:
+ async def one(q: str, args: tuple):
+ async with db.execute(q, args) as cur:
+ return (await cur.fetchone())[0]
+ result["warns"] = await one(
+ f"SELECT COUNT(*) FROM warns WHERE chat_id IN ({ph}) "
+ f"AND (expires_at IS NULL OR expires_at > ?)",
+ tuple(ids) + (ts,),
+ )
+ result["mutes"] = await one(
+ f"SELECT COUNT(*) FROM punish WHERE chat_id IN ({ph}) AND active=1 AND kind='mute'",
+ tuple(ids),
+ )
+ result["bans"] = await one(
+ f"SELECT COUNT(*) FROM punish WHERE chat_id IN ({ph}) AND active=1 AND kind='ban'",
+ tuple(ids),
+ )
+ result["logs"] = await one(
+ f"SELECT COUNT(*) FROM mod_log WHERE chat_id IN ({ph})", tuple(ids)
+ )
+ return result
+
+
async def add_log(chat_id: int, admin_id: int, target_id: int, action: str, reason: str, ts: int) -> None:
async with db_conn() as db:
await db.execute(
--
Gitblit v1.9.3