diff --git a/lib/irc.js b/lib/irc.js index f9ea02c4..86789e46 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -100,6 +100,7 @@ function Client(server, nick, opt) { // (normally this is because you chose something too long and // the server has shortened it self.nick = message.args[0]; + self.emit('nickSet', self.nick); self.emit('registered', message); break; case "rpl_myinfo": @@ -193,6 +194,7 @@ function Client(server, nick, opt) { self.opt.nickMod++; self.send("NICK", self.opt.nick + self.opt.nickMod); self.nick = self.opt.nick + self.opt.nickMod; + self.emit('nickSet', self.nick); break; case "PING": self.send("PONG", message.args[0]); @@ -266,6 +268,7 @@ function Client(server, nick, opt) { if ( message.nick == self.nick ) // the user just changed their own nick self.nick = message.args[0]; + self.emit('nickSet', self.nick); if ( self.opt.debug ) util.log("NICK: " + message.nick + " changes nick to " + message.args[0]); @@ -355,6 +358,12 @@ function Client(server, nick, opt) { case "rpl_endofwhois": self.emit('whois', self._clearWhoisData(message.args[1])); break; + case "rpl_whoreply": + self._addWhoData(message.args[1], message.args[5], message.args); + break; + case "rpl_endofwho": + self.emit('who', self._clearWhoData(message.args[1])); + break; case "rpl_liststart": self.channellist = []; self.emit('channellist_start'); @@ -568,6 +577,7 @@ Client.prototype.prefixForMode = {}; Client.prototype.modeForPrefix = {}; Client.prototype.chans = {}; Client.prototype._whoisData = {}; +Client.prototype._whoData = {}; Client.prototype.chanData = function( name, create ) { // {{{ var key = name.toLowerCase(); if ( create ) { @@ -622,6 +632,7 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{ util.log('Sending irc NICK/USER'); self.send("NICK", self.opt.nick); self.nick = self.opt.nick; + self.emit('nickSet', self.nick); self.send("USER", self.opt.userName, 8, "*", self.opt.realName); self.emit("connect"); } else { @@ -644,6 +655,7 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{ } self.send("NICK", self.opt.nick); self.nick = self.opt.nick; + self.emit('nickSet', self.nick); self.send("USER", self.opt.userName, 8, "*", self.opt.realName); self.emit("connect"); }); @@ -828,6 +840,18 @@ Client.prototype.whois = function(nick, callback) { // {{{ } this.send('WHOIS', nick); } // }}} +Client.prototype.who = function(channel, callback) { // {{{ + if ( typeof callback === 'function' ) { + var callbackWrapper = function(info) { + if ( info.channel == channel ) { + this.removeListener('who', callbackWrapper); + return callback.apply(this, arguments); + } + }; + this.addListener('who', callbackWrapper); + } + this.send('WHO', channel); +} // }}} Client.prototype.list = function() { // {{{ var args = Array.prototype.slice.call(arguments, 0); args.unshift('LIST'); @@ -838,6 +862,22 @@ Client.prototype._addWhoisData = function(nick, key, value, onlyIfExists) { // { this._whoisData[nick] = this._whoisData[nick] || {nick: nick}; this._whoisData[nick][key] = value; } // }}} +Client.prototype._addWhoData = function(channel, nick, value, onlyIfExists) { // {{{ + if ( onlyIfExists && !this._whoData[channel] ) return; + this._whoData[channel] = this._whoData[channel] || { + channel: channel, + nicks: {} + }; + var data = { + user: value[2], + host: value[3], + server: value[4], + nick_status: value[6], + server_hops: value[7].split(' ', 1)[0], + gecos: value[7].split(' ').slice(1).join(' ') + }; + this._whoData[channel]['nicks'][nick] = data; +} // }}} Client.prototype._clearWhoisData = function(nick) { // {{{ // Ensure that at least the nick exists before trying to return this._addWhoisData(nick, 'nick', nick); @@ -845,6 +885,12 @@ Client.prototype._clearWhoisData = function(nick) { // {{{ delete this._whoisData[nick]; return data; } // }}} +Client.prototype._clearWhoData = function(channel) { // {{{ + // Ensure that at least the channel exists before trying to return + var data = this._whoData[channel]; + delete this._whoData[channel]; + return data; +} // }}} Client.prototype._handleCTCP = function(from, to, text, type, message) { text = text.slice(1) text = text.slice(0, text.indexOf('\1'))