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

---
 flood.py |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/flood.py b/flood.py
index b962066..c702cb2 100644
--- a/flood.py
+++ b/flood.py
@@ -4,6 +4,7 @@
 
 from aiogram import types
 
+import cfg
 import db
 from cfg import bot, dp, logger
 from mod import apply_mute
@@ -25,11 +26,17 @@
 
 
 async def _is_staff(chat_id: int, user_id: int) -> bool:
+    # Владельца бота и админов не трогаем никогда.
+    if user_id == cfg.OWNER_ID:
+        return True
     ts = now_ts()
     cached = _STAFF.get((chat_id, user_id))
     if cached and cached[0] > ts:
         return cached[1]
     status = await member_status(chat_id, user_id)
+    if status is None:
+        # Не удалось проверить — не наказываем (безопасный режим), не кэшируем.
+        return True
     result = status in ("administrator", "creator")
     _STAFF[(chat_id, user_id)] = (ts + _STAFF_TTL, result)
     return result
@@ -102,6 +109,10 @@
             is_new = joined and (ts - joined) < cfg["new_member_days"] * 86400
             if is_new:
                 mute = cfg["flood_alarm_mute"]
+        logger.info(
+            "antiflood: chat=%s user=%s messages=%s/%ss mute=%ss alarm=%s",
+            chat_id, user_id, cfg["flood_count"], cfg["flood_window"], mute, on,
+        )
         await apply_mute(chat_id, user_id, u.full_name, ts + mute, 0, "Превышен лимит сообщений")
         return
 
@@ -115,6 +126,7 @@
         users = {uid for _, uid in d}
         if len(users) >= 3:
             d.clear()
+            logger.info("antiflood: копипаста chat=%s users=%s", chat_id, users)
             for uid in users:
                 if not await _is_staff(chat_id, uid):
                     await apply_mute(chat_id, uid, str(uid), ts + cfg["flood_alarm_mute"], 0, "Копипаста при тревоге")

--
Gitblit v1.9.3