Route the !dict fantasy command through the language-aware database too
All checks were successful
CI / check (push) Successful in 5m7s
All checks were successful
CI / check (push) Successful in 5m7s
This commit is contained in:
parent
3473d3afbd
commit
c57683b5e4
2 changed files with 13 additions and 7 deletions
|
|
@ -55,6 +55,16 @@ pub fn dict_db_for(lang: &str) -> Option<(&'static str, &'static str)> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The (database, label) a lookup should use for `lang`: the flagship `dict`
|
||||||
|
// follows the language; every other command is fixed. Shared by DictServ's own
|
||||||
|
// handler and the engine's `!dict` fantasy router so both route identically.
|
||||||
|
pub fn database_for(l: &Lookup, lang: &str) -> (&'static str, &'static str) {
|
||||||
|
match (l.cmd, dict_db_for(lang)) {
|
||||||
|
("dict", Some(loc)) => loc,
|
||||||
|
_ => (l.database, l.label),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const BLURB: &str = "DictServ looks words up in the dict.org dictionaries. Try \x02dict\x02 <word> (WordNet), \x02define\x02 (GCIDE), \x02thes\x02 (thesaurus), \x02acronym\x02, \x02element\x02, \x02law\x02, \x02bible\x02, and more — \x02LOOKUP\x02 lists them all.";
|
const BLURB: &str = "DictServ looks words up in the dict.org dictionaries. Try \x02dict\x02 <word> (WordNet), \x02define\x02 (GCIDE), \x02thes\x02 (thesaurus), \x02acronym\x02, \x02element\x02, \x02law\x02, \x02bible\x02, and more — \x02LOOKUP\x02 lists them all.";
|
||||||
|
|
||||||
const TOPICS: &[HelpEntry] = &[
|
const TOPICS: &[HelpEntry] = &[
|
||||||
|
|
@ -93,12 +103,7 @@ impl Service for DictServ {
|
||||||
ctx.notice(me, from.uid, t!(ctx, "Give a term to look up, e.g. \x02{cmd} cat\x02.", cmd = 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;
|
||||||
}
|
}
|
||||||
// `dict` follows the user's language where dict.org has a matching
|
let (database, label) = database_for(l, ctx.lang());
|
||||||
// dictionary; the specific commands (define, thes, …) stay fixed.
|
|
||||||
let (database, label) = match (l.cmd, dict_db_for(ctx.lang())) {
|
|
||||||
("dict", Some(loc)) => loc,
|
|
||||||
_ => (l.database, l.label),
|
|
||||||
};
|
|
||||||
ctx.dict_lookup(me, from.uid, database, label, query);
|
ctx.dict_lookup(me, from.uid, database, label, query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,8 @@ impl Engine {
|
||||||
if self.service_uid("DictServ").is_some() {
|
if self.service_uid("DictServ").is_some() {
|
||||||
let query = words.collect::<Vec<_>>().join(" ");
|
let query = words.collect::<Vec<_>>().join(" ");
|
||||||
if !query.trim().is_empty() {
|
if !query.trim().is_empty() {
|
||||||
ctx.dict_lookup(botuid.as_str(), chan, l.database, l.label, query);
|
let (database, label) = echo_dictserv::database_for(l, ctx.lang());
|
||||||
|
ctx.dict_lookup(botuid.as_str(), chan, database, label, query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue