IGNORE ADD/DEL/LIST manages a per-account memo-ignore list; a memo from an ignored account is silently dropped, and the sender is still told it was sent so the ignore isn't revealed. New memo_ignore account field + events, and a check in SEND.
This commit is contained in:
parent
ccbbb91fda
commit
b5e08c33cf
13 changed files with 167 additions and 5 deletions
41
modules/memoserv/src/ignore.rs
Normal file
41
modules/memoserv/src/ignore.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use echo_api::{Sender, ServiceCtx, Store};
|
||||
|
||||
// IGNORE ADD <nick> | DEL <nick> | LIST: manage your memo-ignore list. Memos
|
||||
// from an ignored account are silently dropped.
|
||||
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("ADD") => {
|
||||
let Some(&nick) = args.get(2) else {
|
||||
ctx.notice(me, from.uid, "Syntax: IGNORE ADD <nick>");
|
||||
return;
|
||||
};
|
||||
let target = db.resolve_account(nick).map(str::to_string).unwrap_or_else(|| nick.to_string());
|
||||
if db.memo_ignore_add(account, &target) {
|
||||
ctx.notice(me, from.uid, format!("Now ignoring memos from \x02{target}\x02."));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("You're already ignoring \x02{target}\x02."));
|
||||
}
|
||||
}
|
||||
Some("DEL") | Some("REMOVE") => {
|
||||
let Some(&nick) = args.get(2) else {
|
||||
ctx.notice(me, from.uid, "Syntax: IGNORE DEL <nick>");
|
||||
return;
|
||||
};
|
||||
let target = db.resolve_account(nick).map(str::to_string).unwrap_or_else(|| nick.to_string());
|
||||
if db.memo_ignore_del(account, &target) {
|
||||
ctx.notice(me, from.uid, format!("No longer ignoring \x02{target}\x02."));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("You weren't ignoring \x02{target}\x02."));
|
||||
}
|
||||
}
|
||||
Some("LIST") | None => {
|
||||
let list = db.memo_ignores(account);
|
||||
if list.is_empty() {
|
||||
ctx.notice(me, from.uid, "Your memo-ignore list is empty.");
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("You're ignoring memos from: {}", list.join(", ")));
|
||||
}
|
||||
}
|
||||
_ => ctx.notice(me, from.uid, "Syntax: IGNORE ADD <nick> | DEL <nick> | LIST"),
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,8 @@ mod check;
|
|||
mod info;
|
||||
#[path = "sendall.rs"]
|
||||
mod sendall;
|
||||
#[path = "ignore.rs"]
|
||||
mod ignore;
|
||||
|
||||
const BLURB: &str = "MemoServ delivers messages to registered users, online or not. You must be identified to use it.";
|
||||
|
||||
|
|
@ -37,6 +39,7 @@ const TOPICS: &[HelpEntry] = &[
|
|||
HelpEntry { cmd: "CHECK", summary: "see if a memo was read", detail: "Syntax: \x02CHECK <nick>\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 <text>\x02\nLeaves a memo on every registered account. Requires the admin privilege." },
|
||||
HelpEntry { cmd: "IGNORE", summary: "block memos from an account", detail: "Syntax: \x02IGNORE ADD <nick> | DEL <nick> | LIST\x02\nMemos from an ignored account are silently dropped." },
|
||||
];
|
||||
|
||||
pub struct MemoServ {
|
||||
|
|
@ -79,6 +82,7 @@ impl Service for MemoServ {
|
|||
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("IGNORE") => ignore::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 => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut S
|
|||
ctx.notice(me, from.uid, format!("\x02{target}\x02's mailbox is full — they'll need to clear some memos first."));
|
||||
return;
|
||||
}
|
||||
// If the recipient is ignoring the sender, drop it silently — the sender is
|
||||
// told it was sent, so the ignore isn't revealed.
|
||||
if db.memo_is_ignored(&dest, account) {
|
||||
ctx.notice(me, from.uid, format!("Memo sent to \x02{target}\x02."));
|
||||
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