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
+1 -5
View File
@@ -20,9 +20,8 @@ module.exports = class BinaryCommand extends Command {
prompt: 'What text would you like to convert to binary?',
type: 'string',
validate: content => {
if (stringToBinary(content).length < 2000) {
if (stringToBinary(content).length < 2000)
return true;
}
return 'Your message content is too long.';
},
parse: text => stringToBinary(text)
@@ -31,9 +30,6 @@ module.exports = class BinaryCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(text);
}
+1 -5
View File
@@ -12,9 +12,8 @@ module.exports = class CowsayCommand extends Command {
prompt: 'What text would you like the cow to say?',
type: 'string',
validate: text => {
if (text.length < 1500) {
if (text.length < 1500)
return true;
}
return `Please keep your content under 1500 characters, you have ${text.length}.`;
}
}]
@@ -22,9 +21,6 @@ module.exports = class CowsayCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.code(null, `< ${text} >\n \\ ^__^\n \\ (oO)\\_______\n (__)\\ )\\/\\\n U ||----w |\n || ||`);
}
+3 -7
View File
@@ -8,7 +8,6 @@ module.exports = class EmbedCommand extends Command {
group: 'textedit',
memberName: 'embed',
description: 'Sends a message in an embed.',
guildOnly: true,
args: [{
key: 'text',
prompt: 'What text would you like to embed?',
@@ -18,18 +17,15 @@ module.exports = class EmbedCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
if (!message.channel.permissionsFor(this.client.user).hasPermission('MANAGE_MESSAGES')) return message.say(':x: Error! I don\'t have the Manage Messages Permission!');
}
if (message.channel.type !== 'dm')
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS'))
return message.say(':x: Error! I don\'t have the Embed Links Permission!');
const { text } = args;
const embed = new RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setColor(0x00AE86)
.setTimestamp()
.setDescription(text);
message.delete();
return message.embed(embed);
}
};
+2 -9
View File
@@ -1,14 +1,11 @@
const { Command } = require('discord.js-commando');
const { letterTrans } = require('custom-translate');
const dictionary = require('./morsemappings.json');
const dictionary = require('./morsemappings');
module.exports = class MorseCommand extends Command {
constructor(client) {
super(client, {
name: 'morse',
aliases: [
'morsecode'
],
group: 'textedit',
memberName: 'morse',
description: 'Translates text to morse code.',
@@ -17,9 +14,8 @@ module.exports = class MorseCommand extends Command {
prompt: 'What text would you like to convert to morse?',
type: 'string',
validate: content => {
if (letterTrans(content, dictionary, ' ').length < 1999) {
if (letterTrans(content, dictionary, ' ').length < 1999)
return true;
}
return 'Your message content is too long.';
},
parse: text => letterTrans(text.toLowerCase(), dictionary, ' ')
@@ -28,9 +24,6 @@ module.exports = class MorseCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(text);
}
+2 -10
View File
@@ -1,15 +1,11 @@
const { Command } = require('discord.js-commando');
const { wordTrans } = require('custom-translate');
const dictionary = require('./piratewords.json');
const dictionary = require('./piratewords');
module.exports = class PirateCommand extends Command {
constructor(client) {
super(client, {
name: 'pirate',
aliases: [
'piratespeak',
'yarr'
],
group: 'textedit',
memberName: 'pirate',
description: 'Talk like a pirate!',
@@ -18,9 +14,8 @@ module.exports = class PirateCommand extends Command {
prompt: 'What text would you like to convert to pirate?',
type: 'string',
validate: content => {
if (wordTrans(content, dictionary).length < 1999) {
if (wordTrans(content, dictionary).length < 1999)
return true;
}
return 'Your message content is too long.';
},
parse: text => wordTrans(text, dictionary)
@@ -29,9 +24,6 @@ module.exports = class PirateCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(`\u180E${text}`);
}
-3
View File
@@ -17,9 +17,6 @@ module.exports = class ReverseCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(`\u180E${text}`);
}
-7
View File
@@ -7,13 +7,11 @@ module.exports = class SayCommand extends Command {
aliases: [
'copy',
'repeat',
'parrot',
'echo'
],
group: 'textedit',
memberName: 'say',
description: 'Make XiaoBot say what you wish.',
guildOnly: true,
args: [{
key: 'text',
prompt: 'What text would you like XiaoBot to say?',
@@ -23,12 +21,7 @@ module.exports = class SayCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
if (!message.channel.permissionsFor(this.client.user).hasPermission('MANAGE_MESSAGES')) return message.say(':x: Error! I don\'t have the Manage Messages Permission!');
}
const { text } = args;
message.delete();
return message.say(`\u180E${text}`);
}
};
+2 -6
View File
@@ -1,6 +1,6 @@
const { Command } = require('discord.js-commando');
const { wordTrans } = require('custom-translate');
const dictionary = require('./temmiewords.json');
const dictionary = require('./temmiewords');
module.exports = class TemmieCommand extends Command {
constructor(client) {
@@ -14,9 +14,8 @@ module.exports = class TemmieCommand extends Command {
prompt: 'What text would you like to convert to Temmie speak?',
type: 'string',
validate: content => {
if (wordTrans(content, dictionary).length < 1999) {
if (wordTrans(content, dictionary).length < 1999)
return true;
}
return 'Your message content is too long.';
},
parse: text => wordTrans(text, dictionary)
@@ -25,9 +24,6 @@ module.exports = class TemmieCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(`\u180E${text}`);
}
+1 -5
View File
@@ -1,13 +1,12 @@
const { Command } = require('discord.js-commando');
const { letterTrans } = require('custom-translate');
const dictionary = require('./udmappings.json');
const dictionary = require('./udmappings');
module.exports = class UpsideDownCommand extends Command {
constructor(client) {
super(client, {
name: 'upsidedown',
aliases: [
'upside-down',
'udown'
],
group: 'textedit',
@@ -23,9 +22,6 @@ module.exports = class UpsideDownCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(text);
}
+2 -4
View File
@@ -26,10 +26,8 @@ module.exports = class WebhookCommand extends Command {
}
async run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
if (!message.channel.permissionsFor(this.client.user).hasPermission('MANAGE_MESSAGES')) return message.say(':x: Error! I don\'t have the Manage Messages Permission!');
}
if (!message.channel.permissionsFor(this.client.user).hasPermission('MANAGE_MESSAGES'))
return message.say(':x: Error! I don\'t have the Manage Messages Permission!');
const { text } = args;
try {
message.delete();
-3
View File
@@ -24,9 +24,6 @@ module.exports = class ZalgoCommand extends Command {
}
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const { text } = args;
return message.say(`\u180E${text}`);
}