mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 06:10:49 +02:00
Fix willyoupressthebutton
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const cheerio = require('cheerio');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { verify } = require('../../util/Util');
|
||||
|
||||
module.exports = class WillYouPressTheButtonCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -14,7 +15,7 @@ module.exports = class WillYouPressTheButtonCommand extends Command {
|
||||
{
|
||||
name: 'Will You Press The Button?',
|
||||
url: 'https://willyoupressthebutton.com/',
|
||||
reason: 'Dilemma Data'
|
||||
reason: 'API'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -22,13 +23,36 @@ module.exports = class WillYouPressTheButtonCommand extends Command {
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { text } = await request.get('https://willyoupressthebutton.com/');
|
||||
const $ = cheerio.load(text, { normalizeWhitespace: true });
|
||||
const cond = $('div[id="cond"]').first().text().trim();
|
||||
const res = $('div[id="res"]').first().text().trim();
|
||||
return msg.say(`**${cond}** but **${res}**`);
|
||||
const dilemma = await this.fetchDilemma();
|
||||
await msg.reply(stripIndents`
|
||||
**${dilemma.txt1}** but **${dilemma.txt2}**. Will you press the button?
|
||||
_Respond with [y]es or [n]o to continue._
|
||||
`);
|
||||
const verification = await verify(msg.channel, msg.author);
|
||||
if (!verification) return msg.reply('No response? Too bad.');
|
||||
await this.postResponse(dilemma.id, verification);
|
||||
const totalVotes = dilemma.yes + dilemma.no;
|
||||
return msg.reply(stripIndents`
|
||||
**${Math.round(((verification ? dilemma.yes : dilemma.no) / totalVotes) * 100)}%** of people agree!
|
||||
Yes ${dilemma.yes} - ${dilemma.no} No
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async fetchDilemma() {
|
||||
const { body } = await request.post('https://api2.willyoupressthebutton.com/api/v2/dilemma/');
|
||||
return body.dilemma;
|
||||
}
|
||||
|
||||
async postResponse(id, bool) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.post(`https://api2.willyoupressthebutton.com/api/v2/dilemma/${id}/${bool ? 'yes' : 'no'}`);
|
||||
return body.success;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "119.29.7",
|
||||
"version": "119.29.8",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user