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
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
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,
})),
);
}
};

View File

@ -1,5 +1,6 @@
const { SlashCommand } = require('@eartharoid/dbf');
const { ApplicationCommandOptionType } = require('discord.js');
const ExtendedEmbedBuilder = require('../../lib/embed');
module.exports = class TagSlashCommand extends SlashCommand {
constructor(client, options) {
@ -14,7 +15,7 @@ module.exports = class TagSlashCommand extends SlashCommand {
autocomplete: true,
name: 'tag',
required: true,
type: ApplicationCommandOptionType.String,
type: ApplicationCommandOptionType.Integer,
},
{
name: 'for',
@ -48,5 +49,28 @@ module.exports = class TagSlashCommand extends SlashCommand {
});
}
async run(interaction) { }
/**
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async run(interaction) {
/** @type {import("client")} */
const client = this.client;
const user = interaction.options.getUser('for', false);
await interaction.deferReply({ ephemeral: !user });
const tag = await client.prisma.tag.findUnique({
include: { guild: true },
where: { id: interaction.options.getInteger('tag', true) },
});
await interaction.editReply({
allowedMentions: { users: user ? [user.id]: [] },
content: user?.toString(),
embeds: [
new ExtendedEmbedBuilder()
.setColor(tag.guild.primaryColour)
.setDescription(tag.content),
],
});
}
};

View File

@ -179,13 +179,11 @@ module.exports = class extends Listener {
});
}
} else {
let ticket = await client.prisma.ticket.findUnique({
include: { guild: true },
where: { id: message.channel.id },
});
const settings = await client.prisma.guild.findUnique({ where: { id:message.guild.id } });
let ticket = await client.prisma.ticket.findUnique({ where: { id: message.channel.id } });
if (ticket) {
if (ticket.guild.archive) {
if (settings.archive) {
try {
await client.tickets.archiver.saveMessage(ticket.id, message);
} catch (error) {
@ -218,8 +216,26 @@ module.exports = class extends Listener {
// TODO: if (!message.author.bot) staff status alert, working hours alerts
}
// TODO: if (!message.author.bot) auto tag
if (!message.author.bot) {
const enabled =
(settings.autoTag === 'all') ||
(settings.autoTag === 'ticket' && ticket) ||
(settings.autoTag === '!ticket' && !ticket) ||
(settings.autoTag.includes(message.channel.id));
if (enabled) {
const tags = await client.prisma.tag.findMany({ where: { guildId: message.guild.id } });
const tag = tags.find(tag => message.content.match(new RegExp(tag.regex, 'mi')));
if (tag) {
await message.reply({
embeds: [
new EmbedBuilder()
.setColor(settings.primaryColour)
.setDescription(tag.content),
],
});
}
}
}
}
}
};