From 95596f40391268664d8841cb388c5ed72b0d0d37 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Fri, 13 Jun 2014 15:57:11 +0200 Subject: [PATCH] Handle all errors --- lib/server.js | 88 +++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/lib/server.js b/lib/server.js index 11f46749..b7b8aab2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -17,6 +17,7 @@ var sockets = null; var networks = []; var events = [ + "errors", "join", "kick", "mode", @@ -374,6 +375,16 @@ function event(e, data) { var channels = this.channels; switch (e) { + case "errors": + sockets.emit("msg", { + msg: new Msg({ + type: "error", + from: "-!-", + text: data.message, + }), + }); + break; + case "join": var chan = _.findWhere(channels, {name: data.channel}); if (typeof chan === "undefined") { @@ -652,53 +663,36 @@ function event(e, data) { case "whois": if (!data) { - sockets.emit("msg", { - msg: new Msg({ - type: "error", - from: "-!-", - text: "No such nick/channel.", - }), + break; + } + var chan = _.findWhere(channels, {name: data.nickname}); + if (typeof chan === "undefined") { + chan = new Chan({ + type: "query", + name: data.nickname, }); - } else { - var chan = _.findWhere(channels, {name: data.nickname}); - if (typeof chan === "undefined") { - chan = new Chan({ - type: "query", - name: data.nickname, - }); - channels.push(chan); - sockets.emit("join", { - id: this.id, - chan: chan, - }); - } - var prefix = { - hostname: "from", - realname: "is", - channels: "on", - server: "using", - }; - var i = 0; - for (var k in data) { - var key = prefix[k]; - if (!key) { - continue; - } - var msg = new Msg({ - type: "whois", - from: data.nickname, - text: key + " " + data[k], - }); - chan.messages.push(msg); - sockets.emit("msg", { - id: chan.id, - msg: msg, - }); + channels.push(chan); + sockets.emit("join", { + id: this.id, + chan: chan, + }); + } + var prefix = { + hostname: "from", + realname: "is", + channels: "on", + server: "using", + }; + var i = 0; + for (var k in data) { + var key = prefix[k]; + if (!key || data[k].toString() == "") { + continue; } var msg = new Msg({ type: "whois", from: data.nickname, - text: "End of /WHOIS list.", + text: key + " " + data[k], }); chan.messages.push(msg); sockets.emit("msg", { @@ -706,6 +700,16 @@ function event(e, data) { msg: msg, }); } + var msg = new Msg({ + type: "whois", + from: data.nickname, + text: "End of /WHOIS list.", + }); + chan.messages.push(msg); + sockets.emit("msg", { + id: chan.id, + msg: msg, + }); break; } }