fix: check roles for staff-only commands

This commit is contained in:
Isaac
2023-03-10 23:37:40 +00:00
parent b14f057dd0
commit daadb5fe85
4 changed files with 70 additions and 2 deletions

View File

@@ -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) {
@@ -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({

View File

@@ -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) {
@@ -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));