From 34a642228dc36bc4b22d9282ad2e97eb37ce6991 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 10 Mar 2012 15:28:42 +0000 Subject: [PATCH] command execution syntax is now in modules/command.js --- modules/command.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++ run.js | 47 +---------------------------------- 2 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 modules/command.js diff --git a/modules/command.js b/modules/command.js new file mode 100644 index 0000000..7f27361 --- /dev/null +++ b/modules/command.js @@ -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); +}; + diff --git a/run.js b/run.js index 6fa1d1a..5bcd963 100644 --- a/run.js +++ b/run.js @@ -44,7 +44,7 @@ var DBot = function(timers) { this.nickserv = this.config.nickserv || 'zippy'; this.server = this.config.server || 'elara.ivixor.net'; 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(); @@ -142,51 +142,6 @@ DBot.prototype.reloadModules = function() { return module; }.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) {