From dbcf26d1bd07c8512fec25fbe1a05bac6228a31c Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Fri, 4 Jul 2014 00:49:15 +0200 Subject: [PATCH] Implemented the rest of the input plugins --- client/css/style.css | 4 +++- client/js/chat.js | 3 ++- lib/plugins/inputs/action.js | 37 +++++++++++++++++++++++++++++++++- lib/plugins/inputs/connect.js | 2 +- lib/plugins/inputs/invite.js | 8 +++++++- lib/plugins/inputs/join.js | 4 ++-- lib/plugins/inputs/kick.js | 8 +++++++- lib/plugins/inputs/mode.js | 29 +++++++++++++++++++++++++- lib/plugins/inputs/msg.js | 6 +++--- lib/plugins/inputs/nick.js | 8 +++++++- lib/plugins/inputs/notice.js | 6 +++++- lib/plugins/inputs/part.js | 2 +- lib/plugins/inputs/quit.js | 16 ++++++++++++++- lib/plugins/inputs/raw.js | 8 +++++++- lib/plugins/inputs/topic.js | 11 +++++++++- lib/plugins/inputs/whois.js | 8 +++++++- lib/plugins/irc-events/nick.js | 2 +- 17 files changed, 142 insertions(+), 20 deletions(-) diff --git a/client/css/style.css b/client/css/style.css index 0bbd8a94..feb65176 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -239,7 +239,9 @@ button { #messages .nick .type, #messages .kick .type, #messages .quit .type, -#messages .quit .type { +#messages .quit .type, +#messages .notice .type, +#messages .topic .type { display: inline; } #meta { diff --git a/client/js/chat.js b/client/js/chat.js index a470dc12..c1bea430 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -102,11 +102,12 @@ $(function() { }); socket.on("part", function(data) { - console.log(data); + networks.find(".chan[data-id='" + data.chan + "']").remove(); }); socket.on("quit", function(data) { console.log(data); + networks.find(".network[data-id='" + data.network + "']").remove(); }); socket.on("users", function(data) { diff --git a/lib/plugins/inputs/action.js b/lib/plugins/inputs/action.js index 88d20dd4..10614b34 100644 --- a/lib/plugins/inputs/action.js +++ b/lib/plugins/inputs/action.js @@ -1,3 +1,38 @@ +var Msg = require("../../models/msg"); + module.exports = function(network, chan, cmd, args) { - console.log("action"); + if (cmd != "slap" && cmd != "me") { + return; + } + + var client = this; + var irc = network.irc; + + switch (cmd) { + case "slap": + var slap = "slaps " + args[0] + " around a bit with a large trout"; + /* fall through */ + case "me": + if (args.length === 0) { + break; + } + + var text = slap || args.join(" "); + irc.action( + chan.name, + text + ); + + var msg = new Msg({ + type: Msg.Type.ACTION, + from: irc.me, + text: text + }); + chan.messages.push(msg); + client.emit("msg", { + chan: chan.id, + msg: msg + }); + break; + } }; diff --git a/lib/plugins/inputs/connect.js b/lib/plugins/inputs/connect.js index 16be6212..0f765171 100644 --- a/lib/plugins/inputs/connect.js +++ b/lib/plugins/inputs/connect.js @@ -1,3 +1,3 @@ module.exports = function(network, chan, cmd, args) { - console.log("connect"); + // Not yet implemented. }; diff --git a/lib/plugins/inputs/invite.js b/lib/plugins/inputs/invite.js index 11bdbe94..b9c010d1 100644 --- a/lib/plugins/inputs/invite.js +++ b/lib/plugins/inputs/invite.js @@ -1,3 +1,9 @@ module.exports = function(network, chan, cmd, args) { - console.log("invite"); + if (cmd != "invite") { + return; + } + var irc = network.irc; + if (args.length === 2) { + irc.invite(args[0], args[1]); + } }; diff --git a/lib/plugins/inputs/join.js b/lib/plugins/inputs/join.js index 1c508ba3..079036c5 100644 --- a/lib/plugins/inputs/join.js +++ b/lib/plugins/inputs/join.js @@ -1,8 +1,8 @@ module.exports = function(network, chan, cmd, args) { if (cmd != "join") { - return + return; } - if (args.length != 0) { + 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 aa89b3a1..8e2abc90 100644 --- a/lib/plugins/inputs/kick.js +++ b/lib/plugins/inputs/kick.js @@ -1,3 +1,9 @@ module.exports = function(network, chan, cmd, args) { - console.log("kick"); + if (cmd != "kick") { + return; + } + if (args.length !== 0) { + var irc = network.irc; + irc.kick(chan.name, args[0]); + } }; diff --git a/lib/plugins/inputs/mode.js b/lib/plugins/inputs/mode.js index 451f7561..e4a5969d 100644 --- a/lib/plugins/inputs/mode.js +++ b/lib/plugins/inputs/mode.js @@ -1,3 +1,30 @@ module.exports = function(network, chan, cmd, args) { - console.log("mode"); + if (cmd != "mode" && cmd != "op" && cmd != "voice" && cmd != "deop" && cmd != "devoice") { + return; + } else if (args.length === 0) { + return; + } + + var mode; + var user; + if (cmd != "mode") { + user = args[0]; + mode = { + "op": "+o", + "voice": "+v", + "deop": "-o", + "devoice": "-v" + }[cmd]; + } else if (args.length === 1) { + return; + } else { + mode = args[0]; + user = args[1]; + } + var irc = network.irc; + irc.mode( + chan.name, + mode, + user + ); }; diff --git a/lib/plugins/inputs/msg.js b/lib/plugins/inputs/msg.js index 49879a4d..a2e30b45 100644 --- a/lib/plugins/inputs/msg.js +++ b/lib/plugins/inputs/msg.js @@ -3,7 +3,7 @@ var Msg = require("../../models/msg"); module.exports = function(network, chan, cmd, args) { if (cmd != "say" && cmd != "msg") { - return + return; } var client = this; @@ -13,9 +13,9 @@ module.exports = function(network, chan, cmd, args) { return; } - var target = args[0].charAt(0) == "#" ? args[0] : "#" + chan.name; + var target = args[0].charAt(0) == "#" ? args[0] : chan.name; if (target !== chan.name) { - targetChan = _.findWhere(network.channels, { + chan = _.findWhere(network.channels, { name: target }); } diff --git a/lib/plugins/inputs/nick.js b/lib/plugins/inputs/nick.js index 9c125bb5..16a9cc6c 100644 --- a/lib/plugins/inputs/nick.js +++ b/lib/plugins/inputs/nick.js @@ -1,3 +1,9 @@ module.exports = function(network, chan, cmd, args) { - console.log("nick"); + if (cmd != "nick") { + return; + } + if (args.length !== 0) { + var irc = network.irc; + irc.nick(args[0]); + } }; diff --git a/lib/plugins/inputs/notice.js b/lib/plugins/inputs/notice.js index 61f4c8c4..0395a168 100644 --- a/lib/plugins/inputs/notice.js +++ b/lib/plugins/inputs/notice.js @@ -1,3 +1,7 @@ module.exports = function(network, chan, cmd, args) { - console.log("notice"); + if (cmd != "notice" || !args[1]) { + return; + } + var irc = network.irc; + irc.notice(args[0], args.slice(1).join(" ")); }; diff --git a/lib/plugins/inputs/part.js b/lib/plugins/inputs/part.js index 0464c884..0c25f02e 100644 --- a/lib/plugins/inputs/part.js +++ b/lib/plugins/inputs/part.js @@ -4,7 +4,7 @@ module.exports = function(network, chan, cmd, args) { } var irc = network.irc; if (args.length === 0) { - args.push("#" + chan.name); + args.push(chan.name); } irc.part(args); }; diff --git a/lib/plugins/inputs/quit.js b/lib/plugins/inputs/quit.js index 2e640d65..735dd34a 100644 --- a/lib/plugins/inputs/quit.js +++ b/lib/plugins/inputs/quit.js @@ -1,3 +1,17 @@ +var _ = require("lodash"); + module.exports = function(network, chan, cmd, args) { - console.log("quit"); + if (cmd != "quit" && cmd != "disconnect") { + return; + } + + var client = this; + var irc = network.irc; + + client.networks = _.without(client.networks, network); + client.emit("quit", { + network: network.id + }); + + irc.quit(); }; diff --git a/lib/plugins/inputs/raw.js b/lib/plugins/inputs/raw.js index 49448ef4..f0613d7e 100644 --- a/lib/plugins/inputs/raw.js +++ b/lib/plugins/inputs/raw.js @@ -1,3 +1,9 @@ module.exports = function(network, chan, cmd, args) { - console.log("raw"); + if (cmd != "raw") { + return; + } + if (args.length !== 0) { + var irc = network.irc; + irc.write(args.join(" ")); + } }; diff --git a/lib/plugins/inputs/topic.js b/lib/plugins/inputs/topic.js index a53bca0c..b4584d18 100644 --- a/lib/plugins/inputs/topic.js +++ b/lib/plugins/inputs/topic.js @@ -1,3 +1,12 @@ module.exports = function(network, chan, cmd, args) { - console.log("topic"); + if (cmd != "topic") { + return; + } + + var msg = "TOPIC"; + msg += " " + chan.name; + msg += args[0] ? (" :" + args.join(" ")) : ""; + + var irc = network.irc; + irc.write(msg); }; diff --git a/lib/plugins/inputs/whois.js b/lib/plugins/inputs/whois.js index 186261c3..8e615269 100644 --- a/lib/plugins/inputs/whois.js +++ b/lib/plugins/inputs/whois.js @@ -1,3 +1,9 @@ module.exports = function(network, chan, cmd, args) { - console.log("whois"); + if (cmd != "whois" && cmd != "query") { + return; + } + if (args.length !== 0) { + var irc = network.irc; + irc.whois(args[0]); + } }; diff --git a/lib/plugins/irc-events/nick.js b/lib/plugins/irc-events/nick.js index d7e80766..d57800be 100644 --- a/lib/plugins/irc-events/nick.js +++ b/lib/plugins/irc-events/nick.js @@ -9,7 +9,7 @@ module.exports = function(irc, network) { var msg = new Msg({ text: "You're now known as " + data["new"], }); - chan.messages.push(msg); + lobby.messages.push(msg); client.emit("msg", { chan: lobby.id, msg: msg