mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 06:37:32 +02:00
Clean-Ups
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class BattleCommand extends Command {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class LotteryCommand extends Command {
|
||||
constructor(client) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const math = require('mathjs');
|
||||
const operations = ['+', '-', '*'];
|
||||
@@ -10,6 +10,7 @@ module.exports = class MathGameCommand extends Command {
|
||||
group: 'games',
|
||||
memberName: 'math-game',
|
||||
description: 'See how fast you can answer a math problem in a given time limit.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'difficulty',
|
||||
@@ -26,9 +27,6 @@ module.exports = class MathGameCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, args) {
|
||||
if (msg.channel.type !== 'dm')
|
||||
if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { difficulty } = args;
|
||||
const operation = operations[Math.floor(Math.random() * operations.length)];
|
||||
let value;
|
||||
@@ -50,22 +48,21 @@ module.exports = class MathGameCommand extends Command {
|
||||
break;
|
||||
}
|
||||
const expression = `${Math.floor(Math.random() * value) + 1} ${operation} ${Math.floor(Math.random() * value) + 1}`;
|
||||
const solved = math.eval(expression).toString();
|
||||
const answer = math.eval(expression).toString();
|
||||
const embed = new RichEmbed()
|
||||
.setTitle('You have **10** seconds to answer:')
|
||||
.setDescription(expression);
|
||||
msg.embed(embed);
|
||||
await msg.embed(embed);
|
||||
try {
|
||||
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
||||
max: 1,
|
||||
time: 10000,
|
||||
errors: ['time']
|
||||
});
|
||||
if (collected.first().content !== solved)
|
||||
return msg.say(`Nope! The correct answer is: ${solved}.`);
|
||||
return msg.say(`Perfect! ${solved} is the correct answer!`);
|
||||
if (collected.first().content !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
|
||||
return msg.say('Nice job! 10/10! You deserve some cake!');
|
||||
} catch (err) {
|
||||
return msg.say(`Time! The correct answer is ${solved}.`);
|
||||
return msg.say(`Time! It was ${answer}, sorry!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const snekfetch = require('snekfetch');
|
||||
@@ -10,14 +10,12 @@ module.exports = class QuizCommand extends Command {
|
||||
aliases: ['jeopardy'],
|
||||
group: 'games',
|
||||
memberName: 'quiz',
|
||||
description: 'Answer a quiz question.'
|
||||
description: 'Answer a quiz question.',
|
||||
clientPermissions: ['EMBED_LINKS']
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
if (msg.channel.type !== 'dm')
|
||||
if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get('https://opentdb.com/api.php')
|
||||
@@ -33,15 +31,14 @@ module.exports = class QuizCommand extends Command {
|
||||
**${decodeURIComponent(body.results[0].category)}**
|
||||
True or False: ${decodeURIComponent(body.results[0].question)}
|
||||
`);
|
||||
msg.embed(embed);
|
||||
await msg.embed(embed);
|
||||
try {
|
||||
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
||||
max: 1,
|
||||
time: 15000,
|
||||
errors: ['time']
|
||||
});
|
||||
if (collected.first().content.toLowerCase() !== answer)
|
||||
return msg.say(`Nope, sorry, it\'s ${answer}.`);
|
||||
if (collected.first().content.toLowerCase() !== answer) return msg.say(`Nope, sorry, it's ${answer}.`);
|
||||
return msg.say('Nice job! 10/10! You deserve some cake!');
|
||||
} catch (err) {
|
||||
return msg.say(`Time! It was ${answer}, sorry!`);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
const responses = ['Paper', 'Rock', 'Scissors'];
|
||||
|
||||
module.exports = class RockPaperScissorsCommand extends Command {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const slotThing = [':grapes:', ':tangerine:', ':pear:', ':cherries:'];
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Command = require('../../structures/Command');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const sentences = require('../../assets/json/typing-game');
|
||||
|
||||
@@ -9,6 +9,7 @@ module.exports = class TypingGameCommand extends Command {
|
||||
group: 'games',
|
||||
memberName: 'typing-game',
|
||||
description: 'See how fast you can type a sentence in a given time limit.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'difficulty',
|
||||
@@ -25,9 +26,6 @@ module.exports = class TypingGameCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, args) {
|
||||
if (msg.channel.type !== 'dm')
|
||||
if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { difficulty } = args;
|
||||
const sentence = sentences[Math.floor(Math.random() * sentences.length)];
|
||||
let time;
|
||||
@@ -51,18 +49,17 @@ module.exports = class TypingGameCommand extends Command {
|
||||
const embed = new RichEmbed()
|
||||
.setTitle(`You have **${time / 1000}** seconds to type:`)
|
||||
.setDescription(sentence);
|
||||
msg.embed(embed);
|
||||
await msg.embed(embed);
|
||||
try {
|
||||
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
||||
max: 1,
|
||||
time: time,
|
||||
errors: ['time']
|
||||
});
|
||||
if (collected.first().content !== sentence)
|
||||
return msg.say('Nope, your sentence does not match the original. Try again next time!');
|
||||
if (collected.first().content !== sentence) return msg.say('Nope, sorry!');
|
||||
return msg.say(`Good Job! You won!`);
|
||||
} catch (err) {
|
||||
return msg.say('Time! Try again next time!');
|
||||
return msg.say('Time! Sorry!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user