From 6f8af10b277f5eb053f8312a1d39178e25eee84e Mon Sep 17 00:00:00 2001
From: Roman Sergienko <romasergienko@outlook.com>
Date: Sat, 10 Oct 2026 17:25:15 +0000
Subject: [PATCH] fix: длительность мутов/банов (команды и триггеры варнов) считалась как абсолютное время; текст и срок теперь верные
---
util.py | 2 +-
flood.py | 4 ++--
web/templates/user.html | 2 +-
web/templates/users.html | 2 +-
web/templates/chat.html | 2 +-
mod.py | 11 +++++++----
6 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/flood.py b/flood.py
index c702cb2..41fa980 100644
--- a/flood.py
+++ b/flood.py
@@ -113,7 +113,7 @@
"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, "Превышен лимит сообщений")
+ await apply_mute(chat_id, user_id, u.full_name, mute, 0, "Превышен лимит сообщений")
return
# Копипаста во время тревоги: одинаковый текст от 3+ разных аккаунтов.
@@ -129,4 +129,4 @@
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, "Копипаста при тревоге")
+ await apply_mute(chat_id, uid, str(uid), cfg["flood_alarm_mute"], 0, "Копипаста при тревоге")
diff --git a/mod.py b/mod.py
index ca36c64..9adda98 100644
--- a/mod.py
+++ b/mod.py
@@ -21,8 +21,10 @@
# --- Ядро действий ---
-async def apply_mute(chat_id: int, user_id: int, name: str, until: Optional[int], admin_id: int, reason: str) -> bool:
+async def apply_mute(chat_id: int, user_id: int, name: str, dur: Optional[int], admin_id: int, reason: str) -> bool:
+ # dur — длительность в секундах (None или 0 = бессрочно). until_date — абсолютное время.
ts = now_ts()
+ until = None if not dur else ts + dur
try:
await bot.restrict_chat_member(chat_id, user_id, permissions=NO_PERMS, until_date=until)
except Exception as e:
@@ -30,12 +32,13 @@
return False
await db.add_punish(chat_id, user_id, "mute", admin_id, reason, ts, until)
await db.add_log(chat_id, admin_id, user_id, "mute", reason, ts)
- await _notice(chat_id, f"Пользователь {mention(user_id, name)} замучен на {fmt_dur(until)}. Причина: {reason or '-'}")
+ await _notice(chat_id, f"Пользователь {mention(user_id, name)} замучен на {fmt_dur(dur)}. Причина: {reason or '-'}")
return True
-async def apply_ban(chat_id: int, user_id: int, name: str, until: Optional[int], admin_id: int, reason: str) -> bool:
+async def apply_ban(chat_id: int, user_id: int, name: str, dur: Optional[int], admin_id: int, reason: str) -> bool:
ts = now_ts()
+ until = None if not dur else ts + dur
try:
await bot.ban_chat_member(chat_id, user_id)
except Exception as e:
@@ -43,7 +46,7 @@
return False
await db.add_punish(chat_id, user_id, "ban", admin_id, reason, ts, until)
await db.add_log(chat_id, admin_id, user_id, "ban", reason, ts)
- await _notice(chat_id, f"Пользователь {mention(user_id, name)} забанен на {fmt_dur(until)}. Причина: {reason or '-'}")
+ await _notice(chat_id, f"Пользователь {mention(user_id, name)} забанен на {fmt_dur(dur)}. Причина: {reason or '-'}")
return True
diff --git a/util.py b/util.py
index 4937b3f..a42ec70 100644
--- a/util.py
+++ b/util.py
@@ -79,7 +79,7 @@
def fmt_dur(seconds: Optional[int]) -> str:
- if seconds is None:
+ if not seconds:
return "бессрочно"
parts = []
for name, size in (("д", 86400), ("ч", 3600), ("м", 60), ("с", 1)):
diff --git a/web/templates/chat.html b/web/templates/chat.html
index 3cf1f24..0de6a8c 100644
--- a/web/templates/chat.html
+++ b/web/templates/chat.html
@@ -242,7 +242,7 @@
<span class="min-w-0 truncate">
{{ "мут" if p.kind == "mute" else "бан" }} ·
<a class="text-brand-600 hover:underline dark:text-brand-400" href="/users/{{ chat.chat_id }}/{{ p.user_id }}">{{ p.user_id }}</a>
- · {{ fmt_dur(p.until) if p.until else "бессрочно" }}
+ · {{ fmt_dt(p.until) if p.until else "бессрочно" }}
{% if not p.active %}<span class="text-xs text-gray-400">(снято)</span>{% endif %}
</span>
<span class="ml-2 shrink-0 text-gray-500">{{ fmt_dt(p.created_at) }}</span>
diff --git a/web/templates/user.html b/web/templates/user.html
index b5d5cd6..7a209b5 100644
--- a/web/templates/user.html
+++ b/web/templates/user.html
@@ -51,7 +51,7 @@
<div class="divide-y divide-gray-100 dark:divide-gray-800">
{% for p in hist %}
<div class="px-5 py-3 text-sm flex items-center justify-between">
- <span>{{ "мут" if p.kind == "mute" else "бан" }} · {{ fmt_dur(p.until) if p.until else "бессрочно" }} {% if not p.active %}<span class="text-xs text-gray-400">(снято)</span>{% endif %}</span>
+ <span>{{ "мут" if p.kind == "mute" else "бан" }} · {{ fmt_dt(p.until) if p.until else "бессрочно" }} {% if not p.active %}<span class="text-xs text-gray-400">(снято)</span>{% endif %}</span>
<span class="text-gray-500">{{ fmt_dt(p.created_at) }}</span>
</div>
{% else %}
diff --git a/web/templates/users.html b/web/templates/users.html
index 349a787..7cee534 100644
--- a/web/templates/users.html
+++ b/web/templates/users.html
@@ -17,7 +17,7 @@
</span>
</div>
<div class="mt-1 truncate text-xs text-gray-500">{{ names.get(p.chat_id, p.chat_id) }}</div>
- <div class="mt-2 text-sm">Срок: {{ fmt_dur(p.until) if p.until else "бессрочно" }}</div>
+ <div class="mt-2 text-sm">Срок: до {{ fmt_dt(p.until) if p.until else "бессрочно" }}</div>
<div class="mt-1 line-clamp-2 text-xs text-gray-500">{{ p.reason or "без причины" }} · {{ fmt_dt(p.created_at) }}</div>
</a>
{% else %}
--
Gitblit v1.9.3