generated from Baipyrus/DiscordJS-Template
implement removal methods
This commit is contained in:
parent
d10dd2da00
commit
54dc8bd245
@ -115,34 +115,46 @@ async function addResponse(interaction) {
|
|||||||
await interaction.showModal(modal);
|
await interaction.showModal(modal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param {ChatInputCommandInteraction} interaction */
|
||||||
|
async function removeKeyword(interaction) {
|
||||||
|
const { options } = interaction;
|
||||||
|
|
||||||
|
// Get command options
|
||||||
|
const keyword = options.getString('name');
|
||||||
|
|
||||||
|
// Try deleting keyword from database
|
||||||
|
await Keywords.destroy({
|
||||||
|
where: {
|
||||||
|
guild: interaction.guildId,
|
||||||
|
name: keyword
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** @param {ChatInputCommandInteraction} interaction */
|
/** @param {ChatInputCommandInteraction} interaction */
|
||||||
async function removeResponse(interaction) {
|
async function removeResponse(interaction) {
|
||||||
const { options } = interaction;
|
const { options } = interaction;
|
||||||
|
|
||||||
// Get command options
|
// Get command options
|
||||||
/** @type {'keyword'|'response'} */
|
const keyword = options.getString('keyword');
|
||||||
const type = options.getString('type');
|
|
||||||
const name = options.getString('name');
|
const name = options.getString('name');
|
||||||
|
|
||||||
switch (type) {
|
// Find keyword in database
|
||||||
case 'keyword':
|
/** @type {import('../../models/keywords.js').Keyword} */
|
||||||
// Try removing keyword
|
const found = await Keywords.findOne({
|
||||||
await Keywords.destroy({
|
|
||||||
where: {
|
where: {
|
||||||
guild: interaction.guildId,
|
guild: interaction.guildId,
|
||||||
name
|
name: keyword
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
case 'response':
|
// Try deleting response from database
|
||||||
// Try removing response
|
|
||||||
await Responses.destroy({
|
await Responses.destroy({
|
||||||
where: {
|
where: {
|
||||||
guild: interaction.guildId,
|
keyword: found.id,
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {ChatInputCommandInteraction} interaction */
|
/** @param {ChatInputCommandInteraction} interaction */
|
||||||
@ -364,7 +376,7 @@ export const data = new SlashCommandBuilder()
|
|||||||
.setDescription('Deletes a keyword completely.')
|
.setDescription('Deletes a keyword completely.')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('keyword')
|
.setName('name')
|
||||||
.setDescription('The keyword to be deleted.')
|
.setDescription('The keyword to be deleted.')
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
@ -472,14 +484,21 @@ export async function autocomplete(interaction) {
|
|||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
const { options } = interaction;
|
const { options } = interaction;
|
||||||
|
|
||||||
switch (options.getSubcommand()) {
|
const command = options.getSubcommand();
|
||||||
|
const group = options.getSubcommandGroup();
|
||||||
|
const joined = group === null ? command : `${group} ${command}`;
|
||||||
|
|
||||||
|
switch (joined) {
|
||||||
case 'create':
|
case 'create':
|
||||||
createResponse(interaction);
|
createResponse(interaction);
|
||||||
break;
|
break;
|
||||||
case 'add':
|
case 'add':
|
||||||
addResponse(interaction);
|
addResponse(interaction);
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'remove keyword':
|
||||||
|
removeKeyword(interaction);
|
||||||
|
break;
|
||||||
|
case 'remove response':
|
||||||
removeResponse(interaction);
|
removeResponse(interaction);
|
||||||
break;
|
break;
|
||||||
case 'list':
|
case 'list':
|
||||||
|
Loading…
Reference in New Issue
Block a user