modified: src/main.js

This commit is contained in:
Flummi 2016-08-14 02:55:56 +02:00
parent 0b220ced8f
commit 71bff2ef5b

View File

@ -6,6 +6,10 @@ var mysql = require('mysql');
var bot = require('coffea')(); var bot = require('coffea')();
const path = require('path'); const path = require('path');
var allowed = [
'image/png', 'video/webm'
];
cfg.server.forEach((e,i,a) => { cfg.server.forEach((e,i,a) => {
bot.add({ bot.add({
"name": e.name, "name": e.name,
@ -33,13 +37,20 @@ bot.on('message', (e) => {
var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
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
e.reply(cb); if(cb.status === true) {
var tmp = getUser(e.user.getNick(), e.network);
setTimeout(()=>{
e.reply(cb.msg+" for "+tmp['nick']+" ("+tmp['username']+"@"+tmp['hostname']+")");
}, 1600);
}
else
e.reply(cb.msg);
}); });
}); });
} }
else if(orig.match(/^\.user/)) { // (debug) get userinfos else if(orig.match(/^\.user/)) { // (debug) get userinfos
var tmp = getUser(e.user.getNick(), e.network); var tmp = getUser(e.user.getNick(), e.network);
setTimeout(()=>{ e.reply(tmp); }, 2000); setTimeout(()=>{ e.reply(tmp); }, 1500);
} }
} }
}); });
@ -56,19 +67,24 @@ var dl = (url, dest, cb) => {
var file = fs.createWriteStream(dest); var file = fs.createWriteStream(dest);
var request = (url.match(/^https/)?https:http).get(url, (response) => { var request = (url.match(/^https/)?https:http).get(url, (response) => {
try { try {
response.pipe(file); if(allowed.indexOf(response.headers['content-type']) != -1) {
file.on('finish', () => { response.pipe(file);
file.close(); file.on('finish', () => {
cb('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(err.message); file.close();
}); cb({'status':false, 'msg':err.message});
});
}
else {
cb({'status':false, 'msg':'f0ck you'});
}
} }
catch(ex) { catch(ex) {
e.reply(ex); e.reply(ex);
} }
}); });
} };