nickserv: AJOIN auto-join list
Adds the account auto-join list (AJOIN ADD/DEL/LIST): NickServ SVSJOINs you into your listed channels each time you identify. The list is a typed Vec<AjoinEntry> on the account, folded through the event log like the cert and akick lists (persists and replays; no separate store), reached by modules through the Store trait. New ForceJoin action serialises to InspIRCd SVSJOIN. Shown in INFO. Operates on the caller's own account; the oper form for other users waits on a privilege system.
This commit is contained in:
parent
e0bb3a1fea
commit
75ba9b35b4
9 changed files with 211 additions and 5 deletions
63
nickserv/src/ajoin.rs
Normal file
63
nickserv/src/ajoin.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use fedserv_api::Store;
|
||||
use fedserv_api::{Sender, ServiceCtx};
|
||||
|
||||
// A sane cap so a runaway list can't bloat an account or flood a user on identify.
|
||||
const MAX_AJOIN: usize = 25;
|
||||
|
||||
// AJOIN [ADD <#channel> [key] | DEL <#channel> | LIST]: manage your auto-join
|
||||
// list — the channels NickServ joins you to each time you identify.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let Some(account) = from.account else {
|
||||
ctx.notice(me, from.uid, "You must identify to NickServ to use \x02AJOIN\x02.");
|
||||
return;
|
||||
};
|
||||
match args.get(1).map(|s| s.to_ascii_uppercase()).as_deref() {
|
||||
Some("ADD") => {
|
||||
let Some(&channel) = args.get(2) else {
|
||||
ctx.notice(me, from.uid, "Syntax: AJOIN ADD <#channel> [key]");
|
||||
return;
|
||||
};
|
||||
if !channel.starts_with('#') {
|
||||
ctx.notice(me, from.uid, "That doesn't look like a channel name.");
|
||||
return;
|
||||
}
|
||||
let key = args.get(3).copied().unwrap_or("");
|
||||
if db.ajoin_list(account).len() >= MAX_AJOIN {
|
||||
ctx.notice(me, from.uid, format!("Your auto-join list is full (max {MAX_AJOIN})."));
|
||||
return;
|
||||
}
|
||||
match db.ajoin_add(account, channel, key) {
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("Added \x02{channel}\x02 to your auto-join list.")),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("Updated the key for \x02{channel}\x02 on your auto-join list.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
Some("DEL") => {
|
||||
let Some(&channel) = args.get(2) else {
|
||||
ctx.notice(me, from.uid, "Syntax: AJOIN DEL <#channel>");
|
||||
return;
|
||||
};
|
||||
match db.ajoin_del(account, channel) {
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("Removed \x02{channel}\x02 from your auto-join list.")),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("\x02{channel}\x02 isn't on your auto-join list.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
None | Some("LIST") => {
|
||||
let list = db.ajoin_list(account);
|
||||
if list.is_empty() {
|
||||
ctx.notice(me, from.uid, "Your auto-join list is empty. Add channels with \x02AJOIN ADD <#channel>\x02.");
|
||||
return;
|
||||
}
|
||||
ctx.notice(me, from.uid, format!("Your auto-join list ({}):", list.len()));
|
||||
for e in &list {
|
||||
if e.key.is_empty() {
|
||||
ctx.notice(me, from.uid, format!(" \x02{}\x02", e.channel));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!(" \x02{}\x02 (key: {})", e.channel, e.key));
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(other) => ctx.notice(me, from.uid, format!("Unknown AJOIN command \x02{other}\x02. Use \x02ADD\x02, \x02DEL\x02 or \x02LIST\x02.")),
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,10 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
let account = account.to_string();
|
||||
ctx.login(from.uid, &account);
|
||||
ctx.notice(me, from.uid, format!("You're now identified as \x02{}\x02. Welcome back!", account));
|
||||
// Apply the account's auto-join list (AJOIN).
|
||||
for entry in db.ajoin_list(&account) {
|
||||
ctx.force_join(from.uid, &entry.channel, &entry.key);
|
||||
}
|
||||
}
|
||||
None => ctx.notice(me, from.uid, "Invalid password. Please try again."),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,9 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
Some(email) => ctx.notice(me, from.uid, format!(" Email : {email} (unconfirmed)")),
|
||||
None => ctx.notice(me, from.uid, " Email : (none set)"),
|
||||
}
|
||||
let ajoin = db.ajoin_list(&acct.name);
|
||||
if !ajoin.is_empty() {
|
||||
ctx.notice(me, from.uid, format!(" Auto-join : {} channel(s) — see \x02AJOIN LIST\x02", ajoin.len()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ mod ghost;
|
|||
mod resetpass;
|
||||
#[path = "confirm.rs"]
|
||||
mod confirm;
|
||||
#[path = "ajoin.rs"]
|
||||
mod ajoin;
|
||||
|
||||
pub struct NickServ {
|
||||
pub uid: String,
|
||||
|
|
@ -70,7 +72,8 @@ impl Service for NickServ {
|
|||
Some("GHOST") | Some("RECOVER") => ghost::handle(me, &self.guest_nick, &mut self.guest_seq, from, args, ctx, net, db),
|
||||
Some("RESETPASS") => resetpass::handle(me, from, args, ctx, db),
|
||||
Some("CONFIRM") => confirm::handle(me, from, args, ctx, db),
|
||||
Some("HELP") => ctx.notice(me, from.uid, "NickServ looks after your nickname. Commands: \x02REGISTER\x02 <password> [email], \x02IDENTIFY\x02 [account] <password>, \x02INFO\x02 [account], \x02ALIST\x02, \x02GROUP\x02/\x02GLIST\x02/\x02UNGROUP\x02, \x02GHOST\x02 <nick> [password], \x02SET\x02 PASSWORD|EMAIL, \x02RESETPASS\x02 <account>, \x02CONFIRM\x02 <code>, \x02DROP\x02 <password>, \x02LOGOUT\x02, \x02CERT\x02 ADD|DEL|LIST <password> [fingerprint]."),
|
||||
Some("AJOIN") => ajoin::handle(me, from, args, ctx, db),
|
||||
Some("HELP") => ctx.notice(me, from.uid, "NickServ looks after your nickname. Commands: \x02REGISTER\x02 <password> [email], \x02IDENTIFY\x02 [account] <password>, \x02INFO\x02 [account], \x02ALIST\x02, \x02GROUP\x02/\x02GLIST\x02/\x02UNGROUP\x02, \x02GHOST\x02 <nick> [password], \x02SET\x02 PASSWORD|EMAIL, \x02AJOIN\x02 ADD|DEL|LIST, \x02RESETPASS\x02 <account>, \x02CONFIRM\x02 <code>, \x02DROP\x02 <password>, \x02LOGOUT\x02, \x02CERT\x02 ADD|DEL|LIST <password> [fingerprint]."),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
None => {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue