Post would-you-rather results

This commit is contained in:
Dragon Fire
2020-11-07 15:01:29 -05:00
parent 400cb51a93
commit 3d4221916d
2 changed files with 13 additions and 1 deletions
+12
View File
@@ -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;
}
}
};