NickServ: add UPDATE and LIST
All checks were successful
CI / check (push) Successful in 3m46s

UPDATE re-applies your auto-joins and vhost and re-checks for waiting
memos without re-identifying. LIST (auspex-gated) shows registered
accounts matching a glob, capped at 100. Adds an accounts_matching store
method.
This commit is contained in:
Jean Chevronnet 2026-07-15 18:24:52 +00:00
parent 959d085e7a
commit 21efbd32c1
No known key found for this signature in database
6 changed files with 91 additions and 0 deletions

View file

@ -32,6 +32,10 @@ mod resetpass;
mod confirm;
#[path = "ajoin.rs"]
mod ajoin;
#[path = "update.rs"]
mod update;
#[path = "list.rs"]
mod list;
#[path = "suspend.rs"]
mod suspend;
mod noexpire;
@ -56,6 +60,8 @@ const TOPICS: &[HelpEntry] = &[
HelpEntry { cmd: "DROP", summary: "delete your account", detail: "Syntax: \x02DROP <password>\x02\nDeletes your account and releases the channels you founded." },
HelpEntry { cmd: "CERT", summary: "manage SASL EXTERNAL certs", detail: "Syntax: \x02CERT ADD <password> [fingerprint]\x02, \x02CERT DEL <fingerprint>\x02, \x02CERT LIST\x02\nManages the TLS certificate fingerprints that can log in via SASL EXTERNAL." },
HelpEntry { cmd: "AJOIN", summary: "auto-join channels on login", detail: "Syntax: \x02AJOIN ADD <#channel>\x02, \x02AJOIN DEL <#channel>\x02, \x02AJOIN LIST\x02\nChannels you are auto-joined to when you identify." },
HelpEntry { cmd: "UPDATE", summary: "refresh your session", detail: "Syntax: \x02UPDATE\x02\nRe-applies your auto-joins and vhost and re-checks for new memos." },
HelpEntry { cmd: "LIST", summary: "list accounts (oper)", detail: "Syntax: \x02LIST <pattern>\x02\nLists registered accounts matching a glob. Requires the auspex privilege." },
HelpEntry { cmd: "SUSPEND", summary: "block an account (operator)", detail: "Syntax: \x02SUSPEND <account> [reason]\x02\nBlocks an account from logging in. Operators only." },
HelpEntry { cmd: "UNSUSPEND", summary: "lift a suspension (operator)", detail: "Syntax: \x02UNSUSPEND <account>\x02\nLifts a suspension. Operators only." },
HelpEntry { cmd: "NOEXPIRE", summary: "pin against expiry (operator)", detail: "Syntax: \x02NOEXPIRE <account> {ON|OFF}\x02\nPins an account so inactivity expiry never drops it. Operators only." },
@ -115,6 +121,8 @@ impl Service for NickServ {
Some("SUSPEND") => suspend::handle(me, from, args, ctx, net, db, true),
Some("UNSUSPEND") => suspend::handle(me, from, args, ctx, net, db, false),
Some("NOEXPIRE") => noexpire::handle(me, from, args, ctx, db),
Some("UPDATE") => update::handle(me, from, ctx, db),
Some("LIST") => list::handle(me, from, 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.")),
None => {}

View file

@ -0,0 +1,23 @@
use echo_api::{human_time, Priv, Sender, ServiceCtx, Store};
// A cap so a broad glob can't flood the requesting oper.
const MAX_SHOWN: usize = 100;
// LIST <pattern>: list registered accounts matching a glob. Oper-only.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &dyn Store) {
if !from.privs.has(Priv::Auspex) {
ctx.notice(me, from.uid, "Access denied — LIST needs the \x02auspex\x02 privilege.");
return;
}
let pattern = args.get(1).copied().unwrap_or("*");
let mut matches = db.accounts_matching(pattern);
matches.sort_by_key(|a| a.name.to_ascii_lowercase());
ctx.notice(me, from.uid, format!("Accounts matching \x02{pattern}\x02:"));
for a in matches.iter().take(MAX_SHOWN) {
let flag = if a.verified { "" } else { " (unconfirmed)" };
ctx.notice(me, from.uid, format!(" \x02{}\x02 registered {}{}", a.name, human_time(a.ts), flag));
}
let more = if matches.len() > MAX_SHOWN { format!(", showing the first {MAX_SHOWN}") } else { String::new() };
ctx.notice(me, from.uid, format!("End of list — {} match(es){more}.", matches.len()));
}

View file

@ -0,0 +1,21 @@
use echo_api::{Sender, ServiceCtx, Store};
// UPDATE: re-apply your account's auto-joins and vhost, and re-check for waiting
// memos, without having to re-identify.
pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &dyn Store) {
let Some(account) = from.account else {
ctx.notice(me, from.uid, "You need to be logged in. Identify to NickServ first.");
return;
};
for entry in db.ajoin_list(account) {
ctx.force_join(from.uid, &entry.channel, &entry.key);
}
if let Some(v) = db.vhost(account) {
ctx.apply_vhost(from.uid, &v.host);
}
let unread = db.unread_memos(account);
if unread > 0 {
ctx.notice(me, from.uid, format!("You have \x02{unread}\x02 new memo(s). Read them with \x02/msg MemoServ READ NEW\x02."));
}
ctx.notice(me, from.uid, "Your status has been refreshed.");
}