generated from Baipyrus/DiscordJS-Template
basic keyword autocompletion
This commit is contained in:
parent
be5f26acca
commit
1bfd25626a
@ -26,14 +26,30 @@ async function listResponse(interaction) {}
|
|||||||
/** @param {ChatInputCommandInteraction} interaction */
|
/** @param {ChatInputCommandInteraction} interaction */
|
||||||
async function infoResponse(interaction) {}
|
async function infoResponse(interaction) {}
|
||||||
|
|
||||||
/** @param {AutocompleteInteraction} interaction */
|
|
||||||
async function addAutocomplete(interaction) {}
|
|
||||||
|
|
||||||
/** @param {AutocompleteInteraction} interaction */
|
/** @param {AutocompleteInteraction} interaction */
|
||||||
async function removeAutocomplete(interaction) {}
|
async function removeAutocomplete(interaction) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} guildId
|
||||||
|
* @param {string} focused
|
||||||
|
*/
|
||||||
|
async function keywordAutocomplete(guildId, focused) {
|
||||||
|
// Get list of keywords from database
|
||||||
|
/** @type {import('../../models/keywords.js').Keyword[]} */
|
||||||
|
const keywords = await Keywords.findAll({
|
||||||
|
where: {
|
||||||
|
guild: guildId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter total list of keywords
|
||||||
|
const filtered = keywords.filter((choice) => choice.name.startsWith(focused));
|
||||||
|
|
||||||
|
// Respond with possible suggestions
|
||||||
|
await interaction.respond(filtered.map((choice) => ({ name: choice.name, value: choice.name })));
|
||||||
|
}
|
||||||
|
|
||||||
/** @param {AutocompleteInteraction} interaction */
|
/** @param {AutocompleteInteraction} interaction */
|
||||||
async function infoAutocomplete(interaction) {}
|
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
.setName('response')
|
.setName('response')
|
||||||
@ -91,7 +107,7 @@ export const data = new SlashCommandBuilder()
|
|||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName('info')
|
.setName('info')
|
||||||
.setDescription('Shows information about a registered keyword.')
|
.setDescription('Shows responses of a registered keyword.')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('keyword')
|
.setName('keyword')
|
||||||
@ -109,14 +125,12 @@ export async function autocomplete(interaction) {
|
|||||||
const { options } = interaction;
|
const { options } = interaction;
|
||||||
|
|
||||||
switch (options.getSubcommand()) {
|
switch (options.getSubcommand()) {
|
||||||
case 'add':
|
|
||||||
addAutocomplete(interaction);
|
|
||||||
break;
|
|
||||||
case 'remove':
|
case 'remove':
|
||||||
removeAutocomplete(interaction);
|
removeAutocomplete(interaction);
|
||||||
break;
|
break;
|
||||||
|
case 'add':
|
||||||
case 'info':
|
case 'info':
|
||||||
infoAutocomplete(interaction);
|
keywordAutocomplete(interaction.guildId, interaction.options.getFocused());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user