[Discord, HQ] Add Split + Answer commands

This commit is contained in:
vilP1L
2019-05-30 19:12:26 -04:00
parent bc7c490c4a
commit 3756f9d71e
2 changed files with 28 additions and 2 deletions

View File

@@ -38,5 +38,5 @@ Orchard Bot + Trivia Emulator
- [X] CheckWeight
- [X] Eval
- [ ] Help
- [ ] S (Split)
- [ ] A (Answer)
- [X] S (Split)
- [X] A (Answer)

View File

@@ -70,6 +70,32 @@ client.on('message', async (msg) => {
canLife.forEach(c => c.useExtraLife());
msg.channel.send(`Used lives for \`${canLife.length}\` client(s)!`);
}
if (command === 's') {
if (!client.activeGames.includes('hq-trivia')) return msg.channel.send('No hq-trivia game is currently active.');
if (!args[0]) return msg.channel.send('No split choice was provided.');
if (Number.isNaN(Number(args[0]))) return msg.channel.send('An invalid split choice was provided.');
const choices = args[0].split('');
const counts = { 1: 0, 2: 0, 3: 0 };
for (let i = 0; i < choices.length; i += 1) counts[choices[i]] += 1;
const canAnswer = client.hqClients.filter(c => c.inTheGame);
const splitArr = [...canAnswer];
Object.keys(counts).forEach((c) => {
const percentage = counts[c] / choices.length;
const num = Math.round(canAnswer.length * percentage);
const clients = splitArr.slice(0, num <= splitArr.length ? num : splitArr.length);
clients.forEach(client => client.submitAnswer(Number(c) - 1));
msg.channel.send(`Went with option ${c} on ${clients.length} clients!`);
});
}
if (command === 'a') {
if (!client.activeGames.includes('hq-trivia')) return msg.channel.send('No hq-trivia game is currently active.');
if (!args[0]) return msg.channel.send('No answer choice was provided.');
if (Number.isNaN(Number(args[0]))) return msg.channel.send('An invalid answer choice was provided.');
if (Number(args[0]) > 3 || Number(args[0]) < 0) return msg.channel.send('An invalid answer choice was provided.');
const canAnswer = client.hqClients.filter(c => c.inTheGame);
canAnswer.forEach(c => c.submitAnswer(Number(args[0]) - 1));
msg.channel.send(`Went with option ${args[0]} on ${canAnswer.length} clients!`);
}
if (command === 'balance') {
const tokenFiles = listTokens();
const embed = new MessageEmbed()