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::{Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, Sender, ServiceCtx, Store};
|
||||
|
||||
// CANCEL: withdraw your own newest open ticket.
|
||||
pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
|
|
@ -15,7 +15,7 @@ pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &mut dyn Store)
|
|||
match mine {
|
||||
Some(t) => {
|
||||
db.help_close(t.id);
|
||||
ctx.notice(me, from.uid, format!("Your request \x02#{}\x02 has been cancelled.", t.id));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Your request \x02#{id}\x02 has been cancelled.", id = t.id));
|
||||
}
|
||||
None => ctx.notice(me, from.uid, "You have no open request to cancel."),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, Sender, ServiceCtx, Store};
|
||||
|
||||
// CLOSE <id> (aka RESOLVE): resolve a ticket.
|
||||
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.help_close(n) {
|
||||
ctx.notice(me, from.uid, format!("Ticket \x02#{n}\x02 closed."));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Ticket \x02#{id}\x02 closed.", id = n));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("Ticket \x02#{n}\x02 isn't open (or doesn't exist)."));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Ticket \x02#{id}\x02 isn't open (or doesn't exist).", id = n));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, Sender, ServiceCtx, Store};
|
||||
|
||||
// A friendly one-liner (with an example) for each extban, keyed by its ircd name.
|
||||
// The letter and whether it's offered come live from the ircd's CAPAB set, so this
|
||||
|
|
@ -53,8 +53,14 @@ pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &dyn Store) {
|
|||
let line = |ctx: &mut ServiceCtx, e: &echo_api::ExtbanCap| {
|
||||
let letter = e.letter.map_or_else(|| "-".to_string(), |c| c.to_string());
|
||||
match DESC.iter().find(|(n, _)| n.eq_ignore_ascii_case(&e.name)) {
|
||||
Some((_, desc)) => say(ctx, format!(" \x02{}\x02 (\x02{}\x02) — {}", e.name, letter, desc)),
|
||||
None => say(ctx, format!(" \x02{}\x02 (\x02{}\x02)", e.name, letter)),
|
||||
Some((_, desc)) => {
|
||||
let s = t!(ctx, " \x02{name}\x02 (\x02{letter}\x02) — {desc}", name = e.name, letter = letter, desc = desc);
|
||||
say(ctx, s)
|
||||
}
|
||||
None => {
|
||||
let s = t!(ctx, " \x02{name}\x02 (\x02{letter}\x02)", name = e.name, letter = letter);
|
||||
say(ctx, s)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -62,7 +68,8 @@ pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &dyn Store) {
|
|||
// We haven't learned the ircd's set yet — show the reference from DESC.
|
||||
say(ctx, "\x02Extban types\x02 (your network's exact set is confirmed on link):".to_string());
|
||||
for (name, desc) in DESC {
|
||||
say(ctx, format!(" \x02{name}\x02 — {desc}"));
|
||||
let s = t!(ctx, " \x02{name}\x02 — {desc}", name = name, desc = desc);
|
||||
say(ctx, s);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
//! `lib.rs` holds the dispatcher and the shared guard/claim helpers; 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 = "request.rs"]
|
||||
mod request;
|
||||
|
|
@ -78,7 +78,7 @@ impl Service for HelpServ {
|
|||
None => {
|
||||
echo_api::help(me, from, ctx, BLURB, TOPICS, other);
|
||||
if other.is_none() {
|
||||
ctx.notice(me, from.uid, format!("For a service's own commands, type \x02HELP <service>\x02. Services: {}.", net.help_services().join(", ")));
|
||||
ctx.notice(me, from.uid, t!(ctx, "For a service's own commands, type \x02HELP <service>\x02. Services: {services}.", services = net.help_services().join(", ")));
|
||||
ctx.notice(me, from.uid, "For the extended ban types you can use, type \x02HELP EXTBANS\x02.");
|
||||
}
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ impl Service for HelpServ {
|
|||
// Not a HelpServ command — maybe the name of a service to get help for.
|
||||
Some(_) => match net.service_help(args[0]) {
|
||||
Some((blurb, topics)) => echo_api::help(me, from, ctx, blurb, topics, args.get(1).copied()),
|
||||
None => ctx.notice(me, from.uid, format!("I don't know \x02{}\x02. Try \x02REQUEST\x02 <message>, \x02HELP\x02, or a service name (e.g. \x02NickServ\x02).", args[0])),
|
||||
None => ctx.notice(me, from.uid, t!(ctx, "I don't know \x02{name}\x02. Try \x02REQUEST\x02 <message>, \x02HELP\x02, or a service name (e.g. \x02NickServ\x02).", name = args[0])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -103,8 +103,8 @@ fn take_id(me: &str, from: &Sender, id: u64, ctx: &mut ServiceCtx, db: &mut dyn
|
|||
let handler = from.account.unwrap_or(from.nick);
|
||||
if db.help_take(id, handler) {
|
||||
let msg = db.help_ticket(id).map(|t| t.message).unwrap_or_default();
|
||||
ctx.notice(me, from.uid, format!("You took ticket \x02#{id}\x02: {msg}"));
|
||||
ctx.notice(me, from.uid, t!(ctx, "You took ticket \x02#{id}\x02: {msg}", id = id, msg = msg));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("Ticket \x02#{id}\x02 isn't open (or doesn't exist)."));
|
||||
ctx.notice(me, from.uid, t!(ctx, "Ticket \x02#{id}\x02 isn't open (or doesn't exist).", id = id));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, Sender, ServiceCtx, Store};
|
||||
|
||||
// LIST [ALL]: operators list the open queue (or every ticket with ALL).
|
||||
pub fn handle(me: &str, from: &Sender, arg: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
|
|
@ -13,12 +13,12 @@ pub fn handle(me: &str, from: &Sender, arg: Option<&str>, ctx: &mut ServiceCtx,
|
|||
}
|
||||
for t in &tickets {
|
||||
let state = match (&t.handler, t.open) {
|
||||
(_, false) => " (closed)".to_string(),
|
||||
(Some(h), true) => format!(" (taken by {h})"),
|
||||
(_, false) => t!(ctx, " (closed)"),
|
||||
(Some(h), true) => t!(ctx, " (taken by {handler})", handler = h),
|
||||
(None, true) => String::new(),
|
||||
};
|
||||
let short: String = t.message.chars().take(60).collect();
|
||||
ctx.notice(me, from.uid, format!("\x02#{}\x02 {} — {}{}", t.id, t.requester, short, state));
|
||||
ctx.notice(me, from.uid, t!(ctx, "\x02#{id}\x02 {requester} — {short}{state}", id = t.id, requester = t.requester, short = short, state = state));
|
||||
}
|
||||
ctx.notice(me, from.uid, format!("{} ticket(s). \x02VIEW\x02 <id> for detail.", tickets.len()));
|
||||
ctx.notice(me, from.uid, t!(ctx, "{count} ticket(s). \x02VIEW\x02 <id> for detail.", count = tickets.len()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{NetView, Sender, ServiceCtx, Store};
|
||||
use echo_api::{t, NetView, Sender, ServiceCtx, Store};
|
||||
|
||||
// REQUEST <message> (aka HELPME): open a help-desk ticket for the staff.
|
||||
pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
|
||||
|
|
@ -11,7 +11,7 @@ pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, net:
|
|||
// Rate-limit on the real host, not the spoofable nick (see REPORT).
|
||||
let cooldown_key = net.host_of(from.uid).unwrap_or(from.uid);
|
||||
match db.help_request(requester, cooldown_key, &message) {
|
||||
Some(id) => ctx.notice(me, from.uid, format!("Thanks — your request (\x02#{id}\x02) is in the queue. A staff member will be with you.")),
|
||||
Some(id) => ctx.notice(me, from.uid, t!(ctx, "Thanks — your request (\x02#{id}\x02) is in the queue. A staff member will be with you.", id = id)),
|
||||
None => ctx.notice(me, from.uid, "You just opened a ticket — please wait a moment before opening another."),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ticket in full.
|
||||
pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
|
|
@ -9,12 +9,12 @@ pub fn handle(me: &str, from: &Sender, id: Option<&str>, ctx: &mut ServiceCtx, d
|
|||
ctx.notice(me, from.uid, "No such ticket. Syntax: VIEW <id>");
|
||||
return;
|
||||
};
|
||||
let state = if !t.open { "closed" } else if t.handler.is_some() { "taken" } else { "open" };
|
||||
ctx.notice(me, from.uid, format!("Ticket \x02#{}\x02 ({state}):", t.id));
|
||||
ctx.notice(me, from.uid, format!(" From : \x02{}\x02", t.requester));
|
||||
let state = if !t.open { t!(ctx, "closed") } else if t.handler.is_some() { t!(ctx, "taken") } else { t!(ctx, "open") };
|
||||
ctx.notice(me, from.uid, t!(ctx, "Ticket \x02#{id}\x02 ({state}):", id = t.id, state = state));
|
||||
ctx.notice(me, from.uid, t!(ctx, " From : \x02{requester}\x02", requester = t.requester));
|
||||
if let Some(h) = &t.handler {
|
||||
ctx.notice(me, from.uid, format!(" Handler : \x02{h}\x02"));
|
||||
ctx.notice(me, from.uid, t!(ctx, " Handler : \x02{handler}\x02", handler = h));
|
||||
}
|
||||
ctx.notice(me, from.uid, format!(" Opened : {}", human_time(t.ts)));
|
||||
ctx.notice(me, from.uid, format!(" Message : {}", t.message));
|
||||
ctx.notice(me, from.uid, t!(ctx, " Opened : {when}", when = human_time(t.ts)));
|
||||
ctx.notice(me, from.uid, t!(ctx, " Message : {msg}", msg = t.message));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue