Quiz Command

This commit is contained in:
Daniel Odendahl Jr
2017-03-23 20:51:39 +00:00
parent 22bf4e8d90
commit 1a6de84223
3 changed files with 51 additions and 2 deletions
+1 -1
View File
@@ -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}`);
});
});
}
+49
View File
@@ -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!");
});
});
}
};
+1 -1
View File
@@ -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, {