mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 13:53:12 +02:00
Quiz Difficulty, Math Game Improvement, Better Today
This commit is contained in:
@@ -1,8 +1,25 @@
|
||||
{
|
||||
"operations": [
|
||||
"+",
|
||||
"-",
|
||||
"*"
|
||||
"operations": {
|
||||
"easy": [
|
||||
"+",
|
||||
"-"
|
||||
],
|
||||
"medium": [
|
||||
"+",
|
||||
"-"
|
||||
],
|
||||
"hard": [
|
||||
"-",
|
||||
"*"
|
||||
],
|
||||
"extreme": [
|
||||
"-",
|
||||
"*"
|
||||
],
|
||||
"impossible": [
|
||||
"*",
|
||||
"/"
|
||||
]
|
||||
],
|
||||
"difficulties": [
|
||||
"easy",
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = class MathGameCommand extends Command {
|
||||
|
||||
async run(msg, args) {
|
||||
const { difficulty } = args;
|
||||
const operation = operations[Math.floor(Math.random() * operations.length)];
|
||||
const operation = operations[difficulty][Math.floor(Math.random() * operations.length)];
|
||||
const value1 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
|
||||
const value2 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
|
||||
const expression = `${value1} ${operation} ${value2}`;
|
||||
|
||||
+15
-3
@@ -3,6 +3,7 @@ const { MessageEmbed } = require('discord.js');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shuffle, list } = require('../../structures/Util');
|
||||
const difficulties = ['easy', 'medium', 'hard'];
|
||||
|
||||
module.exports = class QuizCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -18,25 +19,36 @@ module.exports = class QuizCommand extends Command {
|
||||
key: 'type',
|
||||
prompt: 'Which type of question would you like to have? `multiple` or `boolean`.',
|
||||
type: 'string',
|
||||
default: 'boolean',
|
||||
validate: type => {
|
||||
if (['multiple', 'boolean'].includes(type.toLowerCase())) return true;
|
||||
return 'Please enter either `multiple` or `boolean`.';
|
||||
},
|
||||
parse: type => type.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'difficulty',
|
||||
prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`,
|
||||
type: 'string',
|
||||
default: '',
|
||||
validate: difficulty => {
|
||||
if (difficulties.includes(difficulty.toLowerCase())) return true;
|
||||
return `The difficulty must be one of: ${difficulties.join(', ')}`;
|
||||
},
|
||||
parse: difficulty => difficulty.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, args) {
|
||||
const { type } = args;
|
||||
const { type, difficulty } = args;
|
||||
const { body } = await snekfetch
|
||||
.get('https://opentdb.com/api.php')
|
||||
.query({
|
||||
amount: 1,
|
||||
type,
|
||||
encode: 'url3986'
|
||||
encode: 'url3986',
|
||||
difficulty
|
||||
});
|
||||
if (!body.results) return msg.say('Oh no, a question could not be fetched. Try again later!');
|
||||
const answers = body.results[0].incorrect_answers.map(answer => decodeURIComponent(answer.toLowerCase()));
|
||||
|
||||
@@ -13,34 +13,20 @@ module.exports = class TodayCommand extends Command {
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'month',
|
||||
prompt: 'Which month do you want events for?',
|
||||
type: 'integer',
|
||||
default: '',
|
||||
validate: month => {
|
||||
if (month < 13 && month > 0) return true;
|
||||
return 'Please enter a valid month.';
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'day',
|
||||
prompt: 'Which day do you want events for?',
|
||||
type: 'integer',
|
||||
default: '',
|
||||
validate: day => {
|
||||
if (day < 32 && day > 0) return true;
|
||||
return 'Please enter a valid day.';
|
||||
}
|
||||
key: 'date',
|
||||
prompt: 'What date do you want events for? Month/Day format.',
|
||||
type: 'string',
|
||||
default: ''
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, args) {
|
||||
const { month, day } = args;
|
||||
const { date } = args;
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get(`http://history.muffinlabs.com/date${month && day ? `/${month}/${day}` : ''}`);
|
||||
.get(`http://history.muffinlabs.com/date${date ? `/${date}` : ''}`);
|
||||
const body = JSON.parse(text);
|
||||
const events = body.data.Events;
|
||||
const event = events[Math.floor(Math.random() * events.length)];
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "31.1.2",
|
||||
"version": "31.1.3",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user