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) {
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);
});
};