From 6e9cc965b59946ba08c914c7384e173c4a30f7bc Mon Sep 17 00:00:00 2001
From: Roman Sergienko <romasergienko@outlook.com>
Date: Fri, 04 Dec 2026 11:51:15 +0000
Subject: [PATCH] Update RP actions in place without page reload
---
mod.py | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/mod.py b/mod.py
index a6c949f..9adda98 100644
--- a/mod.py
+++ b/mod.py
@@ -6,9 +6,11 @@
from aiogram.filters import Command, CommandObject
import db
+import cfg
+import alarm
from cfg import OWNER_ID, FULL_PERMS, NO_PERMS, DEF_WARN_EXPIRE, bot, dp, logger
from perms import P_BAN, P_MUTE, P_UNBAN, P_UNMUTE, P_UNWARN, P_WARN, check_perm, member_status
-from util import fmt_dur, mention, msg_target, now_ts, parse_dur, refuse_phrase, resolve_usr
+from util import fmt_dur, mention, msg_target, now_ts, parse_dur, refuse_phrase, refuse_self_phrase, resolve_usr
# Шаблон токена длительности: 10m, 2h, 7d, '-' (бессрочно).
DUR_RE = re.compile(r"^(\d+[smhdwSMHDW]?|-|forever|perm|permanent)$", re.IGNORECASE)
@@ -19,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:
@@ -28,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:
@@ -41,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
@@ -140,6 +145,9 @@
return False
chat_id = message.chat.id
actor = message.from_user.id
+ if target_id == cfg.BOT_ID:
+ await message.reply(refuse_self_phrase())
+ return False
if target_id == OWNER_ID:
await message.reply(f"{OWNER_BLOCK} {refuse_phrase()}")
return False
@@ -265,6 +273,7 @@
async def _bg_tick() -> None:
ts = now_ts()
await db.exp_warns(ts)
+ await alarm.expire_check(ts)
for row in await db.due_unbans(ts):
chat_id = row["chat_id"]
user_id = row["user_id"]
--
Gitblit v1.9.3