subDesTagesMitExtraKaese 3 years ago
parent
commit
bab7cb116c
1 changed files with 21 additions and 11 deletions
  1. 21 11
      channel-statistics.js

+ 21 - 11
channel-statistics.js

@@ -48,6 +48,16 @@ registerPlugin({
       });
       });
     }
     }
   }
   }
+
+  function remove_non_utf8(str) {
+
+    if ((str === null) || (str === ''))
+      return "";
+    else
+      str = str.toString();
+    return str.replace(/[^\w\s\[\]\-:.\/!\?\(\)äáöüéôûµÄÁÖÜß=#<>\+\*\'\\`,\"“„€&%@§~^°|;]/g, '');
+  }
+
   reconnect();
   reconnect();
   setInterval(reconnect, 1000 * 3600);
   setInterval(reconnect, 1000 * 3600);
   
   
@@ -57,7 +67,7 @@ registerPlugin({
     const serverinfo = backend.extended().getServerInfo();
     const serverinfo = backend.extended().getServerInfo();
     updateServer(serverinfo, function(id) {
     updateServer(serverinfo, function(id) {
       serverId = id;
       serverId = id;
-      engine.log('serverId:', serverId);
+      engine.log('serverId: ' + serverId);
       backend.getChannels().forEach(channel => updateChannel(serverId, channel, function(id) {
       backend.getChannels().forEach(channel => updateChannel(serverId, channel, function(id) {
         channelIdMap[channel.id()] = id;
         channelIdMap[channel.id()] = id;
         updateChannelEvent(id, channel);
         updateChannelEvent(id, channel);
@@ -103,13 +113,13 @@ registerPlugin({
               if(!err && res.length > 0) {
               if(!err && res.length > 0) {
                 cb(res[0].id);
                 cb(res[0].id);
               } else {
               } else {
-                console.log(err, res);
+                engine.log(err, res);
               }
               }
             });
             });
           });
           });
         }
         }
       } else {
       } else {
-        console.log(err, res);
+        engine.log(err, res);
       }
       }
     });
     });
   }
   }
@@ -118,28 +128,28 @@ registerPlugin({
     if(!dbc || !serverId) {
     if(!dbc || !serverId) {
       return;
       return;
     }
     }
-    const parentId = channel.parent() ? channel.parent().id() : null;
+    const parentId = channel.parent() ? channel.parent().id() : NaN;
     dbc.query("SELECT * FROM channel WHERE channelId = ? AND serverId = ?", channel.id(), serverId, function(err, res) {
     dbc.query("SELECT * FROM channel WHERE channelId = ? AND serverId = ?", channel.id(), serverId, function(err, res) {
       if (!err) {
       if (!err) {
         if(res.length > 0) {
         if(res.length > 0) {
           const id = res[0].id;
           const id = res[0].id;
           dbc.exec("UPDATE channel SET name = ?, parentId = ?, position = ?, description = ? WHERE id = ?", 
           dbc.exec("UPDATE channel SET name = ?, parentId = ?, position = ?, description = ? WHERE id = ?", 
-                    channel.name(), parentId, channel.position(), channel.description(), id);
+            remove_non_utf8(channel.name()), parentId, channel.position(), remove_non_utf8(channel.description()), id);
           cb(id);
           cb(id);
         } else {
         } else {
           dbc.exec("INSERT INTO channel (channelId, name, serverId, parentId, position, description) VALUES (?, ?, ?, ?, ?, ?)", 
           dbc.exec("INSERT INTO channel (channelId, name, serverId, parentId, position, description) VALUES (?, ?, ?, ?, ?, ?)", 
-            channel.id(), channel.name(), serverId, parentId, channel.position(), channel.description(), function() {
+            channel.id(), remove_non_utf8(channel.name()), serverId, parentId, channel.position(), remove_non_utf8(channel.description()), function() {
               dbc.query("SELECT id FROM channel WHERE channelId = ? AND serverId = ?", channel.id(), serverId, function(err, res) {
               dbc.query("SELECT id FROM channel WHERE channelId = ? AND serverId = ?", channel.id(), serverId, function(err, res) {
                 if(!err && res.length > 0) {
                 if(!err && res.length > 0) {
                   cb(res[0].id);
                   cb(res[0].id);
                 } else {
                 } else {
-                  console.log(err, res);
+                  engine.log(err, res);
                 }
                 }
               });
               });
           });
           });
         }
         }
       } else {
       } else {
-        console.log(err, res);
+        engine.log(err, res);
       }
       }
     });
     });
   }
   }
@@ -152,19 +162,19 @@ registerPlugin({
     dbc.query("SELECT * FROM channelEvent WHERE channelId = ? AND date > DATE_SUB(NOW(), INTERVAL 1 MINUTE) ORDER BY date DESC LIMIT 1", id, function(err, res) {
     dbc.query("SELECT * FROM channelEvent WHERE channelId = ? AND date > DATE_SUB(NOW(), INTERVAL 1 MINUTE) ORDER BY date DESC LIMIT 1", id, function(err, res) {
       if(!err) {
       if(!err) {
         if(res.length > 0) {
         if(res.length > 0) {
-          engine.log('channel ' + channel.name() + ' updated to ' + clients + ' clients');
+          engine.log('channel ' + remove_non_utf8(channel.name()) + ' updated to ' + clients + ' clients');
           dbc.exec("UPDATE channelEvent SET clientCount = ? WHERE id = ?", clients, res[0].id);
           dbc.exec("UPDATE channelEvent SET clientCount = ? WHERE id = ?", clients, res[0].id);
         } else {
         } else {
           dbc.query("SELECT * FROM channelEvent WHERE channelId = ? ORDER BY date DESC LIMIT 1", id, function(err, res) {
           dbc.query("SELECT * FROM channelEvent WHERE channelId = ? ORDER BY date DESC LIMIT 1", id, function(err, res) {
             if(!err && res.length > 0 && res[0].clientCount === clients)
             if(!err && res.length > 0 && res[0].clientCount === clients)
               return;
               return;
             if(clients > 0)
             if(clients > 0)
-              engine.log('channel ' + channel.name() + ' has now ' + clients + ' clients');
+              engine.log('channel ' + remove_non_utf8(channel.name()) + ' has now ' + clients + ' clients');
             dbc.exec("INSERT INTO channelEvent (channelId, clientCount) VALUES (?, ?)", id, clients);
             dbc.exec("INSERT INTO channelEvent (channelId, clientCount) VALUES (?, ?)", id, clients);
           });
           });
         }
         }
       } else {
       } else {
-        console.log(err, res);
+        engine.log(err, res);
       }
       }
     });
     });
   }
   }