Migrate DiceServ and DictServ messages to the t! macro

This commit is contained in:
Jean Chevronnet 2026-07-19 23:46:38 +00:00
parent b28bd2777f
commit ab329fe133
No known key found for this signature in database
3 changed files with 9 additions and 9 deletions

View file

@ -6,7 +6,7 @@
//! `lib.rs` holds the dispatcher; the command lives in roll.rs and the
//! expression evaluator in expr.rs.
use echo_api::{HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
use echo_api::{t, HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
#[path = "expr.rs"]
mod expr;
@ -49,7 +49,7 @@ impl Service for DiceServ {
Some("CALC") => roll::handle(me, from, &args[1..], ctx, false, false),
Some("EXCALC") => roll::handle(me, from, &args[1..], ctx, true, false),
Some("HELP") | None => 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 \x02ROLL\x02, \x02CALC\x02, or \x02HELP\x02.")),
Some(other) => ctx.notice(me, from.uid, t!(ctx, "I don't know \x02{other}\x02. Try \x02ROLL\x02, \x02CALC\x02, or \x02HELP\x02.", other = other)),
}
}
}

View file

@ -1,4 +1,4 @@
use echo_api::{Sender, ServiceCtx};
use echo_api::{t, Sender, ServiceCtx};
use super::expr;
@ -19,7 +19,7 @@ pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, exte
Some((n, body)) => match n.trim().parse::<u32>() {
Ok(t) if (1..=MAX_REPEATS).contains(&t) => (t, body.trim()),
_ => {
ctx.notice(me, from.uid, format!("The repeat count before \x02~\x02 must be a number from 1 to {MAX_REPEATS}."));
ctx.notice(me, from.uid, t!(ctx, "The repeat count before \x02~\x02 must be a number from 1 to {max}.", max = MAX_REPEATS));
return;
}
},
@ -50,7 +50,7 @@ pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, exte
}
}
Err(why) => {
ctx.notice(me, from.uid, format!("I couldn't roll \x02{body}\x02: {why}."));
ctx.notice(me, from.uid, t!(ctx, "I couldn't roll \x02{body}\x02: {why}.", body = body, why = why));
return; // the whole batch shares the expression, so it'll fail the same way
}
}