Skip to content

Commit

Permalink
Added support for channel listings (closes #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
martynsmith committed Oct 27, 2011
1 parent b927d21 commit cf85048
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ Client
generating the whois information and is passed exactly the same
information as a `whois` event described above.

.. js:function:: Client.list([arg1, arg2, ...])

Request a channel listing from the server. The arguments for this method are
fairly server specific, this method just passes them through exactly as
specified.

Responses from the server are available via the `channellist_start`,
`channellist_item`, and `channellist` events.

.. js:function:: Client.disconnect(message)

Expand Down Expand Up @@ -274,6 +282,29 @@ Events
operator: "is an IRC Operator"
}

.. js:data:: 'channellist_start'

`function () {}`

Emitted whenever the server starts a new channel listing

.. js:data:: 'channellist_item'

`function (channel_info) {}`

Emitted for each channel the server returns. The channel_info object
contains keys 'name', 'users' (number of users on the channel), and 'topic'.

.. js:data:: 'channellist'

`function (channel_list) {}`

Emitted when the server has finished returning a channel list. The
channel_list array is simply a list of the objects that were returned in the
intervening `channellist_item` events.

This data is also available via the Client.channellist property after this
event has fired.

.. js:data:: 'raw'

Expand Down
21 changes: 21 additions & 0 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,22 @@ function Client(server, nick, opt) {
case "rpl_endofwhois":
self.emit('whois', self._clearWhoisData(message.args[1]));
break;
case "rpl_liststart":
self.channellist = [];
self.emit('channellist_start');
break;
case "rpl_list":
var channel = {
name: message.args[1],
users: message.args[2],
topic: message.args[3],
};
self.emit('channellist_item', channel);
self.channellist.push(channel);
break;
case "rpl_listend":
self.emit('channellist', self.channellist);
break;
case "333":
// TODO emit?
var channel = self.chans[message.args[1]];
Expand Down Expand Up @@ -1064,6 +1080,11 @@ Client.prototype.whois = function(nick, callback) { // {{{
}
this.send('WHOIS', nick);
} // }}}
Client.prototype.list = function() { // {{{
var args = Array.prototype.slice.call(arguments, 0);
args.unshift('LIST');
this.send.apply(this, args);
} // }}}
Client.prototype._addWhoisData = function(nick, key, value, onlyIfExists) { // {{{
if ( onlyIfExists && !this._whoisData[nick] ) return;
this._whoisData[nick] = this._whoisData[nick] || {nick: nick};
Expand Down

0 comments on commit cf85048

Please sign in to comment.