changed triggersystem

This commit is contained in:
Flummi 2016-09-09 11:18:03 +00:00
parent d5f99d1293
commit 6f6d4309e0
13 changed files with 48 additions and 49 deletions

View File

@ -17,10 +17,24 @@ function Lib(tbot, tsql) {
Lib.prototype.loadUser((cb) => { Lib.prototype.loadUser((cb) => {
console.log((cb)?"Admins wurden geladen":"Admins konnten nicht geladen werden"); console.log((cb)?"Admins wurden geladen":"Admins konnten nicht geladen werden");
}); });
Lib.prototype.loadTrigger();
} }
Lib.prototype.admins = []; Lib.prototype.admins = [];
Lib.prototype.debug = false; Lib.prototype.debug = false;
Lib.prototype.trigger = {
trigger: [],
add: (args) => {
Lib.prototype.trigger.trigger.push({
name: args.name,
call: args.call,
func: args.func,
desc: args.desc,
level: args.level,
active: args.active
});
}
};
Lib.prototype.getUserlevel = (user, network, channel, cb) => { Lib.prototype.getUserlevel = (user, network, channel, cb) => {
bot.whois(user, network, (err, data) => { bot.whois(user, network, (err, data) => {
@ -107,4 +121,14 @@ Lib.prototype.generateThumbs = () => {
Lib.prototype.log = (msg) => { Lib.prototype.log = (msg) => {
if(Lib.prototype.debug) if(Lib.prototype.debug)
bot.send("#f0ck", msg, 'n0xy'); bot.send("#f0ck", msg, 'n0xy');
};
Lib.prototype.loadTrigger = () => {
var files = fs.readdirSync(__dirname+'/trigger/');
files.forEach((file) => {
if(file.substr(-3, 3) === '.js') {
console.log('Loading trigger', file);
require(__dirname+'/trigger/' + file)(bot, Lib.prototype);
}
});
}; };

View File

@ -41,7 +41,7 @@ bot.on('motd', (e) => {
}); });
bot.on('message', (e) => { bot.on('message', (e) => {
trigger.trigger.forEach((entry,i,a) => { lib.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.user.getNick(), e.network, e.channel.getName(), (cb) => { lib.getUserlevel(e.user.getNick(), e.network, e.channel.getName(), (cb) => {
@ -52,29 +52,4 @@ bot.on('message', (e) => {
}); });
} }
}); });
}); });
var trigger = {
trigger: [],
add: (args) => {
trigger.trigger.push({
name: args.name,
call: args.call,
func: args.func,
desc: args.desc,
level: args.level,
active: args.active
});
}
};
var loadPlugins = () => {
var files = fs.readdirSync(__dirname+'/trigger/');
files.forEach((file) => {
if(file.substr(-3, 3) === '.js') {
console.log('Loading plugin', file);
require(__dirname+'/trigger/' + file)(bot, trigger, lib);
}
});
};
loadPlugins();

View File

@ -1,7 +1,7 @@
var fs = require('fs-extra'); var fs = require('fs-extra');
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'clean', name: 'clean',
call: /^\!clean/i, call: /^\!clean/i,
level: 100, level: 100,

View File

@ -1,5 +1,5 @@
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'debug', name: 'debug',
call: /^\!debug$/i, call: /^\!debug$/i,
level: 100, level: 100,

View File

@ -1,5 +1,5 @@
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'delete', name: 'delete',
call: /^\!del (\d+)$/i, call: /^\!del (\d+)$/i,
level: 100, level: 100,

View File

@ -1,5 +1,5 @@
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'level', name: 'level',
call: /^\!level(?: +\@.*)?/i, call: /^\!level(?: +\@.*)?/i,
level: 0, level: 0,

View File

@ -5,8 +5,8 @@ var cloudscraper = require('cloudscraper');
var Mime = require('mime'); var Mime = require('mime');
var cfg = require('../../cfg/main.json'); var cfg = require('../../cfg/main.json');
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'parser', name: 'parser',
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
level: 0, level: 0,

View File

@ -1,7 +1,7 @@
var du = require('du'); var du = require('du');
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'stats', name: 'stats',
call: /^\!stats$/i, call: /^\!stats$/i,
level: 10, level: 10,

View File

@ -1,5 +1,5 @@
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'test', name: 'test',
call: /^\!test/, call: /^\!test/,
level: 0, level: 0,

View File

@ -1,7 +1,7 @@
var fs = require('fs-extra'); var fs = require('fs-extra');
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'thumbnailer', name: 'thumbnailer',
call: /^\!thumb (\d+)$/i, call: /^\!thumb (\d+)$/i,
level: 100, level: 100,

View File

@ -2,8 +2,8 @@ var allowedModes = [
'q','a','o','h','v' 'q','a','o','h','v'
]; ];
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'umode', name: 'umode',
call: /^\!umode .*/i, call: /^\!umode .*/i,
level: 100, level: 100,

View File

@ -1,5 +1,5 @@
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'user', name: 'user',
call: /^\!user( \@.*)?/i, call: /^\!user( \@.*)?/i,
level: 0, level: 0,

View File

@ -2,8 +2,8 @@ var fs = require('fs-extra');
var ytdl = require('ytdl-core'); var ytdl = require('ytdl-core');
var uuid = require('uuid'); var uuid = require('uuid');
module.exports = (bot, trigger, lib) => { module.exports = (bot, lib) => {
trigger.add({ lib.trigger.add({
name: 'ytdl', name: 'ytdl',
call: /https?:\/\/(www\.)?(yotu\.be\/|youtube\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi, call: /https?:\/\/(www\.)?(yotu\.be\/|youtube\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi,
level: 0, level: 0,