Open Role, Add Role, Remove Role

This commit is contained in:
Daniel Odendahl Jr
2017-05-21 03:42:16 +00:00
parent 267614dbff
commit a10996143f
7 changed files with 125 additions and 4 deletions
+10
View File
@@ -0,0 +1,10 @@
[
"inviteGuard",
"modLog",
"memberLog",
"joinMsg",
"leaveMsg",
"staffRole",
"singleRole",
"openRoles"
]
+29
View File
@@ -0,0 +1,29 @@
const { Command } = require('discord.js-commando');
module.exports = class AddRoleCommand extends Command {
constructor(client) {
super(client, {
name: 'add-role',
group: 'settings',
memberName: 'add-role',
description: 'Joins you to one of the open roles.',
guildOnly: true,
args: [
{
key: 'role',
prompt: 'Which role would you like to add?',
type: 'role'
}
]
});
}
run(msg, args) {
const { role } = args;
const roles = msg.guild.settings.get('openRoles');
if (!roles) return msg.say('No Roles are open to join.');
if (!roles.has(role.id)) return msg.say('This role is not open.');
msg.member.addRole(role);
return msg.say(`You have been given the ${role.name} role.`);
}
};
+4 -3
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando');
const settings = require('../../assets/json/clearsetting');
module.exports = class ClearSettingCommand extends Command {
constructor(client) {
@@ -11,11 +12,11 @@ module.exports = class ClearSettingCommand extends Command {
args: [
{
key: 'setting',
prompt: 'What setting do you want to clear? `inviteGuard`, `modLog`, `memberLog`, `joinMsg`, `leaveMsg`, `staffRole`, or `singleRole`?',
prompt: 'What setting do you want to clear?',
type: 'string',
validate: setting => {
if (['inviteGuard', 'modLog', 'memberLog', 'joinMsg', 'leaveMsg', 'staffRole', 'singleRole'].includes(setting)) return true;
return 'Please enter either `inviteGuard`, `modLog`, `memberLog`, `joinMsg`, `leaveMsg`, `staffRole`, or `singleRole`.';
if (settings.includes(setting)) return true;
return `Please enter one of the following: ${settings.join(', ')}.`;
}
}
]
+51
View File
@@ -0,0 +1,51 @@
const { Command } = require('discord.js-commando');
module.exports = class OpenRolesCommand extends Command {
constructor(client) {
super(client, {
name: 'open-roles',
group: 'settings',
memberName: 'open-roles',
description: 'Lets you add or remove roles open for anyone to join.',
guildOnly: true,
args: [
{
key: 'action',
prompt: 'Would you like to `add` or `remove` the role?',
type: 'string',
validate: action => {
if (['add', 'remove'].includes(action.toLowerCase())) return true;
return 'Please enter either `add` or `remove`.';
},
parse: action => action.toLowerCase()
},
{
key: 'role',
prompt: 'Which role would you like to add/remove?',
type: 'role'
}
]
});
}
hasPermission(msg) {
return msg.member.hasPermission('ADMINISTRATOR');
}
run(msg, args) {
const { action, role } = args;
const roles = msg.guild.settings.get('openRoles', new Set());
if (action === 'add') {
if (roles.size > 5) return msg.say('Only 5 roles may be open.');
if (roles.has(role.id)) return msg.say(`${role.name} is already set to open.`);
roles.add(role.id);
msg.guild.settings.set('openRoles', roles);
return msg.say(`${role.name} has been added to the open roles.`);
} else if (action === 'remove') {
if (!roles.has(role.id)) return msg.say(`${role.name} is not set to open.`);
roles.delete(role.id);
msg.guild.settings.set('openRoles', roles);
return msg.say(`${role.name} has been remove from the open roles.`);
}
}
};
+29
View File
@@ -0,0 +1,29 @@
const { Command } = require('discord.js-commando');
module.exports = class RemoveRoleCommand extends Command {
constructor(client) {
super(client, {
name: 'remove-role',
group: 'settings',
memberName: 'remove-role',
description: 'Removes you from one of the open roles.',
guildOnly: true,
args: [
{
key: 'role',
prompt: 'Which role would you like to remove?',
type: 'role'
}
]
});
}
run(msg, args) {
const { role } = args;
const roles = msg.guild.settings.get('openRoles');
if (!roles) return msg.say('No Roles are open to join.');
if (!roles.has(role.id)) return msg.say('This role is not open.');
msg.member.removeRole(role);
return msg.say(`You have been removed from the ${role.name} role.`);
}
};
+1
View File
@@ -26,6 +26,7 @@ module.exports = class SettingListCommand extends Command {
**Join Message:** ${msg.guild.settings.get('joinMsg', 'Welcome <user>! (Default)')}
**Leave Message:** ${msg.guild.settings.get('leaveMsg', 'Bye <user>... (Default)')}
**Single Role:** ${singleRole ? (msg.guild.roles.has(singleRole) ? msg.guild.roles.get(singleRole).name : 'Missing') : 'None'}
**Open Roles:** ${msg.guild.settings.get('openRoles').size}
`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "19.10.2",
"version": "19.11.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {