-
-
Notifications
You must be signed in to change notification settings - Fork 609
Add role handling for add commands #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
14d1046
8e6111a
1a0d9ba
1c612de
d222cd1
15e06cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'); | ||
|
|
@@ -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')), | ||
| ], | ||
| }); | ||
| } | ||
|
Comment on lines
+101
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 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 |
||
|
|
||
| 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) { | ||
Antoine489 marked this conversation as resolved.
Show resolved
Hide 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: [ | ||
|
|
@@ -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(' & '), | ||
Antoine489 marked this conversation as resolved.
Show resolved
Hide 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, | ||
| }); | ||
| } | ||
|
|
||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.