buggsen gefiggst

This commit is contained in:
Flummi 2016-08-23 15:50:30 +00:00
parent 2a2f379939
commit 9e29f0c839
8 changed files with 137 additions and 52 deletions

View File

@ -2,6 +2,9 @@
"name": "keinBotv2",
"version": "0.1.0",
"main": "src/main.js",
"scripts": {
"start": "node src/main.js"
},
"dependencies": {
"coffea": "^0.4.24",
"fs-extra": "^0.30.0",

View File

@ -18,29 +18,42 @@ function Lib(tbot, tsql, tcfg) {
this.admins = [];
}
Lib.prototype.getUser = (u, n, cbgu) => {
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]);
Lib.prototype.getUser = (e, cbgu) => {
var u = e.user.getNick();
var n = e.network;
//console.log(e.user);
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]);
});
});
});
}
else {
cbgu({
nick: e.user.nick,
username: e.user.username,
hostname: e.user.hostname,
realname: e.user.realname
});
}
};
Lib.prototype.getUserlevel = (e, tmp_channel, cb) => {
Lib.prototype.getUser(e.user.getNick(), e.network, (cbgu) => {
Lib.prototype.getUserlevel = (e, cb) => {
Lib.prototype.getUser(e, (cbgu) => {
var host = cbgu.username+'@'+cbgu.hostname;
var lvl_channel = (cbgu.nick in tmp_channel)? cfg.level[ tmp_channel[cbgu.nick] ] : 0;
var lvl_channel = (cbgu.nick in e.channel.names)? cfg.level[ e.channel.names[cbgu.nick] ] : 0;
var lvl_db = 0;
if(host in this.admins)
lvl_db = (this.admins[host].server == e.network)? this.admins[host].level : 0;
@ -98,7 +111,7 @@ Lib.prototype.dl = (url, dest, cb) => {
console.log(response.headers['content-type']);
if(cfg.allowedMimes.hasOwnProperty(response.headers['content-type'])) {
if(response.headers['content-length'] <= cfg.maxFileSize) {
checkRepost(url, (cbcr) => {
Lib.prototype.checkRepost(url, (cbcr) => {
if(cbcr) {
var file = fs.createWriteStream(dest+"."+cfg.allowedMimes[response.headers['content-type']]);
response.pipe(file);
@ -142,15 +155,15 @@ Lib.prototype.generateThumbs = () => {
if(!fs.existsSync(thumbnail)) {
exec('ffmpegthumbnailer -i'+e.dest+' -s256 -o'+thumbnail, (error) => {
if(error) {
log('failed thumbnail for '+e.id+' ('+e.mime+') 1');
Lib.prototype.log('failed thumbnail for '+e.id+' ('+e.mime+') 1');
fs.copySync('./s/mp3.png', thumbnail); // copy standardthumbnail
}
else {
exec('convert '+thumbnail+' -resize "128x128^" -gravity center -crop 128x128+0+0 +repage '+thumbnail, (error) => {
if(error)
log('failed thumbnail for '+e.id+' ('+e.mime+') 2');
Lib.prototype.log('failed thumbnail for '+e.id+' ('+e.mime+') 2');
else
log("generated thumbnail for "+e.id+" ("+e.mime+")");
Lib.prototype.log("generated thumbnail for "+e.id+" ("+e.mime+")");
});
}
});

56
src/lib.js_tmp Normal file
View File

@ -0,0 +1,56 @@
exports.lib = (bot, sql) => {
return {
admins: [],
getUser: (u, n, cbgu) => {
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]);
});
});
},
getUserlevel: (e, tmp_channel, cb) => {
_this.getUser(e.user.getNick(), e.network, (cbgu) => {
var host = cbgu.username+'@'+cbgu.hostname;
var lvl_channel = (cbgu.nick in tmp_channel)? cfg.level[ tmp_channel[cbgu.nick] ] : 0;
var lvl_db = 0;
if(host in admins)
lvl_db = (admins[host].server == e.network)? admins[host].level : 0;
cb({
'channel': lvl_channel,
'db': lvl_db,
'level': Math.max(lvl_channel, lvl_db)
});
});
},
loadUser: (cb) => {
_this.admins = [];
sql.query("select * from `f0ck`.`user`", (err, rows, fields) => {
rows.forEach((e,i,a) => {
_this.admins.push(e.nick);
admins[e.vhost] = {
'id': e.id,
'nick': e.nick,
'vhost': e.vhost,
'level': e.level,
'server': e.server
};
});
cb(true);
}).on('error', () => {
cb(false);
});
}
}
};

View File

@ -9,15 +9,12 @@ var path = require('path');
var exec = require('child_process').exec;
var probe = require('node-ffprobe');
var Lib = require('./lib.js');
var swig = require('swig');
var templates = {};
var debug = false;
var sql;
var haDC = () => {
sql = mysql.createConnection(cfg.mysql);
sql.connect((err) => {
@ -48,21 +45,29 @@ cfg.server.forEach((e,i,a) => {
bot.on('motd', (e) => {
console.log("motd von "+e.network+" erhalten");
bot.join("#kbot-dev"); // tmp
bot.write('MODE f0ck +B', e.network, (c)=>{}); // Botflag
//bot.join("#kbot-dev"); // tmp
bot.write('MODE f0ckyou +B', e.network, (c)=>{}); // Botflag
});
bot.on('message', (e) => {
var orig = e.message;
trigger.trigger.forEach((entry,i,a) => {
if(orig.match(new RegExp(entry.call, "gi"))) {
entry.func(e);
if(e.message.match(entry.call)) {
lib.getUserlevel(e, (cb) => {
if(cb.level >= entry.level) {
//setTimeout(()=>{
entry.func(e);
//}, 100);
}
else
e.reply('no permission, min level '+entry.level+' required');
});
}
});
});
// Webserver
http.createServer((req, res) => {
//console.log(req.connection.remoteAddress);
if(cfg.wlip.hasOwnProperty(req.connection.remoteAddress)) {
var filePath = '.' + req.url;
var url = req.url.split("/")[1];
@ -135,7 +140,7 @@ http.createServer((req, res) => {
data.src = e.src;
data.dest = e.dest;
data.mime = e.mime;
data.size = formatSize(e.size);
data.size = lib.formatSize(e.size);
data.userchannel = e.userchannel;
data.usernetwork = e.usernetwork;
@ -266,6 +271,7 @@ var trigger = {
trigger: [],
add: (args) => {
trigger.trigger.push({
name: args.name,
call: args.call,
func: args.func,
desc: args.desc,

View File

@ -1,19 +1,12 @@
module.exports = (bot, trigger, lib) => {
trigger.add({
name: 'delete',
call: '^\!del (\d+)$',
call: new RegExp('^\\!del (\\d+)$', 'i'),
level: 100,
func: (e) => {
var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names;
lib.getUserlevel(e, e.user.getNick(), tmp_channel, (cb) => {
if(cb.level >= 100) {
var id = orig.split(' ')[1];
sql.query("delete from `f0ck`.`items` where `id` = ?", id).on('end', () => {
e.reply("f0ck "+id+" deleted");
});
}
else
e.reply("no permission");
var id = e.message.split(' ')[1];
lib.sql.query("delete from `f0ck`.`items` where `id` = ?", id).on('end', () => {
e.reply("f0ck "+id+" deleted");
});
},
desc: 'delete f0ck'

View File

@ -1,11 +1,10 @@
module.exports = (bot, trigger, lib) => {
trigger.add({
name: 'level',
call: '^\!level$',
call: new RegExp('^\\!level$', 'i'),
level: 0,
func: (e) => {
var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names;
lib.getUserlevel(e, tmp_channel, (cb) => {
lib.getUserlevel(e, (cb) => {
e.reply("level from "+e.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
});
},

View File

@ -1,10 +1,11 @@
var fs = require('fs-extra');
var uuid = require('uuid');
var path = require('path');
module.exports = (bot, trigger, lib) => {
trigger.add({
name: 'parser',
call: 'https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?',
call: new RegExp('https?:\\/\\/[\\w-]+(\\.[\\w-]+)+\\.?(:\\d+)?(\\/\\S*)?', 'gi'),
level: 0,
func: (e) => {
if(!e.message.match(/\!ignore$/)) {
@ -13,7 +14,7 @@ module.exports = (bot, trigger, lib) => {
var tmpdest = uuid.v1().split('-')[0];
lib.dl(entry, "./b/"+tmpdest, (cb) => { // download item
if(cb.status === true) {
lib.getUser(e.user.getNick(), e.network, (cbgu) => {
lib.getUser(e, (cbgu) => {
lib.getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs) {
@ -29,8 +30,8 @@ module.exports = (bot, trigger, lib) => {
Math.floor(new Date() / 1000),
0
]).on('result', (result) => {
generateThumbs();
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
lib.generateThumbs();
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+lib.formatSize(cb.infos.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
}).on('error', (msg) => {
e.reply(msg);
});

14
src/trigger/user.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = (bot, trigger, lib) => {
trigger.add({
name: 'user',
call: new RegExp('^\\!user$', 'i'),
level: 0,
func: (e) => {
//e.reply(e.user);
lib.getUser(e, (cbgu) => {
e.reply(cbgu);
});
},
desc: 'get Userdata'
});
};