mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 06:42:50 +02:00
Better Error Handling
This commit is contained in:
@@ -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}.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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}.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user