This commit is contained in:
Elizabeth
2017-07-12 19:33:31 -05:00
parent c80caedffe
commit afe98a18a4
181 changed files with 22 additions and 1 deletions
-124
View File
@@ -1,124 +0,0 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
module.exports = class BattleCommand extends Command {
constructor(client) {
super(client, {
name: 'battle',
aliases: ['fight', 'death-battle'],
group: 'games',
memberName: 'battle',
description: 'Engage in a turn-based battle against another user or the AI.',
guildOnly: true,
args: [
{
key: 'opponent',
prompt: 'Who would you like to battle?',
type: 'user',
default: 'AI'
}
]
});
this.fighting = new Set();
}
async run(msg, args) { // eslint-disable-line complexity
const opponent = args.opponent;
if (opponent.bot) return msg.say('Bots may not 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);
try {
if (opponent !== 'AI') {
await msg.say(`${opponent}, do you accept this challenge? **__Y__es** or **No**?`);
const verify = await msg.channel.awaitMessages((res) => res.author.id === opponent.id, {
max: 1,
time: 30000
});
if (!verify.size || !['yes', 'y'].includes(verify.first().content.toLowerCase())) {
this.fighting.delete(msg.guild.id);
return msg.say('Looks like they declined...');
}
}
let userHP = 500;
let oppoHP = 500;
let userTurn = false;
let guard = false;
const reset = (changeGuard = true) => {
if (userTurn) userTurn = false;
else userTurn = true;
if (changeGuard && guard) guard = false;
};
const dealDamage = (damage) => {
if (userTurn) oppoHP -= damage;
else userHP -= damage;
};
const forfeit = () => {
if (userTurn) userHP = 0;
else oppoHP = 0;
};
while (userHP > 0 && oppoHP > 0) { // eslint-disable-line no-unmodified-loop-condition
const user = userTurn ? msg.author : opponent;
let choice;
if (opponent !== 'AI' || (opponent === 'AI' && userTurn)) {
const id = userTurn ? msg.author.id : opponent.id;
await msg.say(stripIndents`
${user}, do you **fight**, **guard**, **special**, or **run**?
**${msg.author.username}**: ${userHP}HP
**${opponent === 'AI' ? 'AI' : opponent.username}**: ${oppoHP}HP
`);
const turn = await msg.channel.awaitMessages((res) => res.author.id === id, {
max: 1,
time: 30000
});
if (!turn.size) {
await msg.say('Time!');
forfeit();
break;
}
choice = turn.first().content.toLowerCase();
} else {
const choices = ['fight', 'guard', 'special'];
choice = choices[Math.floor(Math.random() * choices.length)];
}
if (choice === 'fight') {
const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1;
await msg.say(`${user} deals **${damage}** damage!`);
dealDamage(damage);
reset();
} else if (choice === 'guard') {
await msg.say(`${user} guards!`);
guard = true;
reset(false);
} 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(`${user} deals **${damage}** damage!`);
dealDamage(damage);
reset();
} else {
await msg.say(`${user}'s attack missed!`);
reset();
}
} else if (choice === 'run') {
await msg.say(`${user} flees!`);
forfeit();
break;
} else {
await msg.say(`${user}, I do not understand what you want to do.`);
}
}
this.fighting.delete(msg.guild.id);
return msg.say(stripIndents`
The match is over!
**Winner:** ${userHP > oppoHP ? `${msg.author} (${userHP}HP)` : `${opponent} (${oppoHP}HP)`}
**Loser:** ${userHP > oppoHP ? `${opponent} (${oppoHP}HP)` : `${msg.author} (${userHP}HP)`}
`);
} catch (err) {
this.fighting.delete(msg.guild.id);
return msg.say(`Oh no, an Error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-83
View File
@@ -1,83 +0,0 @@
const Command = require('../../structures/Command');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const { wordnikKey } = require('../../config');
module.exports = class HangmanCommand extends Command {
constructor(client) {
super(client, {
name: 'hangman',
group: 'games',
memberName: 'hangman',
description: 'Play a game of hangman.',
guildOnly: true
});
this.playing = new Set();
}
async run(msg) {
if (this.playing.has(msg.guild.id)) return msg.say('Only one game may be occurring per server.');
this.playing.add(msg.guild.id);
try {
const { body } = await snekfetch
.get('http://api.wordnik.com:80/v4/words.json/randomWord')
.query({
hasDictionaryDef: true,
minCorpusCount: 0,
maxCorpusCount: -1,
minDictionaryCount: 1,
maxDictionaryCount: -1,
minLength: -1,
maxLength: -1,
api_key: wordnikKey
});
const word = body.word.toLowerCase().replace(/[ ]/g, '-');
let points = 0;
const confirmation = [];
const incorrect = [];
const display = '_'.repeat(word.length).split('');
while (word.length !== confirmation.length && points < 7) {
await msg.code(null, stripIndents`
___________
| |
| ${points > 0 ? 'O' : ''}
| ${points > 2 ? '—' : ' '}${points > 1 ? '|' : ''}${points > 3 ? '—' : ''}
| ${points > 4 ? '/' : ''} ${points > 5 ? '\\' : ''}
===========
The word is: ${display.join(' ')}. Which letter do you choose?
`);
const guess = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
time: 30000
});
if (!guess.size) {
await msg.say('Time!');
break;
}
const choice = guess.first().content.toLowerCase();
if (confirmation.includes(choice) || incorrect.includes(choice)) {
await msg.say('You have already picked that letter!');
} else if (word.includes(choice)) {
await msg.say('Nice job!');
for (let i = 0; i < word.length; i++) {
if (word[i] === choice) {
confirmation.push(word[i]);
display[i] = word[i];
}
}
} else {
await msg.say('Nope!');
incorrect.push(choice);
points++;
}
}
this.playing.delete(msg.guild.id);
if (word.length === confirmation.length) return msg.say(`You won, it was ${word}!`);
else return msg.say(`Too bad... It was ${word}...`);
} catch (err) {
this.playing.delete(msg.guild.id);
return msg.say(`Oh no, an Error occurred: \`${err.message}\`. Try again later!`);
}
}
};
-18
View File
@@ -1,18 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class LotteryCommand extends Command {
constructor(client) {
super(client, {
name: 'lottery',
group: 'games',
memberName: 'lottery',
description: 'Attempt to win the lottery, with a 1 in 100 chance of winning.'
});
}
run(msg) {
const lottery = Math.floor(Math.random() * 100) + 1;
if (lottery === 1) return msg.reply(`Wow! You actually won! Great job!`);
else return msg.reply(`Nope, sorry, you lost.`);
}
};
-48
View File
@@ -1,48 +0,0 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const math = require('mathjs');
const { operations, difficulties, maxValues } = require('../../assets/json/math-game');
module.exports = class MathGameCommand extends Command {
constructor(client) {
super(client, {
name: 'math-game',
group: 'games',
memberName: 'math-game',
description: 'See how fast you can answer a math problem in a given time limit.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'difficulty',
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(', ')}`;
},
parse: (difficulty) => difficulty.toLowerCase()
}
]
});
}
async run(msg, args) {
const { difficulty } = args;
const operation = operations[Math.floor(Math.random() * operations.length)];
const value1 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
const value2 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
const expression = `${value1} ${operation} ${value2}`;
const answer = math.eval(expression).toString();
const embed = new MessageEmbed()
.setTitle('You have 10 seconds to answer:')
.setDescription(expression);
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
time: 10000
});
if (!msgs.size) return msg.say(`Time! It was ${answer}, sorry!`);
if (msgs.first().content !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
else return msg.say('Nice job! 10/10! You deserve some cake!');
}
};
-42
View File
@@ -1,42 +0,0 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const snekfetch = require('snekfetch');
module.exports = class QuizCommand extends Command {
constructor(client) {
super(client, {
name: 'quiz',
aliases: ['jeopardy'],
group: 'games',
memberName: 'quiz',
description: 'Answer a true/false quiz question.',
clientPermissions: ['EMBED_LINKS']
});
}
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 MessageEmbed()
.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);
const msgs = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
time: 15000
});
if (!msgs.size) return msg.say(`Time! It was ${answer}, sorry!`);
if (msgs.first().content.toLowerCase() !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
else return msg.say('Nice job! 10/10! You deserve some cake!');
}
};
-42
View File
@@ -1,42 +0,0 @@
const Command = require('../../structures/Command');
const choices = ['paper', 'rock', 'scissors'];
module.exports = class RockPaperScissorsCommand extends Command {
constructor(client) {
super(client, {
name: 'rock-paper-scissors',
aliases: ['rps'],
group: 'games',
memberName: 'rock-paper-scissors',
description: 'Play Rock-Paper-Scissors.',
args: [
{
key: 'choice',
prompt: 'Rock, Paper, or Scissors?',
type: 'string',
parse: (choice) => choice.toLowerCase()
}
]
});
}
run(msg, args) { // eslint-disable-line consistent-return
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...');
} 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!');
} 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...');
} else {
return msg.say('I win by default, you little cheater.');
}
}
};
-31
View File
@@ -1,31 +0,0 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const slots = [':grapes:', ':tangerine:', ':pear:', ':cherries:', ':lemon:'];
module.exports = class SlotsCommand extends Command {
constructor(client) {
super(client, {
name: 'slots',
group: 'games',
memberName: 'slots',
description: 'Play a game of slots.'
});
}
run(msg) {
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!
`);
} else {
return msg.say(stripIndents`
${slotOne}|${slotTwo}|${slotThree}
Aww... You lost... Guess it's just bad luck, huh?
`);
}
}
};
-43
View File
@@ -1,43 +0,0 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const { sentences, difficulties, times } = require('../../assets/json/typing-game');
module.exports = class TypingGameCommand extends Command {
constructor(client) {
super(client, {
name: 'typing-game',
group: 'games',
memberName: 'typing-game',
description: 'See how fast you can type a sentence in a given time limit.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'difficulty',
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(', ')}`;
},
parse: (difficulty) => difficulty.toLowerCase()
}
]
});
}
async run(msg, args) {
const { difficulty } = args;
const sentence = sentences[Math.floor(Math.random() * sentences.length)];
const time = times[difficulty];
const embed = new MessageEmbed()
.setTitle(`You have ${time / 1000} seconds to type:`)
.setDescription(sentence);
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
max: 1,
time
});
if (!msgs.size || msgs.first().content !== sentence) return msg.say('Sorry! You lose!');
else return msg.say('Nice job! 10/10! You deserve some cake!');
}
};