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, });