From 8ea372ea363961dfff05fae14c5d62954aad4001 Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 5 Oct 2022 18:04:29 +0100 Subject: [PATCH] Add `/priority` command --- src/commands/slash/priority.js | 76 +++++++++++++++++++++++++++++++++- src/i18n/en-GB.yml | 6 +++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/commands/slash/priority.js b/src/commands/slash/priority.js index d13aac9..00675ff 100644 --- a/src/commands/slash/priority.js +++ b/src/commands/slash/priority.js @@ -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}`) })), + ], + }); + + } }; \ No newline at end of file diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index a5aedf9..4fef492 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -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