mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Quiz Command
This commit is contained in:
@@ -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}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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!");
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user