diff --git a/core/commands.js b/core/commands.js index 6d4740a..ac1a620 100644 --- a/core/commands.js +++ b/core/commands.js @@ -47,8 +47,7 @@ exports.getPrefix = async (serverID) => { exports.getAllCommands = () => registeredCommands; const getAllowedRoles = (serverPermissions, userRoles, plugin) => { - // eslint-disable-next-line radix - const roles = userRoles.flatMap(x => parseInt(x.id)); + const roles = userRoles.flatMap(x => parseInt(x.id, 10)); const allowedRoles = []; for (let x = 0; x < serverPermissions.length; x += 1) { const perm = serverPermissions[x]; @@ -59,21 +58,34 @@ const getAllowedRoles = (serverPermissions, userRoles, plugin) => { return allowedRoles; }; +const isAdmin = async (serverID, userRoles) => { + const roles = userRoles.flatMap(x => parseInt(x.id, 10)); + const server = await Server.findOne({ serverID }).exec(); + const { adminRole } = await Configuration.findOne({ + server, + }).select({ + adminRole: 1, + _id: 0, + }).exec(); + return roles.includes(adminRole); +}; + client.on('message', async (msg) => { const message = msg.content; if (!msg.guild && msg.author.id !== client.user.id) return msg.reply('I do not work in DMs'); if (msg.author.id === client.user.id) return false; const serverPrefix = await this.getPrefix(msg.guild.id); const serverPermissions = await permissions.getServerPermissions(msg.guild.id); + const userRoles = msg.member.roles.array(); + const adminState = await isAdmin(msg.guild.id, userRoles); for (let i = 0; i < registeredCommands.length; i += 1) { const command = registeredCommands[i]; const regex = new RegExp(`\\${serverPrefix}${command.compiled}`); const match = message.match(regex) ? message.match(regex) : []; const pluginState = loader.commandState(command); const plugin = loader.fromCommand(command); - const userRoles = msg.member.roles.array(); const allowedRoles = getAllowedRoles(serverPermissions, userRoles, plugin); - if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles.length >= 1)) { + if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || adminState || allowedRoles.length >= 1)) { return command.response(msg, match); } } diff --git a/plugins/music.js b/plugins/music.js index 4afcf2c..1b2a12c 100644 --- a/plugins/music.js +++ b/plugins/music.js @@ -33,7 +33,7 @@ commands.register(this.command, '', 'music', 'Get the music help', async (msg) = msg.channel.send(em); }); -commands.register(this.command, 'play (.*)', 'music play /', 'Change the bots game', async (msg, extra) => { +commands.register(this.command, 'play (.*)', 'music play /', 'Change the bots game', (msg, extra) => { const queue = serverQueue(msg.guild.id); if (msg.member.voiceChannel) { msg.member.voiceChannel.join().then((con) => { @@ -50,12 +50,13 @@ commands.register(this.command, 'play (.*)', 'music play /