From fc5c0239ad7cab6c137e1b38f28851251542ff77 Mon Sep 17 00:00:00 2001 From: dennisrijsdijk Date: Wed, 25 Dec 2024 15:42:38 +0100 Subject: [PATCH] feat: allow showing correct trivia question on incorrect answer Co-authored-by: ProditorMagnus --- src/backend/games/builtin/trivia/trivia-command.js | 9 +++++---- src/backend/games/builtin/trivia/trivia.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/games/builtin/trivia/trivia-command.js b/src/backend/games/builtin/trivia/trivia-command.js index 8fba1d159..443bd9ebe 100644 --- a/src/backend/games/builtin/trivia/trivia-command.js +++ b/src/backend/games/builtin/trivia/trivia-command.js @@ -38,7 +38,7 @@ twitchListeners.events.on("chat-message", async (data) => { if (!currentQuestion) { return; } - const { username, question, wager, winningsMultiplier, currencyId, chatter } = currentQuestion; + const { username, question, wager, winningsMultiplier, currencyId, chatter, postCorrectAnswer } = currentQuestion; //ensure chat is from question user if (username !== chatMessage.username) { return; @@ -69,12 +69,12 @@ twitchListeners.events.on("chat-message", async (data) => { await twitchChat.sendChatMessage(`${chatMessage.userDisplayName ?? username}, that is correct! You have won ${util.commafy(winnings)} ${currency.name}`, null, chatter); } else { - await twitchChat.sendChatMessage(`Sorry ${chatMessage.userDisplayName ?? username}, that is incorrect. Better luck next time!`, null, chatter); + await twitchChat.sendChatMessage(`Sorry ${chatMessage.userDisplayName ?? username}, that is incorrect.${postCorrectAnswer ? ` The correct answer was ${question.answers[question.correctIndex - 1]}.` : ""} Better luck next time!`, null, chatter); } clearCurrentQuestion(); }); -const cooldownCache = new NodeCache({checkperiod: 5}); +const cooldownCache = new NodeCache({ checkperiod: 5 }); const TRIVIA_COMMAND_ID = "firebot:trivia"; @@ -237,7 +237,8 @@ const triviaCommand = { wager: wagerAmount, winningsMultiplier: winningsMultiplier, currencyId: currencyId, - chatter: chatter + chatter: chatter, + postCorrectAnswer: triviaSettings.settings.chatSettings.postCorrectAnswer }; const answerTimeout = triviaSettings.settings.questionSettings.answerTime; diff --git a/src/backend/games/builtin/trivia/trivia.js b/src/backend/games/builtin/trivia/trivia.js index d529158fd..79a591f4a 100644 --- a/src/backend/games/builtin/trivia/trivia.js +++ b/src/backend/games/builtin/trivia/trivia.js @@ -311,6 +311,16 @@ module.exports = { validation: { required: true } + }, + postCorrectAnswer: { + type: "boolean", + title: "Post Correct Answer", + tip: "Post the correct answer in chat if the viewer answered incorrectly.", + default: false, + sortRank: 3, + validation: { + required: true + } } } }