diff --git a/commands/random/mathgame.js b/commands/random/mathgame.js index d565146b..a0faa140 100644 --- a/commands/random/mathgame.js +++ b/commands/random/mathgame.js @@ -55,7 +55,7 @@ module.exports = class MathGameCommand extends commando.Command { }).then((collected) => { return message.channel.send(`Good Job! You won!`); }).catch(() => { - return message.channel.send(`Aw... Too bad, try again next time! The correct answer was: ${solved}`); + return message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${solved}`); }); }); } diff --git a/commands/random/quiz.js b/commands/random/quiz.js new file mode 100644 index 00000000..b957d3f1 --- /dev/null +++ b/commands/random/quiz.js @@ -0,0 +1,49 @@ +const commando = require('discord.js-commando'); +const Discord = require('discord.js'); +const request = require('superagent'); + +module.exports = class QuizCommand extends commando.Command { + constructor(Client) { + super(Client, { + name: 'quiz', + aliases: [ + 'jeopardy' + ], + group: 'random', + memberName: 'quiz', + description: 'Answer a quiz question. (;quiz)', + examples: [';quiz'] + }); + } + + async run(message) { + if (message.channel.type !== 'dm') { + if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; + } + console.log("[Command] " + message.content); + return request + .get('http://jservice.io/api/random') + .query({ + count: 1 + }) + .then(function(response) { + const embed = new Discord.RichEmbed() + .setTitle('You have **fifteen** seconds to answer this question:') + .setDescription(`**Category: ${response.body.category}**\n${response.body.question}`); + await message.channel.sendEmbed(embed).then(() => { + message.channel.awaitMessages(res => res.content.toLowerCase() === response.body.answer.toLowerCase() && res.author.id === message.author.id, { + max: 1, + time: 15000, + errors: ['time'], + }).then((collected) => { + return message.channel.send(`Good Job! You won!`); + }).catch(() => { + return message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${response.body.answer}`); + }); + }).catch(function(err) { + console.log(err); + return message.channel.send(":x: Error! Something went wrong!"); + }); + }); + } +}; \ No newline at end of file diff --git a/commands/random/typinggame.js b/commands/random/typinggame.js index ae864ad4..5d647c26 100644 --- a/commands/random/typinggame.js +++ b/commands/random/typinggame.js @@ -55,7 +55,7 @@ module.exports = class TypingGameCommand extends commando.Command { } else { const embed = new Discord.RichEmbed() - .setTitle('You have **' + levelWord + '** seconds to type:') + .setTitle(`You have **${levelWord}** seconds to type:`) .setDescription(randomSentence); await message.channel.sendEmbed(embed).then(() => { message.channel.awaitMessages(response => response.content === randomSentence && response.author.id === message.author.id, {