Migrate interpolated service messages to the t! macro (8 modules)
This commit is contained in:
parent
b462d37bd5
commit
d207c3d60d
133 changed files with 782 additions and 702 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{NewsKind, Priv, Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, NewsKind, Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// DEL/ODEL <number>: remove a bulletin by its listed position. Admin only.
|
||||
pub fn handle(me: &str, from: &Sender, kind: NewsKind, num: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
|
|
@ -8,14 +8,14 @@ pub fn handle(me: &str, from: &Sender, kind: NewsKind, num: Option<&str>, ctx: &
|
|||
}
|
||||
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" }));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Syntax: {cmd} <number>", cmd = 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, t!(ctx, "Removed \x02{which}\x02 bulletin \x02{n}\x02.", which = which, n = n));
|
||||
}
|
||||
_ => ctx.notice(me, from.uid, format!("There's no \x02{which}\x02 bulletin \x02{n}\x02.")),
|
||||
_ => ctx.notice(me, from.uid, t!(ctx, "There's no \x02{which}\x02 bulletin \x02{n}\x02.", which = which, n = n)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
//! and any operator may OLIST. `lib.rs` holds the dispatcher; each command
|
||||
//! (parameterised by bulletin kind) lives in its own file.
|
||||
|
||||
use echo_api::{HelpEntry, NetView, NewsKind, Sender, Service, ServiceCtx, Store};
|
||||
use echo_api::{t, HelpEntry, NetView, NewsKind, Sender, Service, ServiceCtx, Store};
|
||||
|
||||
#[path = "post.rs"]
|
||||
mod post;
|
||||
|
|
@ -64,7 +64,7 @@ impl Service for InfoServ {
|
|||
// Oper bulletins are for operators only.
|
||||
Some("OLIST") => list::handle(me, from, OPER, true, ctx, db),
|
||||
Some("HELP") => echo_api::help(me, from, ctx, BLURB, TOPICS, args.get(1).copied()),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know \x02{other}\x02. Try \x02LIST\x02 or \x02HELP\x02.")),
|
||||
Some(other) => ctx.notice(me, from.uid, t!(ctx, "I don't know \x02{other}\x02. Try \x02LIST\x02 or \x02HELP\x02.", other = other)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{NewsKind, Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, 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) {
|
||||
|
|
@ -9,11 +9,11 @@ pub fn handle(me: &str, from: &Sender, kind: NewsKind, oper_only: bool, ctx: &mu
|
|||
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."));
|
||||
ctx.notice(me, from.uid, t!(ctx, "There are no {which} bulletins.", which = which));
|
||||
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, t!(ctx, "{num}. {text} — by {by}", num = i + 1, text = item.text, by = item.setter));
|
||||
}
|
||||
ctx.notice(me, from.uid, format!("End of {which} bulletins ({} shown).", items.len()));
|
||||
ctx.notice(me, from.uid, t!(ctx, "End of {which} bulletins ({count} shown).", which = which, count = items.len()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{NewsKind, Priv, Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, NewsKind, Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// POST/OPOST <message>: add a bulletin (public or oper). Admin only.
|
||||
pub fn handle(me: &str, from: &Sender, kind: NewsKind, rest: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
|
|
@ -8,11 +8,11 @@ pub fn handle(me: &str, from: &Sender, kind: NewsKind, rest: &[&str], ctx: &mut
|
|||
}
|
||||
let message = rest.join(" ");
|
||||
if message.trim().is_empty() {
|
||||
ctx.notice(me, from.uid, format!("Syntax: {} <message>", if kind == super::OPER { "OPOST" } else { "POST" }));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Syntax: {cmd} <message>", cmd = if kind == super::OPER { "OPOST" } else { "POST" }));
|
||||
return;
|
||||
}
|
||||
let setter = from.account.unwrap_or(from.nick);
|
||||
db.news_add(kind, &message, setter);
|
||||
let which = if kind == super::OPER { "oper" } else { "public" };
|
||||
ctx.notice(me, from.uid, format!("Added a \x02{which}\x02 bulletin."));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Added a \x02{which}\x02 bulletin.", which = which));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue