Handle all errors

This commit is contained in:
Mattias Erming 2014-06-13 15:57:11 +02:00
parent 047f8b0302
commit 95596f4039

View File

@ -17,6 +17,7 @@ var sockets = null;
var networks = []; var networks = [];
var events = [ var events = [
"errors",
"join", "join",
"kick", "kick",
"mode", "mode",
@ -374,6 +375,16 @@ function event(e, data) {
var channels = this.channels; var channels = this.channels;
switch (e) { switch (e) {
case "errors":
sockets.emit("msg", {
msg: new Msg({
type: "error",
from: "-!-",
text: data.message,
}),
});
break;
case "join": case "join":
var chan = _.findWhere(channels, {name: data.channel}); var chan = _.findWhere(channels, {name: data.channel});
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
@ -652,53 +663,36 @@ function event(e, data) {
case "whois": case "whois":
if (!data) { if (!data) {
sockets.emit("msg", { break;
msg: new Msg({ }
type: "error", var chan = _.findWhere(channels, {name: data.nickname});
from: "-!-", if (typeof chan === "undefined") {
text: "No such nick/channel.", chan = new Chan({
}), type: "query",
name: data.nickname,
}); });
} else { channels.push(chan);
var chan = _.findWhere(channels, {name: data.nickname}); sockets.emit("join", {
if (typeof chan === "undefined") { id: this.id,
chan = new Chan({ chan: chan,
type: "query", });
name: data.nickname, }
}); var prefix = {
channels.push(chan); hostname: "from",
sockets.emit("join", { realname: "is",
id: this.id, channels: "on",
chan: chan, server: "using",
}); };
} var i = 0;
var prefix = { for (var k in data) {
hostname: "from", var key = prefix[k];
realname: "is", if (!key || data[k].toString() == "") {
channels: "on", continue;
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,
});
} }
var msg = new Msg({ var msg = new Msg({
type: "whois", type: "whois",
from: data.nickname, from: data.nickname,
text: "End of /WHOIS list.", text: key + " " + data[k],
}); });
chan.messages.push(msg); chan.messages.push(msg);
sockets.emit("msg", { sockets.emit("msg", {
@ -706,6 +700,16 @@ function event(e, data) {
msg: msg, 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; break;
} }
} }