implement and categorized info methods and completion

This commit is contained in:
Baipyrus 2024-04-05 11:47:50 +02:00
parent 904c33c2f8
commit c666f5bf8d

View File

@ -208,11 +208,62 @@ async function listResponse(interaction) {
} }
/** @param {ChatInputCommandInteraction} interaction */ /** @param {ChatInputCommandInteraction} interaction */
async function infoResponse(interaction) { async function responseInfos(interaction) {
const { options } = interaction; const { options } = interaction;
// Get command options // Get command options
const keyword = options.getString('keyword'); const keyword = options.getString('keyword');
const name = options.getString('name');
// Find keyword in database
/** @type {import('../../models/keywords.js').Keyword|null} */
const found = await Keywords.findOne({
where: {
guild: interaction.guildId,
name: keyword
}
});
// Abort if keyword not found
if (found === null) {
await interaction.reply({
content: 'Unknown keyword was specified!',
ephemeral: true
});
return;
}
// Find response in database
/** @type {import('../../models/responses.js').Response|null} */
const response = await Responses.findOne({
where: {
keyword: found.id,
name
}
});
// Abort if response not found
if (response === null) {
await interaction.reply({
content: 'Unknown response was specified!',
ephemeral: true
});
return;
}
// Reply with success
await interaction.reply({
content: `Response with name '${name}' has data of \`${response.response}\`!`,
ephemeral: true
});
}
/** @param {ChatInputCommandInteraction} interaction */
async function keywordInfos(interaction) {
const { options } = interaction;
// Get command options
const keyword = options.getString('name');
// Find keyword in database // Find keyword in database
/** @type {import('../../models/keywords.js').Keyword|null} */ /** @type {import('../../models/keywords.js').Keyword|null} */
@ -402,17 +453,41 @@ export const data = new SlashCommandBuilder()
.addSubcommand((subcommand) => .addSubcommand((subcommand) =>
subcommand.setName('list').setDescription('Lists all registered keywords.') subcommand.setName('list').setDescription('Lists all registered keywords.')
) )
.addSubcommandGroup((group) =>
group
.setName('info')
.setDescription('Lists information about a response or a keyword.')
.addSubcommand((subcommand) => .addSubcommand((subcommand) =>
subcommand subcommand
.setName('info') .setName('keyword')
.setDescription('Shows responses of a registered keyword.') .setDescription('Lists registered responses of a keyword.')
.addStringOption((option) =>
option
.setName('name')
.setDescription('The keyword to be shown the details of.')
.setAutocomplete(true)
.setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('response')
.setDescription('Lists the data being sent by a response.')
.addStringOption((option) => .addStringOption((option) =>
option option
.setName('keyword') .setName('keyword')
.setDescription('The keyword to show the details of.') .setDescription('The keyword that would trigger the response.')
.setAutocomplete(true) .setAutocomplete(true)
.setRequired(true) .setRequired(true)
) )
.addStringOption((option) =>
option
.setName('name')
.setDescription('The name of the data to be listed.')
.setAutocomplete(true)
.setRequired(true)
)
)
); );
/** @param {ModalSubmitInteraction} interaction */ /** @param {ModalSubmitInteraction} interaction */
export async function modalSubmit(interaction) { export async function modalSubmit(interaction) {
@ -465,14 +540,15 @@ export async function autocomplete(interaction) {
const joined = group === null ? command : `${group} ${command}`; const joined = group === null ? command : `${group} ${command}`;
switch (joined) { switch (joined) {
case 'info keyword':
case 'remove keyword': case 'remove keyword':
await keywordAutocomplete(interaction); await keywordAutocomplete(interaction);
break; break;
case 'info response':
case 'remove response': case 'remove response':
await responseAutocomplete(interaction); await responseAutocomplete(interaction);
break; break;
case 'add': case 'add':
case 'info':
keywordAutocomplete(interaction); keywordAutocomplete(interaction);
break; break;
} }
@ -501,8 +577,11 @@ export async function execute(interaction) {
case 'list': case 'list':
listResponse(interaction); listResponse(interaction);
break; break;
case 'info': case 'info keyword':
infoResponse(interaction); keywordInfos(interaction);
break;
case 'info response':
responseInfos(interaction);
break; break;
} }
} }