From e22935532216595ff15d1deec155dd6cc0874e64 Mon Sep 17 00:00:00 2001 From: choelzl Date: Mon, 14 Feb 2022 17:56:00 +0100 Subject: [PATCH] WIP --- twitch/chatguessr.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/twitch/chatguessr.js b/twitch/chatguessr.js index 16bf58e..1073a42 100644 --- a/twitch/chatguessr.js +++ b/twitch/chatguessr.js @@ -120,6 +120,24 @@ })); } + function accGuesses(){ + var res = {}; + for(var rr = 0; rr < guesses.round; ++rr){ + for(var s = 0; s < guesses[rr].length; ++s){ + if(!res[guesses[rr][s].user]){ + res[guesses[rr][s].user] = {score:0,distance:0} + } + res[guesses[rr][s].user].score += guessses[rr][s].score + res[guesses[rr][s].user].distance += guessses[rr][s].distance + } + } + return Object.keys(res).map(k => { + let v = res[k] + v.user = k; + return v; + }); + } + $.bind('command', function(event) { const sender = event.getSender().toLowerCase(), command = event.getCommand(), @@ -159,8 +177,9 @@ addGuess($.channelName,gp); }else if(newseed.state=="finished"){ $.setIniDbBoolean('chatguessr', 'isOpen',false) //FINISHED - //Compute total scores + give reward seed = newseed; + guesses.final = accGuesses() + //Compute total scores + give reward sendGuessData(); }else{ $.setIniDbBoolean('chatguessr', 'isOpen',true) //NEW ROUD /Guess