From 2709679bb051eb987175885b1d7cfed338ee44bc Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 3 Oct 2017 20:10:46 +0000 Subject: [PATCH] Beep --- .../games/{quizlet-game.js => quizlet.js} | 18 ++++--- commands/search/quizlet.js | 51 ------------------- 2 files changed, 11 insertions(+), 58 deletions(-) rename commands/games/{quizlet-game.js => quizlet.js} (84%) delete mode 100644 commands/search/quizlet.js diff --git a/commands/games/quizlet-game.js b/commands/games/quizlet.js similarity index 84% rename from commands/games/quizlet-game.js rename to commands/games/quizlet.js index f9b7ee69..e6725111 100644 --- a/commands/games/quizlet-game.js +++ b/commands/games/quizlet.js @@ -7,11 +7,11 @@ const { QUIZLET_KEY } = process.env; module.exports = class QuizletGameCommand extends Command { constructor(client) { super(client, { - name: 'quizlet-game', - aliases: ['quizlet-quiz', 'quizlet-test'], + name: 'quizlet', + aliases: ['quizlet-game', 'quizlet-quiz', 'quizlet-test'], group: 'games', - memberName: 'quizlet-game', - description: 'Shuffle a Quizlet study deck and play a game similar to a quiz.', + memberName: 'quizlet', + description: 'Shuffle a Quizlet study set and play a game similar to a quiz.', args: [ { key: 'id', @@ -26,7 +26,7 @@ module.exports = class QuizletGameCommand extends Command { } async run(msg, { id }) { - if (this.playing.has(msg.channel.id)) return msg.say('Only one fight may be occurring per channel.'); + if (this.playing.has(msg.channel.id)) return msg.say('Only one game may be occurring per channel.'); this.playing.add(msg.channel.id); try { const { body } = await snekfetch @@ -38,13 +38,17 @@ module.exports = class QuizletGameCommand extends Command { const term = terms[0]; await msg.say(stripIndents` **You have 30 seconds to answer which word this is. (type "end game" to end the game)** - ${term.definition}${term.image ? `\n${term.image.url}` : ''} + ${term.definition} + ${term.image ? term.image.url : ''} `); const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: 30000 }); - if (!msgs.size) break; + if (!msgs.size) { + await msg.say('Time!'); + break; + } const choice = msgs.first().content.toLowerCase(); if (choice === 'end game') break; if (choice !== term.term.toLowerCase()) { diff --git a/commands/search/quizlet.js b/commands/search/quizlet.js deleted file mode 100644 index 75e323a4..00000000 --- a/commands/search/quizlet.js +++ /dev/null @@ -1,51 +0,0 @@ -const { Command } = require('discord.js-commando'); -const { MessageEmbed } = require('discord.js'); -const snekfetch = require('snekfetch'); -const { QUIZLET_KEY } = process.env; - -module.exports = class QuizletCommand extends Command { - constructor(client) { - super(client, { - name: 'quizlet', - aliases: ['quizlet-set'], - group: 'search', - memberName: 'quizlet', - description: 'Searches Quizlet for study sets.', - clientPermissions: ['EMBED_LINKS'], - args: [ - { - key: 'query', - prompt: 'What study set would you like to search for?', - type: 'string' - } - ] - }); - } - - async run(msg, { query }) { - try { - const { body } = await snekfetch - .get('https://api.quizlet.com/2.0/search/sets') - .query({ - q: query, - client_id: QUIZLET_KEY - }); - if (!body.sets.length) return msg.say('Could not find any results.'); - const data = body.sets[0]; - const embed = new MessageEmbed() - .setAuthor('Quizlet', 'https://i.imgur.com/mUvSPJn.png') - .setColor(0x4257B2) - .setURL(`https://quizlet.com${data.url}`) - .setTitle(data.title) - .addField('❯ Creator', - data.created_by, true) - .addField('❯ ID', - data.id, true) - .addField('❯ Term Count', - data.term_count, true); - return msg.embed(embed); - } catch (err) { - return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -};