Browse Source

Merge branch 'bugfixes' of irc.knacki.info/ircbot-quizz into master

isundil 6 years ago
parent
commit
6b2bf41387
3 changed files with 52 additions and 3 deletions
  1. 18 1
      quizz.js
  2. 3 1
      quizz.md
  3. 31 1
      rapido.js

+ 18 - 1
quizz.js

@@ -300,6 +300,7 @@ QuizzBot.prototype.sendNextHint = function(resetTimer) {
 }
 
 QuizzBot.prototype.nextQuestionWrapper = function() {
+    this.previousQuestion = this.currentQuestion ? this.currentQuestion.id : null;
     this.currentQuestion.end();
     this.currentQuestion = null;
     setTimeout(this.nextQuestion.bind(this), this.config.NEXT_QUESTION_DELAY);
@@ -424,7 +425,7 @@ QuizzBot.prototype.buildOverpassedMessage = function(username, diff) {
         exaequo = " est aux coude a coude avec " +diff.exaequo.map(i => i.name).join(", ");
     if (!diff.users || !diff.users.length)
         return exaequo ? (username +exaequo) : null;
-    exaequo = " et" +exaequo;
+    exaequo = exaequo ? (" et" +exaequo) : null;
     const rankStr = diff.newRank == 1 ? "1ere" : `${diff.newRank}eme`;
     if (diff.users.length > 1) // Advanced too much rank at once ! Only display new position
         return `${username} prend la ${rankStr} place ` +(exaequo || "!");
@@ -516,6 +517,22 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
             this.bot.sendMsg(this.room, "Must be channel operator");
         }
     }
+    else if (lmsg === "!report prev") {
+        if (!this.previousQuestion) {
+            this.bot.sendMsg(this.room, "Erreur: question non trouvée");
+        } else {
+            Cache.reportQuestion(this.previousQuestion, username);
+            this.bot.sendMsg(this.room, "Question #" +this.previousQuestion +" marquée comme défectueuse par " +username);
+        }
+    }
+    else if (lmsg === "!report current") {
+        if (!this.currentQuestion) {
+            this.bot.sendMsg(this.room, "Erreur: question non trouvée");
+        } else {
+            Cache.reportQuestion(this.currentQuestion.id, username);
+            this.bot.sendMsg(this.room, "Question #" +this.currentQuestion.id +" marquée comme défectueuse par " +username);
+        }
+    }
     else if (lmsg.startsWith("!report ")) {
         var questionId = msg.substr("!report ".length).trim();
         if (questionId.startsWith('#'))

+ 3 - 1
quizz.md

@@ -3,6 +3,8 @@
 !top : Permet de connaître les 4 premiers du classement 
 !score : Permet de connaître le score des 10 premiers joueurs connectés
 !points : Permet de connaître son score personnel
+!report prev : Permet d'indiquer la question précédente comme défectueuse
+!report current : Permet d'indiquer la question en cours comme défectueuse
 !report #numéroquestion : Permet d'indiquer la question #... comme défectueuse
 !report del #numéroquestion : Permet d'annuler le report (possible uniquement si on a report cette question)
-!help : Permet d'obtenir de l'aide concernant le jeu
+!help : Permet d'obtenir de l'aide concernant le jeu

+ 31 - 1
rapido.js

@@ -122,20 +122,50 @@ Rapido.prototype.onWordTimeout = function() {
         this.currentPoints.forEach(i => {
             this.users[i.username] = this.users[i.username] || this.bot.createUser(i.username);
             this.users[i.username].score += i.pts;
+            this.users[i.username].stats = this.users[i.username].stats || [];
+            this.users[i.username].stats.push({
+                speed: i.fps,
+                time: i.time
+            });
             this.bot.sendMsg(this.room, i.pts +" points pour " +i.username +", qui cumule un total de " +this.users[i.username].score +" points !");
         });
     } else {
         this.bot.sendMsg(this.room, "Bah alors ? " +this.wordRequest.join(", ") +" vous fichez quoi ?");
     }
     this.endWord();
-    if (this.setProgression >= this.config.WORD_IN_SET)
+    if (this.setProgression >= this.config.WORD_IN_SET) {
         this.bot.sendMsg(this.room, "fin du temps réglementaire, tapez !rapido pour une prochaine partie.");
+        var stats = [];
+        for (var i in this.users) {
+            var userStats = this.users[i].stats;
+            if (userStats && userStats.length) {
+                var stat = { name: i, avgSpeed: 0, avgTime: 0 };
+                userStats.forEach(j => {
+                    stat.avgSpeed += j.speed / userStats.length;
+                    stat.avgTime += j.time / userStats.length;
+                }, this);
+                stats.push(stat);
+            }
+        }
+        if (stats.length) {
+            stats.sort((i, j) => j.avgSpeed - i.avgSpeed);
+            var index = 0;
+            var scoreLines = arrayPad(stats.map(i => [ ((++index) +"."), i.name, ("Vitesse: " +(Math.round(i.avgSpeed * 100) / 100)), ("Temps: " +Math.round(i.avgTime) +"ms") ]));
+            this.bot.sendMsg(this.room, "Moyennes des joueurs:");
+            for (var i =0, len = scoreLines.length; i < len; i += 2)
+                this.bot.sendMsg(this.room, ((scoreLines[i] || "") +"  -  " +(scoreLines[i +1] || "")));
+            this.bot.sendMsg(this.room, "Scores:");
+            this.sendScore();
+        }
+    }
     else
         this.startNextWordTimer();
 }
 
 Rapido.prototype.startNewSet = function() {
     this.setProgression = 0;
+    for (var i in this.users)
+        this.users[i].stats = [];
     this.startNextWordTimer();
 }