diff --git a/commands/games/quiz.js b/commands/games/quiz.js index 5886bdd6..8604d488 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); +const { shuffle, list } = require('../../structures/Util'); module.exports = class QuizCommand extends Command { constructor(client) { @@ -38,20 +39,23 @@ module.exports = class QuizCommand extends Command { encode: 'url3986' }); if (!body.results) return msg.say('Oh no, a question could not be fetched. Try again later!'); - const answer = decodeURIComponent(body.results[0].correct_answer.toLowerCase()); + const answers = body.results[0].incorrect_answers.map(answer => decodeURIComponent(answer.toLowerCase())); + const correct = decodeURIComponent(body.results[0].correct_answer.toLowerCase()); + answers.push(correct); const embed = new MessageEmbed() .setTitle('You have 15 seconds to answer this question:') .setDescription(stripIndents` **${decodeURIComponent(body.results[0].category)}** - ${type === 'boolean' ? 'True or False: ' : ''}${decodeURIComponent(body.results[0].question)} + ${type === 'boolean' ? '**True or False:** ' : ''}${decodeURIComponent(body.results[0].question)} + ${type === 'multiple' ? `**Choices:** ${list(shuffle(answers), 'or')}` : ''} `); 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}.`); + if (!msgs.size) return msg.say(`Time! It was ${correct}, sorry!`); + if (msgs.first().content.toLowerCase() !== correct) return msg.say(`Nope, sorry, it's ${correct}.`); return msg.say('Nice job! 10/10! You deserve some cake!'); } }; diff --git a/commands/random-res/ship.js b/commands/random-res/ship.js index f5bf7ff7..d9ef64e6 100644 --- a/commands/random-res/ship.js +++ b/commands/random-res/ship.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { list } = require('../../structures/Util'); module.exports = class ShipCommand extends Command { constructor(client) { @@ -20,7 +21,6 @@ module.exports = class ShipCommand extends Command { run(msg, args) { const { things } = args; - const list = `${things.slice(0, -1).join(', ')}${things.length > 1 ? ' and ' : ''}${things.slice(-1)}`; - return msg.say(`I'd give ${list} a ${Math.floor(Math.random() * 100) + 1}%!`); + return msg.say(`I'd give ${list(things)} a ${Math.floor(Math.random() * 100) + 1}%!`); } }; diff --git a/structures/Util.js b/structures/Util.js index d709f2e2..46d67bf7 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -73,6 +73,10 @@ class Util { } return arr; } + + static list(arr, conj = 'and') { + return `${arr.slice(0, -1).join(', ')}${arr.length > 1 ? `${arr.length > 2 ? ',' : ''} ${conj} ` : ''}${arr.slice(-1)}`; // eslint-disable-line max-len + } } module.exports = Util;