From 6f685dfb0aa1513c127e64986477188697d8e180 Mon Sep 17 00:00:00 2001
From: Roman Sergienko <romasergienko@outlook.com>
Date: Sat, 10 Oct 2026 15:55:26 +0000
Subject: [PATCH] feat: репорты (защита от жалоб на бота/себя, ссылка и текст сообщения, принять/отклонить/очистить) + скрытые фановые команды Steins;Gate

---
 db.py |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/db.py b/db.py
index cedf1ef..058397d 100644
--- a/db.py
+++ b/db.py
@@ -129,7 +129,9 @@
     "target_id INTEGER, "
     "text TEXT, "
     "created_at INTEGER, "
-    "status TEXT DEFAULT 'new')",
+    "status TEXT DEFAULT 'new', "
+    "target_msg_id INTEGER DEFAULT 0, "
+    "target_text TEXT DEFAULT '')",
     "CREATE TABLE IF NOT EXISTS report_block ("
     "user_id INTEGER, "
     "chat_id INTEGER, "
@@ -204,6 +206,11 @@
                 await db.execute(f"ALTER TABLE chat_cfg ADD COLUMN {col} {ddl}")
     if await tbl_exists(db, "alarm") and not await col_exists(db, "alarm", "until"):
         await db.execute("ALTER TABLE alarm ADD COLUMN until INTEGER DEFAULT 0")
+    if await tbl_exists(db, "reports"):
+        if not await col_exists(db, "reports", "target_msg_id"):
+            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 ''")
 
 
 async def init_db() -> None:
@@ -651,17 +658,30 @@
 
 # --- Репорты ---
 
-async def add_report(chat_id: int, user_id: int, target_id: int, text: str, ts: int) -> int:
+async def add_report(chat_id: int, user_id: int, target_id: int, text: str, ts: int, target_msg_id: int = 0, target_text: str = "") -> int:
     async with db_conn() as db:
         cur = await db.execute(
-            "INSERT INTO reports (chat_id, user_id, target_id, text, created_at, status) "
-            "VALUES (?, ?, ?, ?, ?, 'new')",
-            (chat_id, user_id, target_id, text, ts),
+            "INSERT INTO reports (chat_id, user_id, target_id, text, created_at, status, target_msg_id, target_text) "
+            "VALUES (?, ?, ?, ?, ?, 'new', ?, ?)",
+            (chat_id, user_id, target_id, text, ts, target_msg_id, target_text),
         )
         await db.commit()
         return cur.lastrowid
 
 
+async def get_report(report_id: int) -> Optional[dict]:
+    async with db_conn() as db:
+        async with db.execute("SELECT * FROM reports WHERE id=?", (report_id,)) as cur:
+            row = await cur.fetchone()
+    return dict(row) if row else None
+
+
+async def clr_reports(chat_id: int) -> None:
+    async with db_conn() as db:
+        await db.execute("DELETE FROM reports WHERE chat_id=?", (chat_id,))
+        await db.commit()
+
+
 async def list_reports(chat_id: int, limit: int = 200) -> List[dict]:
     async with db_conn() as db:
         async with db.execute(

--
Gitblit v1.9.3