New Would You Rather API

This commit is contained in:
Dragon Fire
2020-09-07 16:41:10 -04:00
parent b807b762c6
commit 5f8719914e
3 changed files with 12 additions and 14 deletions
+9 -11
View File
@@ -12,26 +12,24 @@ module.exports = class WouldYouRatherCommand extends Command {
description: 'Responds with a random "Would you rather ...?" question.',
credit: [
{
name: 'rrrather',
url: 'https://www.rrrather.com/',
reason: 'API',
reasonURL: 'https://www.rrrather.com/botapi'
name: 'either',
url: 'http://either.io',
reason: 'API'
}
]
});
}
async run(msg) {
const data = await this.fetchScenario(msg.channel.nsfw || false);
const data = await this.fetchScenario();
return msg.say(stripIndents`
${data.title}
**${data.choicea}** or **${data.choiceb}**
${data.prefix ? `${data.prefix}, would you rather...` : 'Would you rather...'}
**${data.option_1}** or **${data.option_2}**
`);
}
async fetchScenario(nsfw) {
const { body } = await request.get('https://www.rrrather.com/botapi');
if (body.nsfw && !nsfw) return this.fetchScenario(nsfw);
return body;
async fetchScenario() {
const { text } = await request.get('http://either.io/');
return JSON.parse(text.match(/window.initial_question = (\{.+\})/)[1]).question;
}
};