chanserv: channel SUSPEND / UNSUSPEND (oper-gated)
Freezes a channel gated on Priv::Suspend: a typed Suspension on ChannelInfo (event-logged, snapshotted, lazy expiry — same shape as the account one, no Anope Extensible/Checker or expiry timer). While suspended, ChanServ refuses all management (guards in require_op/require_founder and the founder-inline SET/DROP/MLOCK), the engine skips Join enforcement (no auto-op/akick/entrymsg), and suspending kicks everyone out; INFO shows it. parse_duration moved into the SDK so both SUSPEND commands share it. Data + full-flow tests.
This commit is contained in:
parent
bbbe2c6cb8
commit
cb081a2e95
8 changed files with 241 additions and 18 deletions
53
chanserv/src/suspend.rs
Normal file
53
chanserv/src/suspend.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use fedserv_api::{parse_duration, NetView, Priv, Sender, ServiceCtx, Store};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
// SUSPEND <#channel> [+expiry] [reason] / UNSUSPEND <#channel>: freeze or unfreeze
|
||||
// a channel. Its data is kept but it can't be managed while suspended. Oper-only
|
||||
// (Priv::Suspend). `suspending` selects SUSPEND vs UNSUSPEND.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store, suspending: bool) {
|
||||
if !from.privs.has(Priv::Suspend) {
|
||||
ctx.notice(me, from.uid, "Access denied — that command is for services operators.");
|
||||
return;
|
||||
}
|
||||
let Some(&chan) = args.get(1) else {
|
||||
let syntax = if suspending { "Syntax: SUSPEND <#channel> [+expiry] [reason]" } else { "Syntax: UNSUSPEND <#channel>" };
|
||||
ctx.notice(me, from.uid, syntax);
|
||||
return;
|
||||
};
|
||||
if db.channel(chan).is_none() {
|
||||
ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered."));
|
||||
return;
|
||||
}
|
||||
|
||||
if !suspending {
|
||||
match db.unsuspend_channel(chan) {
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("\x02{chan}\x02 is no longer suspended.")),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't suspended.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let mut rest = &args[2..];
|
||||
let expires = rest.first().and_then(|t| t.strip_prefix('+')).and_then(parse_duration).map(|secs| now_unix() + secs);
|
||||
if expires.is_some() {
|
||||
rest = &rest[1..];
|
||||
}
|
||||
let reason = if rest.is_empty() { "This channel has been suspended.".to_string() } else { rest.join(" ") };
|
||||
let by = from.account.unwrap_or(from.nick);
|
||||
match db.suspend_channel(chan, by, &reason, expires) {
|
||||
Ok(()) => {
|
||||
// Clear the channel: kick everyone currently in it.
|
||||
for uid in net.channel_members(chan) {
|
||||
ctx.kick(me, chan, &uid, &reason);
|
||||
}
|
||||
let expiry = if expires.is_some() { " (with expiry)" } else { "" };
|
||||
ctx.notice(me, from.uid, format!("\x02{chan}\x02 is now suspended{expiry}."));
|
||||
}
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
|
||||
fn now_unix() -> u64 {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue