|
1 |
| -const { loader } = require('@bot'); |
| 1 | +const { loader, permissions } = require('@bot'); |
2 | 2 | const { client } = require('@bot').client;
|
3 | 3 | const { Server, Configuration } = require('@bot').database;
|
4 | 4 |
|
@@ -45,15 +45,32 @@ exports.getPrefix = async (serverID) => {
|
45 | 45 |
|
46 | 46 | exports.getAllCommands = () => registeredCommands;
|
47 | 47 |
|
| 48 | +const getAllowedRoles = (serverPermissions, userRoles, plugin) => { |
| 49 | + // eslint-disable-next-line radix |
| 50 | + const roles = userRoles.flatMap(x => parseInt(x.id)); |
| 51 | + const allowedRoles = []; |
| 52 | + for (let x = 0; x < serverPermissions.length; x += 1) { |
| 53 | + const perm = serverPermissions[x]; |
| 54 | + if (perm.plugin === plugin.discrim && roles.includes(perm.roleID)) { |
| 55 | + allowedRoles.push(perm.roleID); |
| 56 | + } |
| 57 | + } |
| 58 | + return allowedRoles; |
| 59 | +}; |
| 60 | + |
48 | 61 | client.on('message', async (msg) => {
|
49 | 62 | const message = msg.content;
|
50 | 63 | const serverPrefix = await this.getPrefix(msg.guild.id);
|
| 64 | + const serverPermissions = await permissions.getServerPermissions(msg.guild.id); |
51 | 65 | for (let i = 0; i < registeredCommands.length; i += 1) {
|
52 | 66 | const command = registeredCommands[i];
|
53 |
| - const r = new RegExp(`\\${serverPrefix}${command.compiled}`); |
54 |
| - const match = message.match(r) ? message.match(r) : []; |
55 |
| - const plugin = loader.commandState(command); |
56 |
| - if (plugin && (`${serverPrefix}${command.compiled}` === message || match[1])) { |
| 67 | + const regex = new RegExp(`\\${serverPrefix}${command.compiled}`); |
| 68 | + const match = message.match(regex) ? message.match(regex) : []; |
| 69 | + const pluginState = loader.commandState(command); |
| 70 | + const plugin = loader.fromCommand(command); |
| 71 | + const userRoles = msg.member.roles.array(); |
| 72 | + const allowedRoles = getAllowedRoles(serverPermissions, userRoles, plugin); |
| 73 | + if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles >= 1)) { |
57 | 74 | return command.response(msg, match);
|
58 | 75 | }
|
59 | 76 | }
|
|
0 commit comments