NickServ: add SET HIDE STATUS for last-seen privacy

Lets an account keep its last-seen/online line in INFO visible only to
itself and to opers. Default stays public (Anope's default). Accepts
STATUS (with USERMASK as an alias) per Anope's SET HIDE <field> grammar.
This commit is contained in:
Jean Chevronnet 2026-07-16 02:33:55 +00:00
parent 39d7421c06
commit 053f8cf832
No known key found for this signature in database
12 changed files with 116 additions and 19 deletions

View file

@ -10,21 +10,24 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
ctx.notice(me, from.uid, format!("\x02{name}\x02 isn't registered."));
return;
};
let is_owner = from.account == Some(acct.name.as_str());
let privileged = is_owner || from.privs.has(Priv::Auspex);
ctx.notice(me, from.uid, format!("Information for \x02{}\x02:", acct.name));
ctx.notice(me, from.uid, format!(" Registered : {}", human_time(acct.ts)));
// Last-seen is public (Anope shows it by default); a live session reads as online.
let last_seen = if net.uids_logged_into(&acct.name).is_empty() {
human_time(acct.last_seen)
} else {
"now (online)".to_string()
};
ctx.notice(me, from.uid, format!(" Last seen : {last_seen}"));
// Last-seen is public by default; SET HIDE STATUS keeps it to owner and opers.
if privileged || !acct.hide_status {
let last_seen = if net.uids_logged_into(&acct.name).is_empty() {
human_time(acct.last_seen)
} else {
"now (online)".to_string()
};
ctx.notice(me, from.uid, format!(" Last seen : {last_seen}"));
}
// A greet is public — the bot shows it in-channel to everyone anyway.
if !acct.greet.is_empty() {
ctx.notice(me, from.uid, format!(" Greet : {}", acct.greet));
}
let is_owner = from.account == Some(acct.name.as_str());
if is_owner || from.privs.has(Priv::Auspex) {
if privileged {
if let Some(s) = db.suspension(&acct.name) {
ctx.notice(me, from.uid, format!(" Suspended : by \x02{}\x02{}", s.by, s.reason));
}

View file

@ -54,7 +54,7 @@ const TOPICS: &[HelpEntry] = &[
HelpEntry { cmd: "LOGOUT", summary: "log out to a guest nick", detail: "Syntax: \x02LOGOUT\x02\nLogs you out and moves you to a guest nick. Also \x02LOGOFF\x02." },
HelpEntry { cmd: "INFO", summary: "show account information", detail: "Syntax: \x02INFO [account]\x02\nShows account information. The email is shown only to the owner." },
HelpEntry { cmd: "ALIST", summary: "list channels you have access on", detail: "Syntax: \x02ALIST\x02\nLists the channels you hold access on." },
HelpEntry { cmd: "SET", summary: "change password, email, or preferences", detail: "Syntax: \x02SET PASSWORD <new>\x02, \x02SET EMAIL <address>\x02, \x02SET GREET [message]\x02, \x02SET AUTOOP {ON|OFF}\x02, or \x02SET KILL {ON|OFF}\x02\nChanges your password, email, greet, auto-op, or nick-protection preference." },
HelpEntry { cmd: "SET", summary: "change password, email, or preferences", detail: "Syntax: \x02SET PASSWORD <new>\x02, \x02SET EMAIL <address>\x02, \x02SET GREET [message]\x02, \x02SET AUTOOP {ON|OFF}\x02, \x02SET KILL {ON|OFF}\x02, or \x02SET HIDE STATUS {ON|OFF}\x02\nChanges your password, email, greet, auto-op, nick-protection, or last-seen privacy." },
HelpEntry { cmd: "SASET", summary: "change another account's settings (operator)", detail: "Syntax: \x02SASET <account> PASSWORD <new>\x02, \x02EMAIL [address]\x02, or \x02GREET [message]\x02\nEdits another account's settings. Operators only." },
HelpEntry { cmd: "GROUP", summary: "link this nick to an account", detail: "Syntax: \x02GROUP <account> <password>\x02\nLinks your current nick to an account as an alias, so identifying under it logs into that account." },
HelpEntry { cmd: "GLIST", summary: "list your grouped nicks", detail: "Syntax: \x02GLIST\x02\nLists the nicks grouped to your account." },

View file

@ -35,6 +35,26 @@ 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."),
}
}
Some("HIDE") => {
// Anope grammar is SET HIDE <field> {ON|OFF}. The only field that is
// public here is the last-seen/online line (STATUS); USERMASK is an
// accepted alias for it.
match args.get(2).map(|s| s.to_ascii_uppercase()).as_deref() {
Some("STATUS") | Some("USERMASK") => {
let Some(on) = args.get(3).and_then(|s| parse_toggle(s)) else {
let state = if db.account_hides_status(account) { "ON" } else { "OFF" };
ctx.notice(me, from.uid, format!("HIDE STATUS is \x02{state}\x02. Syntax: SET HIDE STATUS {{ON|OFF}}"));
return;
};
match db.set_account_hide_status(account, on) {
Ok(()) if on => ctx.notice(me, from.uid, "Your last-seen and online status are now hidden from other users."),
Ok(()) => ctx.notice(me, from.uid, "Your last-seen and online status are visible to everyone again."),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}
_ => ctx.notice(me, from.uid, "Syntax: SET HIDE STATUS {ON|OFF}"),
}
}
Some("KILL") => {
// Anope accepts ON/QUICK/IMMED/OFF; grace here is a fixed interval, so
// the finer variants simply enable protection like ON.
@ -76,7 +96,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: SET PASSWORD <newpassword> | SET EMAIL [address] | SET GREET [message] | SET AUTOOP {ON|OFF} | SET KILL {ON|OFF}"),
_ => ctx.notice(me, from.uid, "Syntax: SET PASSWORD <newpassword> | SET EMAIL [address] | SET GREET [message] | SET AUTOOP {ON|OFF} | SET KILL {ON|OFF} | SET HIDE STATUS {ON|OFF}"),
}
}