|
@@ -10,50 +10,50 @@ client.on('ready', () => {
|
|
});
|
|
});
|
|
|
|
|
|
client.on('message', message => {
|
|
client.on('message', message => {
|
|
-
|
|
|
|
|
|
+
|
|
if (message.author.bot==true) return;
|
|
if (message.author.bot==true) return;
|
|
-
|
|
|
|
|
|
+
|
|
var serverData = undefined;
|
|
var serverData = undefined;
|
|
-
|
|
|
|
|
|
+
|
|
config.servers.forEach(function(server) {
|
|
config.servers.forEach(function(server) {
|
|
if (message.channel.id==server.channel) serverData = server;
|
|
if (message.channel.id==server.channel) serverData = server;
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
if (serverData==undefined) return;
|
|
if (serverData==undefined) return;
|
|
-
|
|
|
|
|
|
+
|
|
var l = [];
|
|
var l = [];
|
|
-
|
|
|
|
|
|
+
|
|
var msgCopy = message.content;
|
|
var msgCopy = message.content;
|
|
-
|
|
|
|
|
|
+
|
|
msgCopy.replace(urlRegex, function(url) {
|
|
msgCopy.replace(urlRegex, function(url) {
|
|
l.push(url);
|
|
l.push(url);
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
var i = [];
|
|
var i = [];
|
|
-
|
|
|
|
|
|
+
|
|
message.attachments.forEach(attachment => {
|
|
message.attachments.forEach(attachment => {
|
|
i.push(attachment.url);
|
|
i.push(attachment.url);
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
var connection = mysql.createConnection({
|
|
var connection = mysql.createConnection({
|
|
host : serverData.dbHost,
|
|
host : serverData.dbHost,
|
|
user : serverData.dbUser,
|
|
user : serverData.dbUser,
|
|
password : serverData.dbPassword,
|
|
password : serverData.dbPassword,
|
|
database : serverData.db
|
|
database : serverData.db
|
|
});
|
|
});
|
|
-
|
|
|
|
- var post = {Message:message.content, Id:message.id, Time:message.createdTimestamp, User:message.author.id, Links:JSON.stringify(l), Images:JSON.stringify(i)};
|
|
|
|
- var sql = 'INSERT INTO messages SET ?';
|
|
|
|
|
|
+
|
|
|
|
+ var post = {message:message.content, id:message.id, time:message.createdTimestamp, user:message.author.id, links:JSON.stringify(l), images:JSON.stringify(i)};
|
|
|
|
+ var sql = 'INSERT INTO '+serverData.dbTable+' SET ?';
|
|
connection.connect();
|
|
connection.connect();
|
|
-
|
|
|
|
|
|
+
|
|
connection.query(sql, post, function (error, results, fields) {
|
|
connection.query(sql, post, function (error, results, fields) {
|
|
if (error) throw error;
|
|
if (error) throw error;
|
|
console.log('Data sent to db. Result: ', results);
|
|
console.log('Data sent to db. Result: ', results);
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
connection.end();
|
|
connection.end();
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
});
|
|
});
|
|
|
|
|
|
-client.login(config.token);
|
|
|
|
|
|
+client.login(config.token);
|