Migrate interpolated service messages to the t! macro (8 modules)

This commit is contained in:
Jean Chevronnet 2026-07-19 23:22:56 +00:00
parent b462d37bd5
commit d207c3d60d
No known key found for this signature in database
133 changed files with 782 additions and 702 deletions

View file

@ -1,4 +1,4 @@
use echo_api::{Sender, ServiceCtx, Store};
use echo_api::{t, Sender, ServiceCtx, Store};
// CLOSE <id> (aka RESOLVE): mark a report resolved.
pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
@ -10,8 +10,8 @@ pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, d
return;
};
if db.report_close(n) {
ctx.notice(me, from.uid, format!("Report \x02#{n}\x02 closed."));
ctx.notice(me, from.uid, t!(ctx, "Report \x02#{n}\x02 closed.", n = n));
} else {
ctx.notice(me, from.uid, format!("Report \x02#{n}\x02 isn't open (or doesn't exist)."));
ctx.notice(me, from.uid, t!(ctx, "Report \x02#{n}\x02 isn't open (or doesn't exist).", n = n));
}
}

View file

@ -1,4 +1,4 @@
use echo_api::{Sender, ServiceCtx, Store};
use echo_api::{t, Sender, ServiceCtx, Store};
// DEL <id> (aka REMOVE): delete a report outright.
pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
@ -10,8 +10,8 @@ pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, d
return;
};
if db.report_del(n) {
ctx.notice(me, from.uid, format!("Report \x02#{n}\x02 deleted."));
ctx.notice(me, from.uid, t!(ctx, "Report \x02#{n}\x02 deleted.", n = n));
} else {
ctx.notice(me, from.uid, format!("There's no report \x02#{n}\x02."));
ctx.notice(me, from.uid, t!(ctx, "There's no report \x02#{n}\x02.", n = n));
}
}

View file

@ -8,7 +8,7 @@
//! `lib.rs` holds the dispatcher and the shared oper guard; each command lives
//! in its own file.
use echo_api::{HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
use echo_api::{t, HelpEntry, NetView, Sender, Service, ServiceCtx, Store};
#[path = "report.rs"]
mod report;
@ -59,7 +59,7 @@ impl Service for ReportServ {
Some("CLOSE") | Some("RESOLVE") => close::handle(me, from, args.get(1).copied(), ctx, db),
Some("DEL") | Some("REMOVE") => del::handle(me, from, args.get(1).copied(), ctx, db),
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 \x02REPORT\x02 <nick|#channel> <reason> or \x02HELP\x02.")),
Some(other) => ctx.notice(me, from.uid, t!(ctx, "I don't know \x02{other}\x02. Try \x02REPORT\x02 <nick|#channel> <reason> or \x02HELP\x02.", other = other)),
}
}
}

View file

@ -1,4 +1,4 @@
use echo_api::{Sender, ServiceCtx, Store};
use echo_api::{t, Sender, ServiceCtx, Store};
// LIST [ALL]: operators list the open reports (or every report with ALL).
pub fn handle(me: &str, from: &Sender, arg: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
@ -14,7 +14,7 @@ pub fn handle(me: &str, from: &Sender, arg: Option<&str>, ctx: &mut ServiceCtx,
for r in &reports {
let flag = if r.open { "" } else { " (closed)" };
let short: String = r.reason.chars().take(60).collect();
ctx.notice(me, from.uid, format!("\x02#{}\x02 {}\x02{}\x02: {}{}", r.id, r.reporter, r.target, short, flag));
ctx.notice(me, from.uid, t!(ctx, "\x02#{id}\x02 {reporter} → \x02{target}\x02: {short}{flag}", id = r.id, reporter = r.reporter, target = r.target, short = short, flag = flag));
}
ctx.notice(me, from.uid, format!("{} report(s). \x02VIEW\x02 <id> for detail.", reports.len()));
ctx.notice(me, from.uid, t!(ctx, "{n} report(s). \x02VIEW\x02 <id> for detail.", n = reports.len()));
}

View file

@ -1,4 +1,4 @@
use echo_api::{NetView, Sender, ServiceCtx, Store};
use echo_api::{t, NetView, Sender, ServiceCtx, Store};
// REPORT <nick|#channel> <reason>: file an abuse report. Rate-limited.
pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
@ -16,7 +16,7 @@ pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, net:
// reset the cooldown. Anonymous reports still work; the host anchors the limit.
let cooldown_key = net.host_of(from.uid).unwrap_or(from.uid);
match db.report_file(reporter, cooldown_key, target, &reason) {
Some(id) => ctx.notice(me, from.uid, format!("Thanks — your report (\x02#{id}\x02) about \x02{target}\x02 has been sent to the staff.")),
Some(id) => ctx.notice(me, from.uid, t!(ctx, "Thanks — your report (\x02#{id}\x02) about \x02{target}\x02 has been sent to the staff.", id = id, target = target)),
None => ctx.notice(me, from.uid, "You just filed a report — please wait a moment before filing another."),
}
}

View file

@ -1,4 +1,4 @@
use echo_api::{human_time, Sender, ServiceCtx, Store};
use echo_api::{human_time, t, Sender, ServiceCtx, Store};
// VIEW <id> (aka READ): operators read a report in full.
pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
@ -9,9 +9,9 @@ pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, d
ctx.notice(me, from.uid, "No such report. Syntax: VIEW <id>");
return;
};
ctx.notice(me, from.uid, format!("Report \x02#{}\x02 ({}):", r.id, if r.open { "open" } else { "closed" }));
ctx.notice(me, from.uid, format!(" By : \x02{}\x02", r.reporter));
ctx.notice(me, from.uid, format!(" About : \x02{}\x02", r.target));
ctx.notice(me, from.uid, format!(" Filed : {}", human_time(r.ts)));
ctx.notice(me, from.uid, format!(" Reason : {}", r.reason));
ctx.notice(me, from.uid, t!(ctx, "Report \x02#{id}\x02 ({state}):", id = r.id, state = if r.open { "open" } else { "closed" }));
ctx.notice(me, from.uid, t!(ctx, " By : \x02{by}\x02", by = r.reporter));
ctx.notice(me, from.uid, t!(ctx, " About : \x02{target}\x02", target = r.target));
ctx.notice(me, from.uid, t!(ctx, " Filed : {when}", when = human_time(r.ts)));
ctx.notice(me, from.uid, t!(ctx, " Reason : {reason}", reason = r.reason));
}