19 lines
878 B
Rust
19 lines
878 B
Rust
use echo_api::{NewsKind, Sender, ServiceCtx, Store};
|
|
|
|
// LIST/OLIST: show the bulletins of a kind. Public is open; oper is oper-only.
|
|
pub fn handle(me: &str, from: &Sender, kind: NewsKind, oper_only: bool, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
|
if oper_only && !from.privs.any() {
|
|
ctx.notice(me, from.uid, "Access denied — oper bulletins are for services operators.");
|
|
return;
|
|
}
|
|
let items = db.news(kind);
|
|
let which = if kind == super::OPER { "oper" } else { "public" };
|
|
if items.is_empty() {
|
|
ctx.notice(me, from.uid, format!("There are no {which} bulletins."));
|
|
return;
|
|
}
|
|
for (i, item) in items.iter().enumerate() {
|
|
ctx.notice(me, from.uid, format!("{}. {} — by {}", i + 1, item.text, item.setter));
|
|
}
|
|
ctx.notice(me, from.uid, format!("End of {which} bulletins ({} shown).", items.len()));
|
|
}
|