Fix Everything

This commit is contained in:
Daniel Odendahl Jr
2017-06-01 18:31:20 +00:00
parent 66706d9c7b
commit 4e1f83a30f
85 changed files with 721 additions and 851 deletions
+70 -118
View File
@@ -22,17 +22,11 @@ module.exports = class BattleCommand extends Command {
this.fighting = new Set();
}
async run(msg, args) {
async run(msg, args) { // eslint-disable-line complexity
const { opponent } = args;
if (opponent.bot) {
return msg.say('Bots cannot be fought.');
}
if (opponent.id === msg.author.id) {
return msg.say('You may not fight yourself.');
}
if (this.fighting.has(msg.guild.id)) {
return msg.say('Only one fight may be occurring per server.');
}
if (opponent.bot) return msg.say('Bots cannot be fought.');
if (opponent.id === msg.author.id) return msg.say('You may not fight yourself.');
if (this.fighting.has(msg.guild.id)) return msg.say('Only one fight may be occurring per server.');
this.fighting.add(msg.guild.id);
await msg.say(`**${opponent.username}**, do you accept this challenge? **__Y__es** or **No**?`);
try {
@@ -41,117 +35,75 @@ module.exports = class BattleCommand extends Command {
time: 15000,
errors: ['time']
});
if (['yes', 'y'].includes(verify.first().content.toLowerCase())) {
let userHP = 500;
let oppoHP = 500;
let userTurn = true;
let guard = false;
let userCure = true;
let oppoCure = true;
while (userHP > 0 && oppoHP > 0) {
const username = userTurn ? msg.author.username : opponent.username;
await msg.say(stripIndents`
**${username}**, do you **fight**, **guard**, **special**, **cure**, or **run**?
**${msg.author.username}**: ${userHP}HP
**${opponent.username}**: ${oppoHP}HP
`);
try {
const turn = await msg.channel.awaitMessages((res) => res.author.id === (userTurn ? msg.author.id : opponent.id), {
max: 1,
time: 15000,
errors: ['time']
});
const choice = turn.first().content.toLowerCase();
if (choice === 'fight') {
const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1;
await msg.say(`**${username}** deals **${damage}** damage!`);
if (userTurn) {
oppoHP = oppoHP - damage;
userTurn = false;
} else {
userHP = userHP - damage;
userTurn = true;
}
if (guard) {
guard = false;
}
} else if (choice === 'guard') {
await msg.say(`**${username}** guards!`);
guard = true;
if (userTurn) {
userTurn = false;
} else {
userTurn = true;
}
} else if (choice === 'special') {
const hit = Math.floor(Math.random() * 4) + 1;
if (hit === 1) {
const damage = Math.floor(Math.random() * ((guard ? 300 : 150) - 100 + 1) + 100);
await msg.say(`**${username}** deals **${damage}** damage!`);
if (userTurn) {
oppoHP = oppoHP - damage;
userTurn = false;
} else {
userHP = userHP - damage;
userTurn = true;
}
if (guard) {
guard = false;
}
} else {
await msg.say(`**${username}**'s attack missed!`);
if (userTurn) {
userTurn = false;
} else {
userTurn = true;
}
if (guard) {
guard = false;
}
}
} else if (choice === 'cure') {
if (userTurn ? userCure : oppoCure) {
await msg.say(`**${username}** regains **250** health!`);
if (userTurn) {
userHP = userHP + 250;
userCure = false;
userTurn = false;
} else {
oppoHP = oppoHP + 250;
oppoCure = false;
userTurn = true;
}
if (guard) {
guard = false;
}
} else {
await msg.say('You have already cured!');
}
} else if (choice === 'run') {
await msg.say(`**${username}** flees!`);
if (userTurn) {
userHP = 0;
} else {
oppoHP = 0;
}
} else {
await msg.say('I do not understand what you want to do.');
}
} catch (err) {
await msg.say('Time!');
break;
}
}
this.fighting.delete(msg.guild.id);
return msg.say(stripIndents`
The match is over!
**Winner: ${userHP > oppoHP ? `${msg.author.username}** (${userHP}HP)` : `${opponent.username}** (${oppoHP}HP)`}
**Loser: ${userHP > oppoHP ? `${opponent.username}** (${oppoHP}HP)` : `${msg.author.username}** (${userHP}HP)`}
`);
} else {
if (!['yes', 'y'].includes(verify.first().content.toLowerCase())) {
this.fighting.delete(msg.guild.id);
return msg.say('Guess that was a no then...');
}
let userHP = 500;
let oppoHP = 500;
let userTurn = false;
let guard = false;
const reset = () => {
if (userTurn) userTurn = false;
else userTurn = true;
if (guard) guard = false;
};
const dealDamage = (damage) => {
if (userTurn) userHP += damage;
else oppoHP += damage;
};
while (userHP > 0 && oppoHP > 0) { // eslint-disable-line no-unmodified-loop-condition
const username = userTurn ? msg.author.username : opponent.username;
const id = userTurn ? msg.author.id : opponent.id;
await msg.say(stripIndents`
**${username}**, do you **fight**, **guard**, **special**, or **run**?
**${msg.author.username}**: ${userHP}HP
**${opponent.username}**: ${oppoHP}HP
`);
try {
const turn = await msg.channel.awaitMessages((res) => res.author.id === id, {
max: 1,
time: 15000,
errors: ['time']
});
const choice = turn.first().content.toLowerCase();
if (choice === 'fight') {
const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1;
await msg.say(`**${username}** deals **${damage}** damage!`);
dealDamage(damage);
reset();
} else if (choice === 'guard') {
await msg.say(`**${username}** guards!`);
reset();
guard = true;
} else if (choice === 'special') {
const hit = Math.floor(Math.random() * 4) + 1;
if (hit === 1) {
const damage = Math.floor(Math.random() * ((guard ? 300 : 150) - 100 + 1) + 100);
await msg.say(`**${username}** deals **${damage}** damage!`);
dealDamage(damage);
reset();
} else {
await msg.say(`**${username}**'s attack missed!`);
reset();
}
} else if (choice === 'run') {
await msg.say(`**${username}** flees!`);
dealDamage(500 - (userTurn ? userHP : oppoHP));
} else {
await msg.say('I do not understand what you want to do.');
}
} catch (err) {
await msg.say('Time!');
break;
}
}
this.fighting.delete(msg.guild.id);
return msg.say(stripIndents`
The match is over!
**Winner:** ${userHP > oppoHP ? msg.author.username : opponent.username}
**Loser:** ${userHP > oppoHP ? opponent.username : msg.author.username}
`);
} catch (err) {
this.fighting.delete(msg.guild.id);
return msg.say('Looks like they declined...');
+2 -5
View File
@@ -12,10 +12,7 @@ module.exports = class LotteryCommand extends Command {
run(msg) {
const lottery = Math.floor(Math.random() * 100) + 1;
if (lottery === 1) {
return msg.say(`Wow ${msg.author.username}! You actually won! Great job!`);
} else {
return msg.say(`Nope, sorry ${msg.author.username}, you lost.`);
}
if (lottery === 1) return msg.say(`Wow ${msg.author.username}! You actually won! Great job!`);
else return msg.say(`Nope, sorry ${msg.author.username}, you lost.`);
}
};
+8 -12
View File
@@ -17,11 +17,8 @@ module.exports = class MathGameCommand extends Command {
prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`,
type: 'string',
validate: (difficulty) => {
if (difficulties.includes(difficulty.toLowerCase())) {
return true;
} else {
return `The difficulty must be one of: ${difficulties.join(', ')}`;
}
if (difficulties.includes(difficulty.toLowerCase())) return true;
else return `The difficulty must be one of: ${difficulties.join(', ')}`;
},
parse: (difficulty) => difficulty.toLowerCase()
}
@@ -32,8 +29,10 @@ module.exports = class MathGameCommand extends Command {
async run(msg, args) {
const { difficulty } = args;
const operation = operations[Math.floor(Math.random() * operations.length)];
const value = maxValues[difficulty];
const expression = `${Math.floor(Math.random() * value) + 1} ${operation} ${Math.floor(Math.random() * value) + 1}`;
const maxValue = maxValues[difficulty];
const value1 = Math.floor(Math.random() * maxValue) + 1;
const value2 = Math.floor(Math.random() * maxValue) + 1;
const expression = `${value1} ${operation} ${value2}`;
const answer = math.eval(expression).toString();
const embed = new RichEmbed()
.setTitle('You have 10 seconds to answer:')
@@ -45,11 +44,8 @@ module.exports = class MathGameCommand extends Command {
time: 10000,
errors: ['time']
});
if (collected.first().content !== answer) {
return msg.say(`Nope, sorry, it's ${answer}.`);
} else {
return msg.say('Nice job! 10/10! You deserve some cake!');
}
if (collected.first().content !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
else return msg.say('Nice job! 10/10! You deserve some cake!');
} catch (err) {
return msg.say(`Time! It was ${answer}, sorry!`);
}
+2 -5
View File
@@ -37,11 +37,8 @@ module.exports = class QuizCommand extends Command {
time: 15000,
errors: ['time']
});
if (collected.first().content.toLowerCase() !== answer) {
return msg.say(`Nope, sorry, it's ${answer}.`);
} else {
return msg.say('Nice job! 10/10! You deserve some cake!');
}
if (collected.first().content.toLowerCase() !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
else return msg.say('Nice job! 10/10! You deserve some cake!');
} catch (err) {
return msg.say(`Time! It was ${answer}, sorry!`);
}
+11 -28
View File
@@ -14,13 +14,6 @@ module.exports = class RockPaperScissorsCommand extends Command {
key: 'choice',
prompt: '`Rock`, `Paper`, or `Scissors`?',
type: 'string',
validate: (choice) => {
if (choices.includes(choice.toLowerCase())) {
return true;
} else {
return 'Please enter either `rock`, `paper`, or `scissors`.';
}
},
parse: (choice) => choice.toLowerCase()
}
]
@@ -31,29 +24,19 @@ module.exports = class RockPaperScissorsCommand extends Command {
const { choice } = args;
const response = choices[Math.floor(Math.random() * choices.length)];
if (choice === 'rock') {
if (response === 'rock') {
return msg.say('Rock! Aw... A tie...');
} else if (response === 'paper') {
return msg.say('Paper! Yes! I win!');
} else if (response === 'scissors') {
return msg.say('Scissors! Aw... I lose...');
}
if (response === 'rock') return msg.say('Rock! Aw... A tie...');
else if (response === 'paper') return msg.say('Paper! Yes! I win!');
else return msg.say('Scissors! Aw... I lose...');
} else if (choice === 'paper') {
if (response === 'rock') {
return msg.say('Rock! Aw... I lose...');
} else if (response === 'paper') {
return msg.say('Paper! Aw... A tie...');
} else if (response === 'scissors') {
return msg.say('Scissors! Yes! I win!');
}
if (response === 'rock') return msg.say('Rock! Aw... I lose...');
else if (response === 'paper') return msg.say('Paper! Aw... A tie...');
else return msg.say('Scissors! Yes! I win!');
} else if (choice === 'scissors') {
if (response === 'rock') {
return msg.say('Rock! Yes! I win!');
} else if (response === 'paper') {
return msg.say('Paper! Aw... I lose...');
} else if (response === 'scissors') {
return msg.say('Scissors! Aw... A tie...');
}
if (response === 'rock') return msg.say('Rock! Yes! I win!');
else if (response === 'paper') return msg.say('Paper! Aw... I lose...');
else return msg.say('Scissors! Aw... A tie...');
} else {
return msg.say('I win by default, you little cheater.');
}
}
};
+4 -10
View File
@@ -16,11 +16,8 @@ module.exports = class TypingGameCommand extends Command {
prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`,
type: 'string',
validate: (difficulty) => {
if (difficulties.includes(difficulty.toLowerCase())) {
return true;
} else {
return `The difficulty must be one of: ${difficulties.join(', ')}`;
}
if (difficulties.includes(difficulty.toLowerCase())) return true;
else return `The difficulty must be one of: ${difficulties.join(', ')}`;
},
parse: (difficulty) => difficulty.toLowerCase()
}
@@ -42,11 +39,8 @@ module.exports = class TypingGameCommand extends Command {
time: time,
errors: ['time']
});
if (collected.first().content !== sentence) {
return msg.say('Nope, sorry!');
} else {
return msg.say('Nice job! 10/10! You deserve some cake!');
}
if (collected.first().content !== sentence) return msg.say('Nope, sorry!');
else return msg.say('Nice job! 10/10! You deserve some cake!');
} catch (err) {
return msg.say('Time! Sorry!');
}