3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39: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 {
'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'
};
};

View File

@ -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'
};
}

View File

@ -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'
};
};

View File

@ -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'
};
}

View File

@ -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;
}
};
};

View File

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

View File

@ -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'
};
};

View File

@ -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'
};
};

View File

@ -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'
};
}

View File

@ -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
};
};

View File

@ -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'
}
}

View File

@ -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
}
};
};

View File

@ -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'
};
};

6
run.js
View File

@ -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];