diff --git a/src/lib.js b/src/lib.js index 6dc9ea8..e3fe374 100644 --- a/src/lib.js +++ b/src/lib.js @@ -17,10 +17,24 @@ function Lib(tbot, tsql) { Lib.prototype.loadUser((cb) => { console.log((cb)?"Admins wurden geladen":"Admins konnten nicht geladen werden"); }); + Lib.prototype.loadTrigger(); } Lib.prototype.admins = []; 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) => { bot.whois(user, network, (err, data) => { @@ -107,4 +121,14 @@ Lib.prototype.generateThumbs = () => { Lib.prototype.log = (msg) => { if(Lib.prototype.debug) 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); + } + }); }; \ No newline at end of file diff --git a/src/main.js b/src/main.js index cd6b464..c5b54f4 100644 --- a/src/main.js +++ b/src/main.js @@ -41,7 +41,7 @@ bot.on('motd', (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) { lib.log('trigger: '+entry.name); 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(); \ No newline at end of file +}); \ No newline at end of file diff --git a/src/trigger/clean.js b/src/trigger/clean.js index bda75ef..2bebedc 100644 --- a/src/trigger/clean.js +++ b/src/trigger/clean.js @@ -1,7 +1,7 @@ var fs = require('fs-extra'); -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'clean', call: /^\!clean/i, level: 100, diff --git a/src/trigger/debug.js b/src/trigger/debug.js index 6e8f61e..407a200 100644 --- a/src/trigger/debug.js +++ b/src/trigger/debug.js @@ -1,5 +1,5 @@ -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'debug', call: /^\!debug$/i, level: 100, diff --git a/src/trigger/del.js b/src/trigger/del.js index e1d4f61..c4b12de 100644 --- a/src/trigger/del.js +++ b/src/trigger/del.js @@ -1,5 +1,5 @@ -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'delete', call: /^\!del (\d+)$/i, level: 100, diff --git a/src/trigger/level.js b/src/trigger/level.js index 55d6d0e..31f2ea7 100644 --- a/src/trigger/level.js +++ b/src/trigger/level.js @@ -1,5 +1,5 @@ -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'level', call: /^\!level(?: +\@.*)?/i, level: 0, diff --git a/src/trigger/parser.js b/src/trigger/parser.js index 8e791b1..951c5e3 100644 --- a/src/trigger/parser.js +++ b/src/trigger/parser.js @@ -5,8 +5,8 @@ var cloudscraper = require('cloudscraper'); var Mime = require('mime'); var cfg = require('../../cfg/main.json'); -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'parser', call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, level: 0, diff --git a/src/trigger/stats.js b/src/trigger/stats.js index 9652d72..8ef0952 100644 --- a/src/trigger/stats.js +++ b/src/trigger/stats.js @@ -1,7 +1,7 @@ var du = require('du'); -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'stats', call: /^\!stats$/i, level: 10, diff --git a/src/trigger/test.js b/src/trigger/test.js index 1c7cc08..6f0c08c 100644 --- a/src/trigger/test.js +++ b/src/trigger/test.js @@ -1,5 +1,5 @@ -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'test', call: /^\!test/, level: 0, diff --git a/src/trigger/thumb.js b/src/trigger/thumb.js index f759058..5724483 100644 --- a/src/trigger/thumb.js +++ b/src/trigger/thumb.js @@ -1,7 +1,7 @@ var fs = require('fs-extra'); -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'thumbnailer', call: /^\!thumb (\d+)$/i, level: 100, diff --git a/src/trigger/umode.js b/src/trigger/umode.js index 8879a80..de7bbd3 100644 --- a/src/trigger/umode.js +++ b/src/trigger/umode.js @@ -2,8 +2,8 @@ var allowedModes = [ 'q','a','o','h','v' ]; -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'umode', call: /^\!umode .*/i, level: 100, diff --git a/src/trigger/user.js b/src/trigger/user.js index b2e40b2..f527201 100644 --- a/src/trigger/user.js +++ b/src/trigger/user.js @@ -1,5 +1,5 @@ -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'user', call: /^\!user( \@.*)?/i, level: 0, diff --git a/src/trigger/ytdl.js b/src/trigger/ytdl.js index 9c99c43..b0d5f04 100644 --- a/src/trigger/ytdl.js +++ b/src/trigger/ytdl.js @@ -2,8 +2,8 @@ var fs = require('fs-extra'); var ytdl = require('ytdl-core'); var uuid = require('uuid'); -module.exports = (bot, trigger, lib) => { - trigger.add({ +module.exports = (bot, lib) => { + lib.trigger.add({ name: 'ytdl', call: /https?:\/\/(www\.)?(yotu\.be\/|youtube\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi, level: 0,