chanserv: give SOP/AOP/HOP/VOP four distinct access tiers matching Anope, classified by capability
All checks were successful
CI / check (push) Successful in 3m55s

This commit is contained in:
Jean Chevronnet 2026-07-17 14:54:36 +00:00
parent f5c976eb56
commit c8106035df
No known key found for this signature in database
6 changed files with 119 additions and 41 deletions

View file

@ -1,10 +1,14 @@
use echo_api::Store;
use echo_api::{Sender, ServiceCtx};
// ACCESS <#channel> LIST | ADD <account> <op|voice> | DEL <account>
// The named tiers ACCESS ADD accepts, high to low; the granular FLAGS command
// covers anything finer. Kept in step with the XOP presets in `level_caps`.
const TIERS: [&str; 4] = ["sop", "op", "halfop", "voice"];
// ACCESS <#channel> LIST | ADD <account> <sop|op|halfop|voice> | DEL <account>
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
let Some(&chan) = args.get(1) else {
ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD <account|!group> <op|voice> | DEL <account|!group>");
ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD <account|!group> <sop|op|halfop|voice> | DEL <account|!group>");
return;
};
match args.get(2).map(|s| s.to_ascii_uppercase()).as_deref() {
@ -20,12 +24,12 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
},
Some("ADD") => {
let (Some(&account), Some(&level)) = (args.get(3), args.get(4)) else {
ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> ADD <account> <op|voice>");
ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> ADD <account> <sop|op|halfop|voice>");
return;
};
let level = level.to_ascii_lowercase();
if level != "op" && level != "voice" {
ctx.notice(me, from.uid, "Level must be \x02op\x02 or \x02voice\x02.");
if !TIERS.contains(&level.as_str()) {
ctx.notice(me, from.uid, "Level must be \x02sop\x02, \x02op\x02, \x02halfop\x02 or \x02voice\x02.");
return;
}
if !is_founder(me, from, chan, ctx, db) {
@ -50,7 +54,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}
_ => ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD <account|!group> <op|voice> | DEL <account|!group>"),
_ => ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD <account|!group> <sop|op|halfop|voice> | DEL <account|!group>"),
}
}

View file

@ -52,9 +52,9 @@ const TOPICS: &[HelpEntry] = &[
HelpEntry { cmd: "INFO", summary: "show channel information", detail: "Syntax: \x02INFO <#channel>\x02\nShows a channel's registration and settings." },
HelpEntry { cmd: "LIST", summary: "list registered channels", detail: "Syntax: \x02LIST\x02\nLists registered channels." },
HelpEntry { cmd: "SET", summary: "change founder or settings", detail: "Syntax: \x02SET <#channel> FOUNDER <account> | DESC <text> | URL [address] | EMAIL [address] | SUCCESSOR <account>|OFF | SIGNKICK|PRIVATE|PEACE|SECUREOPS|RESTRICTED|AUTOOP|KEEPTOPIC|TOPICLOCK {ON|OFF}\x02\nTransfers the founder or changes a channel setting." },
HelpEntry { cmd: "ACCESS", summary: "manage the access list", detail: "Syntax: \x02ACCESS <#channel> LIST | ADD <account|!group> <op|voice> | DEL <account|!group>\x02\nManages the channel access list. The target may be a GroupServ \x02!group\x02; each of its members holding the group's \x02c\x02 flag then inherits the access." },
HelpEntry { cmd: "ACCESS", summary: "manage the access list", detail: "Syntax: \x02ACCESS <#channel> LIST | ADD <account|!group> <sop|op|halfop|voice> | DEL <account|!group>\x02\nManages the channel access list. The target may be a GroupServ \x02!group\x02; each of its members holding the group's \x02c\x02 flag then inherits the access." },
HelpEntry { cmd: "FLAGS", summary: "granular per-account flags", detail: "Syntax: \x02FLAGS <#channel> [account [+/-flags]]\x02\nViews or changes granular per-account channel flags." },
HelpEntry { cmd: "AOP/SOP/VOP", summary: "tiered access shortcuts", detail: "Syntax: \x02AOP|SOP|VOP <#channel> ADD <account> | DEL <account> | LIST\x02\nTiered shortcuts over ACCESS: AOP and SOP grant op, VOP grants voice." },
HelpEntry { cmd: "SOP/AOP/HOP/VOP", summary: "tiered access shortcuts", detail: "Syntax: \x02SOP|AOP|HOP|VOP <#channel> ADD <account> | DEL <account> | LIST\x02\nTiered shortcuts over ACCESS: SOP grants op plus access-list management, AOP grants op, HOP grants halfop, VOP grants voice." },
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: "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." },
@ -298,8 +298,9 @@ impl Service for ChanServ {
// the mode lock and akick list, so SYNC is the same handler.
Some("ENFORCE") | Some("SYNC") => enforce::handle(me, from, args, ctx, net, db),
Some("CLONE") => clone::handle(me, from, args, ctx, db),
Some("SOP") => xop::handle(me, from, "SOP", "sop", args, ctx, db),
Some("AOP") => xop::handle(me, from, "AOP", "op", args, ctx, db),
Some("SOP") => xop::handle(me, from, "SOP", "op", args, ctx, db),
Some("HOP") => xop::handle(me, from, "HOP", "halfop", args, ctx, db),
Some("VOP") => xop::handle(me, from, "VOP", "voice", args, ctx, db),
Some("HELP") => echo_api::help(me, from, ctx, BLURB, TOPICS, args.get(1).copied()),
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),

View file

@ -1,5 +1,5 @@
use echo_api::Store;
use echo_api::{Sender, ServiceCtx};
use echo_api::{access_role, Sender, ServiceCtx};
use echo_api::NetView;
// STATUS <#channel> [nick]: show a user's access level (self if no nick).
@ -19,10 +19,11 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
let level = match account.as_deref() {
None => "none (not logged in)",
Some(a) if info.founder.eq_ignore_ascii_case(a) => "founder",
Some(a) => match info.join_mode(a) {
Some("+o") => "op",
Some("+v") => "voice",
_ => "none",
// Classify by resolved tier so halfop and sop read distinctly, matching
// ALIST and the XOP lists.
Some(a) => match info.access.iter().find(|e| e.account.eq_ignore_ascii_case(a)) {
Some(e) => access_role(&e.level).label(),
None => "none",
},
};
ctx.notice(me, from.uid, format!("\x02{label}\x02 access on \x02{chan}\x02: \x02{level}\x02"));

View file

@ -1,8 +1,8 @@
use echo_api::{level_caps, Sender, ServiceCtx, Store};
use echo_api::{access_role, Sender, ServiceCtx, Store};
// AOP/SOP/VOP <#channel> ADD <account> | DEL <account> | LIST — tiered
// shortcuts over the access list. `level` is the access level they map to
// ("op" for AOP/SOP, "voice" for VOP); `word` is what the user typed.
// SOP/AOP/HOP/VOP <#channel> ADD <account> | DEL <account> | LIST — tiered
// shortcuts over the access list. `level` is the tier they map to ("sop", "op",
// "halfop", "voice"); `word` is the tier the user typed ("SOP".."VOP").
pub fn handle(me: &str, from: &Sender, word: &str, level: &str, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
let Some(&chan) = args.get(1) else {
ctx.notice(me, from.uid, format!("Syntax: {word} <#channel> ADD <account> | DEL <account> | LIST"));
@ -13,14 +13,9 @@ pub fn handle(me: &str, from: &Sender, word: &str, level: &str, args: &[&str], c
None => ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered.")),
Some(info) => {
ctx.notice(me, from.uid, format!("{word} list for \x02{}\x02:", info.name));
// Match by capability, not the raw level string, so entries set via
// granular FLAGS still list under the right tier (VOP = voice-only,
// AOP/SOP = op).
let want_op = level_caps(level).op;
for a in info.access.iter().filter(|a| {
let c = level_caps(&a.level);
if want_op { c.op } else { c.auto == Some("+v") && !c.op }
}) {
// List by resolved tier, not the raw level string, so an entry set
// via granular FLAGS appears under the same tier a XOP ADD would.
for a in info.access.iter().filter(|a| access_role(&a.level).xop_word() == Some(word)) {
ctx.notice(me, from.uid, format!(" \x02{}\x02", a.account));
}
}