From 49c80b7f5e50598029d004a89f2474d5bd5f464b Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 25 Feb 2023 01:12:41 -0500 Subject: [PATCH] Added authorization middleware for commands --- utilities/discordAuthorization.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 utilities/discordAuthorization.js diff --git a/utilities/discordAuthorization.js b/utilities/discordAuthorization.js new file mode 100644 index 0000000..2e6c035 --- /dev/null +++ b/utilities/discordAuthorization.js @@ -0,0 +1,16 @@ +// To authorize a message sender for admin level commands + +const { DebugBuilder } = require("./debugBuilder"); +const log = new DebugBuilder("server", "discordAuthorization"); + +const botAdmins = process.env.BOT_ADMINS; + +exports.authorizeCommand = async (interaction, command, next) => { + log.DEBUG(`${interaction.member.user} is attempting to run the privileged command '${command}'`); + if (!interaction.member.roles.cache.has(`${botAdmins}`)) { + log.DEBUG(`Unauthorized - ${interaction.member.user} does not have the privilege to run '${command}'`); + return await interaction.reply(`Sorry ${interaction.member.tag}, you are not permitted to run that command`); + } + log.DEBUG(`Authorized - ${interaction.member.user} can run '${command}'`); + next(true); +} \ No newline at end of file