Discord-Trivia-Bot icon indicating copy to clipboard operation
Discord-Trivia-Bot copied to clipboard

feat(answers): ignore incorrect_answers if there isn't

Open Mte90 opened this issue 3 years ago • 19 comments

Fix https://github.com/LakeYS/Discord-Trivia-Bot/issues/247

Mte90 avatar Dec 16 '21 10:12 Mte90

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)
{}

LakeYS avatar Dec 17 '21 21:12 LakeYS

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"
  }
}

Mte90 avatar Dec 17 '21 21:12 Mte90

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

Mte90 avatar Dec 20 '21 10:12 Mte90

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

LakeYS avatar Jan 09 '22 20:01 LakeYS

So what changes i can do to get approved this PR?

Mte90 avatar Jan 09 '22 20:01 Mte90

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.

LakeYS avatar Jan 09 '22 20:01 LakeYS

I should be able to fix those crash.

Mte90 avatar Jan 10 '22 08:01 Mte90

Fixes look good so far. I will do a final round of testing and approve this after 2.0 hits stable.

LakeYS avatar Feb 01 '22 22:02 LakeYS

Update: Still awaiting the final changes and release of 2.0. Afterwards, this PR will be my first priority here. Thanks for your patience.

LakeYS avatar Mar 11 '22 20:03 LakeYS

No problem, I will fix the merge conflicts on monday.

Mte90 avatar Mar 12 '22 10:03 Mte90

Fixed the rebase issues.

Mte90 avatar Mar 14 '22 14:03 Mte90

Ping

Mte90 avatar Jul 20 '22 09:07 Mte90

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.

LakeYS avatar Jul 23 '22 17:07 LakeYS

  1. 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.
  1. 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

LakeYS avatar Aug 10 '22 00:08 LakeYS

I have no time to work on this after all this months... I am still running my patched bot

Mte90 avatar Aug 10 '22 12:08 Mte90

I understand. Feel free to close this out, or you can keep it open if you think your situation will change eventually.

LakeYS avatar Aug 11 '22 03:08 LakeYS

If you can fix those issues I can share the italian question database I am using with 38000 questions.

Mte90 avatar Aug 11 '22 18:08 Mte90

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.

LakeYS avatar Aug 11 '22 23:08 LakeYS

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.

Mte90 avatar Aug 12 '22 11:08 Mte90