From 10ef6bb6176a6f8794bc5770c93875e77cb15225 Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 29 Sep 2022 16:08:46 +0100 Subject: [PATCH] Add pin command --- src/commands/message/pin.js | 60 ++++++++++++++++++++++++++++++++++++- src/i18n/en-GB.yml | 11 +++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/commands/message/pin.js b/src/commands/message/pin.js index fbcfb05..be09d7e 100644 --- a/src/commands/message/pin.js +++ b/src/commands/message/pin.js @@ -1,4 +1,5 @@ const { MessageCommand } = require('@eartharoid/dbf'); +const ExtendedEmbedBuilder = require('../../lib/embed'); module.exports = class PinMessageCommand extends MessageCommand { constructor(client, options) { @@ -13,5 +14,62 @@ module.exports = class PinMessageCommand extends MessageCommand { }); } - async run(interaction) { } + /** + * @param {import("discord.js").MessageContextMenuCommandInteraction} interaction + */ + async run(interaction) { + /** @type {import("client")} */ + const client = this.client; + + await interaction.deferReply({ ephemeral: true }); + const ticket = await client.prisma.ticket.findUnique({ + include: { guild: true }, + where: { id: interaction.channel.id }, + }); + + if (!ticket) { + const settings = await client.prisma.guild.findUnique({ where: { id: interaction.guild.id } }); + const getMessage = client.i18n.getLocale(settings.locale); + return await interaction.editReply({ + embeds: [ + new ExtendedEmbedBuilder({ + iconURL: interaction.guild.iconURL(), + text: settings.footer, + }) + .setColor(settings.errorColour) + .setTitle(getMessage('commands.message.pin.not_ticket.title')) + .setDescription(getMessage('commands.message.pin.not_ticket.description')), + ], + }); + } + + const getMessage = client.i18n.getLocale(ticket.guild.locale); + + if (!interaction.targetMessage.pinnable) { + return await interaction.editReply({ + embeds: [ + new ExtendedEmbedBuilder({ + iconURL: interaction.guild.iconURL(), + text: ticket.guild.footer, + }) + .setColor(ticket.guild.errorColour) + .setTitle(getMessage('commands.message.pin.not_pinnable.title')) + .setDescription(getMessage('commands.message.pin.not_pinnable.description')), + ], + }); + } + + await interaction.targetMessage.pin(); + return await interaction.editReply({ + embeds: [ + new ExtendedEmbedBuilder({ + iconURL: interaction.guild.iconURL(), + text: ticket.guild.footer, + }) + .setColor(ticket.guild.successColour) + .setTitle(getMessage('commands.message.pin.pinned.title')) + .setDescription(getMessage('commands.message.pin.pinned.description')), + ], + }); + } }; \ No newline at end of file diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index 8a66dbd..a5aedf9 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -23,6 +23,17 @@ commands: name: Create a ticket from message pin: name: Pin message + not_pinnable: + description: | + This message can't be pinned. + Please ask an administrator to check the bot's permissions. + title: ❌ Error + not_ticket: + description: You can only pin messages in tickets. + title: ❌ This isn't a ticket channel + pinned: + description: The message has been pinned. + title: ✅ Pinned message slash: add: description: Add a member to a ticket