mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 15:57:54 +02:00
True or False split from quiz
This commit is contained in:
@@ -256,7 +256,7 @@ in the appropriate channel's topic to use it.
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
Total: 541
|
Total: 542
|
||||||
|
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
@@ -564,6 +564,7 @@ Total: 541
|
|||||||
* **slots:** Play a game of slots.
|
* **slots:** Play a game of slots.
|
||||||
* **sorting-hat:** Take a quiz to determine your Hogwarts house.
|
* **sorting-hat:** Take a quiz to determine your Hogwarts house.
|
||||||
* **the-game:** If you think about the game, you lose.
|
* **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.
|
* **typing-test:** See how fast you can type a sentence in a given time limit.
|
||||||
* **waldo:** Try to find Waldo with spoiler tags!
|
* **waldo:** Try to find Waldo with spoiler tags!
|
||||||
* **whos-that-pokemon:** Guess who that Pokémon is.
|
* **whos-that-pokemon:** Guess who that Pokémon is.
|
||||||
@@ -1413,6 +1414,7 @@ here.
|
|||||||
* lie-swatter ([API](https://opentdb.com/api_config.php))
|
* lie-swatter ([API](https://opentdb.com/api_config.php))
|
||||||
* quiz ([API](https://opentdb.com/api_config.php))
|
* quiz ([API](https://opentdb.com/api_config.php))
|
||||||
* quiz-duel ([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/)
|
- [OpenWeatherMap](https://openweathermap.org/)
|
||||||
* weather ([API](https://openweathermap.org/api))
|
* weather ([API](https://openweathermap.org/api))
|
||||||
- [OPTIFONT](http://opti.netii.net/)
|
- [OPTIFONT](http://opti.netii.net/)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const Command = require('../../structures/Command');
|
|||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const { shuffle, list } = require('../../util/Util');
|
const { shuffle, list } = require('../../util/Util');
|
||||||
const types = ['multiple', 'boolean'];
|
|
||||||
const difficulties = ['easy', 'medium', 'hard'];
|
const difficulties = ['easy', 'medium', 'hard'];
|
||||||
const choices = ['A', 'B', 'C', 'D'];
|
const choices = ['A', 'B', 'C', 'D'];
|
||||||
|
|
||||||
@@ -14,10 +13,7 @@ module.exports = class QuizCommand extends Command {
|
|||||||
group: 'games-sp',
|
group: 'games-sp',
|
||||||
memberName: 'quiz',
|
memberName: 'quiz',
|
||||||
description: 'Answer a quiz question.',
|
description: 'Answer a quiz question.',
|
||||||
details: stripIndents`
|
details: `**Difficulties:** ${difficulties.join(', ')}`,
|
||||||
**Types:** ${types.join(', ')}
|
|
||||||
**Difficulties:** ${difficulties.join(', ')}
|
|
||||||
`,
|
|
||||||
credit: [
|
credit: [
|
||||||
{
|
{
|
||||||
name: 'Open Trivia DB',
|
name: 'Open Trivia DB',
|
||||||
@@ -27,14 +23,6 @@ module.exports = class QuizCommand extends Command {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
args: [
|
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',
|
key: 'difficulty',
|
||||||
prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`,
|
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 {
|
try {
|
||||||
const { body } = await request
|
const { body } = await request
|
||||||
.get('https://opentdb.com/api.php')
|
.get('https://opentdb.com/api.php')
|
||||||
.query({
|
.query({
|
||||||
amount: 1,
|
amount: 1,
|
||||||
type,
|
type: 'multiple',
|
||||||
encode: 'url3986',
|
encode: 'url3986',
|
||||||
difficulty
|
difficulty
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "119.24.3",
|
"version": "119.25.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user