Add SIGNKICK LEVEL mode: sign only kicks by users without op access
All checks were successful
CI / check (push) Successful in 5m19s

This commit is contained in:
Jean Chevronnet 2026-07-20 22:00:34 +00:00
parent ae90388fbf
commit 140b19ee04
No known key found for this signature in database
9 changed files with 72 additions and 8 deletions

View file

@ -20,9 +20,13 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
return;
}
let mut reason = if args.len() > 3 { args[3..].join(" ") } else { "Kicked".to_string() };
// SIGNKICK: attribute the kick to whoever asked for it.
if db.channel(chan).is_some_and(|c| c.signkick) {
reason = format!("{reason} (requested by {})", from.nick);
// SIGNKICK: attribute the kick to the requester. LEVEL mode signs only kicks
// by users without op-level access, leaving trusted ops' kicks unsigned.
if let Some(c) = db.channel(chan) {
let kicker_op = from.account.is_some_and(|a| c.is_op(a));
if c.signkick && (!c.signkick_level || !kicker_op) {
reason = format!("{reason} (requested by {})", from.nick);
}
}
ctx.kick(me, chan, target, &reason);
}

View file

@ -197,7 +197,7 @@ impl Service for ChanServ {
ctx.notice(me, from.uid, t!(ctx, " Suspended : by \x02{by}\x02 — {reason}", by = s.by, reason = s.reason));
}
let mut opts = Vec::new();
if info.signkick { opts.push("SIGNKICK"); }
if info.signkick { opts.push(if info.signkick_level { "SIGNKICK (level)" } else { "SIGNKICK" }); }
if info.private { opts.push("PRIVATE"); }
if info.peace { opts.push("PEACE"); }
if info.secureops { opts.push("SECUREOPS"); }

View file

@ -89,7 +89,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}
Some("SIGNKICK") => toggle(me, from, ctx, db, chan, ChanSetting::SignKick, args.get(3).copied()),
Some("SIGNKICK") => signkick_set(me, from, ctx, db, chan, args.get(3).copied()),
Some("PRIVATE") => toggle(me, from, ctx, db, chan, ChanSetting::Private, args.get(3).copied()),
Some("PEACE") => toggle(me, from, ctx, db, chan, ChanSetting::Peace, args.get(3).copied()),
Some("SECUREOPS") => toggle(me, from, ctx, db, chan, ChanSetting::SecureOps, args.get(3).copied()),
@ -98,14 +98,14 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
Some("AUTOOP") => toggle(me, from, ctx, db, chan, ChanSetting::AutoOp, args.get(3).copied()),
Some("KEEPTOPIC") => toggle(me, from, ctx, db, chan, ChanSetting::KeepTopic, args.get(3).copied()),
Some("TOPICLOCK") => toggle(me, from, ctx, db, chan, ChanSetting::TopicLock, args.get(3).copied()),
_ => ctx.notice(me, from.uid, "Syntax: SET <#channel> FOUNDER <account> | SUCCESSOR <account>|OFF | DESC <text> | URL [address] | EMAIL [address] | SIGNKICK {ON|OFF} | PRIVATE {ON|OFF} | PEACE {ON|OFF} | SECUREOPS {ON|OFF} | SECUREVOICES {ON|OFF} | RESTRICTED {ON|OFF} | AUTOOP {ON|OFF} | KEEPTOPIC {ON|OFF} | TOPICLOCK {ON|OFF}"),
_ => ctx.notice(me, from.uid, "Syntax: SET <#channel> FOUNDER <account> | SUCCESSOR <account>|OFF | DESC <text> | URL [address] | EMAIL [address] | SIGNKICK {ON|OFF|LEVEL} | PRIVATE {ON|OFF} | PEACE {ON|OFF} | SECUREOPS {ON|OFF} | SECUREVOICES {ON|OFF} | RESTRICTED {ON|OFF} | AUTOOP {ON|OFF} | KEEPTOPIC {ON|OFF} | TOPICLOCK {ON|OFF}"),
}
}
// The SET keyword for a channel option, used in its messages.
fn label(setting: ChanSetting) -> &'static str {
match setting {
ChanSetting::SignKick => "SIGNKICK",
ChanSetting::SignKick | ChanSetting::SignKickLevel => "SIGNKICK",
ChanSetting::Private => "PRIVATE",
ChanSetting::Peace => "PEACE",
ChanSetting::SecureOps => "SECUREOPS",
@ -120,6 +120,25 @@ fn label(setting: ChanSetting) -> &'static str {
}
// Flip one on/off channel option, reporting the new state.
// SIGNKICK is three-state: ON (sign every CS KICK), LEVEL (sign only kicks by
// users without op access), OFF. Stored as the signkick + signkick_level pair.
fn signkick_set(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &mut dyn Store, chan: &str, arg: Option<&str>) {
let (on, level, state) = match arg.map(|s| s.to_ascii_uppercase()).as_deref() {
Some("ON") => (true, false, "on"),
Some("LEVEL") => (true, true, "level"),
Some("OFF") => (false, false, "off"),
_ => {
ctx.notice(me, from.uid, "Syntax: SET <#channel> SIGNKICK {ON|OFF|LEVEL}");
return;
}
};
let _ = db.set_channel_setting(chan, ChanSetting::SignKick, on);
match db.set_channel_setting(chan, ChanSetting::SignKickLevel, level) {
Ok(()) => ctx.notice(me, from.uid, t!(ctx, "\x02{name}\x02 for \x02{chan}\x02 is now \x02{state}\x02.", name = "SIGNKICK", chan = chan, state = state)),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}
fn toggle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &mut dyn Store, chan: &str, setting: ChanSetting, arg: Option<&str>) {
let name = label(setting);
let on = match arg.map(|s| s.to_ascii_uppercase()).as_deref() {