Add /priority command

This commit is contained in:
Isaac 2022-10-05 18:04:29 +01:00
parent 8b55c351ad
commit 8ea372ea36
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 81 additions and 1 deletions

View File

@ -1,5 +1,6 @@
const { SlashCommand } = require('@eartharoid/dbf');
const { ApplicationCommandOptionType } = require('discord.js');
const ExtendedEmbedBuilder = require('../../lib/embed');
module.exports = class PrioritySlashCommand extends SlashCommand {
constructor(client, options) {
@ -55,5 +56,78 @@ module.exports = class PrioritySlashCommand extends SlashCommand {
});
}
async run(interaction) { }
getEmoji(priority) {
let emoji;
switch (priority) {
case 'HIGH': {
emoji = '🔴';
break;
}
case 'MEDIUM': {
emoji = '🟠';
break;
}
case 'LOW': {
emoji = '🟢';
break;
}
}
return emoji;
}
/**
*
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async run(interaction) {
/** @type {import("client")} */
const client = this.client;
await interaction.deferReply();
const settings = await client.prisma.guild.findUnique({ where: { id: interaction.guild.id } });
const getMessage = client.i18n.getLocale(settings.locale);
const ticket = await client.prisma.ticket.findUnique({
include: { category: { select: { channelName: true } } },
where: { id: interaction.channel.id },
});
if (!ticket) {
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: settings.footer,
})
.setColor(settings.errorColour)
.setTitle(getMessage('misc.not_ticket.title'))
.setDescription(getMessage('misc.not_ticket.description')),
],
});
}
const priority = interaction.options.getString('priority', true);
let name = interaction.channel.name;
if (ticket.priority) name = name.replace(this.getEmoji(ticket.priority), this.getEmoji(priority));
else name = this.getEmoji(priority) + name;
await interaction.channel.setName(name);
await client.prisma.ticket.update({
data: { priority },
where: { id: interaction.channel.id },
});
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: settings.footer,
})
.setColor(settings.successColour)
.setTitle(getMessage('commands.slash.priority.success.title'))
.setDescription(getMessage('commands.slash.priority.success.description', { priority: getMessage(`commands.slash.priority.options.priority.choices.${priority}`) })),
],
});
}
};

View File

@ -95,6 +95,9 @@ commands:
LOW: 🟢 Low
description: The priority of the ticket
name: priority
success:
description: This ticket's priority has been set to `{priority}`.
title: ✅ Priority set
release:
description: Release (unclaim) a ticket
name: release
@ -218,6 +221,9 @@ misc:
no_categories:
description: No ticket categories have been configured.
title: ❌ There are no ticket categories
not_ticket:
description: You can only use this command in tickets.
title: ❌ This isn't a ticket channel
ratelimited:
description: Try again in a few seconds.
title: 🐢 Please slow down