Skip to content

Commit

Permalink
Allow plugins to send raw commands; nickserv changes nick if incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
saltire committed Jul 8, 2015
1 parent 9cd5784 commit f8110b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
15 changes: 12 additions & 3 deletions bot/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion plugins/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
8 changes: 7 additions & 1 deletion plugins/nickserv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit f8110b1

Please sign in to comment.