Single-Role Mode

This commit is contained in:
Daniel Odendahl Jr
2017-05-04 20:43:53 +00:00
parent b1444572d1
commit e560359445
4 changed files with 42 additions and 5 deletions
+3 -3
View File
@@ -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`.';
}
}
]
+30
View File
@@ -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}.`);
}
};
+8 -1
View File
@@ -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;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "18.0.3",
"version": "18.1.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {