Split BotServ and MemoServ into one-file-per-command modules
Match the NickServ/ChanServ layout: lib.rs keeps only the service struct and the on_command dispatcher, and each command moves to its own file bridged with #[path]. No behaviour change. BotServ: bot.rs, assign.rs. MemoServ: send.rs, list.rs, read.rs, del.rs.
This commit is contained in:
parent
b25870e14b
commit
6a794eabff
8 changed files with 234 additions and 209 deletions
26
memoserv/src/send.rs
Normal file
26
memoserv/src/send.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use fedserv_api::{Sender, ServiceCtx, Store};
|
||||
|
||||
// A full mailbox rejects new memos, so nobody can be flooded.
|
||||
const MAX_MEMOS: usize = 30;
|
||||
|
||||
// SEND <nick> <text>: leave a memo on a registered account's mailbox.
|
||||
pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
if args.len() < 3 {
|
||||
ctx.notice(me, from.uid, "Syntax: SEND <nick> <text>");
|
||||
return;
|
||||
}
|
||||
let target = args[1];
|
||||
let text = args[2..].join(" ");
|
||||
let Some(dest) = db.resolve_account(target).map(str::to_string) else {
|
||||
ctx.notice(me, from.uid, format!("\x02{target}\x02 isn't registered."));
|
||||
return;
|
||||
};
|
||||
if db.memo_list(&dest).len() >= MAX_MEMOS {
|
||||
ctx.notice(me, from.uid, format!("\x02{target}\x02's mailbox is full — they'll need to clear some memos first."));
|
||||
return;
|
||||
}
|
||||
match db.memo_send(&dest, account, &text) {
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Memo sent to \x02{target}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue