From f8110b13d1c1840483a729e1175f9df29ee18b79 Mon Sep 17 00:00:00 2001 From: saltire sable Date: Wed, 8 Jul 2015 12:43:46 -0400 Subject: [PATCH] Allow plugins to send raw commands; nickserv changes nick if incorrect --- bot/plugin.js | 15 ++++++++++++--- plugins/modes.js | 2 +- plugins/nickserv.js | 8 +++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bot/plugin.js b/bot/plugin.js index e8b3de4..947c3e6 100644 --- a/bot/plugin.js +++ b/bot/plugin.js @@ -32,6 +32,7 @@ Plugin.prototype._addMessageListener = function (pattern, callback, opts, parseM else if (opts.ignorePrivate) type = 'message#'; else if (opts.ignorePublic) type = 'pm'; + // FIXME: this won't work for private messages, as they don't include a nick argument this.on(type, function (network, nick, target, text, msg) { var match = text.match(pattern); if (match) { @@ -103,18 +104,26 @@ Plugin.prototype.say = function (network, target) { this._bot.clients[network].say(target, text); }; - // Join a channel on one of the connected networks. Plugin.prototype.join = function (network, channel, callback) { if (!this._bot.clients[network] || !channel) return; this._bot.clients[network].join(util.isArray(channel) ? channel.join(' ') : channel, callback); -} +}; // Part from a connected channel. Plugin.prototype.part = function (network, channel, message, callback) { if (!this._bot.clients[network] || !(channel in this._bot.clients[network].chans)) return; this._bot.clients[network].part(channel, message, callback); -} +}; + +// Send a raw command with any number of arguments. +Plugin.prototype.sendRaw = function (network, type) { + if (!this._bot.clients[network]) return; + + var cmdArgs = Array.prototype.slice.call(arguments, 2); + this._bot.log.debug('%s: ->', type, cmdArgs); + this._bot.clients[network].send.apply(this._bot.clients[network], [type].concat(cmdArgs)); +}; // Add a line to the log. diff --git a/plugins/modes.js b/plugins/modes.js index d9717f5..ac836e6 100644 --- a/plugins/modes.js +++ b/plugins/modes.js @@ -4,7 +4,7 @@ module.exports = function () { if (typeof modes == 'string') modes = [modes]; modes.forEach(function (mode) { this.log('Setting mode on %s:', network, mode); - this._bot.clients[network].send('MODE', this.networks[network].nick, mode); + this.sendRaw(network, 'MODE', this.networks[network].nick, mode); }, this); }); }; diff --git a/plugins/nickserv.js b/plugins/nickserv.js index af272d1..b0a437b 100644 --- a/plugins/nickserv.js +++ b/plugins/nickserv.js @@ -18,9 +18,15 @@ function checkForIdentifySuccess(network, nick, target, text, msg) { if ((waitingForNickServ[network]) && nick == 'NickServ' && - target == this.networks[network].config.nick && text.match(nickserv_opts.success)) { + // Change our nick if it is currently not correct. + if (target != this.networks[network].config.nick) { + this.log('Nick is currently %s, requesting change to %s.', + target, this.networks[network].config.nick); + this.sendRaw(network, 'NICK', this.networks[network].config.nick); + } + // Join all NickServ-only channels on this network. if (Array.isArray(nickserv_opts.channels) && nickserv_opts.channels.length) { this.log('%s: Identified with NickServ, joining %d NickServ-only channel%s.',