From 6bc1048a90e0b03fba1721cba7d95fd58455aca1 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Mon, 10 Jan 2022 23:42:17 +0100 Subject: [PATCH] Fixed being able to score multiple points per round in Trivia timeout mode. --- src/games/trivia.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/games/trivia.js b/src/games/trivia.js index ce3e311..5564f7b 100644 --- a/src/games/trivia.js +++ b/src/games/trivia.js @@ -17,11 +17,11 @@ const help = { let game = null; function scoreRound(context, round) { - if (game.answers.length === 0) { + if (game.answers.size === 0) { return `No one scored in round ${round + 1}, better luck next time!`; } - return game.answers.map(({ user }) => { + return Array.from(game.answers.values()).map(({ user }) => { if (user) { context.setPoints(user, 1); game.points[user.username] = (game.points[user.username] || 0) + 1; @@ -37,7 +37,7 @@ async function playRound(context, round = 0) { const ac = new AbortController(); // eslint-disable-line no-undef const now = new Date(); - game.answers = []; + game.answers = new Map(); game.round = round; game.ac = ac; @@ -80,7 +80,7 @@ async function playRound(context, round = 0) { return; } - if (game.answers.length === 0) { + if (game.answers.size === 0) { context.sendMessage(`**TIME'S UP!** No one guessed the answer: **${question.answer}**`, context.room.id); } else { const scores = scoreRound(context, round); @@ -185,8 +185,8 @@ async function onMessage(message, context) { const { answer, fullAnswer } = game.questions[game.round]; - if (new RegExp(answer, 'i').test(decode(message.originalBody || message.body))) { // resolve HTML entities in case original body is not available, such as & to & - game.answers.push({ + if (new RegExp(answer, 'i').test(decode(message.originalBody || message.body)) && !game.answers.has(context.user.id)) { // resolve HTML entities in case original body is not available, such as & to & + game.answers.set(context.user.id, { user: context.user, answer: message.body, });