diff --git a/lib/server.js b/lib/server.js index 02e60e11..e474326b 100644 --- a/lib/server.js +++ b/lib/server.js @@ -167,6 +167,13 @@ function handleInput(input) { } break; + case "WHOIS": + var irc = network.irc; + if (typeof irc !== "undefined") { + irc.send(cmd, argv[1] || target.channel.get("name")); + } + break; + default: channel.get("messages").add( new models.Message({ @@ -187,16 +194,6 @@ function handleEvent(argv) { switch (event) { - case "ERROR": - var args = argv.args; - channels.first().get("messages").add( - new models.Message({ - text: args[args.length - 1], - type: "error" - }) - ); - break; - case "PRIVMSG": var target = argv.args[0]; if (target.charAt(0) != "#") { @@ -229,6 +226,7 @@ function handleEvent(argv) { text: "notice: " + argv.args[1], type: "notice" }); + channels.each(function(channel) { channel.get("messages").add(message); }); @@ -243,10 +241,10 @@ function handleEvent(argv) { }) ); } - + var users = channel.get("users"); var messages = channel.get("messages"); - + if (argv.nick != network.get("nick")) { users.add( new models.User({ @@ -254,6 +252,7 @@ function handleEvent(argv) { }) ); } + messages.add( new models.Message({ user: argv.nick, @@ -290,6 +289,7 @@ function handleEvent(argv) { user: argv.nick, text: "changed name to " + argv.args[0] }); + channels.each(function(channel) { var user = channel.get("users").findWhere({name: argv.nick}); if (typeof user !== "undefined") { @@ -297,6 +297,7 @@ function handleEvent(argv) { channel.get("messages").add(message); } }); + if (argv.nick == network.get("nick")) { network.set("nick", argv.args[0]); } @@ -305,6 +306,7 @@ function handleEvent(argv) { case "TOPIC": var channel = channels.findWhere({name: argv.args[0]}); var messages = channel.get("messages"); + messages.add( new models.Message({ user: argv.nick, @@ -331,6 +333,7 @@ function handleEvent(argv) { case "rpl_namreply": var names = argv.args[3].split(' '); var channel = network.get("channels").findWhere({name: argv.args[2]}); + if (typeof channel === "undefined") { channel = channels.add( new models.Channel({ @@ -338,7 +341,7 @@ function handleEvent(argv) { }) ); } - + var users = channel.get("users"); if (names[0] == network.get("nick")) { users.reset(); @@ -355,6 +358,7 @@ function handleEvent(argv) { case "rpl_endofnames": var channel = network.get("channels").findWhere({name: argv.args[1]}); var users = channel.get("users"); + users.trigger( "add", {}, users ); @@ -373,6 +377,39 @@ function handleEvent(argv) { ); break; + case "rpl_whoisuser": + case "rpl_whoischannels": + case "rpl_whoisserver": + case "rpl_endofwhois": + var channel = channels.findWhere({name: argv.args[1]}); + var message = argv.args.slice(2).join(" "); + + if (typeof channel == "undefined") { + channel = channels.add( + new models.Channel({ + name: argv.args[1] + }) + ); + } + + channel.get("messages").add( + new models.Message({ + user: argv.args[1], + text: message + }) + ); + break; + + case "ERROR": + var args = argv.args; + channels.first().get("messages").add( + new models.Message({ + text: args[args.length - 1], + type: "error" + }) + ); + break; + } // Debug