mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +02:00
Post would-you-rather results
This commit is contained in:
@@ -48,6 +48,7 @@ module.exports = class WouldYouRatherCommand extends Command {
|
||||
`);
|
||||
}
|
||||
const option1 = msgs.first().content.toLowerCase() === '1';
|
||||
await this.postResponse(data.id, option1);
|
||||
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);
|
||||
@@ -65,4 +66,15 @@ module.exports = class WouldYouRatherCommand extends Command {
|
||||
const { text } = await request.get('http://either.io/');
|
||||
return JSON.parse(text.match(/window.initial_question = (\{.+\})/)[1]).question;
|
||||
}
|
||||
|
||||
async postResponse(id, bool) {
|
||||
try {
|
||||
const { text } = await request
|
||||
.get(`http://either.io/vote/${id}/${bool ? '1' : '2'}`)
|
||||
.set({ 'X-Requested-With': 'XMLHttpRequest' });
|
||||
return JSON.parse(text).result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user