diff --git a/src/commands/slash/add.js b/src/commands/slash/add.js index b19697822..dc1256c90 100644 --- a/src/commands/slash/add.js +++ b/src/commands/slash/add.js @@ -1,6 +1,7 @@ const { SlashCommand } = require('@eartharoid/dbf'); const { - ApplicationCommandOptionType, MessageFlags, + ApplicationCommandOptionType, + MessageFlags, } = require('discord.js'); const ExtendedEmbedBuilder = require('../../lib/embed'); const { isStaff } = require('../../lib/users'); @@ -19,9 +20,14 @@ module.exports = class AddSlashCommand extends SlashCommand { options: [ { name: 'member', - required: true, + required: false, type: ApplicationCommandOptionType.User, }, + { + name: 'role', + required: false, + type: ApplicationCommandOptionType.Role, + }, { autocomplete: true, name: 'ticket', @@ -38,10 +44,10 @@ module.exports = class AddSlashCommand extends SlashCommand { } /** - * @param {import("discord.js").ChatInputCommandInteraction} interaction + * @param {import('discord.js').ChatInputCommandInteraction} interaction */ async run(interaction) { - /** @type {import("client")} */ + /** @type {import('client')} */ const client = this.client; await interaction.deferReply({ flags: MessageFlags.Ephemeral }); @@ -87,32 +93,81 @@ module.exports = class AddSlashCommand extends SlashCommand { }); } - /** @type {import("discord.js").TextChannel} */ + /** @type {import('discord.js').TextChannel} */ const ticketChannel = await interaction.guild.channels.fetch(ticket.id); - const member = interaction.options.getMember('member', true); - - await ticketChannel.permissionOverwrites.edit( - member, - { - AttachFiles: true, - EmbedLinks: true, - ReadMessageHistory: true, - SendMessages: true, - ViewChannel: true, - }, - `${interaction.user.tag} added ${member.user.tag} to the ticket`, - ); - - await ticketChannel.send({ - embeds: [ - new ExtendedEmbedBuilder() - .setColor(ticket.guild.primaryColour) - .setDescription(getMessage('commands.slash.add.added', { - added: member.toString(), - by: interaction.member.toString(), - })), - ], - }); + const member = interaction.options.getMember('member', false); + const role = interaction.options.getRole('role', false); + + if (!member && !role) { + return await interaction.editReply({ + embeds: [ + new ExtendedEmbedBuilder({ + iconURL: interaction.guild.iconURL(), + text: ticket.guild.footer, + }) + .setColor(ticket.guild.errorColour) + .setTitle(getMessage('commands.slash.add.no_args.title')) + .setDescription(getMessage('commands.slash.add.no_args.description')), + ], + }); + } + + if (member) { + + await ticketChannel.permissionOverwrites.edit( + member, + { + AttachFiles: true, + EmbedLinks: true, + ReadMessageHistory: true, + SendMessages: true, + ViewChannel: true, + }, + `${interaction.user.tag} added ${member.user.tag} to the ticket`, + ); + + + await ticketChannel.send({ + embeds: [ + new ExtendedEmbedBuilder() + .setColor(ticket.guild.primaryColour) + .setDescription(getMessage('commands.slash.add.added', { + added: member.toString(), + by: interaction.member.toString(), + })), + ], + }); + + } + + if (role) { + + await ticketChannel.permissionOverwrites.edit( + role, + { + AttachFiles: true, + EmbedLinks: true, + ReadMessageHistory: true, + SendMessages: true, + ViewChannel: true, + }, + `${interaction.user.tag} added ${role.name} to the ticket`, + ); + + + await ticketChannel.send({ + embeds: [ + new ExtendedEmbedBuilder() + .setColor(ticket.guild.primaryColour) + .setDescription(getMessage('commands.slash.add.added', { + added: role.toString(), + by: interaction.member.toString(), + })), + ], + }); + + } + await interaction.editReply({ embeds: [ @@ -123,24 +178,41 @@ module.exports = class AddSlashCommand extends SlashCommand { .setColor(ticket.guild.successColour) .setTitle(getMessage('commands.slash.add.success.title')) .setDescription(getMessage('commands.slash.add.success.description', { - member: member.toString(), + args: [member?.toString(), role?.toString()].filter(Boolean).join(' & '), ticket: ticketChannel.toString(), })), ], }); - logTicketEvent(this.client, { - action: 'update', - diff: { - original: {}, - updated: { [getMessage('log.ticket.added')]: member.user.tag }, - }, - target: { - id: ticket.id, - name: `<#${ticket.id}>`, - }, - userId: interaction.user.id, - }); + if (member) { + logTicketEvent(this.client, { + action: 'update', + diff: { + original: {}, + updated: { [getMessage('log.ticket.addedMember')]: member.user.tag }, + }, + target: { + id: ticket.id, + name: `<#${ticket.id}>`, + }, + userId: interaction.user.id, + }); + } + + if (role) { + logTicketEvent(this.client, { + action: 'update', + diff: { + original: {}, + updated: { [getMessage('log.ticket.addedRole')]: role.name }, + }, + target: { + id: ticket.id, + name: `<#${ticket.id}>`, + }, + userId: interaction.user.id, + }); + } } }; diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index ed76dc059..1595998ff 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -54,15 +54,21 @@ commands: not_staff: description: Only staff members can add members to others' tickets. title: ❌ Error + no_args: + description: You must specify a member or a role to add to the ticket. + title: ❌ Missing arguments options: member: description: The member to add to the ticket name: member + role: + description: The role to add to the ticket + name: role ticket: description: The ticket to add the member to name: ticket success: - description: "{member} has been added to {ticket}." + description: "{args} has been added to {ticket}." title: ✅ Added claim: description: Claim a ticket @@ -333,7 +339,8 @@ log: delete: deleted update: updated ticket: - added: Added members + addedMember: Added member + addedRole: Added role description: "{user} {verb} a ticket" removed: Removed members ticket: Ticket