Rewrite Permission Checks and Validators

This commit is contained in:
Daniel Odendahl Jr
2017-04-25 02:37:14 +00:00
parent 9a75ee549b
commit 3ccce0ba66
105 changed files with 248 additions and 581 deletions
+4 -8
View File
@@ -13,9 +13,8 @@ module.exports = class LockdownCommand extends Command {
prompt: 'Please enter either start or stop.',
type: 'string',
validate: type => {
if (type.toLowerCase() === 'start' || type.toLowerCase() === 'stop') {
if (['start', 'stop'].includes(type.toLowerCase()))
return true;
}
return 'Please enter either `start` or `stop`.';
},
parse: text => text.toLowerCase()
@@ -28,10 +27,8 @@ module.exports = class LockdownCommand extends Command {
}
async run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['READ_MESSAGES', 'SEND_MESSAGES'])) return;
if (!message.channel.permissionsFor(this.client.user).hasPermission('ADMINISTRATOR')) return message.say(':x: Error! I don\'t have the Administrator permission! This is not given by default, as that\'s quite bad practice. Please give it to me to use the lockdown command!');
}
if (!message.channel.permissionsFor(this.client.user).hasPermission('ADMINISTRATOR'))
return message.say(':x: Error! I don\'t have the Administrator Permission!');
const { type } = args;
if (type === 'start') {
try {
@@ -42,8 +39,7 @@ module.exports = class LockdownCommand extends Command {
} catch (err) {
return message.say(':x: Error! Something went wrong!');
}
}
if (type === 'stop') {
} else if (type === 'stop') {
try {
await message.channel.overwritePermissions(message.guild.defaultRole, {
SEND_MESSAGES: true