Skip to content

Commit

Permalink
fix: check roles for staff-only commands
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Mar 10, 2023
1 parent b14f057 commit daadb5f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/commands/slash/move.js
@@ -1,6 +1,7 @@
const { SlashCommand } = require('@eartharoid/dbf');
const { ApplicationCommandOptionType } = require('discord.js');
const ExtendedEmbedBuilder = require('../../lib/embed');
const { isStaff } = require('../../lib/users');

module.exports = class MoveSlashCommand extends SlashCommand {
constructor(client, options) {
Expand Down Expand Up @@ -62,10 +63,25 @@ module.exports = class MoveSlashCommand extends SlashCommand {
});
}

const getMessage = client.i18n.getLocale(ticket.guild.locale);

if (!(await isStaff(interaction.guild, interaction.user.id))) { // if user is not staff
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.errorColour)
.setTitle(getMessage('commands.slash.move.not_staff.title'))
.setDescription(getMessage('commands.slash.move.not_staff.description')),
],
});
}

const creator = await interaction.guild.members.fetch(ticket.createdById);
const newCategory = await client.prisma.category.findUnique({ where: { id: interaction.options.getInteger('category', true) } });
const discordCategory = await interaction.guild.channels.fetch(newCategory.discordCategory);
const getMessage = client.i18n.getLocale(ticket.guild.locale);

if (discordCategory.children.cache.size === 50) {
return await interaction.editReply({
Expand Down
15 changes: 15 additions & 0 deletions src/commands/slash/priority.js
Expand Up @@ -2,6 +2,7 @@ const { SlashCommand } = require('@eartharoid/dbf');
const { ApplicationCommandOptionType } = require('discord.js');
const ExtendedEmbedBuilder = require('../../lib/embed');
const { logTicketEvent } = require('../../lib/logging');
const { isStaff } = require('../../lib/users');

module.exports = class PrioritySlashCommand extends SlashCommand {
constructor(client, options) {
Expand Down Expand Up @@ -86,6 +87,20 @@ module.exports = class PrioritySlashCommand extends SlashCommand {
});
}

if (!(await isStaff(interaction.guild, interaction.user.id))) { // if user is not staff
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.errorColour)
.setTitle(getMessage('commands.slash.move.not_staff.title'))
.setDescription(getMessage('commands.slash.move.not_staff.description')),
],
});
}

const priority = interaction.options.getString('priority', true);
let name = interaction.channel.name;
if (ticket.priority) name = name.replace(this.getEmoji(ticket.priority), this.getEmoji(priority));
Expand Down
11 changes: 10 additions & 1 deletion src/i18n/en-GB.yml
Expand Up @@ -64,6 +64,9 @@ commands:
claim:
description: Claim a ticket
name: claim
not_staff:
description: Only staff members can claim tickets.
title: ❌ Error
close:
description: Request a ticket to be closed
invalid_time:
Expand Down Expand Up @@ -126,6 +129,9 @@ commands:
description: Move a ticket to another category
moved: 🗃️ {by} has moved this ticket from **{from}** to **{to}**.
name: move
not_staff:
description: Only staff members can move tickets.
title: ❌ Error
options:
category:
description: The category to move the ticket to
Expand All @@ -140,6 +146,9 @@ commands:
priority:
description: Set the priority of a ticket
name: priority
not_staff:
description: Only staff members can change the priority of tickets.
title: ❌ Error
options:
priority:
choices:
Expand All @@ -158,7 +167,7 @@ commands:
description: Remove a member from a ticket
name: remove
not_staff:
description: Only staff members can removed members from others' tickets.
description: Only staff members can remove members from others' tickets.
title: ❌ Error
options:
member:
Expand Down
28 changes: 28 additions & 0 deletions src/lib/tickets/manager.js
Expand Up @@ -698,6 +698,20 @@ module.exports = class TicketManager {
});
const getMessage = this.client.i18n.getLocale(ticket.guild.locale);

if (!(await isStaff(interaction.guild, interaction.user.id))) { // if user is not staff
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.errorColour)
.setTitle(getMessage('commands.slash.claim.not_staff.title'))
.setDescription(getMessage('commands.slash.claim.not_staff.description')),
],
});
}

await Promise.all([
interaction.channel.permissionOverwrites.edit(interaction.user, { 'ViewChannel': true }, `Ticket claimed by ${interaction.user.tag}`),
...ticket.category.staffRoles.map(role => interaction.channel.permissionOverwrites.edit(role, { 'ViewChannel': false }, `Ticket claimed by ${interaction.user.tag}`)),
Expand Down Expand Up @@ -784,6 +798,20 @@ module.exports = class TicketManager {
});
const getMessage = this.client.i18n.getLocale(ticket.guild.locale);

if (!(await isStaff(interaction.guild, interaction.user.id))) { // if user is not staff
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.errorColour)
.setTitle(getMessage('commands.slash.claim.not_staff.title'))
.setDescription(getMessage('commands.slash.claim.not_staff.description')),
],
});
}

await Promise.all([
interaction.channel.permissionOverwrites.delete(interaction.user, `Ticket released by ${interaction.user.tag}`),
...ticket.category.staffRoles.map(role => interaction.channel.permissionOverwrites.edit(role, { 'ViewChannel': true }, `Ticket released by ${interaction.user.tag}`)),
Expand Down

0 comments on commit daadb5f

Please sign in to comment.