wiktionary improvements

This commit is contained in:
artie 2025-02-09 12:29:00 +01:00
parent cf61068a28
commit dfda1c85f7

View File

@ -40,7 +40,7 @@ export default defineCommand({
const choices = suggestions const choices = suggestions
.map((suggestion) => ({ .map((suggestion) => ({
name: suggestion.title, name: suggestion.title,
value: suggestion.key, value: `:${suggestion.key}`,
})) }))
.slice(0, 25); .slice(0, 25);
@ -48,7 +48,18 @@ export default defineCommand({
}, },
async execute(interaction) { async execute(interaction) {
const term = interaction.options.getString("term", true); let term = interaction.options.getString("term", true);
// autocomplete value vs user value
if (term.startsWith(":")) {
term = term.slice(1);
} else {
const suggestions = await getSuggestions(term);
if (!suggestions) {
abort("No definitions found");
}
term = suggestions[0].key;
}
const definitions = await getDefinitions(term); const definitions = await getDefinitions(term);
if (!definitions?.length) { if (!definitions?.length) {