Browse Source

Mettre à jour 'quizz.js'

refs #10
Julia 6 years ago
parent
commit
59587c6dea
1 changed files with 21 additions and 21 deletions
  1. 21 21
      quizz.js

+ 21 - 21
quizz.js

@@ -6,7 +6,7 @@ const
 
 Object.assign(global, require("./config.js"));
 
-const MySQL = USE_MYSQL ? (function() { return require("mysql2").createConnection({host: MySQL_HOST, user: MySQL_USER, database: MySQL_DB, password: MySQL_PASS}); })  : null;
+const MySQL = USE_MYSQL ? require("mysql2").createConnection({host: MySQL_HOST, user: MySQL_USER, database: MySQL_DB, password: MySQL_PASS}) : null;
 
 const HOSTNAME = require('os').hostname(); // For Mysql bot identification
 
@@ -377,8 +377,8 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
         else
             this.bot.sendMsg(this.room, "Must be channel operator");
     }
-    else if (lmsg.startsWith("!aide")) {
-        this.bot.sendMsg(this.room, "Usage: !aide | !indice | !reload | !next | !rename | !score [del pseudo] || !top");
+    else if (lmsg.startsWith("!help")) {
+        this.bot.sendMsg(this.room, "Besoin d'aide ? La liste des commandes utiles est sur ce site : https://git.knacki.info/irc.knacki.info/ircbot-quizz/src/master/quizz.md");
     }
     else if (lmsg === "!indice" || lmsg === "!conseil") {
         if (this.currentQuestion) {
@@ -436,6 +436,7 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
             this.bot.sendMsg(this.room, "Question #" +questionId +" marquée comme restaurée");
         } else if (Cache.isReportedBy(questionId, username)) {
             Cache.unreportQuestion(questionId, username);
+            this.bot.sendMsg(this.room, "Question #" +questionId +" marquée comme restaurée");
             this.bot.sendMsg(this.room, "Question #" +questionId +" n'est plus marquée comme défectueuse par " +username);
         } else {
             this.bot.sendMsg(this.room, "Must be channel operator");
@@ -463,7 +464,7 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
         else
             this.bot.sendMsg(this.room, "Must be channel operator");
     }
-    else if (lmsg.startsWith("!rename ")) {
+    else if (lmsg.startsWith("!rename")) {
         if (!user.admin) {
             this.bot.sendMsg(this.room, "Must be channel operator");
             return;
@@ -492,9 +493,7 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
         }
         if (!userToMod) {
             userToMod = this.users[target] = this.bot.createUser(target);
-            this.bot.sendMsg(this.room, "Created user " +target +" with " +sum +" points");
-        } else if (sum) {
-            this.bot.sendMsg(this.room, "Added " +sum +" points to " +target);
+            this.bot.sendMsg(this.room, "Created user " +target);
         }
         userToMod.score += sum;
         Cache.SetScores(this.users);
@@ -538,6 +537,16 @@ QuizzBot.prototype.onMessageInternal = function(username, user, msg) {
     }
 };
 
+
+
+
+
+
+
+
+
+
+
 QuizzBot.prototype.mySQLExportWrapper = function() {
     if (!USE_MYSQL)
         return;
@@ -563,14 +572,10 @@ QuizzBot.prototype.mySQLExport = function() {
 }
 
 QuizzBot.prototype.exportScores = function() {
-    console.log("Start exporting scores");
     return new Promise((ok, ko) => {
-        if (!MySQL)
-            return ko();
         var ts = Cache.getLastMysqlSave() || this.config.START_TIME;
-            mySQL = MySQL();
         ts = Math.floor(ts / 1000) *1000;
-        ts = mySQL.escape(new Date(ts));
+        ts = MySQL.escape(new Date(ts));
         ts = ts.substr(1, ts.length -2);
         var sep = ts.lastIndexOf('.');
         if (sep > 12) ts = ts.substr(0, sep);
@@ -581,17 +586,12 @@ QuizzBot.prototype.exportScores = function() {
                 toSave.push(this.users[i].name);
                 toSave.push(this.users[i].score);
             }
-        if (toSave.length == 0) {
-            mySQL.end();
+        if (toSave.length == 0)
             return ok();
-        }
-        mySQL.execute("INSERT INTO " +this.config.MySQL_PERIOD_TABLE +" (start, host) VALUES(?, ?)", [ts, HOSTNAME], (err, result) => {
-            if (err || !result.insertId) {
-                mySQL.end();
+        MySQL.execute("INSERT INTO " +this.config.MySQL_PERIOD_TABLE +" (start, host) VALUES(?, ?)", [ts, HOSTNAME], (err, result) => {
+            if (err || !result.insertId)
                 return ko(err || "Cannot get last inserted id");
-            }
-            mySQL.execute("INSERT INTO " +this.config.MySQL_SCORES_TABLE +"(period_id, pseudo, score) VALUES " +(",("+result.insertId+",?,?)").repeat(toSave.length /2).substr(1), toSave, (err) => {
-                mySQL.end();
+            MySQL.execute("INSERT INTO " +this.config.MySQL_SCORES_TABLE +"(period_id, pseudo, score) VALUES " +(",("+result.insertId+",?,?)").repeat(toSave.length /2).substr(1), toSave, (err) => {
                 if (err)
                     ko(err);
                 else