ChanServ: add OWNER/PROTECT/HALFOP status commands
All checks were successful
CI / check (push) Successful in 3m47s
All checks were successful
CI / check (push) Successful in 3m47s
OWNER/DEOWNER (+q), PROTECT/DEPROTECT (+a, alias ADMIN), and HALFOP/DEHALFOP (+h) set the higher channel-status modes. They reuse the OP handler's target resolution and PEACE check; OWNER is founder-only, the rest need op access.
This commit is contained in:
parent
30e91bb295
commit
6e3a758cc1
3 changed files with 51 additions and 1 deletions
|
|
@ -58,6 +58,7 @@ const TOPICS: &[HelpEntry] = &[
|
||||||
HelpEntry { cmd: "STATUS", summary: "show a user's access", detail: "Syntax: \x02STATUS <#channel> [nick]\x02\nShows a user's access level on a channel." },
|
HelpEntry { cmd: "STATUS", summary: "show a user's access", detail: "Syntax: \x02STATUS <#channel> [nick]\x02\nShows a user's access level on a channel." },
|
||||||
HelpEntry { cmd: "OP/DEOP/VOICE/DEVOICE", summary: "give or take op/voice", detail: "Syntax: \x02OP|DEOP|VOICE|DEVOICE <#channel> [nick]\x02\nGives or takes channel op or voice." },
|
HelpEntry { cmd: "OP/DEOP/VOICE/DEVOICE", summary: "give or take op/voice", detail: "Syntax: \x02OP|DEOP|VOICE|DEVOICE <#channel> [nick]\x02\nGives or takes channel op or voice." },
|
||||||
HelpEntry { cmd: "UP/DOWN", summary: "apply or drop your status", detail: "Syntax: \x02UP|DOWN <#channel>\x02\nUP re-applies the op/voice your access entitles you to; DOWN removes your status." },
|
HelpEntry { cmd: "UP/DOWN", summary: "apply or drop your status", detail: "Syntax: \x02UP|DOWN <#channel>\x02\nUP re-applies the op/voice your access entitles you to; DOWN removes your status." },
|
||||||
|
HelpEntry { cmd: "OWNER/PROTECT/HALFOP", summary: "give or take higher status", detail: "Syntax: \x02OWNER|PROTECT|HALFOP <#channel> [nick]\x02 (and \x02DEOWNER|DEPROTECT|DEHALFOP\x02)\nSets +q/+a/+h. OWNER is founder-only; PROTECT and HALFOP need op access." },
|
||||||
HelpEntry { cmd: "KICK", summary: "kick from the channel", detail: "Syntax: \x02KICK <#channel> <nick> [reason]\x02\nKicks a user from the channel." },
|
HelpEntry { cmd: "KICK", summary: "kick from the channel", detail: "Syntax: \x02KICK <#channel> <nick> [reason]\x02\nKicks a user from the channel." },
|
||||||
HelpEntry { cmd: "BAN/UNBAN", summary: "ban or unban a user", detail: "Syntax: \x02BAN <#channel> <nick> [reason]\x02, \x02UNBAN <#channel> [nick]\x02\nBans or unbans a user by host." },
|
HelpEntry { cmd: "BAN/UNBAN", summary: "ban or unban a user", detail: "Syntax: \x02BAN <#channel> <nick> [reason]\x02, \x02UNBAN <#channel> [nick]\x02\nBans or unbans a user by host." },
|
||||||
HelpEntry { cmd: "AKICK", summary: "manage the auto-kick list", detail: "Syntax: \x02AKICK <#channel> ADD <mask> [reason] | DEL <mask> | LIST | CLEAR\x02\nManages the auto-kick list; matches are banned and kicked on join. CLEAR empties it." },
|
HelpEntry { cmd: "AKICK", summary: "manage the auto-kick list", detail: "Syntax: \x02AKICK <#channel> ADD <mask> [reason] | DEL <mask> | LIST | CLEAR\x02\nManages the auto-kick list; matches are banned and kicked on join. CLEAR empties it." },
|
||||||
|
|
@ -255,6 +256,12 @@ impl Service for ChanServ {
|
||||||
Some("DEVOICE") => op::handle(me, from, "-v", args, ctx, net, db),
|
Some("DEVOICE") => op::handle(me, from, "-v", args, ctx, net, db),
|
||||||
Some("UP") => updown::handle(me, from, true, args, ctx, net, db),
|
Some("UP") => updown::handle(me, from, true, args, ctx, net, db),
|
||||||
Some("DOWN") => updown::handle(me, from, false, args, ctx, net, db),
|
Some("DOWN") => updown::handle(me, from, false, args, ctx, net, db),
|
||||||
|
Some("OWNER") => op::handle(me, from, "+q", args, ctx, net, db),
|
||||||
|
Some("DEOWNER") => op::handle(me, from, "-q", args, ctx, net, db),
|
||||||
|
Some("PROTECT") | Some("ADMIN") => op::handle(me, from, "+a", args, ctx, net, db),
|
||||||
|
Some("DEPROTECT") | Some("DEADMIN") => op::handle(me, from, "-a", args, ctx, net, db),
|
||||||
|
Some("HALFOP") => op::handle(me, from, "+h", args, ctx, net, db),
|
||||||
|
Some("DEHALFOP") => op::handle(me, from, "-h", args, ctx, net, db),
|
||||||
Some("KICK") => kick::handle(me, from, args, ctx, net, db),
|
Some("KICK") => kick::handle(me, from, args, ctx, net, db),
|
||||||
Some("BAN") => ban::handle(me, from, args, ctx, net, db),
|
Some("BAN") => ban::handle(me, from, args, ctx, net, db),
|
||||||
Some("UNBAN") => unban::handle(me, from, args, ctx, net, db),
|
Some("UNBAN") => unban::handle(me, from, args, ctx, net, db),
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,13 @@ pub fn handle(me: &str, from: &Sender, mode: &str, args: &[&str], ctx: &mut Serv
|
||||||
ctx.notice(me, from.uid, "Syntax: OP/DEOP/VOICE/DEVOICE <#channel> [nick]");
|
ctx.notice(me, from.uid, "Syntax: OP/DEOP/VOICE/DEVOICE <#channel> [nick]");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if !super::require_op(me, from, chan, ctx, db) {
|
// Granting owner (+q) is founder-only; op/halfop/protect need op access.
|
||||||
|
let allowed = if mode.contains('q') {
|
||||||
|
super::require_founder(me, from, chan, ctx, db)
|
||||||
|
} else {
|
||||||
|
super::require_op(me, from, chan, ctx, db)
|
||||||
|
};
|
||||||
|
if !allowed {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let target = match args.get(2) {
|
let target = match args.get(2) {
|
||||||
|
|
|
||||||
|
|
@ -866,6 +866,43 @@
|
||||||
assert!(out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("empty"))), "now empty: {out:?}");
|
assert!(out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("empty"))), "now empty: {out:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChanServ OWNER (+q) is founder-only; PROTECT (+a) and HALFOP (+h) need op.
|
||||||
|
#[test]
|
||||||
|
fn chanserv_owner_protect_halfop() {
|
||||||
|
use echo_chanserv::ChanServ;
|
||||||
|
use echo_nickserv::NickServ;
|
||||||
|
let path = std::env::temp_dir().join("echo-csstatus.jsonl");
|
||||||
|
let _ = std::fs::remove_file(&path);
|
||||||
|
let mut db = Db::open(&path, "42S");
|
||||||
|
db.scram_iterations = 4096;
|
||||||
|
db.register("alice", "sesame", None).unwrap();
|
||||||
|
db.register("bob", "pw", None).unwrap();
|
||||||
|
db.register_channel("#c", "alice").unwrap();
|
||||||
|
let mut e = Engine::new(
|
||||||
|
vec![
|
||||||
|
Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }),
|
||||||
|
Box::new(ChanServ { uid: "42SAAAAAB".into() }),
|
||||||
|
],
|
||||||
|
db,
|
||||||
|
);
|
||||||
|
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "alice".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||||
|
e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY sesame".into() });
|
||||||
|
e.handle(NetEvent::Join { uid: "000AAAAAB".into(), channel: "#c".into(), op: false });
|
||||||
|
e.handle(NetEvent::UserConnect { uid: "000AAAAAC".into(), nick: "bob".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||||
|
e.handle(NetEvent::Privmsg { from: "000AAAAAC".into(), to: "42SAAAAAA".into(), text: "IDENTIFY pw".into() });
|
||||||
|
|
||||||
|
let cs = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAB".into(), text: t.into() });
|
||||||
|
let mode = |out: &[NetAction], m: &str| out.iter().any(|a| matches!(a, NetAction::ChannelMode { modes, .. } if modes == m));
|
||||||
|
|
||||||
|
assert!(mode(&cs(&mut e, "000AAAAAB", "OWNER #c"), "+q 000AAAAAB"), "founder grants +q to self");
|
||||||
|
assert!(mode(&cs(&mut e, "000AAAAAB", "PROTECT #c"), "+a 000AAAAAB"), "founder grants +a");
|
||||||
|
assert!(mode(&cs(&mut e, "000AAAAAB", "HALFOP #c"), "+h 000AAAAAB"), "founder grants +h");
|
||||||
|
|
||||||
|
// bob has no access: OWNER is refused (no +q emitted for him).
|
||||||
|
let out = cs(&mut e, "000AAAAAC", "OWNER #c");
|
||||||
|
assert!(!mode(&out, "+q 000AAAAAC"), "non-founder cannot grant owner: {out:?}");
|
||||||
|
}
|
||||||
|
|
||||||
// BotServ BOT ADD/LIST is oper-gated (Priv::Admin) and the bot is remembered.
|
// BotServ BOT ADD/LIST is oper-gated (Priv::Admin) and the bot is remembered.
|
||||||
#[test]
|
#[test]
|
||||||
fn botserv_bot_add_list_is_oper_gated() {
|
fn botserv_bot_add_list_is_oper_gated() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue