From 14296fb3a81a0bcee8741f6ed8e1eb75bebe8ae6 Mon Sep 17 00:00:00 2001 From: vilP1L Date: Mon, 10 Jun 2019 22:43:19 -0400 Subject: [PATCH] [HQ, Config] Auto split enhancements + more hq config --- README.md | 2 +- config.json | 6 ++++-- src/modules/hq-discord.js | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9f3555e..12528aa 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Wilder Emu Bot + Trivia Emulator - [X] Checkpoint Support (HQ) - [X] Auto Checkpoint Claiming - [X] Auto Splitting -- [ ] Auto Split Enhancements (split on last q, prize qs, etc) +- [X] Auto Split Enhancements (split on last q, prize qs, etc) ### Discord Bot Commands diff --git a/config.json b/config.json index dfeadfd..004530e 100644 --- a/config.json +++ b/config.json @@ -80,10 +80,10 @@ ] }, "mongo": { - "dbName": "weights", "user": "mongoadmin", "pass": "torchard#", - "host": "skysilk.vilp1l.dev" + "host": "skysilk.vilp1l.dev", + "dbName": "weights" }, "proxy": { "user": "grbyzyjh", @@ -98,6 +98,8 @@ }, "hq": { "autoSplit": true, + "autoSplitOnPrizeQuestions": true, + "autoSplitOnLastQuestion": true, "splitThreshold": 0.65, "autoCheckpoints": true, "checkpointThreshold": 1 diff --git a/src/modules/hq-discord.js b/src/modules/hq-discord.js index 66e3f86..530d26c 100644 --- a/src/modules/hq-discord.js +++ b/src/modules/hq-discord.js @@ -78,7 +78,16 @@ export default async (client, prize) => { const bestAnswerPercentage = client.weights.hq[bestAnswer] / total; const canAnswer = client.hqClients.filter(c => c.inTheGame); const splitArr = [...canAnswer]; - if ((bestAnswerPercentage < hq.splitThreshold) && hq.autoSplit) { + // eslint-disable-next-line max-len + const splitLastQ = hq.autoSplitOnLastQuestion && json.questionNumber === json.questionCount; + const splitOnPrizeQ = hq.autoSplitOnPrizeQuestions && !json.nextCheckpointIn; + if (splitOnPrizeQ || splitLastQ) { + for (let i = 0; i < 3; i += 1) { + const num = Math.round(canAnswer / 3); + const clients = splitArr.slice(0, num <= splitArr.length ? num : splitArr.length); + clients.forEach(c => c.submitAnswer(i)); + } + } else if ((bestAnswerPercentage < hq.splitThreshold) && hq.autoSplit) { client.weights.hq.forEach((w, i) => { const percentage = w / total; const num = Math.round(canAnswer.length * percentage);