Бот для капчи в чатах
Roman Sergienko
12 hours ago 809dbd0256d170a5c868f2bb112dbc92cc3f23d2
mod.py
@@ -7,6 +7,7 @@
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, refuse_self_phrase, resolve_usr
@@ -20,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:
@@ -29,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:
@@ -42,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
@@ -269,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"]