3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00

Changed commands to property rather than object to be returned by onLoad functionality

This commit is contained in:
Luke Slater 2012-06-05 00:17:51 +01:00
parent 181c3a2628
commit 54dc7f2236
14 changed files with 46 additions and 76 deletions

View File

@ -114,6 +114,7 @@ var admin = function(dbot) {
return { return {
'name': 'admin', 'name': 'admin',
'ignorable': false,
/** /**
* Run the appropriate admin command given the input (and user). * Run the appropriate admin command given the input (and user).
@ -125,9 +126,7 @@ var admin = function(dbot) {
dbot.save(); dbot.save();
} }
}, },
'on': 'PRIVMSG'
'on': 'PRIVMSG',
'ignorable': false
}; };
}; };

View File

@ -6,10 +6,10 @@
var http = require('http'); var http = require('http');
var autoshorten = function(dbot) { var autoshorten = function(dbot) {
var name = 'autoshorten';
var dbot = dbot;
return { return {
'name': 'autoshorten',
'ignorable': true,
'listener': function(event) { 'listener': function(event) {
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var urlMatches = event.message.match(urlRegex); var urlMatches = event.message.match(urlRegex);
@ -32,10 +32,7 @@ var autoshorten = function(dbot) {
}); });
} }
}, },
'on': 'PRIVMSG'
'on': 'PRIVMSG',
'name': name,
'ignorable': true
}; };
} }

View File

@ -51,6 +51,7 @@ var command = function(dbot) {
return { return {
'name': 'command', 'name': 'command',
'ignorable': false,
/** /**
* Run the appropriate command given the input. * Run the appropriate command given the input.
@ -76,9 +77,7 @@ var command = function(dbot) {
} }
} }
}, },
'on': 'PRIVMSG'
'on': 'PRIVMSG',
'ignorable': false
}; };
}; };

View File

@ -57,9 +57,9 @@ var drama = function(dbot) {
} }
return { return {
'onLoad': function() { 'name': 'drama',
return commands; 'ignorable': false,
}, 'commands': commands,
'listener': function(data) { 'listener': function(data) {
var category = bayes.classify(data.message, function(category) { var category = bayes.classify(data.message, function(category) {
@ -87,12 +87,7 @@ var drama = function(dbot) {
last[event.channel][event.user] = data.message; last[event.channel][event.user] = data.message;
} }
}, },
'on': 'PRIVMSG'
'on': 'PRIVMSG',
'name': 'drama',
'ignorable': false
}; };
} }

View File

@ -61,6 +61,7 @@ var ignore = function(dbot) {
return { return {
'name': 'ignore', 'name': 'ignore',
'ignorable': false, 'ignorable': false,
'commands': commands,
'onLoad': function() { 'onLoad': function() {
dbot.instance.clearIgnores(); dbot.instance.clearIgnores();
@ -71,7 +72,6 @@ var ignore = function(dbot) {
} }
} }
} }
return commands;
} }
}; };
}; };

View File

@ -34,10 +34,7 @@ var js = function(dbot) {
return { return {
'name': 'js', 'name': 'js',
'ignorable': true, 'ignorable': true,
'commands': commands
'onLoad': function() {
return commands;
}
}; };
}; };

View File

@ -50,6 +50,10 @@ var kick = function(dbot) {
}; };
return { return {
'name': 'kick',
'ignorable': false,
'commands': commands,
'listener': function(event) { 'listener': function(event) {
if(event.kickee == dbot.name) { if(event.kickee == dbot.name) {
dbot.instance.join(event, event.channel); 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]}) + ')'); {'user': event.kickee, 'kicks': dbot.db.kicks[event.kickee], 'kicked': dbot.db.kickers[event.kickee]}) + ')');
} }
}, },
on: 'KICK'
on: 'KICK',
'onLoad': function() {
return commands;
},
'name': 'kick',
'ignorable': false
}; };
}; };

View File

@ -34,10 +34,7 @@ var link = function(dbot) {
return { return {
'name': 'link', 'name': 'link',
'ignorable': true, 'ignorable': true,
'commands': commands,
'onLoad': function() {
return commands;
},
'listener': function(event) { 'listener': function(event) {
var urlMatches = event.message.match(urlRegex); var urlMatches = event.message.match(urlRegex);
@ -45,7 +42,6 @@ var link = function(dbot) {
links[event.channel] = urlMatches[0]; links[event.channel] = urlMatches[0];
} }
}, },
'on': 'PRIVMSG' 'on': 'PRIVMSG'
}; };
}; };

View File

@ -3,6 +3,9 @@ var puns = function(dbot) {
var dbot = dbot; var dbot = dbot;
return { return {
'name': name,
'ignorable': true,
'listener': function(event) { 'listener': function(event) {
event.user = dbot.cleanNick(event.user); event.user = dbot.cleanNick(event.user);
if(dbot.moduleNames.include('quotes') && if(dbot.moduleNames.include('quotes') &&
@ -10,15 +13,10 @@ var puns = function(dbot) {
event.message = '~q ' + event.user; event.message = '~q ' + event.user;
event.action = 'PRIVMSG'; event.action = 'PRIVMSG';
event.params = event.message.split(' '); event.params = event.message.split(' ');
dbot.instance.emit(event) dbot.instance.emit(event);
} }
}, },
'on': 'JOIN'
'on': 'JOIN',
'name': name,
'ignorable': true
}; };
} }

View File

@ -218,11 +218,14 @@ var quotes = function(dbot) {
commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
return { return {
'name': 'quotes',
'ignorable': true,
'commands': commands,
'onLoad': function() { 'onLoad': function() {
dbot.timers.addTimer(1000 * 60 * 3, function() { dbot.timers.addTimer(1000 * 60 * 3, function() {
rmAllowed = true; rmAllowed = true;
}); });
return commands;
}, },
/* For automatic quote retrieval /* For automatic quote retrieval
@ -254,10 +257,6 @@ var quotes = function(dbot) {
}, },
'on': 'PRIVMSG',*/ 'on': 'PRIVMSG',*/
'name': name,
'ignorable': true
}; };
}; };

View File

@ -1,6 +1,4 @@
var spelling = function(dbot) { var spelling = function(dbot) {
var name = 'spelling';
var dbot = dbot;
var last = {}; var last = {};
var correct = function (event, correction, candidate, output_callback) { var correct = function (event, correction, candidate, output_callback) {
@ -38,6 +36,9 @@ var spelling = function(dbot) {
} }
return { return {
'name': 'spelling',
'ignorable': true,
'listener': function(event) { 'listener': function(event) {
var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); 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); 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'
'on': 'PRIVMSG',
'name': name,
'ignorable': true
} }
} }

View File

@ -37,13 +37,12 @@ var webInterface = function(dbot) {
app.listen(dbot.webPort); app.listen(dbot.webPort);
return { return {
'name': 'web',
'ignorable': false,
'onDestroy': function() { 'onDestroy': function() {
app.close(); app.close();
}, }
'name': 'web',
'ignorable': false
}; };
}; };

View File

@ -1,7 +1,8 @@
var youAre = function(dbot) { var youAre = function(dbot) {
var name = 'youare';
return { return {
'name': 'youare',
'ignorable': false,
'listener': function(event) { 'listener': function(event) {
var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); 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] + '.'); event.reply(event.user + ': You\'re ' + key[2] + '.');
} }
}, },
'on': 'PRIVMSG'
'on': 'PRIVMSG',
'name': name,
'ignorable': false
}; };
}; };

6
run.js
View File

@ -158,7 +158,11 @@ DBot.prototype.reloadModules = function() {
} }
if(module.onLoad) { if(module.onLoad) {
var newCommands = module.onLoad(); module.onLoad();
}
if(module.commands) {
var newCommands = module.commands;
for(key in newCommands) { for(key in newCommands) {
if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) { if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) {
this.commands[key] = newCommands[key]; this.commands[key] = newCommands[key];