diff --git a/commands/util/clearsetting.js b/commands/util/clearsetting.js index 4f6c9aa8..46558f07 100644 --- a/commands/util/clearsetting.js +++ b/commands/util/clearsetting.js @@ -11,12 +11,12 @@ module.exports = class ClearSettingCommand extends Command { args: [ { key: 'setting', - prompt: 'What setting do you want to clear? `modLog`, `memberLog`, or `staffRole`?', + prompt: 'What setting do you want to clear? `modLog`, `memberLog`, `staffRole`, or `singleRole`?', type: 'string', validate: setting => { - if(['modLog', 'memberLog', 'staffRole'].includes(setting)) + if(['modLog', 'memberLog', 'staffRole', 'singleRole'].includes(setting)) return true; - return 'Please enter either `modLog`, `memberLog`, or `staffRole`.'; + return 'Please enter either `modLog`, `memberLog`, `staffRole`, or `singleRole`.'; } } ] diff --git a/commands/util/singlerole.js b/commands/util/singlerole.js new file mode 100644 index 00000000..a630774f --- /dev/null +++ b/commands/util/singlerole.js @@ -0,0 +1,30 @@ +const { Command } = require('discord.js-commando'); + +module.exports = class SingleRoleCommand extends Command { + constructor(client) { + super(client, { + name: 'singlerole', + group: 'util', + memberName: 'singlerole', + description: 'Sets a single role that is able to use commands.', + guildOnly: true, + args: [ + { + key: 'role', + prompt: 'What role should be able to use commands?', + type: 'role' + } + ] + }); + } + + hasPermission(msg) { + return msg.member.hasPermission('ADMINISTRATOR'); + } + + run(msg, args) { + const { role } = args; + msg.guild.settings.set('singleRole', role.id); + return msg.say(`Single role mode has been enabled with the role ${role.name}.`); + } +}; diff --git a/index.js b/index.js index ea40ceb0..c26c8556 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,14 @@ client.registry .registerDefaultGroups() .registerDefaultCommands({ help: false }) .registerCommandsIn(path.join(__dirname, 'commands')); - + +client.dispatcher.addInhibitor(msg => { + const role = msg.guild.settings.get('singleRole'); + if(!role) return false; + if(!msg.member.roles.has(role)) + return `Only the ${msg.guild.roles.get(role).name} may use commands.`; +}); + client.on('guildMemberAdd', (member) => { const channel = member.guild.channels.get(member.guild.settings.get('memberLog')); if(!channel) return; diff --git a/package.json b/package.json index 2cc96bfd..ac971823 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "18.0.3", + "version": "18.1.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": {