Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 81 additions & 27 deletions src/commands/slash/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,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',
Expand All @@ -36,10 +41,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({ ephemeral: true });
Expand Down Expand Up @@ -85,32 +90,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);
const role = interaction.options.getRole('role', false);

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`,
);
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')),
],
});
}
Comment on lines +101 to +113
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add validation for invalid targets.

While the guard correctly ensures at least one of member or role is provided, there's no validation for invalid targets. The remove command (lines 55-58 in remove.js) checks that the member is not the bot or the ticket creator.

Consider adding similar validation:

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 && (member.id === client.user.id || member.id === ticket.createdById)) {
	return await interaction.editReply({
		embeds: [
			new ExtendedEmbedBuilder({
				iconURL: interaction.guild.iconURL(),
				text: ticket.guild.footer,
			})
				.setColor(ticket.guild.errorColour)
				.setTitle(getMessage('commands.slash.add.invalid_target.title'))
				.setDescription(getMessage('commands.slash.add.invalid_target.description')),
		],
	});
}
🤖 Prompt for AI Agents
In src/commands/slash/add.js around lines 101 to 113, the guard checks that
either member or role is supplied but does not validate that the provided member
is a valid target (e.g., not the bot or the ticket creator). Add a validation
after the existing guard: if member is present and its id equals client.user.id
or ticket.createdById, send an error reply using the same ExtendedEmbedBuilder
pattern but with a new title/description keys
(commands.slash.add.invalid_target.title/description) and the
ticket.guild.errorColour/footer; return after sending the reply so execution
stops.


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 ticketChannel.send({
embeds: [
new ExtendedEmbedBuilder()
.setColor(ticket.guild.primaryColour)
.setDescription(getMessage('commands.slash.add.added', {
added: member.toString(),
by: interaction.member.toString(),
})),
],
});

await interaction.editReply({
embeds: [
Expand All @@ -121,7 +175,7 @@ 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 ? member.toString() : '') + (role ? ` and ${role.toString()}` : ''),
ticket: ticketChannel.toString(),
})),
],
Expand All @@ -141,4 +195,4 @@ module.exports = class AddSlashCommand extends SlashCommand {
});

}
};
};
8 changes: 7 additions & 1 deletion src/i18n/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,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
Expand Down
Loading