Improved Discord Auth System
- Used on all commands - Moved to middleware dir
This commit is contained in:
23
middleware/discordAuthorization.js
Normal file
23
middleware/discordAuthorization.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// To authorize a message sender for admin level commands
|
||||||
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||||
|
const log = new DebugBuilder("server", "discordAuthorization");
|
||||||
|
|
||||||
|
const botAdmins = process.env.BOT_ADMINS;
|
||||||
|
|
||||||
|
exports.authorizeCommand = async (interaction, command, next) => {
|
||||||
|
log.DEBUG("Command is privileged? ", command.isPrivileged)
|
||||||
|
|
||||||
|
// If the command is not privileged, run the command
|
||||||
|
if (!command.isPrivileged) return next(true);
|
||||||
|
|
||||||
|
log.DEBUG(`${interaction.member.user} is attempting to run the privileged command '${command}'`);
|
||||||
|
|
||||||
|
// Check to see if the user has the role specified in the config
|
||||||
|
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({ content: `Sorry ${interaction.member.user}, you are not permitted to run that command`, ephemeral: true });
|
||||||
|
} else {
|
||||||
|
log.DEBUG(`Authorized - ${interaction.member.user} can run '${command}'`);
|
||||||
|
return next(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// 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);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user