27 lines
1.2 KiB
Rust
27 lines
1.2 KiB
Rust
use echo_api::{t, Sender, ServiceCtx, Store};
|
|
|
|
// DEL <num>|ALL: remove a memo (or the whole mailbox).
|
|
pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
|
match args.get(1).map(|s| s.to_ascii_uppercase()).as_deref() {
|
|
Some("ALL") => {
|
|
let count = db.memo_list(account).len();
|
|
// Delete from the end so earlier indices stay valid as we go.
|
|
for i in (0..count).rev() {
|
|
db.memo_del(account, i);
|
|
}
|
|
ctx.notice(me, from.uid, echo_api::plural!(ctx, count, one = "Deleted all \x02{count}\x02 memo.", other = "Deleted all \x02{count}\x02 memos.", count = count));
|
|
}
|
|
Some(numstr) => {
|
|
let Some(n) = numstr.parse::<usize>().ok().filter(|n| *n >= 1) else {
|
|
ctx.notice(me, from.uid, "Syntax: DEL <num>|ALL");
|
|
return;
|
|
};
|
|
if db.memo_del(account, n - 1) {
|
|
ctx.notice(me, from.uid, t!(ctx, "Memo #\x02{n}\x02 deleted.", n = n));
|
|
} else {
|
|
ctx.notice(me, from.uid, t!(ctx, "You have no memo #\x02{n}\x02.", n = n));
|
|
}
|
|
}
|
|
None => ctx.notice(me, from.uid, "Syntax: DEL <num>|ALL"),
|
|
}
|
|
}
|