| | |
| | | } |
| | | |
| | | |
| | | 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( |