Skip to content

Add support to handle reply from 'WHO' command. #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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");
});
Expand Down Expand Up @@ -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');
Expand All @@ -838,13 +862,35 @@ 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);
var data = this._whoisData[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'))
Expand Down