Migrate DiceServ and DictServ messages to the t! macro
This commit is contained in:
parent
b28bd2777f
commit
ab329fe133
3 changed files with 9 additions and 9 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
//! `lib.rs` holds the dispatcher; the command lives in roll.rs and the
|
//! `lib.rs` holds the dispatcher; the command lives in roll.rs and the
|
||||||
//! expression evaluator in expr.rs.
|
//! 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"]
|
#[path = "expr.rs"]
|
||||||
mod expr;
|
mod expr;
|
||||||
|
|
@ -49,7 +49,7 @@ impl Service for DiceServ {
|
||||||
Some("CALC") => roll::handle(me, from, &args[1..], ctx, false, false),
|
Some("CALC") => roll::handle(me, from, &args[1..], ctx, false, false),
|
||||||
Some("EXCALC") => roll::handle(me, from, &args[1..], ctx, true, 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("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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use echo_api::{Sender, ServiceCtx};
|
use echo_api::{t, Sender, ServiceCtx};
|
||||||
|
|
||||||
use super::expr;
|
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>() {
|
Some((n, body)) => match n.trim().parse::<u32>() {
|
||||||
Ok(t) if (1..=MAX_REPEATS).contains(&t) => (t, body.trim()),
|
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;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -50,7 +50,7 @@ pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, exte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(why) => {
|
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
|
return; // the whole batch shares the expression, so it'll fail the same way
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
//! Works two ways: `/msg DictServ dict cat` (DictServ replies), or the fantasy
|
//! Works two ways: `/msg DictServ dict cat` (DictServ replies), or the fantasy
|
||||||
//! `!dict cat` in a channel with an assigned bot (the bot speaks the answer).
|
//! `!dict cat` in a channel with an assigned bot (the bot speaks the answer).
|
||||||
|
|
||||||
use echo_api::{HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
|
use echo_api::{t, HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
|
||||||
|
|
||||||
// One lookup command: the fantasy/word, the DICT database it queries, and a human
|
// One lookup command: the fantasy/word, the DICT database it queries, and a human
|
||||||
// label shown in the reply. Shared by DictServ and the engine's fantasy router so
|
// label shown in the reply. Shared by DictServ and the engine's fantasy router so
|
||||||
|
|
@ -75,7 +75,7 @@ impl Service for DictServ {
|
||||||
if let Some(l) = lookup_for(cmd) {
|
if let Some(l) = lookup_for(cmd) {
|
||||||
let query = args[1..].join(" ");
|
let query = args[1..].join(" ");
|
||||||
if query.trim().is_empty() {
|
if query.trim().is_empty() {
|
||||||
ctx.notice(me, from.uid, format!("Give a term to look up, e.g. \x02{} cat\x02.", l.cmd));
|
ctx.notice(me, from.uid, t!(ctx, "Give a term to look up, e.g. \x02{cmd} cat\x02.", cmd = l.cmd));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx.dict_lookup(me, from.uid, l.database, l.label, query);
|
ctx.dict_lookup(me, from.uid, l.database, l.label, query);
|
||||||
|
|
@ -85,11 +85,11 @@ impl Service for DictServ {
|
||||||
"LOOKUP" | "LIST" => {
|
"LOOKUP" | "LIST" => {
|
||||||
ctx.notice(me, from.uid, "Lookup commands (use in a channel as \x02!cmd <term>\x02, or here as \x02/msg DictServ cmd <term>\x02):");
|
ctx.notice(me, from.uid, "Lookup commands (use in a channel as \x02!cmd <term>\x02, or here as \x02/msg DictServ cmd <term>\x02):");
|
||||||
for l in LOOKUPS {
|
for l in LOOKUPS {
|
||||||
ctx.notice(me, from.uid, format!(" \x02{}\x02 — {}", l.cmd, l.label));
|
ctx.notice(me, from.uid, t!(ctx, " \x02{cmd}\x02 — {label}", cmd = l.cmd, label = l.label));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"HELP" | "" => echo_api::help(me, from, ctx, BLURB, TOPICS, args.get(1).copied()),
|
"HELP" | "" => echo_api::help(me, from, ctx, BLURB, TOPICS, args.get(1).copied()),
|
||||||
other => ctx.notice(me, from.uid, format!("I don't know \x02{other}\x02. Try \x02LOOKUP\x02 for the list, or \x02HELP\x02.")),
|
other => ctx.notice(me, from.uid, t!(ctx, "I don't know \x02{other}\x02. Try \x02LOOKUP\x02 for the list, or \x02HELP\x02.", other = other)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue