From 4d986537bc188872d43ea90d7b8e6c6755357bbe Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 8 Mar 2016 11:54:17 +0200 Subject: [PATCH] Handle error --- src/plugins/irc-events/error.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/plugins/irc-events/error.js b/src/plugins/irc-events/error.js index 020ceeef..fd65e494 100644 --- a/src/plugins/irc-events/error.js +++ b/src/plugins/irc-events/error.js @@ -2,21 +2,31 @@ var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; - irc.on("errors", function(data) { + irc.on("irc_error", function(data) { + console.log(data); var lobby = network.channels[0]; var msg = new Msg({ type: Msg.Type.ERROR, - text: data.message, + text: data.error, }); client.emit("msg", { chan: lobby.id, msg: msg }); - if (!network.connected) { - if (data.cmd === "ERR_NICKNAMEINUSE") { - var random = irc.user.nick + Math.floor(10 + (Math.random() * 89)); - irc.nick(random); - } - } + }); + + irc.on("nick in use", function(data) { + var lobby = network.channels[0]; + var msg = new Msg({ + type: Msg.Type.ERROR, + text: "Nickname " + data.nick + " is already in use: " + data.reason, + }); + client.emit("msg", { + chan: lobby.id, + msg: msg + }); + + var random = irc.user.nick + Math.floor(10 + (Math.random() * 89)); + irc.raw("NICK", random); }); };