Make /tag and auto tag replies work

(very cool)
This commit is contained in:
Isaac
2022-10-18 16:39:03 +01:00
parent 90c0521e35
commit 59c6ab3537
3 changed files with 73 additions and 10 deletions

View File

@@ -8,5 +8,28 @@ module.exports = class TagCompleter extends Autocompleter {
});
}
async run(value, comamnd, interaction) { }
/**
* @param {string} value
* @param {*} command
* @param {import("discord.js").AutocompleteInteraction} interaction
*/
async run(value, command, interaction) {
/** @type {import("client")} */
const client = this.client;
const tags = await client.prisma.tag.findMany({ where: { guildId: interaction.guild.id } });
const options = value ? tags.filter(tag =>
tag.name.match(new RegExp(value, 'i')) ||
tag.content.match(new RegExp(value, 'i')) ||
tag.regex?.match(new RegExp(value, 'i')),
) : tags;
await interaction.respond(
options
.slice(0, 25)
.map(tag => ({
name: tag.name,
value: tag.id,
})),
);
}
};