echo/modules/infoserv/src/del.rs
Jean 993f5b2eea
Rename the project to Echo (was fedserv)
Rebrand the daemon and workspace: the binary is now `echo`, every crate
is `echo-*` (`echo-api` and the module crates), Rust imports use
`echo_*`, the gRPC proto is `proto/echo.proto` with package `echo.v1`,
and the log filter, gossip peer-name default, and on-disk store default
(`echo.db.jsonl`) follow. Docs updated throughout. No behaviour change;
crate directories and the config schema are untouched.
2026-07-14 15:24:41 +00:00

21 lines
1,001 B
Rust

use echo_api::{Priv, Sender, ServiceCtx, Store};
// DEL/ODEL <number>: remove a bulletin by its listed position. Admin only.
pub fn handle(me: &str, from: &Sender, kind: &str, num: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
if !from.privs.has(Priv::Admin) {
ctx.notice(me, from.uid, "Access denied — that command is for services operators.");
return;
}
let which = if kind == super::OPER { "oper" } else { "public" };
let Some(n) = num.and_then(|n| n.parse::<usize>().ok()) else {
ctx.notice(me, from.uid, format!("Syntax: {} <number>", if kind == super::OPER { "ODEL" } else { "DEL" }));
return;
};
match db.news(kind).get(n.wrapping_sub(1)) {
Some(item) if n >= 1 => {
db.news_del(item.id);
ctx.notice(me, from.uid, format!("Removed \x02{which}\x02 bulletin \x02{n}\x02."));
}
_ => ctx.notice(me, from.uid, format!("There's no \x02{which}\x02 bulletin \x02{n}\x02.")),
}
}