Discord-Trivia-Bot
Discord-Trivia-Bot copied to clipboard
feat(answers): ignore incorrect_answers if there isn't
Fix https://github.com/LakeYS/Discord-Trivia-Bot/issues/247
Can you send a working config? I receive this error when running under a default configuration, with the incorrect_answers field removed from a category.
TypeError: Cannot read property '0' of null
at FileDB.validateQuestion (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\database\filedb.js:74:80)
at FileDB.updateGlobals (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\database\filedb.js:121:16)
at new TriviaDiscord (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\platform\discord_main.js:82:19)
at Object.<anonymous> (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\platform\discord_shard.js:20:30)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
And this error after enabling database-allow-long-answers
TypeError: Cannot read property 'length' of null
at C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\database\filedb.js:310:59
at Array.forEach (<anonymous>)
at FileDB.fetchQuestions (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\database\filedb.js:307:27)
at async TriviaDiscord.getTriviaQuestion (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\platform\discord_main.js:429:16)
at async HangmanGame.initializeRound (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game.js:231:18)
{}
I shared the questions on the support channel on discord in a zip few days ago.
{
"use-reactions": false,
"hangman-mode": true,
"hangman-hints": true,
"hide-difficulty": true,
"auto-delete-msgs": false,
"auto-delete-msgs-timer": 25000,
"auto-delete-answers": false,
"auto-delete-answers-timer": 0,
"round-length": 15000,
"round-timeout": 4000,
"round-end-warnings-disabled": false,
"rounds-end-after": 2,
"use-fixed-rounds": false,
"rounds-fixed-number": 15,
"disable-score-display": false,
"score-value": { "medium": 1 },
"score-multiplier-max": 2,
"command-whitelist": [],
"accept-first-answer-only": true,
"reveal-answers": true,
"participant-role-name": "Giocatore Trivia",
"prefix": "trivia ",
"allow-eval": false,
"shard-count": "auto",
"disable-admin-commands": false,
"disable-version-check": false,
"allow-bots": false,
"databaseURL": "file://./Domande",
"database-merge": false,
"database-cache-size": 50,
"database-allow-long-answers": false,
"stat-file": "./stats.json",
"stat-guild-recording": false,
"embed-color": "006CFF",
"channel-whitelist": ["trivia"],
"config-commands-enabled": false,
"additional-packages": [],
"additional-packages-root": [],
"debug-mode": false,
"debug-log": false,
"debug-database-flush": false,
"display-ascii-logo": false,
"fallback-mode": false,
"fallback-silent": false,
"fallback-exceptions": [],
"fallback-intents": false,
"enable-listings": false,
"listing-tokens": {
"discord.bots.gg": "optionaltokenhere",
"discords.com": "optionaltokenhere",
"discordlist.space": "optionaltokenhere",
"top.gg": "optionaltokenhere"
}
}
A question example:
questions:
- question: Assassinio allo...
correct_answer: specchio
difficulty: medium
- question: Assassinio sull'Orient...
correct_answer: Express
difficulty: medium
- question: Avversario...
correct_answer: segreto
difficulty: medium
- question: Carte in...
correct_answer: tavola
difficulty: medium
This appears to conflict with other configurations. We will need some sort of handling for the following:
- Making admins aware that once they set up questions without incorrect answers, they're stuck using hangman mode unless they go back and add incorrect answers. This will likely be a given for many, but it's best to make it as clear as possible. Similar handling to
database-allow-long-answers
being opt-in with ample warning in the documentation. - Handling for configurations (incl. standard multiple-choice games) where the bot can't use the questions missing incorrect answers. We can either error out entirely, or try to filter these questions out, which would display the "No questions available under the current configuration" error if all of the questions are missing incorrect answers.
Some examples of results of the conflict: Using the attached config, type "trivia play advanced 1 r 1 1 h'. Results in the following error:
C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game.js:135
answers[i] = answers[i].toString();
^
TypeError: Cannot read property 'toString' of undefined
at Game.buildAnswers (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game.js:135:31)
at Game.initializeRound (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game.js:291:29)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Using the attached config, but with hangman-mode set to false:
Failed to initialize the database. Errors may occur when attempting to start a game. The following error has occurred:
TypeError: Cannot read property '0' of undefined
at FileDB.validateQuestion (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\database\filedb.js:74:80)
at FileDB.updateGlobals (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\database\filedb.js:121:16)
at new TriviaDiscord (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\platform\discord_main.js:82:19)
at Object.<anonymous> (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\platform\discord_shard.js:20:30)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
So what changes i can do to get approved this PR?
For approval, these errors need to be fixed so that your changes will not interfere with anyone else's configurations of the bot.
I am willing to work on this for you when I can, but it may take some time, as some other critical fixes and changes for 2.0 will take precedence.
I should be able to fix those crash.
Fixes look good so far. I will do a final round of testing and approve this after 2.0 hits stable.
Update: Still awaiting the final changes and release of 2.0. Afterwards, this PR will be my first priority here. Thanks for your patience.
No problem, I will fix the merge conflicts on monday.
Fixed the rebase issues.
Ping
Still here. I will be looking at this shortly. I'm hoping to submit any reviews (if needed) for this soon--couple weeks at the latest. Thanks again for waiting.
- Errors out if you attempt to start a normal trivia game with questions that do not have all incorrect answers:
C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game\game.js:167
answers[i] = answers[i].toString();
^
TypeError: Cannot read properties of undefined (reading 'toString')
at Game.buildAnswers (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game\game.js:167:33)
at Game.initializeRound (C:\Content\Dev\_Discord\Discord-Trivia-Bot\lib\game\game.js:309:29)
You could fix this by using the exclusion array to filter out these questions if the game isn't in hangman mode. I recommend looking into creating a new type for this alongside 'boolean' and 'multiple'. These types correspond to the number of incorrect answers, which in your case is 0.
If the exclusion array filters out everything, you'll see the following, which is the desired result if your whole database consists of questions that don't apply to your config (in this case, hangman-specific questions with no incorrect answers):
An error occurred while querying the trivia database: Error: There are no questions available under the current configuration.
- True/false questions are visible in hangman mode. In normal operation, the file database will look for whether the question has a single incorrect answer. If it does, it is marked as a true/false question and excluded from hangman games.
For both of these, see filedb,js: Assignment of type, and check of type and exclusion
I have no time to work on this after all this months... I am still running my patched bot
I understand. Feel free to close this out, or you can keep it open if you think your situation will change eventually.
If you can fix those issues I can share the italian question database I am using with 38000 questions.
If this change can't be completed here, it will most likely end up on my roadmap, meaning it will likely be fixed eventually. However, I unfortunately can't guarantee a timeframe.
What you do with your database is up to you--it sounds great, but I wouldn't be able to do much with it myself.
For the database is just useless to share it if this change is not merged but i can upload it somewhere is not a problem.