Files
xiao/commands/random-res/would-you-rather.js
T
2020-09-07 16:41:10 -04:00

36 lines
964 B
JavaScript

const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { stripIndents } = require('common-tags');
module.exports = class WouldYouRatherCommand extends Command {
constructor(client) {
super(client, {
name: 'would-you-rather',
aliases: ['wy-rather', 'wyr'],
group: 'random-res',
memberName: 'would-you-rather',
description: 'Responds with a random "Would you rather ...?" question.',
credit: [
{
name: 'either',
url: 'http://either.io',
reason: 'API'
}
]
});
}
async run(msg) {
const data = await this.fetchScenario();
return msg.say(stripIndents`
${data.prefix ? `${data.prefix}, would you rather...` : 'Would you rather...'}
**${data.option_1}** or **${data.option_2}**
`);
}
async fetchScenario() {
const { text } = await request.get('http://either.io/');
return JSON.parse(text.match(/window.initial_question = (\{.+\})/)[1]).question;
}
};