diff --git a/package.json b/package.json index 9e03e73..bf44c96 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,9 @@ "main": "src/main.js", "dependencies": { "coffea": "^0.4.24", + "fs-extra": "^0.30.0", "mysql": "^2.11.1", - "repl": "^0.1.3", + "repl": "^0.1.3" }, "repository": { "type": "git", diff --git a/src/main.js b/src/main.js index bfb017f..2515c12 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,5 @@ var cfg = require('../../cfg.json'); -var fs = require('fs'); +var fs = require('fs-extra'); var http = require('http'); var https = require('https'); var mysql = require('mysql'); @@ -9,8 +9,6 @@ var crypto = require('crypto'); var path = require('path'); var exec = require('child_process').exec; -var neu = true; - var sql; var haDC = () => { sql = mysql.createConnection(cfg.mysql); @@ -45,47 +43,49 @@ bot.on('motd', (e) => { bot.on('message', (e) => { var orig = e.message; - if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher - var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links - tmp.forEach((entry,i,a) => { - var tmpdest = uuid.v1().split('-')[0]; - dl(entry, "./b/"+tmpdest, (cb) => { // download item - if(cb.status === true) { - var tmpuser = getUser(e.user.getNick(), e.network); - getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => { - checkRepostCheckSum(cbcs, (cbcrcs) => { - if(cbcrcs) { - sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`thumb`,`active`) values (?,?,?,?,?,?,?,?,?,?,?)", [ - entry, - "./b/"+tmpdest+"."+cb.infos.ext, - cb.infos.mime, - cb.infos.size, - cbcs, - tmpuser['nick'], - e.channel.getName(), - e.network, - Math.floor(new Date() / 1000), - '', - 0 - ]).on('result', (result) => { - neu = true; - e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")"); - }).on('error', (msg) => { - e.reply(msg); - }); - } - else { - fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost - e.reply("repost motherf0cker"); - } + if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi) && e.channel.getName() == "#f0ck") { // shitpostcatcher + if(!orig.match(/\!ignore$/)) { + var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links + tmp.forEach((entry,i,a) => { + var tmpdest = uuid.v1().split('-')[0]; + dl(entry, "./b/"+tmpdest, (cb) => { // download item + if(cb.status === true) { + var tmpuser = getUser(e.user.getNick(), e.network); + getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => { + checkRepostCheckSum(cbcs, (cbcrcs) => { + if(cbcrcs) { + sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`thumb`,`active`) values (?,?,?,?,?,?,?,?,?,?,?)", [ + entry, + "./b/"+tmpdest+"."+cb.infos.ext, + cb.infos.mime, + cb.infos.size, + cbcs, + tmpuser['nick'], + e.channel.getName(), + e.network, + Math.floor(new Date() / 1000), + '', + 0 + ]).on('result', (result) => { + generateThumbs(); + e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")"); + }).on('error', (msg) => { + e.reply(msg); + }); + } + else { + fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost + e.reply("repost motherf0cker"); + } + }); }); - }); - } - else - if(cb.type == 1) - e.reply(cb.msg); + } + else + if(cb.type == 1) + e.reply(cb.msg); + }); }); - }); + } } else if(orig.match(/^\.user/)) { // (debug) get userinfos var tmp = getUser(e.user.getNick(), e.network); @@ -187,10 +187,10 @@ http.createServer((req, res) => { }; if(filePath == "./index.html") { // mainpage - sql.query("select * from `f0ck`.`items`", (err, rows, fields) => { + sql.query("select * from `f0ck`.`items` order by `id` desc", (err, rows, fields) => { var tmpres = "
\n";
+ tmpres += "\n";
});
tmpres += "";
res.writeHead(200, { 'Content-Type': 'text/html' });
@@ -199,30 +199,38 @@ http.createServer((req, res) => {
}
else if(Number.isInteger(parseInt(url))) { // itempage
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1", url, (err, rows, fields) => {
- var tmpres = "";
+ var tmpres = "";
rows.forEach((e,i,a) => {
- tmpres += "ID: "+e.id+"
\n";
+ tmpres += "\n";
});
tmpres += "";
res.writeHead(200, { 'Content-Type': 'text/html' });
@@ -199,30 +199,38 @@ http.createServer((req, res) => {
}
else if(Number.isInteger(parseInt(url))) { // itempage
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1", url, (err, rows, fields) => {
- var tmpres = "";
+ var tmpres = "";
rows.forEach((e,i,a) => {
- tmpres += "ID: "+e.id+"