From 7e55b01df38d403c2f782b5c31baae4f0c7de6f6 Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 8 Sep 2016 15:42:38 +0000 Subject: [PATCH] blah --- bot.js | 5 +---- src/lib.js | 45 ++++++------------------------------------- src/main.js | 2 +- src/trigger/level.js | 37 +++++++++++++---------------------- src/trigger/parser.js | 4 ++-- src/trigger/test.js | 12 ++++++++++++ src/trigger/user.js | 27 +++++++------------------- src/trigger/ytdl.js | 7 +------ 8 files changed, 43 insertions(+), 96 deletions(-) create mode 100644 src/trigger/test.js diff --git a/bot.js b/bot.js index 845f0ba..cf601c6 100644 --- a/bot.js +++ b/bot.js @@ -22,7 +22,7 @@ var putlog = (msg) => { var child = new (forever.Monitor)('./src/main.js', { max: 1, - silent: true, + silent: false, args: [], watch: true, watchIgnoreDotFiles: true, @@ -48,7 +48,4 @@ child.on('exit:code', (code) => { putlog('detected bot exited with code ' + code + '\n'); child.restart(); }); -child.on('stderr', (data) => { - putlog(data); -}); child.start(); \ No newline at end of file diff --git a/src/lib.js b/src/lib.js index b95576d..a529807 100644 --- a/src/lib.js +++ b/src/lib.js @@ -23,46 +23,13 @@ function Lib(tbot, tsql) { Lib.prototype.admins = []; Lib.prototype.debug = false; -Lib.prototype.getUser = (e, cbgu) => { - var u = e.user.getNick(); - var n = e.network; - if(!e.user.hasOwnProperty('hostname')) { - 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({ - nick: e.user.nick, - username: e.user.username, - hostname: e.user.hostname, - realname: e.user.realname - }); - } -}; -Lib.prototype.getUserlevel = (e, cb) => { - Lib.prototype.getUser(e, (cbgu) => { - var host = cbgu.username+'@'+cbgu.hostname; - var lvl_channel = (cbgu.nick in e.channel.names)? cfg.level[ e.channel.names[cbgu.nick] ] : 0; +Lib.prototype.getUserlevel = (user, network, channel, cb) => { + bot.whois(user, network, (err, data) => { + var host = data.username+'@'+data.hostname; + var lvl_channel = (data.nick in channel)? cfg.level[ channel[data.nick] ] : 0; var lvl_db = 0; if(host in Lib.prototype.admins) - lvl_db = (Lib.prototype.admins[host].server == e.network)? Lib.prototype.admins[host].level : 0; + lvl_db = (Lib.prototype.admins[host].server == network)? Lib.prototype.admins[host].level : 0; cb({ 'channel': lvl_channel, 'db': lvl_db, @@ -113,7 +80,7 @@ Lib.prototype.getCheckSum = (file, cbcs) => { }); }; Lib.prototype.dl = (url, dest, cb) => { - var request = (url.match(/^https/)?https:http).get(url, (response) => { // type:1=post,type:2=stfu + (url.match(/^https/)?https:http).get(url, (response) => { // type:1=post,type:2=stfu console.log(response.headers['content-type']); if(cfg.allowedMimes.hasOwnProperty(response.headers['content-type'])) { if(response.headers['content-length'] <= cfg.maxFileSize) { diff --git a/src/main.js b/src/main.js index 3baf2d3..594cce1 100644 --- a/src/main.js +++ b/src/main.js @@ -44,7 +44,7 @@ bot.on('message', (e) => { trigger.trigger.forEach((entry,i,a) => { if(e.message.match(entry.call) && entry.active == 1) { lib.log('trigger: '+entry.name); - lib.getUserlevel(e, (cb) => { + lib.getUserlevel(e.user.getNick(), e.network, e.channel.names, (cb) => { if(cb.level >= entry.level) entry.func(e, cb.level); else diff --git a/src/trigger/level.js b/src/trigger/level.js index 32e3ea8..029fab3 100644 --- a/src/trigger/level.js +++ b/src/trigger/level.js @@ -13,26 +13,26 @@ module.exports = (bot, trigger, lib) => { var level = (args[2]>=100)?100:args[2]; if( name in e.channel.names ) { - lib.getUser( { network: e.network, user: { getNick: () => { return name.trim(); } }, channel: { names: e.channel.names } }, cb => { - var host = cb.username+'@'+cb.hostname; - if( host in lib.admins ) { + bot.whois(name.trim(), e.network, (err, data) => { + var host = data.username+'@'+data.hostname; + if(host in lib.admins) { if(level <= 0) { lib.sql.query('delete from `f0ck`.`user` where `id` = ? limit 1', [lib.admins[host].id], () => { lib.loadUser(); - e.reply('deleted user '+cb.nick+' ('+host+')'); + e.reply('deleted user '+data.nick+' ('+host+')'); }); } else { lib.sql.query('update `f0ck`.`user` set `level` = ? where `id` = ?', [level, lib.admins[host].id], () => { lib.loadUser(); - e.reply('changed user '+cb.nick+' ('+host+') to level '+level); + e.reply('changed user '+data.nick+' ('+host+') to level '+level); }); } } else { - lib.sql.query('insert into `f0ck`.`user` (`nick`,`vhost`,`level`,`server`) values (?,?,?,?)', [cb.nick, host, level, e.network], () => { + lib.sql.query('insert into `f0ck`.`user` (`nick`,`vhost`,`level`,`server`) values (?,?,?,?)', [data.nick, host, level, e.network], () => { lib.loadUser(); - e.reply('added new user '+cb.nick+' ('+host+') with level '+level); + e.reply('added new user '+data.nick+' ('+host+') with level '+level); }); } }); @@ -44,24 +44,13 @@ module.exports = (bot, trigger, lib) => { e.reply('no permission, min level 100 required'); } else { - var user, etmp; - if(user = e.message.match(/^\!level(?: +@(.*))?/i)[1]) { - etmp = { - network: e.network, - user: { - getNick: () => { - return user.trim(); - } - }, - channel: { - names: e.channel.names - } - }; - } + var user; + if(!(user = e.message.match(/^\!level(?: +@(.*))?/i)[1])) + user = e.user.getNick(); else - etmp = e; - lib.getUserlevel(etmp, (cb) => { - e.reply("level from "+etmp.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")"); + user = user.trim(); + lib.getUserlevel(user, e.network, e.channel.names, cb => { + e.reply("level from "+user+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")"); }); } }, diff --git a/src/trigger/parser.js b/src/trigger/parser.js index d24cf8d..cb853ac 100644 --- a/src/trigger/parser.js +++ b/src/trigger/parser.js @@ -9,7 +9,7 @@ module.exports = (bot, trigger, lib) => { level: 0, active: 1, func: (e) => { - if(e.channel.getName() == '#f0ck') { + if(e.channel.getName() == '#kbot-dev') { if(!e.message.match(/\!ignore$/)) { var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links tmp.forEach((entry,i,a) => { @@ -17,7 +17,7 @@ module.exports = (bot, trigger, lib) => { if(!entry.match(/f0ck\.me/i)) { lib.dl(entry, "./b/"+tmpdest, (cb) => { // download item if(cb.status === true) { - lib.getUser(e, (cbgu) => { + bot.whois(e.user.getNick(), e.network, (err, cbgu) => { lib.getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => { lib.checkRepostCheckSum(cbcs, (cbcrcs) => { if(cbcrcs === true) { diff --git a/src/trigger/test.js b/src/trigger/test.js new file mode 100644 index 0000000..99cacb6 --- /dev/null +++ b/src/trigger/test.js @@ -0,0 +1,12 @@ +module.exports = (bot, trigger, lib) => { + trigger.add({ + name: 'test', + call: /^\!test/, + level: 0, + active: 1, + func: (e) => { + + }, + desc: 'test' + }); +}; \ No newline at end of file diff --git a/src/trigger/user.js b/src/trigger/user.js index 3bf99a0..b2e40b2 100644 --- a/src/trigger/user.js +++ b/src/trigger/user.js @@ -5,26 +5,13 @@ module.exports = (bot, trigger, lib) => { level: 0, active: 1, func: (e) => { - var tmp = e.message.match(/^\!user( +@(.*))?/i); - if(tmp[2] !== undefined) { - // e nachbauen xD - var etmp = { - network: e.network, - user: { - getNick: () => { - return tmp[2].trim(); - } - } - }; - lib.getUser(etmp, (cbgu) => { - e.reply(cbgu); - }); - } - else { - lib.getUser(e, (cbgu) => { - e.reply(cbgu); - }); - } + if(!(user = e.message.match(/^\!user( +@(.*))?/i)[2])) + user = e.user.getNick(); + else + user = user.trim(); + bot.whois(user, e.network, (err, data) => { + e.reply(data); + }); }, desc: 'get Userdata' }); diff --git a/src/trigger/ytdl.js b/src/trigger/ytdl.js index 4b0b39a..095ae02 100644 --- a/src/trigger/ytdl.js +++ b/src/trigger/ytdl.js @@ -22,7 +22,6 @@ module.exports = (bot, trigger, lib) => { if(!err) { var title = info.title; var dat = fs.createWriteStream('./b/'+tmpdest+'.webm'); - try { ytdl.downloadFromInfo(info, { filter: (format) => { return format.container === 'webm'; } }) .on('response', (res) => { @@ -40,12 +39,11 @@ module.exports = (bot, trigger, lib) => { catch(ex) { e.reply(ex); } - dat.on('finish', () => { if(dl) { dat.close(); var stat = fs.statSync("./b/"+tmpdest+".webm"); - lib.getUser(e, (cbgu) => { + bot.whois(e.user.getNick(), e.network, (err, cbgu) => { lib.getCheckSum("./b/"+tmpdest+".webm", (cbcs) => { lib.checkRepostCheckSum(cbcs, (cbcrcs) => { if(cbcrcs === true) { @@ -79,9 +77,6 @@ module.exports = (bot, trigger, lib) => { fs.unlink('./b/'+tmpdest+'.webm'); }); } - else { - e.reply("f0ck GEMA"); - } }); } else