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', {
|
var child = new (forever.Monitor)('./src/main.js', {
|
||||||
max: 1,
|
max: 1,
|
||||||
silent: true,
|
silent: false,
|
||||||
args: [],
|
args: [],
|
||||||
watch: true,
|
watch: true,
|
||||||
watchIgnoreDotFiles: true,
|
watchIgnoreDotFiles: true,
|
||||||
|
@ -48,7 +48,4 @@ child.on('exit:code', (code) => {
|
||||||
putlog('detected bot exited with code ' + code + '\n');
|
putlog('detected bot exited with code ' + code + '\n');
|
||||||
child.restart();
|
child.restart();
|
||||||
});
|
});
|
||||||
child.on('stderr', (data) => {
|
|
||||||
putlog(data);
|
|
||||||
});
|
|
||||||
child.start();
|
child.start();
|
45
src/lib.js
45
src/lib.js
|
@ -23,46 +23,13 @@ function Lib(tbot, tsql) {
|
||||||
Lib.prototype.admins = [];
|
Lib.prototype.admins = [];
|
||||||
Lib.prototype.debug = false;
|
Lib.prototype.debug = false;
|
||||||
|
|
||||||
Lib.prototype.getUser = (e, cbgu) => {
|
Lib.prototype.getUserlevel = (user, network, channel, cb) => {
|
||||||
var u = e.user.getNick();
|
bot.whois(user, network, (err, data) => {
|
||||||
var n = e.network;
|
var host = data.username+'@'+data.hostname;
|
||||||
if(!e.user.hasOwnProperty('hostname')) {
|
var lvl_channel = (data.nick in channel)? cfg.level[ channel[data.nick] ] : 0;
|
||||||
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;
|
|
||||||
var lvl_db = 0;
|
var lvl_db = 0;
|
||||||
if(host in Lib.prototype.admins)
|
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({
|
cb({
|
||||||
'channel': lvl_channel,
|
'channel': lvl_channel,
|
||||||
'db': lvl_db,
|
'db': lvl_db,
|
||||||
|
@ -113,7 +80,7 @@ Lib.prototype.getCheckSum = (file, cbcs) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Lib.prototype.dl = (url, dest, cb) => {
|
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']);
|
console.log(response.headers['content-type']);
|
||||||
if(cfg.allowedMimes.hasOwnProperty(response.headers['content-type'])) {
|
if(cfg.allowedMimes.hasOwnProperty(response.headers['content-type'])) {
|
||||||
if(response.headers['content-length'] <= cfg.maxFileSize) {
|
if(response.headers['content-length'] <= cfg.maxFileSize) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ bot.on('message', (e) => {
|
||||||
trigger.trigger.forEach((entry,i,a) => {
|
trigger.trigger.forEach((entry,i,a) => {
|
||||||
if(e.message.match(entry.call) && entry.active == 1) {
|
if(e.message.match(entry.call) && entry.active == 1) {
|
||||||
lib.log('trigger: '+entry.name);
|
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)
|
if(cb.level >= entry.level)
|
||||||
entry.func(e, cb.level);
|
entry.func(e, cb.level);
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,26 +13,26 @@ module.exports = (bot, trigger, lib) => {
|
||||||
var level = (args[2]>=100)?100:args[2];
|
var level = (args[2]>=100)?100:args[2];
|
||||||
|
|
||||||
if( name in e.channel.names ) {
|
if( name in e.channel.names ) {
|
||||||
lib.getUser( { network: e.network, user: { getNick: () => { return name.trim(); } }, channel: { names: e.channel.names } }, cb => {
|
bot.whois(name.trim(), e.network, (err, data) => {
|
||||||
var host = cb.username+'@'+cb.hostname;
|
var host = data.username+'@'+data.hostname;
|
||||||
if( host in lib.admins ) {
|
if(host in lib.admins) {
|
||||||
if(level <= 0) {
|
if(level <= 0) {
|
||||||
lib.sql.query('delete from `f0ck`.`user` where `id` = ? limit 1', [lib.admins[host].id], () => {
|
lib.sql.query('delete from `f0ck`.`user` where `id` = ? limit 1', [lib.admins[host].id], () => {
|
||||||
lib.loadUser();
|
lib.loadUser();
|
||||||
e.reply('deleted user '+cb.nick+' ('+host+')');
|
e.reply('deleted user '+data.nick+' ('+host+')');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lib.sql.query('update `f0ck`.`user` set `level` = ? where `id` = ?', [level, lib.admins[host].id], () => {
|
lib.sql.query('update `f0ck`.`user` set `level` = ? where `id` = ?', [level, lib.admins[host].id], () => {
|
||||||
lib.loadUser();
|
lib.loadUser();
|
||||||
e.reply('changed user '+cb.nick+' ('+host+') to level '+level);
|
e.reply('changed user '+data.nick+' ('+host+') to level '+level);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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();
|
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');
|
e.reply('no permission, min level 100 required');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var user, etmp;
|
var user;
|
||||||
if(user = e.message.match(/^\!level(?: +@(.*))?/i)[1]) {
|
if(!(user = e.message.match(/^\!level(?: +@(.*))?/i)[1]))
|
||||||
etmp = {
|
user = e.user.getNick();
|
||||||
network: e.network,
|
|
||||||
user: {
|
|
||||||
getNick: () => {
|
|
||||||
return user.trim();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
names: e.channel.names
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
etmp = e;
|
user = user.trim();
|
||||||
lib.getUserlevel(etmp, (cb) => {
|
lib.getUserlevel(user, e.network, e.channel.names, cb => {
|
||||||
e.reply("level from "+etmp.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
|
e.reply("level from "+user+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,7 +9,7 @@ module.exports = (bot, trigger, lib) => {
|
||||||
level: 0,
|
level: 0,
|
||||||
active: 1,
|
active: 1,
|
||||||
func: (e) => {
|
func: (e) => {
|
||||||
if(e.channel.getName() == '#f0ck') {
|
if(e.channel.getName() == '#kbot-dev') {
|
||||||
if(!e.message.match(/\!ignore$/)) {
|
if(!e.message.match(/\!ignore$/)) {
|
||||||
var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
|
var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
|
||||||
tmp.forEach((entry,i,a) => {
|
tmp.forEach((entry,i,a) => {
|
||||||
|
@ -17,7 +17,7 @@ module.exports = (bot, trigger, lib) => {
|
||||||
if(!entry.match(/f0ck\.me/i)) {
|
if(!entry.match(/f0ck\.me/i)) {
|
||||||
lib.dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
lib.dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
||||||
if(cb.status === true) {
|
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.getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
|
||||||
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||||||
if(cbcrcs === true) {
|
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,
|
level: 0,
|
||||||
active: 1,
|
active: 1,
|
||||||
func: (e) => {
|
func: (e) => {
|
||||||
var tmp = e.message.match(/^\!user( +@(.*))?/i);
|
if(!(user = e.message.match(/^\!user( +@(.*))?/i)[2]))
|
||||||
if(tmp[2] !== undefined) {
|
user = e.user.getNick();
|
||||||
// e nachbauen xD
|
else
|
||||||
var etmp = {
|
user = user.trim();
|
||||||
network: e.network,
|
bot.whois(user, e.network, (err, data) => {
|
||||||
user: {
|
e.reply(data);
|
||||||
getNick: () => {
|
});
|
||||||
return tmp[2].trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
lib.getUser(etmp, (cbgu) => {
|
|
||||||
e.reply(cbgu);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lib.getUser(e, (cbgu) => {
|
|
||||||
e.reply(cbgu);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
desc: 'get Userdata'
|
desc: 'get Userdata'
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,6 @@ module.exports = (bot, trigger, lib) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
var title = info.title;
|
var title = info.title;
|
||||||
var dat = fs.createWriteStream('./b/'+tmpdest+'.webm');
|
var dat = fs.createWriteStream('./b/'+tmpdest+'.webm');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ytdl.downloadFromInfo(info, { filter: (format) => { return format.container === 'webm'; } })
|
ytdl.downloadFromInfo(info, { filter: (format) => { return format.container === 'webm'; } })
|
||||||
.on('response', (res) => {
|
.on('response', (res) => {
|
||||||
|
@ -40,12 +39,11 @@ module.exports = (bot, trigger, lib) => {
|
||||||
catch(ex) {
|
catch(ex) {
|
||||||
e.reply(ex);
|
e.reply(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
dat.on('finish', () => {
|
dat.on('finish', () => {
|
||||||
if(dl) {
|
if(dl) {
|
||||||
dat.close();
|
dat.close();
|
||||||
var stat = fs.statSync("./b/"+tmpdest+".webm");
|
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.getCheckSum("./b/"+tmpdest+".webm", (cbcs) => {
|
||||||
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||||||
if(cbcrcs === true) {
|
if(cbcrcs === true) {
|
||||||
|
@ -79,9 +77,6 @@ module.exports = (bot, trigger, lib) => {
|
||||||
fs.unlink('./b/'+tmpdest+'.webm');
|
fs.unlink('./b/'+tmpdest+'.webm');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
e.reply("f0ck GEMA");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user