Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions without incorrect answers #247

Open
Mte90 opened this issue Dec 11, 2021 · 1 comment
Open

Questions without incorrect answers #247

Mte90 opened this issue Dec 11, 2021 · 1 comment

Comments

@Mte90
Copy link

Mte90 commented Dec 11, 2021

As I have a db with questions without incorrect answers I had to edit the bot to ignore that feature.
It is possible to implement it natively?

@Mte90 Mte90 changed the title Questions wihout incorrect answers Questions without incorrect answers Dec 12, 2021
@Mte90
Copy link
Author

Mte90 commented Dec 15, 2021

The diff of my changes to be able of that:

diff --git a/lib/database/filedb.js b/lib/database/filedb.js
index 2b8753b..59e6fe5 100644
--- a/lib/database/filedb.js
+++ b/lib/database/filedb.js
@@ -58,14 +58,15 @@ class FileDB extends Database {
     }
 
     // Invalid incorrect_answers
-    if(typeof question.incorrect_answers !== "object" || question.incorrect_answers === null) {
-      throw new Error(`Unable to identify the "incorrect-answers" field for the question "${question.question}"`);
-    }
-
-    // Wrong count for incorrect_answers
-    if(question.incorrect_answers.length !== 1 && question.incorrect_answers.length !== 3) {
-      throw new Error(`Invalid number of answers for the question "${question.question}"`);
-    }
+//     if(typeof question.incorrect_answers !== "object" || question.incorrect_answers === null) {
+//       throw new Error(`Unable to identify the "incorrect-answers" field for the question "${question.question}"`);
+//     }
+// 
+//     // Wrong count for incorrect_answers
+//     if(question.incorrect_answers.length !== 1 && question.incorrect_answers.length !== 3) {
+//       throw new Error(`Invalid number of answers for the question "${question.question}"`);
+//     }
+question.incorrect_answers = ''
 
     // Invalid difficulty
     if(typeof question.difficulty !== "string" || question.difficulty === null) {
@@ -315,12 +316,11 @@ class FileDB extends Database {
           // Prep to filter the question pool based on type and difficulty parameters.
           if(typeof options.type !== "undefined" || typeof options.difficulty !== "undefined") {
             exclusionPool.forEach((el) => {
-              el.type = this.types[el.incorrect_answers.length];
 
               if(typeof options.difficulty !== "undefined" && el.difficulty !== options.difficulty) {
                 exclusionArray.push(el.id);
               }
-              else if(typeof options.type !== "undefined" && el.type !== options.type) {
+              else if(typeof options.type !== "undefined") {
                 exclusionArray.push(el.id);
               }
             });
@@ -338,20 +338,20 @@ class FileDB extends Database {
             exclusionPoolCache.push(el.id);
           });
 
-          for(var iB in exclusionArray) {
-            // Match the ID in the array to an ID in the exclusion pool.
-            // In order to filter/splice the questions correctly, We will need to acquire the
-            // "exclusion ID", or the index of the question in the cache during and after splicing.
-            var exclusionID = exclusionPoolCache.indexOf(exclusionArray[iB]);
-
-            var result = exclusionPool.splice(exclusionID, 1);
-            var resultB = exclusionPoolCache.splice(exclusionID, 1); // Keep the cache in sync
-
-            // If the splice doesn't echo the question back, something has gone horribly wrong.
-            if(result.length === 0 || resultB.length === 0) {
-              throw new Error(`Failed to process question pool at index ${iB}/${length}`);
-            }
-          }
+//           for(var iB in exclusionArray) {
+//             // Match the ID in the array to an ID in the exclusion pool.
+//             // In order to filter/splice the questions correctly, We will need to acquire the
+//             // "exclusion ID", or the index of the question in the cache during and after splicing.
+//             var exclusionID = exclusionPoolCache.indexOf(exclusionArray[iB]);
+// 
+//             var result = exclusionPool.splice(exclusionID, 1);
+//             var resultB = exclusionPoolCache.splice(exclusionID, 1); // Keep the cache in sync
+// 
+//             // If the splice doesn't echo the question back, something has gone horribly wrong.
+//             if(result.length === 0 || resultB.length === 0) {
+//               throw new Error(`Failed to process question pool at index ${iB}/${length}`);
+//             }
+//           }
 
           var erAfter = Date.now();
           this.emit("debuglog", `Spliced ${exclusionArray.length} questions of ${length} with remainder ${exclusionPool.length} in ${erAfter-erBefore}ms`);
@@ -382,7 +382,7 @@ class FileDB extends Database {
         // Add additional information based on the question.
         // Note that the parameter .category is the same as .categoryName in the master pool.
         question.category = categoryName;
-        question.type = this.types[question.incorrect_answers.length];
+        question.type = '';
 
         // Add it to the question pool for export.
         questions.push(question);
diff --git a/lib/game.js b/lib/game.js
index 234dcba..918a8c7 100644
--- a/lib/game.js
+++ b/lib/game.js
@@ -268,7 +268,7 @@ class Game extends EventEmitter {
     this.inRound = false;
 
     // Parse the game type and difficulty
-    this.question.isTrueFalse = question.incorrect_answers.length === 1;
+    this.question.isTrueFalse = 0;
     if(!this.getConfig("hide-difficulty")) {
       switch(difficultyReceived) {
         case "easy":

Probably instead commenting is better to add a check to execute that code but atleast the line involved are there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants