From 22a84cafd4145c6f1ca2f43ba65d8717cc93e3f8 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 5 Jun 2012 13:55:09 +0200 Subject: improved client. --- irc-client.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/irc-client.js b/irc-client.js index ad21a5e..9d0e616 100644 --- a/irc-client.js +++ b/irc-client.js @@ -43,7 +43,7 @@ IrcClient.prototype.init = function(irc) { var client = this; this.debugLevel && irc.setDebugLevel(this.debugLevel); irc.on('connected', function() { - info('Connected, channels: ' + _.keys(client.channels).join(', ')); + info('Connected'); _.each(client.channels, function(channel) { info('JOINing ' + channel.name); irc.join(channel.name); @@ -51,19 +51,25 @@ IrcClient.prototype.init = function(irc) { }); irc.on('disconnected', function() { info('Disconnected, reconnecting...'); - client.connect(); + // A small sleep here is nice + setTimeout(function() { + info('Connecting'); + client.connect(); + }, 1000); }); irc.on('join', function(nick, channelName) { + if(nick != irc.whoami()) { + return; + } info('JOINed ' + channelName); client.getChannel(channelName).fire(channelName); }); - irc.on('privmsg', function(nick, channel, message) { - client.emit.call(['privmsg'].slice.apply(arguments)); -// client.emit('privmsg', nick, channel, message); - }); - irc.on('topic', function() { - console.log('topic: ' + util.inspect(arguments)); - client.emit.call(null, ['topic'].slice.apply(arguments)); + _.each(['privmsg', 'topic', 'join'], function(e) { + irc.on(e, function() { + var args = [e]; + args.push.apply(args, arguments); + client.emit.apply(client, args); + }); }); return irc; } -- cgit v1.2.3