Would You Rather like WYPTB

This commit is contained in:
Dragon Fire
2020-11-07 11:34:55 -05:00
parent 0da8578f09
commit 56bdbf033a
4 changed files with 69 additions and 37 deletions
+1 -1
View File
@@ -358,7 +358,6 @@ Total: 555
* **the-onion:** Responds with a random "The Onion" article.
* **this-for-that:** So, basically, it's like a bot command for this dumb meme.
* **word:** Responds with a random word.
* **would-you-rather:** Responds with a random "Would you rather ...?" question.
* **xiao-fact:** Responds with a random fact about Xiao.
### Random Image:
@@ -580,6 +579,7 @@ Total: 555
* **whos-that-pokemon-cry:** Guess who that Pokémon is, based on their cry.
* **whos-that-pokemon:** Guess who that Pokémon is, based on their silhouette.
* **will-you-press-the-button:** Responds with a random "Will You Press The Button?" dilemma.
* **would-you-rather:** Responds with a random "Would you rather ...?" question.
### Multi-Player Games:
+67
View File
@@ -0,0 +1,67 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { stripIndents } = require('common-tags');
const choices = ['1', '2'];
module.exports = class WouldYouRatherCommand extends Command {
constructor(client) {
super(client, {
name: 'would-you-rather',
aliases: ['wy-rather', 'wyr'],
group: 'games-sp',
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 current = this.client.games.get(msg.channel.id);
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
this.client.games.set(msg.channel.id, { name: this.name });
try {
const data = await this.fetchScenario();
await msg.say(stripIndents`
${data.prefix ? `${data.prefix}, would you rather...` : 'Would you rather...'}
**1.** ${data.option_1}
**2.** ${data.option_2}
_Respond with either **1** or **2** to continue._
`);
const filter = res => res.author.id === msg.author.id && choices.includes(res.content.toLowerCase());
const msgs = await msg.channel.awaitMessages(filter, {
time: 30000,
max: 1
});
if (!msgs.size) {
this.client.games.delete(msg.channel.id);
return msg.reply(stripIndents`
No response? Too bad.
1 ${formatNumber(data.option1_total)} - ${formatNumber(data.option2_total)} 2
`);
}
const option1 = msgs.first().content.toLowerCase() === '1';
const totalVotes = Number.parseInt(data.option1_total, 10) + Number.parseInt(data.option2_total, 10);
const numToUse = option1 ? Number.parseInt(data.option1_total, 10) : Number.parseInt(data.option2_total, 10);
this.client.games.delete(msg.channel.id);
return msg.reply(stripIndents`
**${Math.round((numToUse / totalVotes) * 100)}%** of people agree!
1 ${formatNumber(data.option1_total)} - ${formatNumber(data.option2_total)} 2
`);
} catch (err) {
this.client.games.delete(msg.channel.id);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async fetchScenario() {
const { text } = await request.get('http://either.io/');
return JSON.parse(text.match(/window.initial_question = (\{.+\})/)[1]).question;
}
};
-35
View File
@@ -1,35 +0,0 @@
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;
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.38.2",
"version": "119.39.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {