This commit is contained in:
Daniel Odendahl Jr
2017-10-03 20:10:46 +00:00
parent 89d13ece2a
commit 2709679bb0
2 changed files with 11 additions and 58 deletions
@@ -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()) {
-51
View File
@@ -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!`);
}
}
};