From cea2994aeaa997bbc4da55ca9fa984792d32eaf5 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Thu, 13 Mar 2014 01:00:59 +0100 Subject: [PATCH] Implemented NOTICE events --- lib/server.js | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/lib/server.js b/lib/server.js index 65c9fa7..8b60d7e 100644 --- a/lib/server.js +++ b/lib/server.js @@ -61,7 +61,8 @@ function handleInput(input) { case "": var irc = target.network.irc; if (typeof irc !== "undefined") { - irc.say(target.channel.get("name"), input.text); + var chan = target.channel.get("name"); + irc.say(chan, input.text); } target.channel.get("messages").add( new models.Message({ @@ -71,6 +72,24 @@ function handleInput(input) { ); break; + case "NOTICE": + var irc = target.network.irc; + if (argv[2] && typeof irc !== "undefined") { + var user = argv[1]; + var text = argv + .slice(2) + .join(" "); + + irc.notice(user, text); + target.channel.get("messages").add( + new models.Message({ + user: target.network.get("nick"), + text: "to " + user + ": " + text + }) + ); + } + break; + case "QUERY": var irc = target.network.irc; if (argv[1] && typeof irc !== "undefined") { @@ -154,15 +173,6 @@ function handleEvent(argv) { var network = this; var channels = network.get("channels"); - // Temp - var network_lobby = channels.first().get("messages"); - network_lobby.add( - new models.Message({ - user: argv.args[0], - text: argv.args[1] - }) - ); - var event = argv.command; switch (event) { @@ -191,6 +201,17 @@ function handleEvent(argv) { ); break; + case "NOTICE": + var from = argv.nick ? argv.nick : argv.prefix; + var message = new models.Message({ + user: from, + text: "notice: " + argv.args[1] + }); + channels.each(function(c) { + c.get("messages").add(message); + }); + break; + case "JOIN": if (argv.nick == network.get("nick")) { channels.add( @@ -293,12 +314,20 @@ function handleEvent(argv) { case "err_nosuchchannel": case "err_cannotsendtochan": case "err_nosuchnick": - network_lobby.add( + channels.first().get("messages").add( new models.Message({ text: argv.args[2] }) ); break; + + default: + channels.first().get("messages").add( + new models.Message({ + user: "-!-", + text: argv.args[1] + }) + ); } // Debug