From 54dc7f2236502609a5ac6cb14ade4a9b058ab26d Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 5 Jun 2012 00:17:51 +0100 Subject: [PATCH] Changed commands to property rather than object to be returned by onLoad functionality --- modules/admin.js | 5 ++--- modules/autoshorten.js | 11 ++++------- modules/command.js | 5 ++--- modules/drama.js | 13 ++++--------- modules/ignore.js | 2 +- modules/js.js | 5 +---- modules/kick.js | 15 +++++---------- modules/link.js | 6 +----- modules/puns.js | 12 +++++------- modules/quotes.js | 9 ++++----- modules/spelling.js | 12 ++++-------- modules/web.js | 9 ++++----- modules/youare.js | 12 ++++-------- run.js | 6 +++++- 14 files changed, 46 insertions(+), 76 deletions(-) diff --git a/modules/admin.js b/modules/admin.js index 3c15948..2a79884 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -114,6 +114,7 @@ var admin = function(dbot) { return { 'name': 'admin', + 'ignorable': false, /** * Run the appropriate admin command given the input (and user). @@ -125,9 +126,7 @@ var admin = function(dbot) { dbot.save(); } }, - - 'on': 'PRIVMSG', - 'ignorable': false + 'on': 'PRIVMSG' }; }; diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 9ad8a86..426941a 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -6,10 +6,10 @@ var http = require('http'); var autoshorten = function(dbot) { - var name = 'autoshorten'; - var dbot = dbot; - return { + 'name': 'autoshorten', + 'ignorable': true, + 'listener': function(event) { var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; var urlMatches = event.message.match(urlRegex); @@ -32,10 +32,7 @@ var autoshorten = function(dbot) { }); } }, - - 'on': 'PRIVMSG', - 'name': name, - 'ignorable': true + 'on': 'PRIVMSG' }; } diff --git a/modules/command.js b/modules/command.js index 6c6c118..5f78d8e 100644 --- a/modules/command.js +++ b/modules/command.js @@ -51,6 +51,7 @@ var command = function(dbot) { return { 'name': 'command', + 'ignorable': false, /** * Run the appropriate command given the input. @@ -76,9 +77,7 @@ var command = function(dbot) { } } }, - - 'on': 'PRIVMSG', - 'ignorable': false + 'on': 'PRIVMSG' }; }; diff --git a/modules/drama.js b/modules/drama.js index 51e82e7..fc9aa3a 100644 --- a/modules/drama.js +++ b/modules/drama.js @@ -57,9 +57,9 @@ var drama = function(dbot) { } return { - 'onLoad': function() { - return commands; - }, + 'name': 'drama', + 'ignorable': false, + 'commands': commands, 'listener': function(data) { var category = bayes.classify(data.message, function(category) { @@ -87,12 +87,7 @@ var drama = function(dbot) { last[event.channel][event.user] = data.message; } }, - - 'on': 'PRIVMSG', - - 'name': 'drama', - - 'ignorable': false + 'on': 'PRIVMSG' }; } diff --git a/modules/ignore.js b/modules/ignore.js index 60d75cc..b7330b7 100644 --- a/modules/ignore.js +++ b/modules/ignore.js @@ -61,6 +61,7 @@ var ignore = function(dbot) { return { 'name': 'ignore', 'ignorable': false, + 'commands': commands, 'onLoad': function() { dbot.instance.clearIgnores(); @@ -71,7 +72,6 @@ var ignore = function(dbot) { } } } - return commands; } }; }; diff --git a/modules/js.js b/modules/js.js index 3aee828..024f763 100644 --- a/modules/js.js +++ b/modules/js.js @@ -34,10 +34,7 @@ var js = function(dbot) { return { 'name': 'js', 'ignorable': true, - - 'onLoad': function() { - return commands; - } + 'commands': commands }; }; diff --git a/modules/kick.js b/modules/kick.js index 05711dd..ff1e42d 100644 --- a/modules/kick.js +++ b/modules/kick.js @@ -50,6 +50,10 @@ var kick = function(dbot) { }; return { + 'name': 'kick', + 'ignorable': false, + 'commands': commands, + 'listener': function(event) { if(event.kickee == dbot.name) { dbot.instance.join(event, event.channel); @@ -72,16 +76,7 @@ var kick = function(dbot) { {'user': event.kickee, 'kicks': dbot.db.kicks[event.kickee], 'kicked': dbot.db.kickers[event.kickee]}) + ')'); } }, - - on: 'KICK', - - 'onLoad': function() { - return commands; - }, - - 'name': 'kick', - - 'ignorable': false + on: 'KICK' }; }; diff --git a/modules/link.js b/modules/link.js index 82df1c4..9d37459 100644 --- a/modules/link.js +++ b/modules/link.js @@ -34,10 +34,7 @@ var link = function(dbot) { return { 'name': 'link', 'ignorable': true, - - 'onLoad': function() { - return commands; - }, + 'commands': commands, 'listener': function(event) { var urlMatches = event.message.match(urlRegex); @@ -45,7 +42,6 @@ var link = function(dbot) { links[event.channel] = urlMatches[0]; } }, - 'on': 'PRIVMSG' }; }; diff --git a/modules/puns.js b/modules/puns.js index 099d31a..7144932 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -3,6 +3,9 @@ var puns = function(dbot) { var dbot = dbot; return { + 'name': name, + 'ignorable': true, + 'listener': function(event) { event.user = dbot.cleanNick(event.user); if(dbot.moduleNames.include('quotes') && @@ -10,15 +13,10 @@ var puns = function(dbot) { event.message = '~q ' + event.user; event.action = 'PRIVMSG'; event.params = event.message.split(' '); - dbot.instance.emit(event) + dbot.instance.emit(event); } }, - - 'on': 'JOIN', - - 'name': name, - - 'ignorable': true + 'on': 'JOIN' }; } diff --git a/modules/quotes.js b/modules/quotes.js index 64829ed..0a044a3 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -218,11 +218,14 @@ var quotes = function(dbot) { commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; return { + 'name': 'quotes', + 'ignorable': true, + 'commands': commands, + 'onLoad': function() { dbot.timers.addTimer(1000 * 60 * 3, function() { rmAllowed = true; }); - return commands; }, /* For automatic quote retrieval @@ -254,10 +257,6 @@ var quotes = function(dbot) { }, 'on': 'PRIVMSG',*/ - - 'name': name, - - 'ignorable': true }; }; diff --git a/modules/spelling.js b/modules/spelling.js index e52e2fe..28d6006 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -1,6 +1,4 @@ var spelling = function(dbot) { - var name = 'spelling'; - var dbot = dbot; var last = {}; var correct = function (event, correction, candidate, output_callback) { @@ -38,6 +36,9 @@ var spelling = function(dbot) { } return { + 'name': 'spelling', + 'ignorable': true, + 'listener': function(event) { var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); @@ -58,12 +59,7 @@ var spelling = function(dbot) { } } }, - - 'on': 'PRIVMSG', - - 'name': name, - - 'ignorable': true + 'on': 'PRIVMSG' } } diff --git a/modules/web.js b/modules/web.js index c2bc7bf..911e88f 100644 --- a/modules/web.js +++ b/modules/web.js @@ -37,13 +37,12 @@ var webInterface = function(dbot) { app.listen(dbot.webPort); return { + 'name': 'web', + 'ignorable': false, + 'onDestroy': function() { app.close(); - }, - - 'name': 'web', - - 'ignorable': false + } }; }; diff --git a/modules/youare.js b/modules/youare.js index 3627b28..ddb25e0 100644 --- a/modules/youare.js +++ b/modules/youare.js @@ -1,7 +1,8 @@ var youAre = function(dbot) { - var name = 'youare'; - return { + 'name': 'youare', + 'ignorable': false, + 'listener': function(event) { var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); @@ -9,12 +10,7 @@ var youAre = function(dbot) { event.reply(event.user + ': You\'re ' + key[2] + '.'); } }, - - 'on': 'PRIVMSG', - - 'name': name, - - 'ignorable': false + 'on': 'PRIVMSG' }; }; diff --git a/run.js b/run.js index 9973c64..e6505a5 100644 --- a/run.js +++ b/run.js @@ -158,7 +158,11 @@ DBot.prototype.reloadModules = function() { } if(module.onLoad) { - var newCommands = module.onLoad(); + module.onLoad(); + } + + if(module.commands) { + var newCommands = module.commands; for(key in newCommands) { if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) { this.commands[key] = newCommands[key];