endcancer

This commit is contained in:
Flummi 2016-08-14 02:01:16 +02:00
parent 959ba2a84d
commit 039ca5dd80

View File

@ -1,5 +1,6 @@
var cfg = require('../../cfg.json'); var cfg = require('../../cfg.json');
var fs = require('fs'); var fs = require('fs');
var http = require("http");
var https = require("https"); var https = require("https");
var mysql = require('mysql'); var mysql = require('mysql');
var bot = require('coffea')(); var bot = require('coffea')();
@ -28,8 +29,8 @@ bot.on('motd', (e) => {
bot.on('message', (e) => { bot.on('message', (e) => {
var orig = e.message; var orig = e.message;
if(e.channel.getName().toString() == "#f0ck") { // (debug) only in channel #f0ck if(e.channel.getName().toString() == "#f0ck") { // (debug) only in channel #f0ck
if(orig.match(/(https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher
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); e.reply(cb);
@ -53,16 +54,42 @@ var getUser = (u, n) => {
var dl = (url, dest, cb) => { var dl = (url, dest, cb) => {
var file = fs.createWriteStream(dest); var file = fs.createWriteStream(dest);
var request = https.get(url, (response) => { if(url.match(/https/)) {
response.pipe(file); var request = https.get(url, (response) => {
file.on('finish', () => { try {
file.close(); response.pipe(file);
cb('downloaded '+dest); file.on('finish', () => {
file.close();
cb('(https) downloaded '+dest);
});
file.on('error', (err) => {
fs.unlink(dest);
file.close();
cb(err.message);
});
}
catch(ex) {
e.reply(ex);
}
}); });
file.on('error', (err) => { }
fs.unlink(dest); else {
file.close(); var request = http.get(url, (response) => {
cb(err.message); try {
response.pipe(file);
file.on('finish', () => {
file.close();
cb('(http) downloaded '+dest);
});
file.on('error', (err) => {
fs.unlink(dest);
file.close();
cb(err.message);
});
}
catch(ex) {
e.reply(ex);
}
}); });
}); }
} }