diff --git a/docs/API.rst b/docs/API.rst index 4b3dc81b..53eda88a 100644 --- a/docs/API.rst +++ b/docs/API.rst @@ -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) @@ -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' diff --git a/lib/irc.js b/lib/irc.js index 594c7b94..f0110fc6 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -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]]; @@ -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};