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

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

isundil 6 жил өмнө
parent
commit
a109d57eb8
3 өөрчлөгдсөн 14 нэмэгдсэн , 5 устгасан
  1. 9 3
      quizz.js
  2. 4 1
      rapido.js
  3. 1 1
      rapido.md

+ 9 - 3
quizz.js

@@ -135,6 +135,7 @@ const ScoreUtils = (function() {
         scores = this.sort((a, b) => b.score - a.score);
         var newIndex = this.getRank(pseudo) -1;
         var result = { newRank: newIndex +1, oldRank: oldIndex +1 };
+        result.exaequo = this.filter(i => i.score === score && i.name !== pseudo);
         if (newIndex < 0 || newIndex === oldIndex)
             return result;
         result.users = this.slice(newIndex +1, oldIndex +1);
@@ -418,11 +419,15 @@ QuizzBot.prototype.resetScores = function() {
  * @return a string with a message to be displayed or null if nothing to say
 **/
 QuizzBot.prototype.buildOverpassedMessage = function(username, diff) {
+    var exaequo = null;
+    if (diff.exaequo.length)
+        exaequo = " est aux coude a coude avec " +diff.exaequo.map(i => i.name).join(", ");
     if (!diff.users || !diff.users.length)
-        return null;
+        return exaequo ? (username +exaequo) : null;
+    exaequo = " et" +exaequo;
     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 !`;
+        return `${username} prend la ${rankStr} place ` +(exaequo || "!");
 
     const looser = diff.users[0].name,
         insults = [
@@ -435,7 +440,8 @@ QuizzBot.prototype.buildOverpassedMessage = function(username, diff) {
             () => `La ${rankStr} place est maintenant la propriété de ${username} qui a envoyé ${looser} au tapis`,
             () => `${username} tatoue un gros L de la loose sur le front de ${looser} qui vient de perdre la ${rankStr} place`
         ];
-    return insults[Math.floor(Math.random() * insults.length)]();
+    var insultStr = insults[Math.floor(Math.random() * insults.length)]();
+    return insultStr +(exaequo || "!");
 }
 
 QuizzBot.prototype.onMessageInternal = function(username, user, msg) {

+ 4 - 1
rapido.js

@@ -129,7 +129,7 @@ Rapido.prototype.onWordTimeout = function() {
     }
     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.");
+        this.bot.sendMsg(this.room, "fin du temps réglementaire, tapez !rapido pour une prochaine partie.");
     else
         this.startNextWordTimer();
 }
@@ -193,8 +193,11 @@ Rapido.prototype.computeScore = function(ellapsed, word, index) {
 
 Rapido.prototype.onMessageInternal = function(username, user, msg) {
     const lmsg = msg.toLowerCase();
+    msg = lmsg.substr(0, 1) + msg.substr(1);
 
     if (lmsg === "!next") {
+        this.bot.sendMsg(this.room, "La commande !next a été remplacé par !rapido.");
+    } else if (lmsg === "!rapido") {
         if (this.wordRequest.indexOf(username) === -1)
             this.wordRequest.push(username);
         if (!this.currentWord && this.wordRequest.length >= this.config.MIN_PLAYERS)

+ 1 - 1
rapido.md

@@ -16,6 +16,6 @@ Joueur1 sera noté 2 points pour avoir trouvé + 2 points pour avoir été le pr
 Joueur2 sera noté 2 points pour avoir trouvé + 0-8 points suivant sa vitesse
 
 ## Commandes :
-**!next** : Lance un mot dans 10 secondes
+**!rapido** : Lance un mot dans 10 secondes
 **!regles** ou **!help** : Rappel les règles et des commandes
 **!scores** : Rappel des scores