diff --git a/client/css/style.css b/client/css/style.css index c57572a..0bbd8a9 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -216,6 +216,7 @@ button { } #messages .from { background: #f9f9f9; + border-right: 1px solid #f4f4f4; color: #ddd; padding-right: 10px; text-align: right; diff --git a/client/js/chat.js b/client/js/chat.js index 3fc6f3f..a470dc1 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -120,17 +120,6 @@ $(function() { } }); - networks.on("click", ".chan", function() { - var id = $(this).data("id"); - var chan = find(id); - if (typeof chan !== "undefined") { - activeChannel = chan; - chat.html( - render("chat", chan) - ); - } - }); - var input = $("#input").tab(complete, { hint: false }); @@ -140,10 +129,23 @@ $(function() { var value = input.val(); input.val(""); socket.emit("input", { - // .. + target: chat.data("target"), + text: value }); }); + networks.on("click", ".chan", function() { + var id = $(this).data("id"); + var chan = find(id); + chat.data("target", id); + if (typeof chan !== "undefined") { + activeChannel = chan; + chat.html( + render("chat", chan) + ); + } + }); + function isActive(chan) { return activeChannel !== null && chan == activeChannel; } diff --git a/lib/models/client.js b/lib/models/client.js index 6517be1..ed38f0a 100644 --- a/lib/models/client.js +++ b/lib/models/client.js @@ -20,3 +20,22 @@ Client.prototype.emit = function(event, data) { this.sockets.in(this.id).emit(event, data); } }; + +Client.prototype.find = function(id) { + var network = null; + var chan = null; + this.networks.forEach(function(n) { + chan = _.find(n.channels, {id: id}); + if (chan) { + network = n; + } + }); + if (network && chan) { + return { + network: network, + chan: chan + }; + } else { + return false; + } +}; diff --git a/lib/plugins/inputs/action.js b/lib/plugins/inputs/action.js index 89e5d4c..88d20dd 100644 --- a/lib/plugins/inputs/action.js +++ b/lib/plugins/inputs/action.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("action"); }; diff --git a/lib/plugins/inputs/connect.js b/lib/plugins/inputs/connect.js new file mode 100644 index 0000000..16be621 --- /dev/null +++ b/lib/plugins/inputs/connect.js @@ -0,0 +1,3 @@ +module.exports = function(network, chan, cmd, args) { + console.log("connect"); +}; diff --git a/lib/plugins/inputs/invite.js b/lib/plugins/inputs/invite.js index 89e5d4c..11bdbe9 100644 --- a/lib/plugins/inputs/invite.js +++ b/lib/plugins/inputs/invite.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("invite"); }; diff --git a/lib/plugins/inputs/join.js b/lib/plugins/inputs/join.js index 89e5d4c..1c508ba 100644 --- a/lib/plugins/inputs/join.js +++ b/lib/plugins/inputs/join.js @@ -1,2 +1,9 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + if (cmd != "join") { + return + } + if (args.length != 0) { + var irc = network.irc; + irc.join(args); + } }; diff --git a/lib/plugins/inputs/kick.js b/lib/plugins/inputs/kick.js index 89e5d4c..aa89b3a 100644 --- a/lib/plugins/inputs/kick.js +++ b/lib/plugins/inputs/kick.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("kick"); }; diff --git a/lib/plugins/inputs/mode.js b/lib/plugins/inputs/mode.js index 89e5d4c..451f756 100644 --- a/lib/plugins/inputs/mode.js +++ b/lib/plugins/inputs/mode.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("mode"); }; diff --git a/lib/plugins/inputs/msg.js b/lib/plugins/inputs/msg.js index 89e5d4c..49879a4 100644 --- a/lib/plugins/inputs/msg.js +++ b/lib/plugins/inputs/msg.js @@ -1,2 +1,38 @@ -module.exports = function() { +var _ = require("lodash"); +var Msg = require("../../models/msg"); + +module.exports = function(network, chan, cmd, args) { + if (cmd != "say" && cmd != "msg") { + return + } + + var client = this; + var irc = network.irc; + + if (args.length === 0) { + return; + } + + var target = args[0].charAt(0) == "#" ? args[0] : "#" + chan.name; + if (target !== chan.name) { + targetChan = _.findWhere(network.channels, { + name: target + }); + } + + var text = args.join(" "); + irc.send(target, text); + + if (typeof chan !== "undefined") { + var msg = new Msg({ + type: Msg.Type.MESSAGE, + from: irc.me, + text: text + }); + chan.messages.push(msg); + client.emit("msg", { + chan: chan.id, + msg: msg + }); + } }; diff --git a/lib/plugins/inputs/nick.js b/lib/plugins/inputs/nick.js index 89e5d4c..9c125bb 100644 --- a/lib/plugins/inputs/nick.js +++ b/lib/plugins/inputs/nick.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("nick"); }; diff --git a/lib/plugins/inputs/notice.js b/lib/plugins/inputs/notice.js index 89e5d4c..61f4c8c 100644 --- a/lib/plugins/inputs/notice.js +++ b/lib/plugins/inputs/notice.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("notice"); }; diff --git a/lib/plugins/inputs/part.js b/lib/plugins/inputs/part.js index 89e5d4c..0464c88 100644 --- a/lib/plugins/inputs/part.js +++ b/lib/plugins/inputs/part.js @@ -1,2 +1,10 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + if (cmd != "part") { + return; + } + var irc = network.irc; + if (args.length === 0) { + args.push("#" + chan.name); + } + irc.part(args); }; diff --git a/lib/plugins/inputs/quit.js b/lib/plugins/inputs/quit.js index 89e5d4c..2e640d6 100644 --- a/lib/plugins/inputs/quit.js +++ b/lib/plugins/inputs/quit.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("quit"); }; diff --git a/lib/plugins/inputs/raw.js b/lib/plugins/inputs/raw.js index 89e5d4c..49448ef 100644 --- a/lib/plugins/inputs/raw.js +++ b/lib/plugins/inputs/raw.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("raw"); }; diff --git a/lib/plugins/inputs/server.js b/lib/plugins/inputs/server.js deleted file mode 100644 index 89e5d4c..0000000 --- a/lib/plugins/inputs/server.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = function() { -}; diff --git a/lib/plugins/inputs/topic.js b/lib/plugins/inputs/topic.js index 89e5d4c..a53bca0 100644 --- a/lib/plugins/inputs/topic.js +++ b/lib/plugins/inputs/topic.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("topic"); }; diff --git a/lib/plugins/inputs/whois.js b/lib/plugins/inputs/whois.js index 89e5d4c..186261c 100644 --- a/lib/plugins/inputs/whois.js +++ b/lib/plugins/inputs/whois.js @@ -1,2 +1,3 @@ -module.exports = function() { +module.exports = function(network, chan, cmd, args) { + console.log("whois"); }; diff --git a/lib/shout.js b/lib/shout.js index 04f559c..1476d87 100644 --- a/lib/shout.js +++ b/lib/shout.js @@ -13,6 +13,7 @@ var clients = []; var inputs = [ "action", + "connect", "invite", "join", "kick", @@ -23,7 +24,6 @@ var inputs = [ "part", "quit", "raw", - "server", "topic", "whois" ]; @@ -75,7 +75,7 @@ function auth(data) { // Temporary: var client = clients[0]; if (clients.length === 0) { - var client = new Client({sockets: sockets}); + client = new Client({sockets: sockets}); clients.push(client); connect(client, { host: "irc.freenode.org" @@ -126,5 +126,20 @@ function connect(client, args) { } function input(client, data) { - console.log(data); + var target = client.find(data.target); + if (!target) { + return; + } + + var text = data.text; + if (text.charAt(0) !== "/") { + text = "/say " + text; + } + + var args = text.split(" "); + var cmd = args.shift().replace("/", "").toLowerCase(); + + inputs.forEach(function(plugin) { + require("./plugins/inputs/" + plugin).apply(client, [target.network, target.chan, cmd, args]); + }); }