3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00

command execution syntax is now in modules/command.js

This commit is contained in:
Luke Slater 2012-03-10 15:28:42 +00:00
parent 28f78373d8
commit 34a642228d
2 changed files with 62 additions and 46 deletions

61
modules/command.js Normal file
View File

@ -0,0 +1,61 @@
// Module which handles the command execution syntax for DBot. Not much is going
// to work without this.
var command = function(dbot) {
var dbot = dbot;
return {
'listener': function(data) {
params = data.message.split(' ');
if(data.channel == dbot.name) data.channel = data.user;
if(dbot.commands.hasOwnProperty(params[0])) {
if((dbot.db.bans.hasOwnProperty(params[0]) &&
dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user))
dbot.say(data.channel, data.user +
' is banned from using this command. Commence incineration.');
else {
dbot.commands[params[0]](data, params);
dbot.save();
}
} else {
var q = data.message.valMatch(/^~([\d\w\s-]*)/, 2);
if(q) {
if(dbot.db.bans['*'].include(data.user)) {
dbot.say(data.channel, data.user +
' is banned from using this command. Commence incineration.');
} else {
q[1] = q[1].trim();
key = dbot.cleanNick(q[1])
if(dbot.db.quoteArrs.hasOwnProperty(key)) {
dbot.say(data.channel, q[1] + ': ' + dbot.interpolatedQuote(key));
} else {
// See if it's similar to anything
var winnerDistance = Infinity;
var winner = false;
for(var commandName in dbot.commands) {
var distance = String.prototype.distance(params[0], commandName);
if(distance < winnerDistance) {
winner = commandName;
winnerDistance = distance;
}
}
if(winnerDistance < 3) {
dbot.say(data.channel, 'Did you mean ' + winner + '? Learn to type, hippie!');
}
}
}
}
}
},
'on': 'PRIVMSG',
'requires': [ 'quotes' ]
};
};
exports.fetch = function(dbot) {
return command(dbot);
};

47
run.js
View File

@ -44,7 +44,7 @@ var DBot = function(timers) {
this.nickserv = this.config.nickserv || 'zippy'; this.nickserv = this.config.nickserv || 'zippy';
this.server = this.config.server || 'elara.ivixor.net'; this.server = this.config.server || 'elara.ivixor.net';
this.port = this.config.port || 6667; this.port = this.config.port || 6667;
this.moduleNames = this.config.modules || [ 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ]; this.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ];
this.timers = timers.create(); this.timers = timers.create();
@ -142,51 +142,6 @@ DBot.prototype.reloadModules = function() {
return module; return module;
}.bind(this)); }.bind(this));
this.instance.addListener('PRIVMSG', function(data) {
params = data.message.split(' ');
if(data.channel == this.name) data.channel = data.user;
if(this.commands.hasOwnProperty(params[0])) {
if((this.db.bans.hasOwnProperty(params[0]) &&
this.db.bans[params[0]].include(data.user)) || this.db.bans['*'].include(data.user))
this.say(data.channel, data.user +
' is banned from using this command. Commence incineration.');
else {
this.commands[params[0]](data, params);
this.save();
}
} else {
var q = data.message.valMatch(/^~([\d\w\s-]*)/, 2);
if(q) {
if(this.db.bans['*'].include(data.user)) {
this.say(data.channel, data.user +
' is banned from using this command. Commence incineration.');
} else {
q[1] = q[1].trim();
key = this.cleanNick(q[1])
if(this.db.quoteArrs.hasOwnProperty(key)) {
this.say(data.channel, q[1] + ': ' + this.interpolatedQuote(key));
} else {
// See if it's similar to anything
var winnerDistance = Infinity;
var winner = false;
for(var commandName in this.commands) {
var distance = String.prototype.distance(params[0], commandName);
if(distance < winnerDistance) {
winner = commandName;
winnerDistance = distance;
}
}
if(winnerDistance < 3) {
this.say(data.channel, 'Did you mean ' + winner + '? Learn to type, hippie!');
}
}
}
}
}
}.bind(this));
}; };
DBot.prototype.cleanNick = function(key) { DBot.prototype.cleanNick = function(key) {