Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
184 changes: 142 additions & 42 deletions src/commands/slash/add.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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',
Expand All @@ -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 });
Comment thread
eartharoid marked this conversation as resolved.
Expand Down Expand Up @@ -87,32 +93,109 @@ 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')),
],
});
}
Comment thread
Antoine489 marked this conversation as resolved.

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')),
],
});
}
Comment thread
Antoine489 marked this conversation as resolved.

if (role && (role.id === interaction.guild.id || role.managed)) {
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_role.title'))
.setDescription(getMessage('commands.slash.add.invalid_role.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) {
Comment thread
Antoine489 marked this conversation as resolved.

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: [
Expand All @@ -123,24 +206,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(' & '),
Comment thread
Antoine489 marked this conversation as resolved.
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,
});
}

}
};
17 changes: 15 additions & 2 deletions src/i18n/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,27 @@ 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
invalid_target:
description: Your target is invalid.
title: ❌ Invalid target
invalid_role:
description: You cannot add the @everyone role or a managed role (bot or integration).
title: ❌ Invalid role
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}."
Comment thread
Antoine489 marked this conversation as resolved.
title: ✅ Added
claim:
description: Claim a ticket
Expand Down Expand Up @@ -333,7 +345,8 @@ log:
delete: deleted
update: updated
ticket:
added: Added members
addedMember: Added member
Comment thread
Antoine489 marked this conversation as resolved.
addedRole: Added role
description: "{user} {verb} a ticket"
removed: Removed members
ticket: Ticket
Expand Down
Loading