[HQ, Config] Auto checkpoints, threshold changes

This commit is contained in:
vilP1L
2019-06-07 17:53:16 -04:00
parent 980c74f8f4
commit 67f01e80db
2 changed files with 21 additions and 11 deletions

View File

@@ -99,7 +99,7 @@
"hq": {
"autoSplit": true,
"splitThreshold": 0.65,
"autoCheckpoints": false,
"checkpointThreshold": 2
"autoCheckpoints": true,
"checkpointThreshold": 1
}
}

View File

@@ -144,19 +144,29 @@ export default async (client, prize) => {
});
}
if (json.type === 'checkpoint') {
const clientsRemaining = client.hqClients.filter(c => c.inTheGame).length;
const embed = new MessageEmbed()
.setTitle('Checkpoint')
.setDescription(`${json.prizeOffered} is being offered, would you like to accept the prize?`)
.setFooter(`${client.hqClients.filter(c => c.inTheGame).length} clients are still in.`);
.setTitle(`Checkpoint (Q ${json.questionNumber}/${json.questionCount})`)
.setDescription(`${json.prizeOffered} is being offered to ${json.playersRemaining} players`)
.setFooter(`${clientsRemaining} clients are still in`);
channels.forEach(async (c) => {
const m = await c.send(embed);
await m.react('✅');
const filter = (r, u) => r.emoji.name === '✅' && discord.admins.includes(u.id);
m.awaitReactions(filter, { time: 60000, max: 1, errors: ['time'] })
.then(async () => {
if (hq.autoCheckpoints) {
const checkpointPrize = Number(json.prizeOffered.replace('$', ''));
if (hq.checkpointThreshold >= checkpointPrize) {
if (clientsRemaining === 0) return;
client.hqClients.forEach(c => c.checkpoint(true));
channels.forEach(c => c.send(`Claimed ${json.prizeOffered} on ${client.hqClients.filter(c => c.inTheGame).length} clients!`));
}).catch(() => {});
channels.forEach(c => c.send(`Claimed ${json.prizeOffered} on ${clientsRemaining} clients!`));
}
} else {
await m.react('✅');
const filter = (r, u) => r.emoji.name === '✅' && discord.admins.includes(u.id);
m.awaitReactions(filter, { time: 60000, max: 1, errors: ['time'] })
.then(async () => {
client.hqClients.forEach(c => c.checkpoint(true));
channels.forEach(c => c.send(`Claimed ${json.prizeOffered} on ${clientsRemaining} clients!`));
}).catch(() => {});
}
});
}
});