Permalink
Browse files

Update code/docs/examples to reflect API changes in node.js

  • Loading branch information...
1 parent 5204bcc commit d5131af252094d3b3b7d7ec27fac28a73de10048 @martynsmith martynsmith committed May 11, 2011
Showing with 42 additions and 41 deletions.
  1. +3 −3 README.md
  2. +7 −8 example/bot.js
  3. +14 −12 example/secure.js
  4. +17 −17 lib/irc.js
  5. +1 −1 package.json
View
@@ -34,19 +34,19 @@ normally see in your favourite IRC client. Most likely the first one you'll
want to use is:
client.addListener('message', function (from, to, message) {
- sys.puts(from + ' => ' + to + ': ' + message);
+ console.log(from + ' => ' + to + ': ' + message);
});
or if you're only interested in messages to the bot itself:
client.addListener('pm', function (from, message) {
- sys.puts(from + ' => ME: ' + message);
+ console.log(from + ' => ME: ' + message);
});
or to a particular channel:
client.addListener('message#yourchannel', function (from, message) {
- sys.puts(from + ' => #yourchannel: ' + message);
+ console.log(from + ' => #yourchannel: ' + message);
});
At the moment there are functions for joining:
View
@@ -3,7 +3,6 @@
// Make sure the irc lib is available
require.paths.unshift(__dirname + '/../lib');
-var sys = require('sys');
var irc = require('irc');
var bot = new irc.Client('irc.dollyfish.net.nz', 'nodebot', {
@@ -12,15 +11,15 @@ var bot = new irc.Client('irc.dollyfish.net.nz', 'nodebot', {
});
bot.addListener('error', function(message) {
- sys.puts('ERROR: ' + message.command + ': ' + message.args.join(' '));
+ console.error('ERROR: %s: %s', message.command, message.args.join(' '));
});
bot.addListener('message#blah', function (from, message) {
- sys.puts('<' + from + '> ' + message);
+ console.log('<%s> %s', from, message);
});
bot.addListener('message', function (from, to, message) {
- sys.puts(from + ' => ' + to + ': ' + message);
+ console.log('%s => %s: %s', from, to, message);
if ( to.match(/^[#&]/) ) {
// channel message
@@ -39,14 +38,14 @@ bot.addListener('message', function (from, to, message) {
}
});
bot.addListener('pm', function(nick, message) {
- sys.puts('Got private message from ' + nick + ': ' + message);
+ console.log('Got private message from %s: %s', nick, message);
});
bot.addListener('join', function(channel, who) {
- sys.puts(who + ' has joined ' + channel);
+ console.log('%s has joined %s', who, channel);
});
bot.addListener('part', function(channel, who, reason) {
- sys.puts(who + ' has left ' + channel + ': ' + reason);
+ console.log('%s has left %s: %s', who, channel, reason);
});
bot.addListener('kick', function(channel, who, by, reason) {
- sys.puts(who + ' was kicked from ' + channel + ' by ' + by + ': ' + reason);
+ console.log('%s was kicked from %s by %s: %s', who, channel, by, reason);
});
View
26 example/secure.js 100644 → 100755
@@ -1,8 +1,9 @@
+#!/usr/bin/env node
+
// Make sure the irc lib is available
require.paths.unshift(__dirname + '/../lib');
-var sys = require('sys');
-var irc = require(__dirname + '/../lib/irc');
+var irc = require('irc');
/*
* To set the key/cert explicitly, you could do the following
var fs = require('fs');
@@ -16,22 +17,23 @@ var options = {
// Or to just use defaults
var options = true;
-var bot = new irc.Client('irc.dollyfish.net.nz', 'nodebot', {
- port: 7000,
+var bot = new irc.Client('chat.us.freenode.net', 'nodebot', {
+ port: 6697,
+ debug: true,
secure: options,
- channels: ['#blah', '#test'],
+ channels: ['#botwar'],
});
bot.addListener('error', function(message) {
- sys.puts('ERROR: ' + message.command + ': ' + message.args.join(' '));
+ console.error('ERROR: %s: %s', message.command, message.args.join(' '));
});
bot.addListener('message#blah', function (from, message) {
- sys.puts('<' + from + '> ' + message);
+ console.log('<%s> %s', from, message);
});
bot.addListener('message', function (from, to, message) {
- sys.puts(from + ' => ' + to + ': ' + message);
+ console.log('%s => %s: %s', from, to, message);
if ( to.match(/^[#&]/) ) {
// channel message
@@ -50,14 +52,14 @@ bot.addListener('message', function (from, to, message) {
}
});
bot.addListener('pm', function(nick, message) {
- sys.puts('Got private message from ' + nick + ': ' + message);
+ console.log('Got private message from %s: %s', nick, message);
});
bot.addListener('join', function(channel, who) {
- sys.puts(who + ' has joined ' + channel);
+ console.log('%s has joined %s', who, channel);
});
bot.addListener('part', function(channel, who, reason) {
- sys.puts(who + ' has left ' + channel + ': ' + reason);
+ console.log('%s has left %s: %s', who, channel, reason);
});
bot.addListener('kick', function(channel, who, by, reason) {
- sys.puts(who + ' was kicked from ' + channel + ' by ' + by + ': ' + reason);
+ console.log('%s was kicked from %s by %s: %s', who, channel, by, reason);
});
View
@@ -19,9 +19,9 @@
exports.Client = Client;
-var sys = require('sys');
-var net = require('net');
-var tls = require('tls');
+var net = require('net');
+var tls = require('tls');
+var util = require('util');
const replyFor = { // {{{
"200" : {
@@ -567,11 +567,11 @@ function Client(server, nick, opt) {
self.emit('notice', from, to, text);
if ( self.opt.debug && to == self.nick )
- sys.log('GOT NOTICE from ' + (from?'"'+from+'"':'the server') + ': "' + text + '"');
+ util.log('GOT NOTICE from ' + (from?'"'+from+'"':'the server') + ': "' + text + '"');
break;
case "MODE":
if ( self.opt.debug )
- sys.log("MODE:" + message.args[0] + " sets mode: " + message.args[1]);
+ util.log("MODE:" + message.args[0] + " sets mode: " + message.args[1]);
// properly handle mode changes for users
if ( message.args.length >= 3 ) {
var channel = self.chans[message.args[0]],
@@ -595,7 +595,7 @@ function Client(server, nick, opt) {
break;
case "NICK":
if ( self.opt.debug )
- sys.log("NICK: " + message.nick + " changes nick to " + message.args[0]);
+ util.log("NICK: " + message.nick + " changes nick to " + message.args[0]);
var channels = [];
@@ -729,7 +729,7 @@ function Client(server, nick, opt) {
if ( to == self.nick ) self.emit('pm', from, text);
if ( self.opt.debug && to == self.nick )
- sys.log('GOT MESSAGE from ' + from + ': ' + text);
+ util.log('GOT MESSAGE from ' + from + ': ' + text);
break;
case "INVITE":
var from = message.nick;
@@ -739,7 +739,7 @@ function Client(server, nick, opt) {
break;
case "QUIT":
if ( self.opt.debug )
- sys.log("QUIT: " + message.prefix + " " + message.args.join(" "));
+ util.log("QUIT: " + message.prefix + " " + message.args.join(" "));
if ( self.nick == message.nick ) {
// TODO handle?
break;
@@ -764,11 +764,11 @@ function Client(server, nick, opt) {
if ( message.commandType == 'error' ) {
self.emit('error', message);
if ( self.opt.showErrors )
- sys.log("\033[01;31mERROR: " + sys.inspect(message) + "\033[0m");
+ util.log("\033[01;31mERROR: " + util.inspect(message) + "\033[0m");
}
else {
if ( self.opt.debug )
- sys.log("\033[01;31mUnhandled message: " + sys.inspect(message) + "\033[0m");
+ util.log("\033[01;31mUnhandled message: " + util.inspect(message) + "\033[0m");
}
break;
}
@@ -787,7 +787,7 @@ function Client(server, nick, opt) {
process.EventEmitter.call(this);
}
-sys.inherits(Client, process.EventEmitter);
+util.inherits(Client, process.EventEmitter);
Client.prototype.conn = null;
Client.prototype.chans = {};
@@ -812,14 +812,14 @@ Client.prototype.connect = function ( retryCount ) { // {{{
if ( self.opt.password !== null ) {
self.send( "PASS", self.opt.password );
}
- console.log('Sending irc NICK/USER');
+ util.log('Sending irc NICK/USER');
self.send("NICK", self.opt.nick);
self.nick = self.opt.nick;
self.send("USER", self.opt.userName, 8, "*", self.opt.realName);
self.emit("connect");
} else {
// authorization failed
- console.log(self.conn.authorizationError);
+ util.log(self.conn.authorizationError);
}
});
}else {
@@ -857,17 +857,17 @@ Client.prototype.connect = function ( retryCount ) { // {{{
if ( self.conn.requestedDisconnect )
return;
if ( self.opt.debug )
- sys.log('Disconnected: reconnecting');
+ util.log('Disconnected: reconnecting');
if ( self.opt.retryCount !== null && retryCount >= self.opt.retryCount ) {
if ( self.opt.debug ) {
- sys.log( 'Maximum retry count (' + self.opt.retryCount + ') reached. Aborting' );
+ util.log( 'Maximum retry count (' + self.opt.retryCount + ') reached. Aborting' );
}
self.emit( 'abort', self.opt.retryCount );
return;
}
if ( self.opt.debug ) {
- sys.log( 'Waiting ' + self.opt.retryDelay + 'ms before retrying' );
+ util.log( 'Waiting ' + self.opt.retryDelay + 'ms before retrying' );
}
setTimeout( function() {
self.connect( retryCount + 1 );
@@ -893,7 +893,7 @@ Client.prototype.send = function(command) { // {{{
args.shift();
if ( this.opt.debug )
- sys.log('SEND: ' + command + " " + args.join(" "));
+ util.log('SEND: ' + command + " " + args.join(" "));
this.conn.write(command + " " + args.join(" ") + "\r\n");
}; // }}}
View
@@ -13,7 +13,7 @@
"web" : "http://github.com/martynsmith/node-irc/issues"
},
"main" : "lib/irc",
- "engines" : { "node" : ">=0.1.91" },
+ "engines" : { "node" : ">=0.4.0" },
"licenses" : [ {
"type" : "GPL",
"url" : "http://github.com/martynsmith/node-irc/raw/master/COPYING"

0 comments on commit d5131af

Please sign in to comment.