From 9119555f442140126e0b8159fd15de62af4a40a0 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Wed, 2 Apr 2014 17:24:33 +0200 Subject: [PATCH] Added whois --- .gitignore | 1 + .gitmodules | 3 ++ client/css/style.css | 3 ++ client/index.html | 6 +-- client/js/chat.js | 2 +- lib/models.js | 2 +- lib/server.js | 103 +++++++++++++++++++++++++++++------------ node_modules/slate-irc | 1 + 8 files changed, 86 insertions(+), 35 deletions(-) create mode 100644 .gitmodules create mode 160000 node_modules/slate-irc diff --git a/.gitignore b/.gitignore index c2658d7d..495c5bf2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +!node_modules/slate-irc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..c40ff071 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "node_modules/slate-irc"] + path = node_modules/slate-irc + url = http://github.com/erming/slate-irc diff --git a/client/css/style.css b/client/css/style.css index d7c7d84e..96eecb22 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -194,6 +194,9 @@ h2 { line-height: 1.4em; padding: 0 6px; } +#chat .message div { + display: inline; +} #chat .message .time { color: #bbb; } diff --git a/client/index.html b/client/index.html index f25d5ee7..a1b93bdd 100644 --- a/client/index.html +++ b/client/index.html @@ -109,9 +109,9 @@ diff --git a/client/js/chat.js b/client/js/chat.js index 69347b3d..632f7d67 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -31,7 +31,7 @@ $(function() { var html = ""; var partials = { users: render("#user"), - messages: render("#message") + messages: render("#message"), }; json.forEach(function(network) { html += render("#window", network, partials); diff --git a/lib/models.js b/lib/models.js index 444a0369..1109f897 100644 --- a/lib/models.js +++ b/lib/models.js @@ -40,7 +40,7 @@ models.Message = Backbone.Model.extend({ defaults: { type: "", time: "", - from: "", + from: "-!-", message: "", }, initialize: function() { diff --git a/lib/server.js b/lib/server.js index 508d867a..117c6ea8 100644 --- a/lib/server.js +++ b/lib/server.js @@ -59,8 +59,8 @@ function connect(host) { client.user("t_user", "temp user"); events.forEach(function(e) { - client.on(e, function(data) { - event.apply(network, [e, data]); + client.on(e, function() { + event.apply(network, [e, arguments]); }); }); } @@ -127,6 +127,16 @@ function input(json) { } break; + case "query": + case "whois": + if (client && args[1]) { + client["whois"](args[1]); + } + break; + + case "kick": + break; + case "quit": case "disconnect": networks.remove(network); @@ -142,10 +152,10 @@ function event(event, data) { switch (event) { case "join": - var chan = channels.findWhere({name: data.channel}) || channels.add({name: data.channel}); - chan.addUser({name: data.nick}); + var chan = channels.findWhere({name: data[0].channel}) || channels.add({name: data[0].channel}); + chan.addUser({name: data[0].nick}); chan.addMessage({ - from: data.nick, + from: data[0].nick, type: "join", }); break; @@ -155,53 +165,65 @@ function event(event, data) { break; case "message": - var chan = channels.findWhere({name: data.to}) || channels.add({type: "query", name: data.from}); + var chan = channels.findWhere({name: data[0].to}) || channels.add({type: "query", name: data[0].from}); chan.addMessage({ - from: data.from, - message: data.message + from: data[0].from, + message: data[0].message }); break; case "names": - var chan = channels.findWhere({name: data.channel}); - chan.get("users").reset(_.map(data.names, function(n) { return {name: n}; })); + var chan = channels.findWhere({name: data[0].channel}); + chan.get("users").reset( + _.map(data[0].names, function(n) { + return {name: n}; + }) + ); break; case "nick": + if (data[0].new == this.get("client").me) { + channels.first().addMessage({ + message: "You're now known as " + data[0]["new"], + }); + } channels.each(function(chan) { var users = chan.get("users"); - var user = users.findWhere({name: data.nick}); + var user = users.findWhere({name: data[0].nick}); if (!user) { return; } - user.set("name", data["new"]); + user.set("name", data[0]["new"]); users.trigger("change", {}, users); chan.addMessage({ - from: data.nick, - message: data["new"], + from: data[0].nick, + message: data[0]["new"], type: "nick", }); }); break; case "notice": - channels.first().addMessage(data); + if (data[0].to = "*") { + data[0].from = "-!-"; + } + channels.first().addMessage(data[0]); break; case "part": - var i = data.channels.length; + var i = data[0].channels.length; while (i--) { - var chan = channels.findWhere({name: data.channels[i]}); - if (data.nick == this.get("client").me) { + var chan = channels.findWhere({name: data[0].channels[i]}); + if (data[0].nick == this.get("client").me) { channels.remove(chan); return; } var users = chan.get("users"); - users.remove(users.findWhere({name: data.nick})); + users.remove(users.findWhere({name: data[0].nick})); chan.addMessage({ - from: data.nick, + from: data[0].nick, type: "part", }); } @@ -210,11 +232,11 @@ function event(event, data) { case "quit": channels.each(function(chan) { var users = chan.get("users"); - var user = users.findWhere({name: data.nick}); + var user = users.findWhere({name: data[0].nick}); if (user) { users.remove(user); chan.addMessage({ - from: data.nick, + from: data[0].nick, type: "quit", }); } @@ -222,29 +244,50 @@ function event(event, data) { break; case "topic": - var chan = channels.findWhere({name: data.channel}); - var from = data.nick; + var chan = channels.findWhere({name: data[0].channel}); + var from = data[0].nick; if (from == this.get("client").me) { - from = data.channel; + from = data[0].channel; } chan.addMessage({ from: from, - message: data.topic, + message: data[0].topic, type: "topic", }); break; case "welcome": - channels.first().addMessage({message: "Connected."}); + channels.first().addMessage([ + {message: "You're now connected to " + this.get("host")}, + {message: "You're now known as " + data[0]} + ]); break; case "whois": - // .. + // If this value is null, an error has occured. + if (data[1] == null) { + channels.first().addMessage({ + type: "error", + message: data[0] + }); + break; + } + + var name = data[1].nickname; + var chan = channels.findWhere({name: name}) || channels.add({type: "query", name: name}); + + var i = 0; + for (var k in data[1]) { + if (i++ == 5) break; + chan.addMessage({ + message: k + ": " + data[1][k] + }); + } break; } // Debug - console.log(event + ":"); + console.log(event); console.log(data); -} \ No newline at end of file +} diff --git a/node_modules/slate-irc b/node_modules/slate-irc new file mode 160000 index 00000000..6f23d25c --- /dev/null +++ b/node_modules/slate-irc @@ -0,0 +1 @@ +Subproject commit 6f23d25c4e8163fff06c6d0751219b5d96a3916c