True or False split from quiz

This commit is contained in:
Dragon Fire
2020-09-15 15:49:00 -04:00
parent 8372c0e568
commit 211cbc2cb8
4 changed files with 81 additions and 17 deletions
+3 -1
View File
@@ -256,7 +256,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 541
Total: 542
### Utility:
@@ -564,6 +564,7 @@ Total: 541
* **slots:** Play a game of slots.
* **sorting-hat:** Take a quiz to determine your Hogwarts house.
* **the-game:** If you think about the game, you lose.
* **true-or-false:** Answer a true or false question.
* **typing-test:** See how fast you can type a sentence in a given time limit.
* **waldo:** Try to find Waldo with spoiler tags!
* **whos-that-pokemon:** Guess who that Pokémon is.
@@ -1413,6 +1414,7 @@ here.
* lie-swatter ([API](https://opentdb.com/api_config.php))
* quiz ([API](https://opentdb.com/api_config.php))
* quiz-duel ([API](https://opentdb.com/api_config.php))
* true-or-false ([API](https://opentdb.com/api_config.php))
- [OpenWeatherMap](https://openweathermap.org/)
* weather ([API](https://openweathermap.org/api))
- [OPTIFONT](http://opti.netii.net/)
+3 -15
View File
@@ -2,7 +2,6 @@ const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const request = require('node-superfetch');
const { shuffle, list } = require('../../util/Util');
const types = ['multiple', 'boolean'];
const difficulties = ['easy', 'medium', 'hard'];
const choices = ['A', 'B', 'C', 'D'];
@@ -14,10 +13,7 @@ module.exports = class QuizCommand extends Command {
group: 'games-sp',
memberName: 'quiz',
description: 'Answer a quiz question.',
details: stripIndents`
**Types:** ${types.join(', ')}
**Difficulties:** ${difficulties.join(', ')}
`,
details: `**Difficulties:** ${difficulties.join(', ')}`,
credit: [
{
name: 'Open Trivia DB',
@@ -27,14 +23,6 @@ module.exports = class QuizCommand extends Command {
}
],
args: [
{
key: 'type',
prompt: `Which type of question would you like to have? Either ${list(types, 'or')}.`,
type: 'string',
default: 'multiple',
oneOf: types,
parse: type => type.toLowerCase()
},
{
key: 'difficulty',
prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`,
@@ -47,13 +35,13 @@ module.exports = class QuizCommand extends Command {
});
}
async run(msg, { type, difficulty }) {
async run(msg, { difficulty }) {
try {
const { body } = await request
.get('https://opentdb.com/api.php')
.query({
amount: 1,
type,
type: 'multiple',
encode: 'url3986',
difficulty
});
+74
View File
@@ -0,0 +1,74 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const request = require('node-superfetch');
const { list } = require('../../util/Util');
const difficulties = ['easy', 'medium', 'hard'];
const trueAns = ['true', 't', 'tru', 'yes', 'y'];
const falseAns = ['false', 'f', 'no', 'n'];
module.exports = class TrueOrFalseCommand extends Command {
constructor(client) {
super(client, {
name: 'true-or-false',
aliases: ['true-false', 'tf', 'quiz-boolean'],
group: 'games-sp',
memberName: 'true-or-false',
description: 'Answer a true or false question.',
details: `**Difficulties:** ${difficulties.join(', ')}`,
credit: [
{
name: 'Open Trivia DB',
url: 'https://opentdb.com/',
reason: 'API',
reasonURL: 'https://opentdb.com/api_config.php'
}
],
args: [
{
key: 'difficulty',
prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`,
type: 'string',
default: '',
oneOf: difficulties,
parse: difficulty => difficulty.toLowerCase()
}
]
});
}
async run(msg, { difficulty }) {
try {
const { body } = await request
.get('https://opentdb.com/api.php')
.query({
amount: 1,
type: 'boolean',
encode: 'url3986',
difficulty
});
if (!body.results) return msg.reply('Oh no, a question could not be fetched. Try again later!');
const correct = decodeURIComponent(body.results[0].correct_answer.toLowerCase());
const correctBool = correct === 'true';
await msg.reply(stripIndents`
**You have 15 seconds to answer this question.**
${decodeURIComponent(body.results[0].question)}
**[T]rue or [F]alse?**
`);
const filter = res => {
if (res.author.id !== msg.author.id) return false;
return trueAns.includes(res.content.toUpperCase()) || falseAns.includes(res.content.toUpperCase());
}
const msgs = await msg.channel.awaitMessages(filter, {
max: 1,
time: 15000
});
if (!msgs.size) return msg.reply(`Sorry, time is up! It was ${correctBool}.`);
const ans = msgs.first().content.toLowerCase();
const ansBool = trueAns.includes(ans);
if (correctBool !== ansBool) return msg.reply(`Nope, sorry, it's ${correctBool}.`);
return msg.reply('Nice job! 10/10! You deserve some cake!');
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.24.3",
"version": "119.25.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {