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,7 +80,8 @@ 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) => {
if(cbcr) {
response.pipe(file); response.pipe(file);
file.on('finish', () => { file.on('finish', () => {
file.close(); file.close();
@ -95,6 +96,7 @@ var dl = (url, dest, cb) => {
else { else {
cb({'status':false, 'msg':'repost motherf0cker'}); 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;
}; };