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
+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!');
}
}
};