Added authorization middleware for commands

This commit is contained in:
Logan Cusano
2023-02-25 01:12:41 -05:00
parent 4710dd4358
commit 49c80b7f5e

View File

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