2024-04-04 05:42:25 +00:00
|
|
|
import {
|
2024-04-04 18:23:26 +00:00
|
|
|
ModalBuilder,
|
|
|
|
TextInputBuilder,
|
|
|
|
ActionRowBuilder,
|
2024-04-04 05:42:25 +00:00
|
|
|
SlashCommandBuilder,
|
|
|
|
PermissionFlagsBits,
|
|
|
|
ModalSubmitInteraction,
|
|
|
|
AutocompleteInteraction,
|
2024-04-04 18:23:26 +00:00
|
|
|
ChatInputCommandInteraction,
|
|
|
|
TextInputStyle
|
2024-04-04 05:42:25 +00:00
|
|
|
} from 'discord.js';
|
2024-04-04 18:23:26 +00:00
|
|
|
import { Guilds, Keywords, Responses } from '../../database.js';
|
2024-04-04 05:42:25 +00:00
|
|
|
|
|
|
|
/** @param {ChatInputCommandInteraction} interaction */
|
|
|
|
async function createResponse(interaction) {}
|
|
|
|
|
|
|
|
/** @param {ChatInputCommandInteraction} interaction */
|
|
|
|
async function addResponse(interaction) {}
|
|
|
|
|
|
|
|
/** @param {ChatInputCommandInteraction} interaction */
|
|
|
|
async function removeResponse(interaction) {}
|
|
|
|
|
|
|
|
/** @param {ChatInputCommandInteraction} interaction */
|
|
|
|
async function listResponse(interaction) {}
|
|
|
|
|
|
|
|
/** @param {ChatInputCommandInteraction} interaction */
|
|
|
|
async function infoResponse(interaction) {}
|
|
|
|
|
2024-04-04 18:27:00 +00:00
|
|
|
/**
|
|
|
|
* @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 })));
|
|
|
|
}
|
|
|
|
|
2024-04-04 05:42:25 +00:00
|
|
|
/** @param {AutocompleteInteraction} interaction */
|
2024-04-04 18:29:01 +00:00
|
|
|
async function removeAutocomplete(interaction) {
|
|
|
|
const { options } = interaction;
|
|
|
|
|
|
|
|
const type = options.getString('type');
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'keyword':
|
|
|
|
await keywordAutocomplete(interaction.guildId, options.getFocused());
|
|
|
|
break;
|
|
|
|
case 'response':
|
|
|
|
await responseAutocomplete(
|
|
|
|
interaction.guildId,
|
|
|
|
options.getFocused(),
|
|
|
|
options.getString('keyword')
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-04-04 05:42:25 +00:00
|
|
|
|
|
|
|
export const data = new SlashCommandBuilder()
|
|
|
|
.setName('response')
|
|
|
|
.setDMPermission(false)
|
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
|
|
|
|
.setDescription('Event based responses to specific messages with keywords.')
|
|
|
|
.addSubcommand((subcommand) =>
|
|
|
|
subcommand
|
|
|
|
.setName('create')
|
|
|
|
.setDescription('Creates a new event based response.')
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName('keyword')
|
|
|
|
.setDescription('The keyword to trigger the response.')
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.addSubcommand((subcommand) =>
|
|
|
|
subcommand
|
|
|
|
.setName('add')
|
|
|
|
.setDescription('Registers a response to a keyword.')
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName('keyword')
|
|
|
|
.setDescription('The keyword to trigger the response.')
|
|
|
|
.setAutocomplete(true)
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.addSubcommand((subcommand) =>
|
|
|
|
subcommand
|
|
|
|
.setName('remove')
|
|
|
|
.setDescription('Unregisters a response to a keyword.')
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName('type')
|
|
|
|
.setDescription('The type of data to be removed.')
|
|
|
|
.setRequired(true)
|
|
|
|
.addChoices(
|
|
|
|
{ name: 'Keyword', value: 'keyword' },
|
|
|
|
{ name: 'Response', value: 'response' }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName('name')
|
|
|
|
.setDescription('The name of the data to be removed.')
|
|
|
|
.setAutocomplete(true)
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.addSubcommand((subcommand) =>
|
|
|
|
subcommand.setName('list').setDescription('Lists all registered keywords.')
|
|
|
|
)
|
|
|
|
.addSubcommand((subcommand) =>
|
|
|
|
subcommand
|
|
|
|
.setName('info')
|
2024-04-04 18:27:00 +00:00
|
|
|
.setDescription('Shows responses of a registered keyword.')
|
2024-04-04 05:42:25 +00:00
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName('keyword')
|
|
|
|
.setDescription('The keyword to show the details of.')
|
|
|
|
.setAutocomplete(true)
|
|
|
|
.setRequired(true)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
/** @param {ModalSubmitInteraction} interaction */
|
|
|
|
export async function modalSubmit(interaction) {
|
|
|
|
// Only executable in 'add' subcommand
|
|
|
|
}
|
|
|
|
/** @param {AutocompleteInteraction} interaction */
|
|
|
|
export async function autocomplete(interaction) {
|
|
|
|
const { options } = interaction;
|
|
|
|
|
|
|
|
switch (options.getSubcommand()) {
|
|
|
|
case 'remove':
|
|
|
|
removeAutocomplete(interaction);
|
|
|
|
break;
|
2024-04-04 18:27:00 +00:00
|
|
|
case 'add':
|
2024-04-04 05:42:25 +00:00
|
|
|
case 'info':
|
2024-04-04 18:27:00 +00:00
|
|
|
keywordAutocomplete(interaction.guildId, interaction.options.getFocused());
|
2024-04-04 05:42:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** @param {ChatInputCommandInteraction} interaction */
|
|
|
|
export async function execute(interaction) {
|
|
|
|
const { options } = interaction;
|
|
|
|
|
|
|
|
switch (options.getSubcommand()) {
|
|
|
|
case 'create':
|
|
|
|
createResponse(interaction);
|
|
|
|
break;
|
|
|
|
case 'add':
|
|
|
|
addResponse(interaction);
|
|
|
|
break;
|
|
|
|
case 'remove':
|
|
|
|
removeResponse(interaction);
|
|
|
|
break;
|
|
|
|
case 'list':
|
|
|
|
listResponse(interaction);
|
|
|
|
break;
|
|
|
|
case 'info':
|
|
|
|
infoResponse(interaction);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|