blah
This commit is contained in:
parent
33f7b0b4a3
commit
7e55b01df3
5
bot.js
5
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();
|
45
src/lib.js
45
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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+")");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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) {
|
||||
|
|
12
src/trigger/test.js
Normal file
12
src/trigger/test.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
module.exports = (bot, trigger, lib) => {
|
||||
trigger.add({
|
||||
name: 'test',
|
||||
call: /^\!test/,
|
||||
level: 0,
|
||||
active: 1,
|
||||
func: (e) => {
|
||||
|
||||
},
|
||||
desc: 'test'
|
||||
});
|
||||
};
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user