Skip to content

Commit 488eabd

Browse files
authored
Merge pull request #21 from ItsJustMeChris/master
Admin Role bypass all permissions..
2 parents 77827a4 + 36ab3c7 commit 488eabd

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

core/commands.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ exports.getPrefix = async (serverID) => {
4747
exports.getAllCommands = () => registeredCommands;
4848

4949
const getAllowedRoles = (serverPermissions, userRoles, plugin) => {
50-
// eslint-disable-next-line radix
51-
const roles = userRoles.flatMap(x => parseInt(x.id));
50+
const roles = userRoles.flatMap(x => parseInt(x.id, 10));
5251
const allowedRoles = [];
5352
for (let x = 0; x < serverPermissions.length; x += 1) {
5453
const perm = serverPermissions[x];
@@ -59,21 +58,34 @@ const getAllowedRoles = (serverPermissions, userRoles, plugin) => {
5958
return allowedRoles;
6059
};
6160

61+
const isAdmin = async (serverID, userRoles) => {
62+
const roles = userRoles.flatMap(x => parseInt(x.id, 10));
63+
const server = await Server.findOne({ serverID }).exec();
64+
const { adminRole } = await Configuration.findOne({
65+
server,
66+
}).select({
67+
adminRole: 1,
68+
_id: 0,
69+
}).exec();
70+
return roles.includes(adminRole);
71+
};
72+
6273
client.on('message', async (msg) => {
6374
const message = msg.content;
6475
if (!msg.guild && msg.author.id !== client.user.id) return msg.reply('I do not work in DMs');
6576
if (msg.author.id === client.user.id) return false;
6677
const serverPrefix = await this.getPrefix(msg.guild.id);
6778
const serverPermissions = await permissions.getServerPermissions(msg.guild.id);
79+
const userRoles = msg.member.roles.array();
80+
const adminState = await isAdmin(msg.guild.id, userRoles);
6881
for (let i = 0; i < registeredCommands.length; i += 1) {
6982
const command = registeredCommands[i];
7083
const regex = new RegExp(`\\${serverPrefix}${command.compiled}`);
7184
const match = message.match(regex) ? message.match(regex) : [];
7285
const pluginState = loader.commandState(command);
7386
const plugin = loader.fromCommand(command);
74-
const userRoles = msg.member.roles.array();
7587
const allowedRoles = getAllowedRoles(serverPermissions, userRoles, plugin);
76-
if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles.length >= 1)) {
88+
if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || adminState || allowedRoles.length >= 1)) {
7789
return command.response(msg, match);
7890
}
7991
}

plugins/music.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ commands.register(this.command, '', 'music', 'Get the music help', async (msg) =
3333
msg.channel.send(em);
3434
});
3535

36-
commands.register(this.command, 'play (.*)', 'music play <song-name>/<youtube-url>', 'Change the bots game', async (msg, extra) => {
36+
commands.register(this.command, 'play (.*)', 'music play <song-name>/<youtube-url>', 'Change the bots game', (msg, extra) => {
3737
const queue = serverQueue(msg.guild.id);
3838
if (msg.member.voiceChannel) {
3939
msg.member.voiceChannel.join().then((con) => {
@@ -50,12 +50,13 @@ commands.register(this.command, 'play (.*)', 'music play <song-name>/<youtube-ur
5050
queue.push({ title, url, requester });
5151
const stream = ytdl(`http://www.youtube.com${url}`, { filter: 'audioonly' });
5252
con.playStream(stream);
53-
msg.channel.send(em);
53+
return msg.channel.send(em);
5454
});
5555
});
5656
} else {
5757
return msg.reply('You need to be in a voice channel');
5858
}
59+
return true;
5960
});
6061

6162
exports.name = 'Music';

0 commit comments

Comments
 (0)