From fa02763cd7de724a1967550e51ed843d53804f92 Mon Sep 17 00:00:00 2001 From: Wolfdragon24 <31204305+Wolfdragon24@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:13:51 +1000 Subject: [PATCH] Minor fixes to Admin Command (#203) * Update permission field to use new reference * Fix function call name * Fixes to allow functioning of admin delete command --- commands/admin-standup.js | 4 ++-- commands/admin.js | 8 ++++---- commands/anonymouspost.js | 4 ++-- commands/faqadmin.js | 4 ++-- commands/logreport.js | 4 ++-- commands/reactforrole.js | 4 ++-- commands/rolesPermOverride.js | 4 ++-- commands/schedulepost.js | 4 ++-- events/travelguide_ready.js | 1 - 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/commands/admin-standup.js b/commands/admin-standup.js index 31540dba..13a6d8c9 100644 --- a/commands/admin-standup.js +++ b/commands/admin-standup.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { EmbedBuilder, ButtonBuilder, Permissions } = require("discord.js"); +const { EmbedBuilder, ButtonBuilder, PermissionsBitField } = require("discord.js"); const paginationEmbed = require("discordjs-button-pagination"); module.exports = { @@ -28,7 +28,7 @@ module.exports = { const standupDB = global.standupDBGlobal; const TEAM_DIRECTOR_ROLE_ID = "921348676692107274"; if ( - !interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR) && + !interaction.member.permissions.has(PermissionsBitField.Flags.Administrator) && !interaction.member._roles.includes(TEAM_DIRECTOR_ROLE_ID) ) { return await interaction.reply({ diff --git a/commands/admin.js b/commands/admin.js index bea9f98f..29ed0692 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { Permissions } = require("discord.js"); +const { PermissionsBitField } = require("discord.js"); const COMMAND_KICKUNVERIFIED = "kickunverified"; const COMMAND_DROPUSERTABLE = "dropusertable"; @@ -20,7 +20,7 @@ module.exports = { ), async execute(interaction) { try { - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, @@ -63,9 +63,9 @@ module.exports = { return await interaction.reply("Removed unverified members."); } else if (interaction.options.getSubcommand() === COMMAND_DROPUSERTABLE) { const userDB = global.userDB; - await userDB.drop_table(); + await userDB.deleteUsers(); - return await interaction.editReply("Deleted user table."); + return await interaction.reply("Deleted user table."); } return await interaction.reply("Error: unknown subcommand."); diff --git a/commands/anonymouspost.js b/commands/anonymouspost.js index 7f62838e..4d7268f6 100644 --- a/commands/anonymouspost.js +++ b/commands/anonymouspost.js @@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); const { allowedChannels } = require("../config/anon_channel.json"); const paginationEmbed = require("discordjs-button-pagination"); const fs = require("fs"); -const { Util, EmbedBuilder, ButtonBuilder, Permissions } = require("discord.js"); +const { Util, EmbedBuilder, ButtonBuilder, PermissionsBitField } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("anonymouspost") @@ -125,7 +125,7 @@ module.exports = { } // Admin permission check - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, diff --git a/commands/faqadmin.js b/commands/faqadmin.js index 41e91463..544d13ce 100644 --- a/commands/faqadmin.js +++ b/commands/faqadmin.js @@ -1,6 +1,6 @@ // @ts-check const { SlashCommandBuilder, SlashCommandSubcommandBuilder } = require("@discordjs/builders"); -const { Permissions } = require("discord.js"); +const { PermissionsBitField } = require("discord.js"); // //////////////////////////////////////////// // //////// SETTING UP THE COMMANDS /////////// @@ -46,7 +46,7 @@ async function handleInteraction(interaction) { const faqStorage = global.faqStorage; // Admin permission check (this may not work uhm) - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, diff --git a/commands/logreport.js b/commands/logreport.js index 92ca73f6..bd0476ef 100644 --- a/commands/logreport.js +++ b/commands/logreport.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { Permissions } = require("discord.js"); +const { PermissionsBitField } = require("discord.js"); const path = require("path"); const nodemailer = require("nodemailer"); @@ -44,7 +44,7 @@ module.exports = { async execute(interaction) { try { - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, diff --git a/commands/reactforrole.js b/commands/reactforrole.js index e6f52bb6..e170adfa 100644 --- a/commands/reactforrole.js +++ b/commands/reactforrole.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { Permissions, EmbedBuilder } = require("discord.js"); +const { PermissionsBitField, EmbedBuilder } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() @@ -27,7 +27,7 @@ module.exports = { async execute(interaction) { // Only admin users should be able to execute this command - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index f859cff2..0c6c50ed 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { Permissions } = require("discord.js"); +const { PermissionsBitField } = require("discord.js"); const is_valid_course_name = (course) => { const reg_comp_course = /^comp\d{4}$/; @@ -136,7 +136,7 @@ module.exports = { ), async execute(interaction) { try { - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, diff --git a/commands/schedulepost.js b/commands/schedulepost.js index 9d438542..1adc8824 100644 --- a/commands/schedulepost.js +++ b/commands/schedulepost.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { EmbedBuilder, Permissions } = require("discord.js"); +const { EmbedBuilder, PermissionsBitField } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() @@ -67,7 +67,7 @@ module.exports = { async execute(interaction) { // Check if user has admin permission - if (!interaction.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) { + if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.reply({ content: "You do not have permission to execute this command.", ephemeral: true, diff --git a/events/travelguide_ready.js b/events/travelguide_ready.js index ec28b5ee..0f01fbd8 100644 --- a/events/travelguide_ready.js +++ b/events/travelguide_ready.js @@ -1,6 +1,5 @@ // @ts-check const { DBTravelguide } = require("../lib/database/dbtravelguide"); -/* eslint-disable */ module.exports = { name: "ready",