trivia: tldr, dont push into prod without testing

This commit is contained in:
Ayden Jahola 2024-09-06 00:22:36 +01:00
parent 4572fb18ed
commit a7255119f3
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -94,6 +94,9 @@ module.exports = {
const incorrectAnswers = triviaQuestion.incorrect_answers.map(decode); const incorrectAnswers = triviaQuestion.incorrect_answers.map(decode);
let allAnswers = [...incorrectAnswers, correctAnswer]; let allAnswers = [...incorrectAnswers, correctAnswer];
// Declare answerMap before any conditions
let answerMap = {};
// Handle True/False questions specifically // Handle True/False questions specifically
if (triviaQuestion.type === "boolean") { if (triviaQuestion.type === "boolean") {
// Always keep "True" as option 1 and "False" as option 2 // Always keep "True" as option 1 and "False" as option 2
@ -102,21 +105,13 @@ module.exports = {
// Shuffle answers for other types of questions // Shuffle answers for other types of questions
allAnswers = allAnswers.sort(() => Math.random() - 0.5); allAnswers = allAnswers.sort(() => Math.random() - 0.5);
// Create a mapping of numbers to answers // Assign the map without redeclaring
answerMap = allAnswers.reduce((map, answer, index) => { answerMap = allAnswers.reduce((map, answer, index) => {
map[index + 1] = answer; map[index + 1] = answer;
return map; return map;
}, {}); }, {});
} }
allAnswers = allAnswers.sort(() => Math.random() - 0.5); // Shuffle answers
// Create a mapping of numbers to answers
const answerMap = allAnswers.reduce((map, answer, index) => {
map[index + 1] = answer;
return map;
}, {});
// Create an embed with the trivia question and numbered options // Create an embed with the trivia question and numbered options
const triviaEmbed = new EmbedBuilder() const triviaEmbed = new EmbedBuilder()
.setColor("#0099ff") .setColor("#0099ff")