Better Error Handling

This commit is contained in:
Daniel Odendahl Jr
2017-05-05 21:37:30 +00:00
parent d8a773958d
commit 13cbd23f2f
54 changed files with 120 additions and 156 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ module.exports = class YearsCommand extends Command {
avatar.resize(200, 200);
az.composite(avatar, 461, 127);
az.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'az.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -36,7 +36,7 @@ module.exports = class BeautifulCommand extends Command {
grunkle.composite(avatar, 341, 35);
grunkle.composite(avatar, 342, 301);
grunkle.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'beautiful.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -38,7 +38,7 @@ module.exports = class BobRossCommand extends Command {
blank.composite(avatar, 44, 85);
blank.composite(bob, 0, 0);
blank.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'bobross.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -28,7 +28,7 @@ module.exports = class GreyscaleCommand extends Command {
const avatar = await Jimp.read(avatarURL);
avatar.greyscale();
avatar.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'greyscale.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -28,7 +28,7 @@ module.exports = class InvertCommand extends Command {
const avatar = await Jimp.read(avatarURL);
avatar.invert();
avatar.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'invert.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -37,7 +37,7 @@ module.exports = class RIPCommand extends Command {
avatar.resize(200, 200);
grave.composite(avatar, 158, 51);
grave.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'rip.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -40,7 +40,7 @@ module.exports = class SteamCardCommand extends Command {
blank.composite(card, 0, 0);
blank.print(font, 38, 20, username);
blank.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'steamcard.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -34,7 +34,7 @@ module.exports = class TriggeredCommand extends Command {
blank.composite(avatar, 0, 0);
blank.composite(triggered, 0, 0);
blank.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'triggered.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+1 -1
View File
@@ -32,7 +32,7 @@ module.exports = class WantedCommand extends Command {
avatar.resize(500, 500);
wanted.composite(avatar, 189, 438);
wanted.getBuffer(Jimp.MIME_PNG, (err, buff) => {
if(err) return msg.say('An Unknown Error Occurred.');
if(err) return msg.say(`An Error Occurred: ${err}`);
return msg.channel.send({ files: [{ attachment: buff, name: 'wanted.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
});
+6 -14
View File
@@ -1,6 +1,5 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const math = require('mathjs');
const operations = ['+', '-', '*'];
@@ -14,12 +13,11 @@ module.exports = class MathGameCommand extends Command {
args: [
{
key: 'difficulty',
prompt: 'What should the difficulty of the math game be? `Easy`, `Medium`, `Hard`, `Extreme`, or `Impossible`?',
prompt: 'What should the difficulty of the game be? `Easy`, `Medium`, `Hard`, `Extreme`, or `Impossible`?',
type: 'string',
validate: difficulty => {
if(['easy', 'medium', 'hard', 'extreme', 'impossible'].includes(difficulty.toLowerCase()))
return true;
return 'Please set the difficulty to either `easy`, `medium`, `hard`, `extreme`, or `impossible`.';
if(['easy', 'medium', 'hard', 'extreme', 'impossible'].includes(difficulty.toLowerCase())) return true;
return 'The difficulty must be either `easy`, `medium`, `hard`, `extreme`, or `impossible`.';
},
parse: difficulty => difficulty.toLowerCase()
}
@@ -64,16 +62,10 @@ module.exports = class MathGameCommand extends Command {
errors: ['time']
});
if(collected.first().content !== solved)
return msg.say(stripIndents`
Aw... Too bad, try again next time!
The correct answer is: ${solved}
`);
return msg.say(`Good Job! You won! ${solved} is the correct answer!`);
return msg.say(`Nope! The correct answer is: ${solved}.`);
return msg.say(`Perfect! ${solved} is the correct answer!`);
} catch(err) {
return msg.say(stripIndents`
Aw... Too bad, try again next time!
The correct answer is: ${solved}
`);
return msg.say(`Time! The correct answer is ${solved}.`);
}
}
};
+4 -7
View File
@@ -38,16 +38,13 @@ module.exports = class QuizCommand extends Command {
errors: ['time']
});
if(collected.first().content.toLowerCase() !== answer)
return msg.say(`The correct answer is: ${answer}`);
return msg.say(`Perfect! The correct answer is: ${answer}`);
return msg.say(`The correct answer is: ${answer}.`);
return msg.say(`Perfect! The correct answer is: ${answer}.`);
} catch(err) {
return msg.say(stripIndents`
Aw... Too bad, try again next time!
The Correct Answer was: ${answer}
`);
return msg.say(`Time! The correct answer is: ${answer}`);
}
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}.`);
}
}
};
+1 -2
View File
@@ -17,8 +17,7 @@ module.exports = class RockPaperScissorsCommand extends Command {
prompt: '`Rock`, `Paper`, or `Scissors`?',
type: 'string',
validate: choice => {
if(['rock', 'paper', 'scissors'].includes(choice.toLowerCase()))
return true;
if(['rock', 'paper', 'scissors'].includes(choice.toLowerCase())) return true;
return 'Please enter either `rock`, `paper`, or `scissors`.';
},
parse: choice => choice.toLowerCase()
+4 -5
View File
@@ -12,12 +12,11 @@ module.exports = class TypingGameCommand extends Command {
args: [
{
key: 'difficulty',
prompt: 'What should the difficulty of the typing game be? `Easy`, `Medium`, `Hard`, `Extreme`, or `Impossible`?',
prompt: 'What should the difficulty of the game be? `Easy`, `Medium`, `Hard`, `Extreme`, or `Impossible`?',
type: 'string',
validate: difficulty => {
if(['easy', 'medium', 'hard', 'extreme', 'impossible'].includes(difficulty.toLowerCase()))
return true;
return 'Please set the difficulty to either `easy`, `medium`, `hard`, `extreme`, or `impossible`.';
if(['easy', 'medium', 'hard', 'extreme', 'impossible'].includes(difficulty.toLowerCase())) return true;
return 'The difficulty must be either `easy`, `medium`, `hard`, `extreme`, or `impossible`.';
},
parse: difficulty => difficulty.toLowerCase()
}
@@ -63,7 +62,7 @@ module.exports = class TypingGameCommand extends Command {
return msg.say('Nope, your sentence does not match the original. Try again next time!');
return msg.say(`Good Job! You won!`);
} catch(err) {
return msg.say('Aw... Too bad, try again next time!');
return msg.say('Time! Try again next time!');
}
}
};
+4 -15
View File
@@ -15,9 +15,8 @@ module.exports = class MemeCommand extends Command {
prompt: 'What meme type do you want to use?',
type: 'string',
validate: type => {
if(codes.includes(type.toLowerCase()))
return true;
return `${type.toLowerCase()} is not a valid meme type. Use \`help meme\` to view a list of types.`;
if(codes.includes(type.toLowerCase())) return true;
return 'Invalid meme type. Use `help meme` to view a list of meme types.';
},
parse: type => type.toLowerCase()
},
@@ -25,23 +24,13 @@ module.exports = class MemeCommand extends Command {
key: 'top',
prompt: 'What should the top row of the meme to be?',
type: 'string',
validate: top => {
if(/[a-zA-Z0-9.,!?'\s]+$/g.test(top) && top.length < 100)
return true;
return `Please do not use special characters and keep the rows under 100 characters each, top row has ${top.length}.`;
},
parse: top => top.replace(/[ ]/g, '-').replace(/[?]/g, '~q')
parse: top => encodeURIComponent(top.replace(/[ ]/g, '-'))
},
{
key: 'bottom',
prompt: 'What should the bottom row of the meme to be?',
type: 'string',
validate: bottom => {
if(/[a-zA-Z0-9.,!?'\s]+$/g.test(bottom) && bottom.length < 100)
return true;
return `Please do not use special characters and keep the rows under 100 characters each, bottom row has ${bottom.length}.`;
},
parse: bottom => bottom.replace(/[ ]/g, '-').replace(/[?]/g, '~q')
parse: bottom => encodeURIComponent(bottom.replace(/[ ]/g, '-'))
}
]
});
+5 -6
View File
@@ -11,7 +11,7 @@ module.exports = class BanCommand extends Command {
],
group: 'moderation',
memberName: 'ban',
description: 'Bans a user and logs the ban to the mod_logs.',
description: 'Bans a user and logs the ban to the mod logs.',
guildOnly: true,
args: [
{
@@ -24,9 +24,8 @@ module.exports = class BanCommand extends Command {
prompt: 'What do you want to set the reason as?',
type: 'string',
validate: reason => {
if(reason.length < 140)
return true;
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
if(reason.length < 140) return true;
return 'Invalid Reason. Reason must be under 140 characters.';
}
}
]
@@ -55,7 +54,7 @@ module.exports = class BanCommand extends Command {
Reason: ${reason}.
`);
} catch(err) {
await msg.say('Failed to send DM to user.');
await msg.say('Failed to send DM to the user.');
}
await member.ban({ days: 7, reason });
await msg.say(':ok_hand:');
@@ -70,7 +69,7 @@ module.exports = class BanCommand extends Command {
`);
return modlogs.send({ embed });
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+4 -5
View File
@@ -8,7 +8,7 @@ module.exports = class KickCommand extends Command {
name: 'kick',
group: 'moderation',
memberName: 'kick',
description: 'Kicks a user and logs the kick to the mod_logs.',
description: 'Kicks a user and logs the kick to the mod logs.',
guildOnly: true,
args: [
{
@@ -21,9 +21,8 @@ module.exports = class KickCommand extends Command {
prompt: 'What do you want to set the reason as?',
type: 'string',
validate: reason => {
if(reason.length < 140)
return true;
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
if(reason.length < 140) return true;
return 'Invalid Reason. Reason must be under 140 characters.';
}
}
]
@@ -67,7 +66,7 @@ module.exports = class KickCommand extends Command {
`);
return modlogs.send({ embed });
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+4 -5
View File
@@ -15,8 +15,7 @@ module.exports = class LockdownCommand extends Command {
prompt: 'Please enter either `start` or `stop`.',
type: 'string',
validate: type => {
if(['start', 'stop'].includes(type.toLowerCase()))
return true;
if(['start', 'stop'].includes(type.toLowerCase())) return true;
return 'Please enter either `start` or `stop`.';
},
parse: type => type.toLowerCase()
@@ -38,17 +37,17 @@ module.exports = class LockdownCommand extends Command {
await msg.channel.overwritePermissions(msg.guild.defaultRole, { SEND_MESSAGES: false });
return msg.say(stripIndents`
Lockdown Started, users without Administrator can no longer post messages.
Please use \`;lockdown stop\` to end the lockdown.
Please use \`lockdown stop\` to end the lockdown.
`);
} catch(err) {
return msg.say('Something went wrong!');
return msg.say(`An Error Occurred: ${err}`);
}
} else if(type === 'stop') {
try {
await msg.channel.overwritePermissions(msg.guild.defaultRole, { SEND_MESSAGES: true });
return msg.say('Lockdown Ended, users without Administrator can now post messages.');
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
}
+2 -3
View File
@@ -19,9 +19,8 @@ module.exports = class PruneCommand extends Command {
prompt: 'How many messages do you want to delete? Limit of up to 99.',
type: 'integer',
validate: count => {
if(count < 100 && count > 0)
return true;
return `${count} is not a valid amount of messages. Limit 1-99.`;
if(count < 100 && count > 0) return true;
return 'Invalid Count. Count must be from 1-99.';
}
}
]
+4 -5
View File
@@ -8,7 +8,7 @@ module.exports = class SoftbanCommand extends Command {
name: 'softban',
group: 'moderation',
memberName: 'softban',
description: 'Kicks a user and deletes their messages, and logs the softban to the mod_logs.',
description: 'Kicks a user and deletes their messages, and logs the softban to the mod logs.',
guildOnly: true,
args: [
{
@@ -21,9 +21,8 @@ module.exports = class SoftbanCommand extends Command {
prompt: 'What do you want to set the reason as?',
type: 'string',
validate: reason => {
if(reason.length < 140)
return true;
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
if(reason.length < 140) return true;
return 'Invalid Reason. Reason must be under 140 characters.';
}
}
]
@@ -70,7 +69,7 @@ module.exports = class SoftbanCommand extends Command {
`);
return modlogs.send({ embed });
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+7 -9
View File
@@ -11,7 +11,7 @@ module.exports = class UnbanCommand extends Command {
],
group: 'moderation',
memberName: 'unban',
description: 'Unbans a user and logs the unban to the mod_logs.',
description: 'Unbans a user and logs the unban to the mod logs.',
guildOnly: true,
args: [
{
@@ -19,9 +19,8 @@ module.exports = class UnbanCommand extends Command {
prompt: 'What member do you want to unban? Please enter the ID of the user.',
type: 'string',
validate: id => {
if(id.length === 18)
return true;
return `${id} is not a valid ID. Please enter the user you wish to unban's ID.`;
if(id.length === 18) return true;
return 'Invalid ID.';
}
},
{
@@ -29,9 +28,8 @@ module.exports = class UnbanCommand extends Command {
prompt: 'What do you want to set the reason as?',
type: 'string',
validate: reason => {
if(reason.length < 140)
return true;
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
if(reason.length < 140) return true;
return 'Invalid Reason. Reason must be under 140 characters.';
}
}
]
@@ -45,7 +43,7 @@ module.exports = class UnbanCommand extends Command {
async run(msg, args) {
if(!msg.channel.permissionsFor(this.client.user).has('BAN_MEMBERS'))
return msg.say('This Command requires the `Ban Members` Permission.');
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog', 'mod_logs'));
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
if(!modlogs)
return msg.say('This Command requires a channel set with the `modchannel` command.');
if(!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS'))
@@ -69,7 +67,7 @@ module.exports = class UnbanCommand extends Command {
`);
return modlogs.send({ embed });
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+5 -6
View File
@@ -8,7 +8,7 @@ module.exports = class WarnCommand extends Command {
name: 'warn',
group: 'moderation',
memberName: 'warn',
description: 'Warns a user and logs the warn to the mod_logs.',
description: 'Warns a user and logs the warn to the mod logs.',
guildOnly: true,
args: [
{
@@ -21,9 +21,8 @@ module.exports = class WarnCommand extends Command {
prompt: 'What do you want to set the reason as?',
type: 'string',
validate: reason => {
if(reason.length < 140)
return true;
return `Please keep your reason under 140 characters, you have ${reason.length}.`;
if(reason.length < 140) return true;
return 'Invalid Reason. Reason must be under 140 characters.';
}
}
]
@@ -35,7 +34,7 @@ module.exports = class WarnCommand extends Command {
}
async run(msg, args) {
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog', 'mod_logs'));
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
if(!modlogs)
return msg.say('This Command requires a channel set with the `modchannel` command.');
if(!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS'))
@@ -54,7 +53,7 @@ module.exports = class WarnCommand extends Command {
`);
return modlogs.send({ embed });
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+5 -7
View File
@@ -16,9 +16,8 @@ module.exports = class CurrencyCommand extends Command {
prompt: 'What currency code do you want to use as the base?',
type: 'string',
validate: base => {
if(codes.includes(base.toUpperCase()))
return true;
return `${base} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
if(codes.includes(base.toUpperCase())) return true;
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
},
parse: base => base.toUpperCase()
},
@@ -27,9 +26,8 @@ module.exports = class CurrencyCommand extends Command {
prompt: 'What currency code do you want to convert to?',
type: 'string',
validate: to => {
if(codes.includes(to.toUpperCase()))
return true;
return `${to} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
if(codes.includes(to.toUpperCase())) return true;
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
},
parse: to => to.toUpperCase()
},
@@ -52,7 +50,7 @@ module.exports = class CurrencyCommand extends Command {
const converted = rate * amount;
return msg.say(`${amount} ${base} is ${converted} ${to}.`);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -2
View File
@@ -17,8 +17,7 @@ module.exports = class EasterEggCommand extends Command {
prompt: 'What easter egg do you want to view?',
type: 'string',
validate: tag => {
if(eastereggs[tag.toLowerCase()])
return true;
if(eastereggs[tag.toLowerCase()]) return true;
return 'Nope, that\'s not a valid easter egg. Try again!';
},
parse: tag => tag.toLowerCase()
+5 -7
View File
@@ -15,9 +15,8 @@ module.exports = class StrawpollCommand extends Command {
prompt: 'What would you like the title of the Strawpoll to be?',
type: 'string',
validate: title => {
if(title.length < 200)
return true;
return `Please keep your title under 200 characters, you have ${title.length}.`;
if(title.length < 200) return true;
return 'Invalid Title. Title must be under 200 characters.';
}
},
{
@@ -26,9 +25,8 @@ module.exports = class StrawpollCommand extends Command {
type: 'string',
infinite: true,
validate: choice => {
if(choice.length < 160)
return true;
return `Please keep your options under 160 characters each, you have ${choice.length}.`;
if(choice.length < 160) return true;
return 'Invalid Choice. Choices must be under 140 characters each.';
}
}
]
@@ -50,7 +48,7 @@ module.exports = class StrawpollCommand extends Command {
http://strawpoll.me/${body.id}
`);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -31,7 +31,7 @@ module.exports = class TodayCommand extends Command {
.setDescription(`${events[random].year}: ${events[random].text}`);
return msg.embed(embed);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -29,7 +29,7 @@ module.exports = class WouldYouRatherCommand extends Command {
.setDescription(`${body.choicea} OR ${body.choiceb}?`);
return msg.embed(embed);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -24,7 +24,7 @@ module.exports = class CatCommand extends Command {
return msg.channel.send({ files: [body.file] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -21,7 +21,7 @@ module.exports = class DogCommand extends Command {
return msg.channel.send({ files: [body.url] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -2
View File
@@ -14,8 +14,7 @@ module.exports = class RandomNameCommand extends Command {
prompt: 'Which gender do you want to generate a name for?',
type: 'string',
validate: gender => {
if(['male', 'female'].includes(gender.toLowerCase()))
return true;
if(['male', 'female'].includes(gender.toLowerCase())) return true;
return 'Please enter either `male` or `female`.';
},
parse: gender => gender.toLowerCase()
+1 -1
View File
@@ -42,7 +42,7 @@ module.exports = class BotSearchCommand extends Command {
body.prefix, true);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The bot may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -28,13 +28,14 @@ module.exports = class DefineCommand extends Command {
try {
const { body } = await request
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${process.env.WORDNIK_KEY}`);
if(body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0x9797FF)
.setTitle(body[0].word)
.setDescription(body[0].text);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The word may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -2
View File
@@ -18,8 +18,7 @@ module.exports = class DiscrimCommand extends Command {
prompt: 'Which discriminator would you like to search for?',
type: 'string',
validate: discrim => {
if(/[0-9]+$/g.test(discrim) && discrim.length === 4)
return true;
if(/[0-9]+$/g.test(discrim) && discrim.length === 4) return true;
return `${discrim} is not a valid discriminator.`;
}
}
+2 -1
View File
@@ -27,6 +27,7 @@ module.exports = class ForecastCommand extends Command {
try {
const { body } = await request
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")&format=json`);
if(body.query.count === 0) throw new Error('Location Not Found.');
const forecasts = body.query.results.channel.item.forecast;
const embed = new RichEmbed()
.setColor(0x0000FF)
@@ -49,7 +50,7 @@ module.exports = class ForecastCommand extends Command {
`**High:** ${forecasts[6].high}°F, **Low:** ${forecasts[6].low}°F, **Condition:** ${forecasts[6].text}`);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The location may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -2
View File
@@ -29,11 +29,11 @@ module.exports = class GoogleCommand extends Command {
.get(`https://www.google.com/search?q=${query}`);
const $ = cheerio.load(text);
let href = $('.r').first().find('a').first().attr('href');
if(!href) throw new Error('No Results');
if(!href) throw new Error('No Results.');
href = querystring.parse(href.replace('/url?', ''));
return message.edit(href.q);
} catch(err) {
return message.edit('No Results Found.');
return message.edit('An Error Occurred: No Results.');
}
}
};
+2 -1
View File
@@ -28,6 +28,7 @@ module.exports = class IMDBCommand extends Command {
try {
const { body } = await request
.get(`http://www.omdbapi.com/?t=${query}&plot=full`);
if(body.Error) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xDBA628)
.setAuthor('IMDB', 'https://i.imgur.com/sXwwIQs.png')
@@ -50,7 +51,7 @@ module.exports = class IMDBCommand extends Command {
body.Actors);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The film may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -41,7 +41,7 @@ module.exports = class MapCommand extends Command {
return msg.channel.send({ files: [{ attachment: body, name: 'map.png' }] })
.catch(err => msg.say(`An Error Occurred: ${err}`));
} catch(err) {
return msg.say('An Error Occurred. The location may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -3
View File
@@ -27,11 +27,10 @@ module.exports = class NeopetCommand extends Command {
.get(`http://www.sunnyneo.com/petimagefinder.php?name=${query}&size=5&mood=1`);
const $ = cheerio.load(text);
const link = $('textarea').first().text();
if(!link.includes('cp'))
return msg.say('This is not a valid pet name.');
if(!link.includes('cp')) throw new Error('Invalid Pet Name.');
return msg.say(link);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -28,6 +28,7 @@ module.exports = class OsuCommand extends Command {
try {
const { body } = await request
.get(`https://osu.ppy.sh/api/get_user?k=${process.env.OSU_KEY}&u=${query}&type=string`);
if(body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xFF66AA)
.setAuthor('osu!', 'https://i.imgur.com/EmnUp00.png')
@@ -58,7 +59,7 @@ module.exports = class OsuCommand extends Command {
body[0].count_rank_a, true);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The user may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -28,6 +28,7 @@ module.exports = class SoundCloudCommand extends Command {
try {
const { body } = await request
.get(`https://api.soundcloud.com/tracks?q=${query}&client_id=${process.env.SOUNDCLOUD_KEY}`);
if(body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xF15A22)
.setAuthor(body[0].title, 'https://i.imgur.com/lFIz7RU.png')
@@ -45,7 +46,7 @@ module.exports = class SoundCloudCommand extends Command {
body[0].favoritings_count, true);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The song may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -28,6 +28,7 @@ module.exports = class UrbanCommand extends Command {
try {
const { body } = await request
.get(`http://api.urbandictionary.com/v0/define?term=${query}`);
if(body.list.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0x32a8f0)
.setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png')
@@ -38,7 +39,7 @@ module.exports = class UrbanCommand extends Command {
body.list[0].example.substr(0, 2000) || 'None');
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The word may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -29,6 +29,7 @@ module.exports = class WattpadCommand extends Command {
const { body } = await request
.get(`https://api.wattpad.com:443/v4/stories?query=${query}&limit=1`)
.set({ 'Authorization': `Basic ${process.env.WATTPAD_KEY}` });
if(body.stories.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xF89C34)
.setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png')
@@ -49,7 +50,7 @@ module.exports = class WattpadCommand extends Command {
body.stories[0].commentCount, true);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The book may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -27,6 +27,7 @@ module.exports = class WeatherCommand extends Command {
try {
const { body } = await request
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")&format=json`);
if(body.query.count === 0) throw new Error('Location Not Found.');
const embed = new RichEmbed()
.setColor(0x0000FF)
.setAuthor(body.query.results.channel.title, 'https://i.imgur.com/2MT0ViC.png')
@@ -58,7 +59,7 @@ module.exports = class WeatherCommand extends Command {
body.query.results.channel.wind.speed, true);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The location may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -28,6 +28,7 @@ module.exports = class WikipediaCommand extends Command {
try {
const { body } = await request
.get(`https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&titles=${query}&exintro=&explaintext=&redirects=&formatversion=2`);
if(body.query.pages[0].missing) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xE7E7E7)
.setTitle(body.query.pages[0].title)
@@ -36,7 +37,7 @@ module.exports = class WikipediaCommand extends Command {
.setDescription(body.query.pages[0].extract.substr(0, 2000).replace(/[\n]/g, '\n\n'));
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The page may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -1
View File
@@ -28,6 +28,7 @@ module.exports = class YouTubeCommand extends Command {
try {
const { body } = await request
.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&q=${query}&key=${process.env.GOOGLE_KEY}`);
if(body.items.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xDD2825)
.setTitle(body.items[0].snippet.title)
@@ -37,7 +38,7 @@ module.exports = class YouTubeCommand extends Command {
.setThumbnail(body.items[0].snippet.thumbnails.default.url);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The video may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+3 -2
View File
@@ -28,6 +28,7 @@ module.exports = class YuGiOhCommand extends Command {
try {
const { body } = await request
.get(`http://yugiohprices.com/api/card_data/${query}`);
if(body.status === 'fail') throw new Error('No Results.');
if(body.data.card_type === 'monster') {
const embed = new RichEmbed()
.setColor(0xBE5F1F)
@@ -35,7 +36,7 @@ module.exports = class YuGiOhCommand extends Command {
.setDescription(body.data.text)
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png')
.addField('**Card Type:**',
'Monster', true)
'monster', true)
.addField('**Type:**',
body.data.type, true)
.addField('**Attribute:**',
@@ -57,7 +58,7 @@ module.exports = class YuGiOhCommand extends Command {
body.data.card_type, true);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The card may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -3
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: text => {
if(binary(text).length < 2000)
return true;
return 'Your message content is too long.';
if(binary(text).length < 2000) return true;
return 'Your text is too long.';
},
parse: text => binary(text)
}
+2 -3
View File
@@ -14,9 +14,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)
return true;
return `Please keep your content under 1500 characters, you have ${text.length}.`;
if(text.length < 1500) return true;
return 'Invalid Text. Text must be under 1500 characters.';
}
}
]
+2 -3
View File
@@ -15,9 +15,8 @@ module.exports = class MorseCommand extends Command {
prompt: 'What text would you like to convert to morse?',
type: 'string',
validate: text => {
if(letterTrans(text, dictionary, ' ').length < 1999)
return true;
return 'Your message content is too long.';
if(letterTrans(text, dictionary, ' ').length < 1999) return true;
return 'Your text is too long.';
},
parse: text => letterTrans(text.toLowerCase(), dictionary, ' ')
}
+2 -3
View File
@@ -15,9 +15,8 @@ module.exports = class PirateCommand extends Command {
prompt: 'What text would you like to convert to pirate?',
type: 'string',
validate: text => {
if(wordTrans(text, dictionary).length < 1999)
return true;
return 'Your message content is too long.';
if(wordTrans(text, dictionary).length < 1999) return true;
return 'Your text is too long.';
},
parse: text => wordTrans(text, dictionary)
}
+2 -3
View File
@@ -15,9 +15,8 @@ module.exports = class TemmieCommand extends Command {
prompt: 'What text would you like to convert to Temmie speak?',
type: 'string',
validate: text => {
if(wordTrans(text, dictionary).length < 1999)
return true;
return 'Your message content is too long.';
if(wordTrans(text, dictionary).length < 1999) return true;
return 'Your text is too long.';
},
parse: text => wordTrans(text, dictionary)
}
+1 -1
View File
@@ -38,7 +38,7 @@ module.exports = class WebhookCommand extends Command {
.send({ content });
return null;
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+2 -3
View File
@@ -14,9 +14,8 @@ module.exports = class ZalgoCommand extends Command {
prompt: 'What text would you like to convert to zalgo?',
type: 'string',
validate: text => {
if(text.length < 500)
return true;
return `Please keep your text under 500 characters, you have ${text.length}.`;
if(text.length < 500) return true;
return 'Invalid Text. Text must be under 500 characters.';
},
parse: text => zalgo(text)
}
+1 -2
View File
@@ -14,8 +14,7 @@ module.exports = class ClearSettingCommand extends Command {
prompt: 'What setting do you want to clear? `modLog`, `memberLog`, `staffRole`, or `singleRole`?',
type: 'string',
validate: setting => {
if(['modLog', 'memberLog', 'staffRole', 'singleRole'].includes(setting))
return true;
if(['modLog', 'memberLog', 'staffRole', 'singleRole'].includes(setting)) return true;
return 'Please enter either `modLog`, `memberLog`, `staffRole`, or `singleRole`.';
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "18.2.1",
"version": "18.2.2",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {