fix: длительность мутов/банов (команды и триггеры варнов) считалась как абсолютное время; текст и срок теперь верные
| | |
| | | "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+ разных аккаунтов. |
| | |
| | | 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, "Копипаста при тревоге") |
| | |
| | | |
| | | # --- Ядро действий --- |
| | | |
| | | 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: |
| | |
| | | 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: |
| | |
| | | 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 |
| | | |
| | | |
| | |
| | | |
| | | |
| | | def fmt_dur(seconds: Optional[int]) -> str: |
| | | if seconds is None: |
| | | if not seconds: |
| | | return "бессрочно" |
| | | parts = [] |
| | | for name, size in (("д", 86400), ("ч", 3600), ("м", 60), ("с", 1)): |
| | |
| | | <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> |
| | |
| | | <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 %} |
| | |
| | | </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 %} |