OperServ: INFO staff notes on accounts and channels
INFO ADD <target> <note> / DEL <target> / <target> attaches a staff note to an account or channel (a #name is a channel, else an account). The note is shown in that service's INFO — but to operators only (Priv::Auspex), never to the account's own owner. Admin-only to set. Follows the typed-field-on-the-entity pattern: an oper_note field folded through AccountOperNoteSet (Global) / ChannelOperNoteSet (Local) events, read via dedicated Store getters so it stays out of the public views and the directory feed.
This commit is contained in:
parent
8ccc9fa8ea
commit
51d4ebf789
8 changed files with 216 additions and 9 deletions
53
operserv/src/info.rs
Normal file
53
operserv/src/info.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use fedserv_api::{Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// INFO <target> | INFO ADD <target> <note> | INFO DEL <target>: attach a staff
|
||||
// note to an account or channel (a `#name` is a channel, else an account). The
|
||||
// note is shown to operators in that service's INFO. Admin-only.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
if !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, "Access denied — INFO needs the \x02admin\x02 privilege.");
|
||||
return;
|
||||
}
|
||||
match args.get(1).map(|s| s.to_ascii_uppercase()).as_deref() {
|
||||
Some("ADD") | Some("SET") => set(me, from, args.get(2).copied(), args.get(3..).unwrap_or(&[]), ctx, db),
|
||||
Some("DEL") | Some("CLEAR") => set(me, from, args.get(2).copied(), &[], ctx, db),
|
||||
Some(_) => show(me, from, args[1], ctx, db),
|
||||
None => ctx.notice(me, from.uid, "Syntax: INFO <target> | INFO ADD <target> <note> | INFO DEL <target>"),
|
||||
}
|
||||
}
|
||||
|
||||
// `note` empty clears; otherwise it's the joined note words.
|
||||
fn set(me: &str, from: &Sender, target: Option<&str>, note: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let Some(target) = target else {
|
||||
ctx.notice(me, from.uid, "Syntax: INFO ADD <target> <note> | INFO DEL <target>");
|
||||
return;
|
||||
};
|
||||
let text = note.join(" ");
|
||||
let value = if text.trim().is_empty() { None } else { Some(text) };
|
||||
let (ok, kind) = if target.starts_with('#') || target.starts_with('&') {
|
||||
(db.set_channel_note(target, value.clone()), "channel")
|
||||
} else if let Some(account) = db.resolve_account(target).map(str::to_string) {
|
||||
(db.set_account_note(&account, value.clone()), "account")
|
||||
} else {
|
||||
(false, "account")
|
||||
};
|
||||
if !ok {
|
||||
ctx.notice(me, from.uid, format!("There's no {kind} \x02{target}\x02."));
|
||||
} else if value.is_some() {
|
||||
ctx.notice(me, from.uid, format!("Staff note set on \x02{target}\x02."));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("Staff note on \x02{target}\x02 cleared."));
|
||||
}
|
||||
}
|
||||
|
||||
fn show(me: &str, from: &Sender, target: &str, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let note = if target.starts_with('#') || target.starts_with('&') {
|
||||
db.channel_note(target)
|
||||
} else {
|
||||
db.resolve_account(target).map(str::to_string).and_then(|a| db.account_note(&a))
|
||||
};
|
||||
match note {
|
||||
Some(n) => ctx.notice(me, from.uid, format!("Staff note on \x02{target}\x02: {n}")),
|
||||
None => ctx.notice(me, from.uid, format!("No staff note on \x02{target}\x02.")),
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,8 @@ mod ignore;
|
|||
mod stats;
|
||||
#[path = "svs.rs"]
|
||||
mod svs;
|
||||
#[path = "info.rs"]
|
||||
mod info;
|
||||
|
||||
pub struct OperServ {
|
||||
pub uid: String,
|
||||
|
|
@ -55,6 +57,7 @@ impl Service for OperServ {
|
|||
Some(cmd) if cmd.eq_ignore_ascii_case("STATS") => stats::handle(me, from, db, ctx),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("SVSNICK") => svs::nick(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("SVSJOIN") => svs::join(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("INFO") => info::handle(me, from, args, ctx, db),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("HELP") => help(me, from, ctx),
|
||||
None => help(me, from, ctx),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
|
|
@ -63,5 +66,5 @@ impl Service for OperServ {
|
|||
}
|
||||
|
||||
fn help(me: &str, from: &Sender, ctx: &mut ServiceCtx) {
|
||||
ctx.notice(me, from.uid, "OperServ holds network operator tools (Priv::Admin): \x02AKILL\x02 ADD|DEL|LIST (user@host bans), \x02SQLINE\x02 ADD|DEL|LIST (nick bans), \x02GLOBAL\x02 <message> (announce to everyone), \x02KILL\x02 <nick> [reason] (disconnect a user), \x02KICK\x02 <#chan> <nick> [reason], \x02MODE\x02 <#chan> <modes> [params], \x02IGNORE\x02 ADD|DEL|LIST (silence a user from services), \x02STATS\x02 (enforcement overview), \x02SVSNICK\x02 <nick> <newnick>, \x02SVSJOIN\x02 <nick> <#chan> [key].");
|
||||
ctx.notice(me, from.uid, "OperServ holds network operator tools (Priv::Admin): \x02AKILL\x02 ADD|DEL|LIST (user@host bans), \x02SQLINE\x02 ADD|DEL|LIST (nick bans), \x02GLOBAL\x02 <message> (announce to everyone), \x02KILL\x02 <nick> [reason] (disconnect a user), \x02KICK\x02 <#chan> <nick> [reason], \x02MODE\x02 <#chan> <modes> [params], \x02IGNORE\x02 ADD|DEL|LIST (silence a user from services), \x02STATS\x02 (enforcement overview), \x02SVSNICK\x02 <nick> <newnick>, \x02SVSJOIN\x02 <nick> <#chan> [key], \x02INFO\x02 ADD|DEL <target> (staff notes).");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue