From 2870c4da1aedf41926972dd60227c3d62cdaa123 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 16 Jun 2012 14:24:33 +0200 Subject: o Polishing the dynobot a bit. --- irc-client.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'irc-client.js') diff --git a/irc-client.js b/irc-client.js index 275ee72..1be71bf 100644 --- a/irc-client.js +++ b/irc-client.js @@ -1,4 +1,4 @@ -var IRC = require('./node_modules/node-irc/irc').IRC; +var IRC = require('irc.js'); var util = require('util'); var events = require('events'); var _ = require('underscore'); @@ -35,6 +35,10 @@ function IrcClient(nick, realName, ident, server, port, password) { this.connected = false; this.debugLevel = undefined; this.irc = undefined; + + this.nickCount = 0; + this.nickAdditions = [ '', '^', '-', '_', '\\', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ]; + console.log("server: " + server); } util.inherits(IrcClient, events.EventEmitter); @@ -68,6 +72,13 @@ IrcClient.prototype.init = function(irc) { info('JOINed ' + channelName); client.getChannel(channelName).fire(channelName); }); + irc.on('errorcode', function(code) { + if (code == 'ERR_NICKNAMEINUSE') { + var nick = client.findNick(); + info("nick: " + nick); + irc.nick(nick); + } + }); _.each(['privmsg', 'topic', 'join'], function(e) { irc.on(e, function() { var args = [e]; @@ -110,6 +121,13 @@ IrcClient.prototype.join = function(name, cb) { } } +IrcClient.prototype.findNick = function() { + if (this.nickCount == this.nickAdditions.length) { + this.nickCount = 0; + } + return this.nick + this.nickAdditions[this.nickCount++]; +} + // TODO: fix function dispatch(name) { this.irc[name].apply(this.irc, arguments); -- cgit v1.2.3