Fixed being able to score multiple points per round in Trivia timeout mode.

This commit is contained in:
ThePendulum 2022-01-10 23:42:17 +01:00
parent 556540e7ec
commit 6bc1048a90
1 changed files with 6 additions and 6 deletions

View File

@ -17,11 +17,11 @@ const help = {
let game = null; let game = null;
function scoreRound(context, round) { 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 `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) { if (user) {
context.setPoints(user, 1); context.setPoints(user, 1);
game.points[user.username] = (game.points[user.username] || 0) + 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 ac = new AbortController(); // eslint-disable-line no-undef
const now = new Date(); const now = new Date();
game.answers = []; game.answers = new Map();
game.round = round; game.round = round;
game.ac = ac; game.ac = ac;
@ -80,7 +80,7 @@ async function playRound(context, round = 0) {
return; 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); context.sendMessage(`**TIME'S UP!** No one guessed the answer: **${question.answer}**`, context.room.id);
} else { } else {
const scores = scoreRound(context, round); const scores = scoreRound(context, round);
@ -185,8 +185,8 @@ async function onMessage(message, context) {
const { answer, fullAnswer } = game.questions[game.round]; 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 & 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.push({ game.answers.set(context.user.id, {
user: context.user, user: context.user,
answer: message.body, answer: message.body,
}); });