Add pin command

This commit is contained in:
Isaac 2022-09-29 16:08:46 +01:00
parent 9d46abcbb3
commit 10ef6bb617
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 70 additions and 1 deletions

View File

@ -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')),
],
});
}
};

View File

@ -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