Permalink
Browse files

Added AWAY command, with doc & example

  • Loading branch information...
1 parent 5d3622b commit aa933a6a1e0e7851dd6243bd6add7d8407c3c1ea Alexandru Vladutu committed Mar 19, 2012
Showing with 52 additions and 1 deletion.
  1. +9 −0 docs/API.rst
  2. +10 −0 example/bot.js
  3. +10 −0 example/secure.js
  4. +23 −1 lib/irc.js
View
@@ -102,6 +102,15 @@ Client
generating the whois information and is passed exactly the same
information as a `whois` event described above.
+.. js:function:: Client.away(awayMessage, callback)
+
+ Set away status to `awayMessage` or reset it.
+
+ :param string awayMessage: message to be set
+ :param function callback: Optional callback to fire when the server responds
+ to the away call with a message such as 'You have been marked as beeing
+ away.' or 'You are no longer marked as beeing away'.
+
.. js:function:: Client.list([arg1, arg2, ...])
Request a channel listing from the server. The arguments for this method are
View
@@ -26,6 +26,16 @@ bot.addListener('message', function (from, to, message) {
if ( message.match(/hello/i) ) {
bot.say(to, 'Hello there ' + from);
}
+ // set away on request
+ if (message.match(/away/i)) {
+ bot.away('I am not here, leave a msg!', function(serverResponse) {
+ console.log(serverResponse);
+ });
+ }
+ // back
+ if (message.match(/back/i)) {
+ bot.away();
+ }
if ( message.match(/dance/) ) {
setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D\\-<\u0001") }, 1000);
setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D|-<\u0001") }, 2000);
View
@@ -40,6 +40,16 @@ bot.addListener('message', function (from, to, message) {
if ( message.match(/hello/i) ) {
bot.say(to, 'Hello there ' + from);
}
+ // set away on request
+ if (message.match(/away/i)) {
+ bot.away('I am not here, leave a msg!', function(serverResponse) {
+ console.log(serverResponse);
+ });
+ }
+ // back
+ if (message.match(/back/i)) {
+ bot.away();
+ }
if ( message.match(/dance/) ) {
setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D\\-<\u0001") }, 1000);
setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D|-<\u0001") }, 2000);
View
@@ -104,6 +104,12 @@ function Client(server, nick, opt) {
case "rpl_statsconn":
// Random welcome crap, ignoring
break;
+ case "rpl_nowaway":
+ self.emit('nowaway', message.args[1]);
+ break;
+ case "rpl_unaway":
+ self.emit('unaway', message.args[1]);
+ break;
case "err_nicknameinuse":
if ( typeof(self.opt.nickMod) == 'undefined' )
self.opt.nickMod = 0;
@@ -506,7 +512,7 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
util.log(self.conn.authorizationError);
}
});
- }else {
+ } else {
self.conn = net.createConnection(self.opt.port, self.opt.server);
}
self.conn.requestedDisconnect = false;
@@ -695,6 +701,22 @@ Client.prototype.list = function() { // {{{
args.unshift('LIST');
this.send.apply(this, args);
} // }}}
+Client.prototype.away = function(msg, callback) { // {{{
+ if ( typeof callback === 'function' ) {
+ var callbackWrapper = function(msg) {
+ this.removeListener('nowaway', callbackWrapper);
+ this.removeListener('unaway', callbackWrapper);
+ return callback.apply(this, arguments);
+ };
+ this.addListener('nowaway', callbackWrapper);
+ this.addListener('unaway', callbackWrapper);
+ }
+ if (msg) {
+ this.send('AWAY', msg);
+ } else {
+ this.send('AWAY');
+ }
+} // {{{
Client.prototype._addWhoisData = function(nick, key, value, onlyIfExists) { // {{{
if ( onlyIfExists && !this._whoisData[nick] ) return;
this._whoisData[nick] = this._whoisData[nick] || {nick: nick};

0 comments on commit aa933a6

Please sign in to comment.