modified: src/main.js
This commit is contained in:
parent
839186ad13
commit
e341a2d52f
55
src/main.js
55
src/main.js
@ -50,10 +50,10 @@ bot.on('message', (e) => {
|
||||
tmp.forEach((entry,i,a) => {
|
||||
dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item
|
||||
if(cb.status === true) {
|
||||
var tmp = getUser(e.user.getNick(), e.network);
|
||||
var tmpuser = getUser(e.user.getNick(), e.network);
|
||||
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']+")");
|
||||
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 "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")");
|
||||
}, 1600);
|
||||
}
|
||||
else
|
||||
@ -80,21 +80,23 @@ var dl = (url, dest, cb) => {
|
||||
var request = (url.match(/^https/)?https:http).get(url, (response) => {
|
||||
try {
|
||||
if(allowed.indexOf(response.headers['content-type']) != -1) {
|
||||
if(checkRepost(url)) {
|
||||
response.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
cb({'status':true, 'msg':'downloaded '+dest});
|
||||
});
|
||||
file.on('error', (err) => {
|
||||
fs.unlink(dest);
|
||||
file.close();
|
||||
cb({'status':false, 'msg':err.message});
|
||||
});
|
||||
}
|
||||
else {
|
||||
cb({'status':false, 'msg':'repost motherf0cker'});
|
||||
}
|
||||
checkRepost(url, (cbcr) => {
|
||||
if(cbcr) {
|
||||
response.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
cb({'status':true, 'msg':'downloaded '+dest});
|
||||
});
|
||||
file.on('error', (err) => {
|
||||
fs.unlink(dest);
|
||||
file.close();
|
||||
cb({'status':false, 'msg':err.message});
|
||||
});
|
||||
}
|
||||
else {
|
||||
cb({'status':false, 'msg':'repost motherf0cker'});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
cb({'status':false, 'msg':'f0ck you'});
|
||||
@ -106,16 +108,9 @@ 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;
|
||||
var checkRepost = (url, cbcr) => {
|
||||
console.log(url);
|
||||
sql.query("select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => {
|
||||
cbcr((rows[0].count == 0)?true:false);
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user