summaryrefslogtreecommitdiff
path: root/irc-client.js
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-06-16 14:24:33 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-06-16 14:24:33 +0200
commit2870c4da1aedf41926972dd60227c3d62cdaa123 (patch)
treebab887acdac4969c8a4cc3fcaf827ebb81726f6c /irc-client.js
parente971ae61c99c8a602a1d60c95e9f8f908d4cf053 (diff)
downloaddynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.tar.gz
dynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.tar.bz2
dynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.tar.xz
dynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.zip
o Polishing the dynobot a bit.
Diffstat (limited to 'irc-client.js')
-rw-r--r--irc-client.js20
1 files changed, 19 insertions, 1 deletions
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);