diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-06-05 13:55:09 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-06-05 13:55:09 +0200 |
commit | 22a84cafd4145c6f1ca2f43ba65d8717cc93e3f8 (patch) | |
tree | 11eb271f7b643a7560640adebbdd5286ff630c08 | |
parent | 670e34afab386e348e8eb29794def1b511491dea (diff) | |
download | dynobot-irc-22a84cafd4145c6f1ca2f43ba65d8717cc93e3f8.tar.gz dynobot-irc-22a84cafd4145c6f1ca2f43ba65d8717cc93e3f8.tar.bz2 dynobot-irc-22a84cafd4145c6f1ca2f43ba65d8717cc93e3f8.tar.xz dynobot-irc-22a84cafd4145c6f1ca2f43ba65d8717cc93e3f8.zip |
improved client.
-rw-r--r-- | irc-client.js | 24 |
1 files 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; } |