This commit is contained in:
Daniel Odendahl Jr
2017-06-01 08:44:02 +00:00
parent 7802bb49cb
commit 14f85f94bd
129 changed files with 1915 additions and 1720 deletions
+47 -20
View File
@@ -24,13 +24,19 @@ module.exports = class BattleCommand extends Command {
async run(msg, args) {
const { opponent } = args;
if (opponent.bot) return msg.say('You cannot fight bots!');
if (opponent.id === msg.author.id) return msg.say('You cannot fight yourself!');
if (this.fighting.has(msg.guild.id)) return msg.say('There is already a fight in this 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 {
const verify = await msg.channel.awaitMessages(res => res.author.id === opponent.id, {
const verify = await msg.channel.awaitMessages((res) => res.author.id === opponent.id, {
max: 1,
time: 15000,
errors: ['time']
@@ -50,14 +56,14 @@ module.exports = class BattleCommand extends Command {
**${opponent.username}**: ${oppoHP}HP
`);
try {
const turn = await msg.channel.awaitMessages(res => res.author.id === (userTurn ? msg.author.id : opponent.id), {
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 ? 25 : 100)) + 1;
const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1;
await msg.say(`**${username}** deals **${damage}** damage!`);
if (userTurn) {
oppoHP = oppoHP - damage;
@@ -66,12 +72,17 @@ module.exports = class BattleCommand extends Command {
userHP = userHP - damage;
userTurn = true;
}
if (guard) guard = false;
if (guard) {
guard = false;
}
} else if (choice === 'guard') {
await msg.say(`**${username}** guards!`);
guard = true;
if (userTurn) userTurn = false;
else userTurn = true;
if (userTurn) {
userTurn = false;
} else {
userTurn = true;
}
} else if (choice === 'special') {
const hit = Math.floor(Math.random() * 4) + 1;
if (hit === 1) {
@@ -84,12 +95,19 @@ module.exports = class BattleCommand extends Command {
userHP = userHP - damage;
userTurn = true;
}
if (guard) guard = false;
if (guard) {
guard = false;
}
} else {
await msg.say(`**${username}**'s attack missed!`);
if (guard) guard = false;
if (userTurn) userTurn = false;
else userTurn = true;
if (userTurn) {
userTurn = false;
} else {
userTurn = true;
}
if (guard) {
guard = false;
}
}
} else if (choice === 'cure') {
if (userTurn ? userCure : oppoCure) {
@@ -103,13 +121,22 @@ module.exports = class BattleCommand extends Command {
oppoCure = false;
userTurn = true;
}
if (guard) guard = false;
} else await msg.say('You have already cured!');
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.');
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;
@@ -118,8 +145,8 @@ module.exports = class BattleCommand extends Command {
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)`}
**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 {
this.fighting.delete(msg.guild.id);
+5 -2
View File
@@ -12,7 +12,10 @@ module.exports = class LotteryCommand extends Command {
run(msg) {
const lottery = Math.floor(Math.random() * 100) + 1;
if (lottery < 99) return msg.say(`Nope, sorry ${msg.author.username}, you lost.`);
return msg.say(`Wow ${msg.author.username}! You actually won! Great job!`);
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.`);
}
}
};
+17 -28
View File
@@ -1,7 +1,7 @@
const Command = require('../../structures/Command');
const { RichEmbed } = require('discord.js');
const math = require('mathjs');
const operations = ['+', '-', '*'];
const { operations, difficulties, maxValues } = require('../../assets/json/math-game');
module.exports = class MathGameCommand extends Command {
constructor(client) {
@@ -14,13 +14,16 @@ module.exports = class MathGameCommand extends Command {
args: [
{
key: 'difficulty',
prompt: 'What should the difficulty of the game be? `Easy`, `Medium`, `Hard`, `Extreme`, or `Impossible`?',
prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`,
type: 'string',
validate: difficulty => {
if (['easy', 'medium', 'hard', 'extreme', 'impossible'].includes(difficulty.toLowerCase())) return true;
return 'The difficulty must be either `easy`, `medium`, `hard`, `extreme`, or `impossible`.';
validate: (difficulty) => {
if (difficulties.includes(difficulty.toLowerCase())) {
return true;
} else {
return `The difficulty must be one of: ${difficulties.join(', ')}`;
}
},
parse: difficulty => difficulty.toLowerCase()
parse: (difficulty) => difficulty.toLowerCase()
}
]
});
@@ -29,38 +32,24 @@ module.exports = class MathGameCommand extends Command {
async run(msg, args) {
const { difficulty } = args;
const operation = operations[Math.floor(Math.random() * operations.length)];
let value;
switch(difficulty) {
case 'easy':
value = 10;
break;
case 'medium':
value = 50;
break;
case 'hard':
value = 100;
break;
case 'extreme':
value = 1000;
break;
case 'impossible':
value = 10000;
break;
}
const value = maxValues[difficulty];
const expression = `${Math.floor(Math.random() * value) + 1} ${operation} ${Math.floor(Math.random() * value) + 1}`;
const answer = math.eval(expression).toString();
const embed = new RichEmbed()
.setTitle('You have **10** seconds to answer:')
.setTitle('You have 10 seconds to answer:')
.setDescription(expression);
await msg.embed(embed);
try {
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
const collected = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
time: 10000,
errors: ['time']
});
if (collected.first().content !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
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!`);
}
+24 -25
View File
@@ -16,35 +16,34 @@ module.exports = class QuizCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('https://opentdb.com/api.php')
.query({
amount: 1,
type: 'boolean',
encode: 'url3986'
});
const answer = body.results[0].correct_answer.toLowerCase();
const embed = new RichEmbed()
.setTitle('You have 15 seconds to answer this question:')
.setDescription(stripIndents`
**${decodeURIComponent(body.results[0].category)}**
True or False: ${decodeURIComponent(body.results[0].question)}
`);
await msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://opentdb.com/api.php')
.query({
amount: 1,
type: 'boolean',
encode: 'url3986'
});
const answer = body.results[0].correct_answer.toLowerCase();
const embed = new RichEmbed()
.setTitle('You have **15** seconds to answer this question:')
.setDescription(stripIndents`
**${decodeURIComponent(body.results[0].category)}**
True or False: ${decodeURIComponent(body.results[0].question)}
`);
await msg.embed(embed);
try {
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
max: 1,
time: 15000,
errors: ['time']
});
if (collected.first().content.toLowerCase() !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
const collected = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
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!');
} catch (err) {
return msg.say(`Time! It was ${answer}, sorry!`);
}
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
return msg.say(`Time! It was ${answer}, sorry!`);
}
}
};
+30 -15
View File
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command');
const responses = ['Paper', 'Rock', 'Scissors'];
const choices = ['paper', 'rock', 'scissors'];
module.exports = class RockPaperScissorsCommand extends Command {
constructor(client) {
@@ -14,11 +14,14 @@ module.exports = class RockPaperScissorsCommand extends Command {
key: 'choice',
prompt: '`Rock`, `Paper`, or `Scissors`?',
type: 'string',
validate: choice => {
if (['rock', 'paper', 'scissors'].includes(choice.toLowerCase())) return true;
return 'Please enter either `rock`, `paper`, or `scissors`.';
validate: (choice) => {
if (choices.includes(choice.toLowerCase())) {
return true;
} else {
return 'Please enter either `rock`, `paper`, or `scissors`.';
}
},
parse: choice => choice.toLowerCase()
parse: (choice) => choice.toLowerCase()
}
]
});
@@ -26,19 +29,31 @@ module.exports = class RockPaperScissorsCommand extends Command {
run(msg, args) {
const { choice } = args;
const response = responses[Math.floor(Math.random() * responses.length)];
const response = choices[Math.floor(Math.random() * choices.length)];
if (choice === 'rock') {
if (response === 'Rock') return msg.say('Rock! Aw, it\'s a tie!');
if (response === 'Paper') return msg.say('Paper! Yes! I win!');
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 if (response === 'scissors') {
return msg.say('Scissors! Aw... I lose...');
}
} else if (choice === 'paper') {
if (response === 'Rock') return msg.say('Rock! Aw... I lose...');
if (response === 'Paper') return msg.say('Paper! Aw, it\'s a tie!');
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 if (response === 'scissors') {
return msg.say('Scissors! Yes! I win!');
}
} else if (choice === 'scissors') {
if (response === 'Rock') return msg.say('Rock! Yes! I win!');
if (response === 'Paper') return msg.say('Paper! Aw... I lose...');
if (response === 'Scissors') return msg.say('Scissors! Aw, it\'s a tie!');
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...');
}
}
}
};
+11 -9
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const slotThing = [':grapes:', ':tangerine:', ':pear:', ':cherries:'];
const slots = [':grapes:', ':tangerine:', ':pear:', ':cherries:'];
module.exports = class SlotsCommand extends Command {
constructor(client) {
@@ -13,17 +13,19 @@ module.exports = class SlotsCommand extends Command {
}
run(msg) {
const slotOne = slotThing[Math.floor(Math.random() * slotThing.length)];
const slotTwo = slotThing[Math.floor(Math.random() * slotThing.length)];
const slotThree = slotThing[Math.floor(Math.random() * slotThing.length)];
if (slotOne === slotTwo && slotOne === slotThree)
const slotOne = slots[Math.floor(Math.random() * slots.length)];
const slotTwo = slots[Math.floor(Math.random() * slots.length)];
const slotThree = slots[Math.floor(Math.random() * slots.length)];
if (slotOne === slotTwo && slotOne === slotThree) {
return msg.say(stripIndents`
${slotOne}|${slotTwo}|${slotThree}
Wow! You won! Great job... er... luck!
`);
return msg.say(stripIndents`
${slotOne}|${slotTwo}|${slotThree}
Aww... You lost... Guess it's just bad luck, huh?
`);
} else {
return msg.say(stripIndents`
${slotOne}|${slotTwo}|${slotThree}
Aww... You lost... Guess it's just bad luck, huh?
`);
}
}
};
+17 -28
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { RichEmbed } = require('discord.js');
const sentences = require('../../assets/json/typing-game');
const { sentences, difficulties, times } = require('../../assets/json/typing-game');
module.exports = class TypingGameCommand extends Command {
constructor(client) {
@@ -13,13 +13,16 @@ module.exports = class TypingGameCommand extends Command {
args: [
{
key: 'difficulty',
prompt: 'What should the difficulty of the game be? `Easy`, `Medium`, `Hard`, `Extreme`, or `Impossible`?',
prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`,
type: 'string',
validate: difficulty => {
if (['easy', 'medium', 'hard', 'extreme', 'impossible'].includes(difficulty.toLowerCase())) return true;
return 'The difficulty must be either `easy`, `medium`, `hard`, `extreme`, or `impossible`.';
validate: (difficulty) => {
if (difficulties.includes(difficulty.toLowerCase())) {
return true;
} else {
return `The difficulty must be one of: ${difficulties.join(', ')}`;
}
},
parse: difficulty => difficulty.toLowerCase()
parse: (difficulty) => difficulty.toLowerCase()
}
]
});
@@ -28,36 +31,22 @@ module.exports = class TypingGameCommand extends Command {
async run(msg, args) {
const { difficulty } = args;
const sentence = sentences[Math.floor(Math.random() * sentences.length)];
let time;
switch(difficulty) {
case 'easy':
time = 25000;
break;
case 'medium':
time = 20000;
break;
case 'hard':
time = 15000;
break;
case 'extreme':
time = 10000;
break;
case 'impossible':
time = 5000;
break;
}
const time = times[difficulty];
const embed = new RichEmbed()
.setTitle(`You have **${time / 1000}** seconds to type:`)
.setTitle(`You have ${time / 1000} seconds to type:`)
.setDescription(sentence);
await msg.embed(embed);
try {
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
const collected = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
time: time,
errors: ['time']
});
if (collected.first().content !== sentence) return msg.say('Nope, sorry!');
return msg.say(`Good Job! You won!`);
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!');
}