Эх сурвалжийг харах

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

isundil 6 жил өмнө
parent
commit
0c69206fd9
2 өөрчлөгдсөн 17 нэмэгдсэн , 4 устгасан
  1. 1 0
      config.js
  2. 16 4
      rapido.js

+ 1 - 0
config.js

@@ -38,6 +38,7 @@ module.exports.MODULES["#rapido"] = new (require('./rapido.js'))({
     WORD_TIMEO_FPS: 0.5, // 2 seconds per key
     DICTIONARY_PATH: './db/fr.txt',
     MIN_PLAYERS: 1,
+    WORD_IN_SET: 5,
     SCORE_MAP: [
         [ 5, 8 ],
         [ 4.5, 7 ],

+ 16 - 4
rapido.js

@@ -95,7 +95,8 @@ Rapido.prototype.resetScores = function() {
 }
 
 Rapido.prototype.endWord = function() {
-    clearTimeout(this.wordTimeout);
+    this.wordTimeout && clearTimeout(this.wordTimeout);
+    this.wordTimeout = 0;
     this.currentWord = null;
     this.currentPoints = [];
     this.wordRequest = [];
@@ -103,6 +104,8 @@ Rapido.prototype.endWord = function() {
 }
 
 Rapido.prototype.onWordTimeout = function() {
+    this.wordTimeout = 0;
+    ++(this.setProgression);
     if (this.currentPoints.length) {
         this.currentPoints = this.currentPoints.map((i, index) => {
             const time = i.time -this.wordStart;
@@ -123,9 +126,17 @@ Rapido.prototype.onWordTimeout = function() {
         });
     } else {
         this.bot.sendMsg(this.room, "Bah alors ? " +this.wordRequest.join(", ") +" vous fichez quoi ?");
-        this.bot.sendMsg(this.room, "fin du temps réglementaire, tapez !next pour une prochaine partie.");
     }
     this.endWord();
+    if (this.setProgression >= this.config.WORD_IN_SET)
+        this.bot.sendMsg(this.room, "fin du temps réglementaire, tapez !next pour une prochaine partie.");
+    else
+        this.startNextWordTimer();
+}
+
+Rapido.prototype.startNewSet = function() {
+    this.setProgression = 0;
+    this.startNextWordTimer();
 }
 
 Rapido.prototype.startNextWordTimer = function() {
@@ -133,7 +144,8 @@ Rapido.prototype.startNextWordTimer = function() {
     this.currentWord = this.words[Math.floor(Math.random() * this.words.length)];
     console.log(this.currentWord);
     _this.bot.sendMsg(this.room, "Attention attention, prochain mot dans " +Math.floor(this.config.NEXT_WORD_DELAY / 1000) +" secondes");
-    _this.bot.sendMsg(this.room, "Rappel : il faut taper le plus vite possible en minuscule et sans espaces le mot proposé");
+    if (this.setProgression == 0)
+        _this.bot.sendMsg(this.room, "Rappel : il faut taper le plus vite possible en minuscule et sans espaces le mot proposé");
     setTimeout(() => {
         var wordEsc = _this.currentWord.replace(/(\w)/g, ' $1').toUpperCase().trimStart();
         _this.bot.sendMsg(_this.room, wordEsc);
@@ -186,7 +198,7 @@ Rapido.prototype.onMessageInternal = function(username, user, msg) {
         if (this.wordRequest.indexOf(username) === -1)
             this.wordRequest.push(username);
         if (!this.currentWord && this.wordRequest.length >= this.config.MIN_PLAYERS)
-            this.startNextWordTimer();
+            this.startNewSet();
     }
     else if (lmsg.startsWith("!score")) {
         this.sendScore();