Add centralized HELP with per-command subcommands

New echo-api primitive: a HelpEntry table plus a shared help() renderer.
HELP lists a service's commands; HELP <command> prints that command's
detail. Every service routes its HELP arm through the one renderer, so
the shape is identical across the network. Wired into NickServ and the
six newer services so far.
This commit is contained in:
Jean Chevronnet 2026-07-14 17:12:14 +00:00
parent 973d2826de
commit c9e392630b
No known key found for this signature in database
8 changed files with 137 additions and 14 deletions

View file

@ -8,7 +8,7 @@
//! `lib.rs` holds the dispatcher and the shared oper guard; each command lives
//! in its own file.
use echo_api::{NetView, Sender, Service, ServiceCtx, Store};
use echo_api::{HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
#[path = "report.rs"]
mod report;
@ -21,6 +21,16 @@ mod close;
#[path = "del.rs"]
mod del;
const BLURB: &str = "ReportServ takes abuse reports. Anyone can \x02REPORT\x02; operators review the queue.";
const TOPICS: &[HelpEntry] = &[
HelpEntry { cmd: "REPORT", summary: "file an abuse report", detail: "Syntax: \x02REPORT <nick|#channel> <reason>\x02\nTells the staff about a problem. Rate-limited." },
HelpEntry { cmd: "LIST", summary: "list reports", detail: "Syntax: \x02LIST [ALL]\x02\nOperators: list open reports, or every report with ALL." },
HelpEntry { cmd: "VIEW", summary: "read a report", detail: "Syntax: \x02VIEW <id>\x02\nOperators: read a report in full. Also \x02READ\x02." },
HelpEntry { cmd: "CLOSE", summary: "resolve a report", detail: "Syntax: \x02CLOSE <id>\x02\nOperators: mark a report resolved. Also \x02RESOLVE\x02." },
HelpEntry { cmd: "DEL", summary: "delete a report", detail: "Syntax: \x02DEL <id>\x02\nOperators: delete a report outright. Also \x02REMOVE\x02." },
];
pub struct ReportServ {
pub uid: String,
}
@ -44,7 +54,7 @@ impl Service for ReportServ {
Some("VIEW") | Some("READ") => view::handle(me, from, args.get(1).copied(), ctx, db),
Some("CLOSE") | Some("RESOLVE") => close::handle(me, from, args.get(1).copied(), ctx, db),
Some("DEL") | Some("REMOVE") => del::handle(me, from, args.get(1).copied(), ctx, db),
Some("HELP") | None => ctx.notice(me, from.uid, "ReportServ takes abuse reports. \x02REPORT\x02 <nick|#channel> <reason> tells the staff about a problem. Operators review with \x02LIST\x02 [ALL], \x02VIEW\x02 <id>, \x02CLOSE\x02 <id>, \x02DEL\x02 <id>."),
Some("HELP") | None => echo_api::help(me, from, ctx, BLURB, TOPICS, args.get(1).copied()),
Some(other) => ctx.notice(me, from.uid, format!("I don't know \x02{other}\x02. Try \x02REPORT\x02 <nick|#channel> <reason> or \x02HELP\x02.")),
}
}