modified: src/main.js

This commit is contained in:
Flummi 2016-08-14 04:06:01 +02:00
parent 839186ad13
commit e341a2d52f

View File

@ -50,10 +50,10 @@ bot.on('message', (e) => {
tmp.forEach((entry,i,a) => { tmp.forEach((entry,i,a) => {
dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item
if(cb.status === true) { if(cb.status === true) {
var tmp = getUser(e.user.getNick(), e.network); var tmpuser = 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); sql.query("insert into `f0ck`.`items` values (?,?,?,?,?,?,?)",tmp, "./b/"+path.parse(entry).base,tmpuser['username'],e.channel.getName(),new Date().getTime(),0);
e.reply(cb.msg+" for "+tmp['nick']+" ("+tmp['username']+"@"+tmp['hostname']+")"); e.reply(cb.msg+" for "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")");
}, 1600); }, 1600);
} }
else else
@ -80,21 +80,23 @@ 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) {
if(checkRepost(url)) { checkRepost(url, (cbcr) => {
response.pipe(file); if(cbcr) {
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 {
} cb({'status':false, 'msg':'repost motherf0cker'});
}
});
} }
else { else {
cb({'status':false, 'msg':'f0ck you'}); cb({'status':false, 'msg':'f0ck you'});
@ -106,16 +108,9 @@ var dl = (url, dest, cb) => {
}); });
}; };
var checkRepost = (url) => { var checkRepost = (url, cbcr) => {
var result = false; console.log(url);
sql.query( sql.query("select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => {
"select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => { cbcr((rows[0].count == 0)?true:false);
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;
}; };