From ff9ac383ef392821fe806bb6edfa4d22e593dc4f Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 24 Aug 2016 19:15:14 +0200 Subject: [PATCH] timingproblems fixed --- src/lib.js | 44 +++++++++++++++++++++++--------------------- src/trigger/debug.js | 19 +++++++++++++++++++ src/trigger/thumb.js | 21 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 src/trigger/debug.js create mode 100644 src/trigger/thumb.js diff --git a/src/lib.js b/src/lib.js index 4059dfb..16c7d42 100644 --- a/src/lib.js +++ b/src/lib.js @@ -7,13 +7,13 @@ var crypto = require('crypto'); var Mime = require('mime'); var bot, sql, cfg; -var debug = true; module.exports = Lib; function Lib(tbot, tsql, tcfg) { this.bot = bot = tbot; this.sql = sql = tsql; this.cfg = cfg = tcfg; + this.debug = true; this.admins = []; } @@ -21,23 +21,25 @@ Lib.prototype.getUser = (e, cbgu) => { var u = e.user.getNick(); var n = e.network; if(!e.user.hasOwnProperty('hostname')) { - bot.write('WHOIS '+u, n, () => { - bot.once('data', (err, msg) => { - var params; - var map = []; - map.push(u); - if(msg.command == 'RPL_WHOISUSER') { - params = msg.params.split(' '); - map[u] = map[u] || {}; - map[u].nick = u; - map[u].username = params[2]; - map[u].hostname = params[3]; - map[u].realname = msg.trailing; - } - if(typeof(map[u]) === 'object') - cbgu(map[u]); + setTimeout(()=>{ + bot.write('WHOIS '+u, n, () => { + bot.once('data', (err, msg) => { + var params; + var map = []; + map.push(u); + if(msg.command == 'RPL_WHOISUSER') { + params = msg.params.split(' '); + map[u] = map[u] || {}; + map[u].nick = u; + map[u].username = params[2]; + map[u].hostname = params[3]; + map[u].realname = msg.trailing; + } + if(typeof(map[u]) === 'object') + cbgu(map[u]); + }); }); - }); + }, 100); } else { cbgu({ @@ -119,8 +121,8 @@ Lib.prototype.dl = (url, dest, cb) => { if(cfg.allowedMimes.hasOwnProperty(mime)) { probe(dest+"."+cfg.allowedMimes[response.headers['content-type']], (err, probeData) => { if(probeData.streams[0].height !== undefined || probeData.streams[0].width !== undefined) { - if(probeData.streams[0].height <= cfg.minRes || probeData.streams[0].width <= cfg.minRes) - cb({'status':false, 'msg':'f0ck! your shitpost is too small ('+probeData.streams[0].width+' x '+probeData.streams[0].height+'), min '+cfg.minRes+' x '+cfg.minRes+' required', 'type':1}); + if(probeData.streams[0].height + probeData.streams[0].width <= cfg.minRes) + cb({'status':false, 'msg':'f0ck! your shitpost is too small', 'type':1}); else cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length'], 'ext':cfg.allowedMimes[response.headers['content-type']]}}); } @@ -156,7 +158,7 @@ Lib.prototype.generateThumbs = () => { rows.forEach((e,i,a) => { var thumbnail = outdir+e.id+'.png'; if(!fs.existsSync(thumbnail)) { - exec('ffmpegthumbnailer -i'+e.dest+' -s256 -o'+thumbnail, (error) => { + exec('ffmpegthumbnailer -i'+e.dest+' -s1024 -o'+thumbnail, (error) => { if(error) { Lib.prototype.log('failed thumbnail for '+e.id+' ('+e.mime+') 1'); fs.copySync('./s/mp3.png', thumbnail); // copy standardthumbnail @@ -175,6 +177,6 @@ Lib.prototype.generateThumbs = () => { }); }; Lib.prototype.log = (msg) => { - if(debug) + if(this.debug) bot.send("#f0ck", msg, 'n0xy'); }; \ No newline at end of file diff --git a/src/trigger/debug.js b/src/trigger/debug.js new file mode 100644 index 0000000..ed04c64 --- /dev/null +++ b/src/trigger/debug.js @@ -0,0 +1,19 @@ +module.exports = (bot, trigger, lib) => { + trigger.add({ + name: 'debug', + call: new RegExp('^\\!debug$', 'i'), + level: 100, + active: 1, + func: (e) => { + if(lib.debug) { + lib.debug = false; + e.reply('debugmode deactivated'); + } + else { + lib.debug = true; + e.reply('debugmode activated'); + } + }, + desc: 'toggle debug' + }); +}; \ No newline at end of file diff --git a/src/trigger/thumb.js b/src/trigger/thumb.js new file mode 100644 index 0000000..60f8b75 --- /dev/null +++ b/src/trigger/thumb.js @@ -0,0 +1,21 @@ +var fs = require('fs-extra'); + +module.exports = (bot, trigger, lib) => { + trigger.add({ + name: 'thumbnailer', + call: new RegExp('^\\!thumb (\\d+)$', 'i'), + level: 100, + active: 1, + func: (e) => { + var id = e.message.split(' ')[1]; + if(Number.isInteger(parseInt(id))) { + fs.unlink('./t/'+id+'.png', () => { + //e.reply('debug: Thumbnail gelöscht'); + lib.generateThumbs(); + //e.reply('debug: sollte Thumbnail generiert haben'); + }); + } + }, + desc: 'regenerate thumbnail' + }); +}; \ No newline at end of file