From 30e91bb295f33253335902124e94184a4655961c Mon Sep 17 00:00:00 2001 From: Jean Date: Wed, 15 Jul 2026 18:32:46 +0000 Subject: [PATCH] MemoServ SENDALL + ChanServ AKICK CLEAR SENDALL (admin) leaves a memo on every registered account for a network-wide announcement that persists until read. AKICK CLEAR empties a channel's auto-kick list in one command. --- modules/chanserv/src/akick.rs | 13 +++++++- modules/chanserv/src/lib.rs | 2 +- modules/memoserv/src/lib.rs | 4 +++ modules/memoserv/src/sendall.rs | 24 ++++++++++++++ src/engine/tests.rs | 59 +++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 modules/memoserv/src/sendall.rs diff --git a/modules/chanserv/src/akick.rs b/modules/chanserv/src/akick.rs index 42c9f68..ea18342 100644 --- a/modules/chanserv/src/akick.rs +++ b/modules/chanserv/src/akick.rs @@ -47,6 +47,17 @@ 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: AKICK <#channel> ADD [reason] | DEL | LIST"), + Some("CLEAR") => { + if !super::require_op(me, from, chan, ctx, db) { + return; + } + // Snapshot the masks, then remove each (the read borrow ends first). + let masks: Vec = db.channel(chan).map_or_else(Vec::new, |info| info.akick.iter().map(|k| k.mask.clone()).collect()); + for mask in &masks { + let _ = db.akick_del(chan, mask); + } + ctx.notice(me, from.uid, format!("Cleared \x02{}\x02 entr{} from \x02{chan}\x02's auto-kick list.", masks.len(), if masks.len() == 1 { "y" } else { "ies" })); + } + _ => ctx.notice(me, from.uid, "Syntax: AKICK <#channel> ADD [reason] | DEL | LIST | CLEAR"), } } diff --git a/modules/chanserv/src/lib.rs b/modules/chanserv/src/lib.rs index 3cab0b3..7060bfe 100644 --- a/modules/chanserv/src/lib.rs +++ b/modules/chanserv/src/lib.rs @@ -60,7 +60,7 @@ const TOPICS: &[HelpEntry] = &[ HelpEntry { cmd: "UP/DOWN", summary: "apply or drop your status", detail: "Syntax: \x02UP|DOWN <#channel>\x02\nUP re-applies the op/voice your access entitles you to; DOWN removes your status." }, HelpEntry { cmd: "KICK", summary: "kick from the channel", detail: "Syntax: \x02KICK <#channel> [reason]\x02\nKicks a user from the channel." }, HelpEntry { cmd: "BAN/UNBAN", summary: "ban or unban a user", detail: "Syntax: \x02BAN <#channel> [reason]\x02, \x02UNBAN <#channel> [nick]\x02\nBans or unbans a user by host." }, - HelpEntry { cmd: "AKICK", summary: "manage the auto-kick list", detail: "Syntax: \x02AKICK <#channel> ADD [reason] | DEL | LIST\x02\nManages the auto-kick list; matches are banned and kicked on join." }, + HelpEntry { cmd: "AKICK", summary: "manage the auto-kick list", detail: "Syntax: \x02AKICK <#channel> ADD [reason] | DEL | LIST | CLEAR\x02\nManages the auto-kick list; matches are banned and kicked on join. CLEAR empties it." }, HelpEntry { cmd: "ENFORCE", summary: "re-apply lock and access", detail: "Syntax: \x02ENFORCE <#channel>\x02\nRe-applies the mode-lock, access, and akick list to everyone present." }, HelpEntry { cmd: "TOPIC", summary: "set the topic", detail: "Syntax: \x02TOPIC <#channel> \x02\nSets the channel topic." }, HelpEntry { cmd: "ENTRYMSG", summary: "message on join", detail: "Syntax: \x02ENTRYMSG <#channel> [CLEAR | ]\x02\nSets a message noticed to users as they join." }, diff --git a/modules/memoserv/src/lib.rs b/modules/memoserv/src/lib.rs index 7820449..ec1ca6e 100644 --- a/modules/memoserv/src/lib.rs +++ b/modules/memoserv/src/lib.rs @@ -20,6 +20,8 @@ mod cancel; mod check; #[path = "info.rs"] mod info; +#[path = "sendall.rs"] +mod sendall; const BLURB: &str = "MemoServ delivers messages to registered users, online or not. You must be identified to use it."; @@ -34,6 +36,7 @@ const TOPICS: &[HelpEntry] = &[ HelpEntry { cmd: "CANCEL", summary: "recall a memo you sent", detail: "Syntax: \x02CANCEL \x02\nRecalls the last memo you sent them, as long as they haven't read it yet." }, HelpEntry { cmd: "CHECK", summary: "see if a memo was read", detail: "Syntax: \x02CHECK \x02\nReports whether the last memo you sent them has been read." }, HelpEntry { cmd: "INFO", summary: "your mailbox summary", detail: "Syntax: \x02INFO\x02\nShows how many memos you have, how many are unread, and your capacity." }, + HelpEntry { cmd: "SENDALL", summary: "memo every account (admin)", detail: "Syntax: \x02SENDALL \x02\nLeaves a memo on every registered account. Requires the admin privilege." }, ]; pub struct MemoServ { @@ -75,6 +78,7 @@ impl Service for MemoServ { Some("CANCEL") => cancel::handle(me, from, account, args, ctx, db), Some("CHECK") => check::handle(me, from, account, args, ctx, db), Some("INFO") => info::handle(me, from, account, ctx, db), + Some("SENDALL") => sendall::handle(me, from, account, args, ctx, db), Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")), None => {} } diff --git a/modules/memoserv/src/sendall.rs b/modules/memoserv/src/sendall.rs new file mode 100644 index 0000000..6b56c8c --- /dev/null +++ b/modules/memoserv/src/sendall.rs @@ -0,0 +1,24 @@ +use echo_api::{Priv, Sender, ServiceCtx, Store}; + +// SENDALL : leave a memo on every registered account. Admin-only, for +// network-wide announcements that persist until read. +pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) { + if !from.privs.has(Priv::Admin) { + ctx.notice(me, from.uid, "Access denied — SENDALL needs the \x02admin\x02 privilege."); + return; + } + if args.len() < 2 { + ctx.notice(me, from.uid, "Syntax: SENDALL "); + return; + } + let text = args[1..].join(" "); + // Snapshot the names first so the immutable read ends before we send. + let names: Vec = db.accounts_matching("*").into_iter().map(|a| a.name).collect(); + let mut sent = 0usize; + for name in &names { + if db.memo_send(name, account, &text).is_ok() { + sent += 1; + } + } + ctx.notice(me, from.uid, format!("Memo sent to \x02{sent}\x02 account(s).")); +} diff --git a/src/engine/tests.rs b/src/engine/tests.rs index ab36af3..164545d 100644 --- a/src/engine/tests.rs +++ b/src/engine/tests.rs @@ -807,6 +807,65 @@ assert!(notice(&out, "refreshed"), "UPDATE confirms: {out:?}"); } + // MemoServ SENDALL (admin) drops a memo on every registered account. + #[test] + fn memoserv_sendall() { + use echo_memoserv::MemoServ; + use echo_nickserv::NickServ; + let path = std::env::temp_dir().join("echo-mssendall.jsonl"); + let _ = std::fs::remove_file(&path); + let mut db = Db::open(&path, "42S"); + db.scram_iterations = 4096; + db.register("boss", "pw", None).unwrap(); + db.register("alice", "pw", None).unwrap(); + db.register("bob", "pw", None).unwrap(); + let mut e = Engine::new( + vec![ + Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }), + Box::new(MemoServ { uid: "42SAAAAAE".into() }), + ], + db, + ); + let mut opers = std::collections::HashMap::new(); + opers.insert("boss".to_string(), Privs::default().with(echo_api::Priv::Admin)); + e.set_opers(opers); + e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "boss".into(), host: "h".into(), ip: "0.0.0.0".into() }); + e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY pw".into() }); + let out = e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAE".into(), text: "SENDALL hello everyone".into() }); + assert!(out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("sent to") && text.contains('3'))), "sent to all 3: {out:?}"); + assert_eq!(e.db.unread_memos("alice"), 1); + assert_eq!(e.db.unread_memos("bob"), 1); + } + + // ChanServ AKICK CLEAR empties the auto-kick list. + #[test] + fn chanserv_akick_clear() { + use echo_chanserv::ChanServ; + use echo_nickserv::NickServ; + let path = std::env::temp_dir().join("echo-csakickclear.jsonl"); + let _ = std::fs::remove_file(&path); + let mut db = Db::open(&path, "42S"); + db.scram_iterations = 4096; + db.register("boss", "pw", None).unwrap(); + db.register_channel("#c", "boss").unwrap(); + let mut e = Engine::new( + vec![ + Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }), + Box::new(ChanServ { uid: "42SAAAAAB".into() }), + ], + db, + ); + e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "boss".into(), host: "h".into(), ip: "0.0.0.0".into() }); + e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY pw".into() }); + let cs = |e: &mut Engine, t: &str| e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAB".into(), text: t.into() }); + cs(&mut e, "AKICK #c ADD *!*@bad1"); + cs(&mut e, "AKICK #c ADD *!*@bad2"); + let out = cs(&mut e, "AKICK #c CLEAR"); + assert!(out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("Cleared") && text.contains('2'))), "clears 2: {out:?}"); + let out = cs(&mut e, "AKICK #c LIST"); + assert!(out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("empty"))), "now empty: {out:?}"); + } + // BotServ BOT ADD/LIST is oper-gated (Priv::Admin) and the bot is remembered. #[test] fn botserv_bot_add_list_is_oper_gated() {