Handle error

This commit is contained in:
Pavel Djundik 2016-03-08 11:54:17 +02:00 committed by Maxime Poulin
parent 360563528a
commit 4d986537bc

View File

@ -2,21 +2,31 @@ var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("errors", function(data) { irc.on("irc_error", function(data) {
console.log(data);
var lobby = network.channels[0]; var lobby = network.channels[0];
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: data.message, text: data.error,
}); });
client.emit("msg", { client.emit("msg", {
chan: lobby.id, chan: lobby.id,
msg: msg msg: msg
}); });
if (!network.connected) { });
if (data.cmd === "ERR_NICKNAMEINUSE") {
var random = irc.user.nick + Math.floor(10 + (Math.random() * 89)); irc.on("nick in use", function(data) {
irc.nick(random); 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);
}); });
}; };