Permalink
Browse files

Added "error" Event

  • Loading branch information...
1 parent 2b331b2 commit 394f884ae66c1c5bc9873d5a8232c0b64870f843 @martynsmith committed May 15, 2010
Showing with 22 additions and 2 deletions.
  1. +8 −0 API.md
  2. +4 −0 example/bot.js
  3. +10 −2 lib/irc.js
View
8 API.md
@@ -18,6 +18,7 @@ values:
realName: 'nodeJS IRC client',
port: 6667,
debug: false,
+ showErrors: false,
autoRejoin: true,
channels: [],
}
@@ -121,6 +122,13 @@ Emitted when ever the client receives a "message" from the server. A message is
You can read more about the IRC protocol by reading [RFC 1459](http://www.ietf.org/rfc/rfc1459.txt).
+### Event: 'error'
+
+`function (message) { }`
+
+Emitted when ever the server responds with an error-type message. The message
+parameter is exactly as in the 'raw' event.
+
### Client.send(command, arg1, arg2, ...)
Sends a raw message to the server, generally speaking it's best not to use this
View
@@ -11,6 +11,10 @@ var bot = new irc.Client('irc.dollyfish.net.nz', 'nodebot', {
channels: ['#blah', '#test'],
});
+bot.addListener('error', function(message) {
+ sys.puts('ERROR: ' + message.command + ': ' + message.args.join(' '));
+});
+
bot.addListener('message#blah', function (from, message) {
sys.puts('<' + from + '> ' + message);
});
View
@@ -506,6 +506,7 @@ function Client(server, nick, opt) {
realName: 'nodeJS IRC client',
port: 6667,
debug: false,
+ showErrors: false,
autoRejoin: true,
channels: [],
};
@@ -669,8 +670,15 @@ function Client(server, nick, opt) {
sys.log('GOT MESSAGE from ' + from + ': ' + text);
break;
default:
- if ( self.opt.debug )
- sys.log("\033[01;31mUnhandled message: " + sys.inspect(message) + "\033[0m");
+ if ( message.commandType == 'error' ) {
+ self.emit('error', message);
+ if ( self.opt.showErrors )
+ sys.log("\033[01;31mERROR: " + sys.inspect(message) + "\033[0m");
+ }
+ else {
+ if ( self.opt.debug )
+ sys.log("\033[01;31mUnhandled message: " + sys.inspect(message) + "\033[0m");
+ }
break;
}
}); // }}}

0 comments on commit 394f884

Please sign in to comment.