modified: src/main.js

This commit is contained in:
Flummi 2016-08-14 03:41:31 +02:00
parent 208321706f
commit 839186ad13

View File

@ -10,6 +10,18 @@ var allowed = [
'image/png', 'video/webm' 'image/png', 'video/webm'
]; ];
var sql;
function haDC() {
sql = mysql.createConnection(cfg.mysql);
sql.connect((err) => {
if(err) setTimeout(haDC,2000);
});
sql.on('error', (err) => {
if(err.code === 'PROTOCOL_CONNECTION_LOST') haDC();
});
}
haDC();
cfg.server.forEach((e,i,a) => { cfg.server.forEach((e,i,a) => {
bot.add({ bot.add({
"name": e.name, "name": e.name,
@ -40,6 +52,7 @@ bot.on('message', (e) => {
if(cb.status === true) { if(cb.status === true) {
var tmp = getUser(e.user.getNick(), e.network); var tmp = getUser(e.user.getNick(), e.network);
setTimeout(()=>{ setTimeout(()=>{
sql.query("insert into `f0ck`.`items` values (?,?,?,?,?,?,?)",url, "./b/"+path.parse(entry).base,tmp['username'],e.channel.getName(),new Date().getTime(),0);
e.reply(cb.msg+" for "+tmp['nick']+" ("+tmp['username']+"@"+tmp['hostname']+")"); e.reply(cb.msg+" for "+tmp['nick']+" ("+tmp['username']+"@"+tmp['hostname']+")");
}, 1600); }, 1600);
} }
@ -55,7 +68,6 @@ bot.on('message', (e) => {
} }
}); });
var getUser = (u, n) => { var getUser = (u, n) => {
bot.whois(u, n, (fn)=>{ }); // send whois bot.whois(u, n, (fn)=>{ }); // send whois
var start = Date.now(); var start = Date.now();
@ -68,16 +80,21 @@ var dl = (url, dest, cb) => {
var request = (url.match(/^https/)?https:http).get(url, (response) => { var request = (url.match(/^https/)?https:http).get(url, (response) => {
try { try {
if(allowed.indexOf(response.headers['content-type']) != -1) { if(allowed.indexOf(response.headers['content-type']) != -1) {
response.pipe(file); if(checkRepost(url)) {
file.on('finish', () => { response.pipe(file);
file.close(); file.on('finish', () => {
cb({'status':true, 'msg':'downloaded '+dest}); file.close();
}); cb({'status':true, 'msg':'downloaded '+dest});
file.on('error', (err) => { });
fs.unlink(dest); file.on('error', (err) => {
file.close(); fs.unlink(dest);
cb({'status':false, 'msg':err.message}); file.close();
}); cb({'status':false, 'msg':err.message});
});
}
else {
cb({'status':false, 'msg':'repost motherf0cker'});
}
} }
else { else {
cb({'status':false, 'msg':'f0ck you'}); cb({'status':false, 'msg':'f0ck you'});
@ -88,3 +105,17 @@ var dl = (url, dest, cb) => {
} }
}); });
}; };
var checkRepost = (url) => {
var result = false;
sql.query(
"select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => {
result = (rows[0].count == 0)?true:false;
console.log("1: "+result);
}
);
var start = Date.now();
while(Date.now() < start + 1000) {}
console.log("2: "+result);
return result;
};