diff --git a/lib/server.js b/lib/server.js index 2334983a..0475c982 100644 --- a/lib/server.js +++ b/lib/server.js @@ -271,12 +271,17 @@ function handleEvent(argv) { name: argv.nick }) ); + } else { + var irc = network.irc; + if (typeof irc !== "undefined") { + irc.send("TOPIC", argv.args[0]); + } } messages.add( new models.Message({ user: argv.nick, - text: "has joined the channel.", + text: "join", type: "join" }) ); @@ -298,7 +303,7 @@ function handleEvent(argv) { messages.add( new models.Message({ user: argv.nick, - text: "has left the channel.", + text: "part", type: "part" }) ); @@ -308,7 +313,8 @@ function handleEvent(argv) { case "NICK": var message = new models.Message({ user: argv.nick, - text: "changed name to " + argv.args[0] + text: "changed name to " + argv.args[0], + type: "nick" }); channels.each(function(channel) { @@ -330,6 +336,8 @@ function handleEvent(argv) { }); var users = channel.get("users"); + var messages = channel.get("messages"); + if (argv.args[1] == network.get("nick")) { users.reset(); } else { @@ -340,16 +348,52 @@ function handleEvent(argv) { ); } - var messages = channel.get("messages"); messages.add( new models.Message({ user: argv.args[1], - text: "was kicked from " + argv.args[0] + " by " + argv.nick, + text: "was kicked by " + argv.nick, type: "kick" }) ); break; + case "QUIT": + var message = new models.Message({ + user: argv.nick, + text: "quit", + type: "quit" + }); + + channels.each(function(channel) { + var user = channel.get("users").findWhere({name: argv.nick}); + if (typeof user !== "undefined") { + channel.get("users").remove(user); + channel.get("messages").add(message); + } + }); + break; + + case "MODE": + var channel = channels.findWhere({name: argv.args[0]}); + if (typeof channel === "undefined") { + break; + } + + var messages = channel.get("messages"); + messages.add( + new models.Message({ + user: argv.nick, + text: "sets mode: " + argv.args[1] + " " + argv.args[2], + type: "mode" + }) + ); + + var irc = network.irc; + if (typeof irc !== "undefined") { + irc.send("NAMES", argv.args[0]); + } + break; + case "TOPIC": var channel = channels.findWhere({name: argv.args[0]}); var messages = channel.get("messages"); @@ -378,8 +422,8 @@ function handleEvent(argv) { break; case "rpl_namreply": - var names = argv.args[3].split(' '); var channel = network.get("channels").findWhere({name: argv.args[2]}); + var users = channel.get("users"); if (typeof channel === "undefined") { channel = channels.add( @@ -389,10 +433,13 @@ function handleEvent(argv) { ); } - var users = channel.get("users"); - if (names[0] == network.get("nick")) { + var names = argv.args[3].split(' '); + + var first = names[0].replace(/^\W/, ''); // Strip mode prefixes + if (first == network.get("nick")) { users.reset(); } + for (var i in names) { users.add( new models.User({name: names[i]}), { @@ -403,7 +450,7 @@ function handleEvent(argv) { break; case "rpl_endofnames": - var channel = network.get("channels").findWhere({name: argv.args[1]}); + var channel = channels.findWhere({name: argv.args[1]}); var users = channel.get("users"); users.trigger(