diff --git a/src/client.js b/src/client.js index 82f0bccd..46845a2e 100644 --- a/src/client.js +++ b/src/client.js @@ -33,21 +33,21 @@ var events = [ "whois" ]; var inputs = [ + // These inputs are sorted in order that is most likely to be used + "msg", + "whois", + "part", "action", "connect", "invite", "join", "kick", "mode", - "msg", "nick", "notice", - "part", "quit", "raw", - "services", "topic", - "whois" ]; function Client(manager, name, config) { @@ -270,16 +270,22 @@ Client.prototype.input = function(data) { var client = this; var text = data.text.trim(); var target = client.find(data.target); - if (text.charAt(0) !== "/") { - text = "/say " + text; + + // This is either a normal message or a command escaped with a leading '/' + if (text.charAt(0) !== "/" || text.charAt(1) === "/") { + text = "say " + text.replace(/^\//, ""); + } else { + text = text.substr(1); } + var args = text.split(" "); - var cmd = args.shift().replace("/", "").toLowerCase(); - _.each(inputs, function(plugin) { + var cmd = args.shift().toLowerCase(); + + var result = inputs.some(function(plugin) { try { var path = "./plugins/inputs/" + plugin; var fn = require(path); - fn.apply(client, [ + return fn.apply(client, [ target.network, target.chan, cmd, @@ -289,6 +295,10 @@ Client.prototype.input = function(data) { console.log(path + ": " + e); } }); + + if (result !== true) { + target.network.irc.write(text); + } }; Client.prototype.more = function(data) { diff --git a/src/plugins/inputs/action.js b/src/plugins/inputs/action.js index a01f2213..9ed6860c 100644 --- a/src/plugins/inputs/action.js +++ b/src/plugins/inputs/action.js @@ -26,4 +26,6 @@ module.exports = function(network, chan, cmd, args) { }); break; } + + return true; }; diff --git a/src/plugins/inputs/connect.js b/src/plugins/inputs/connect.js index 7bdcb0fe..f2945f5c 100644 --- a/src/plugins/inputs/connect.js +++ b/src/plugins/inputs/connect.js @@ -2,10 +2,13 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "connect" && cmd !== "server") { return; } + if (args.length !== 0) { var client = this; client.connect({ host: args[0] }); } + + return true; }; diff --git a/src/plugins/inputs/invite.js b/src/plugins/inputs/invite.js index e87d320a..7663849a 100644 --- a/src/plugins/inputs/invite.js +++ b/src/plugins/inputs/invite.js @@ -10,4 +10,6 @@ module.exports = function(network, chan, cmd, args) { } else if (args.length === 1 && chan.type === "channel") { irc.invite(args[0], chan.name); // Current channel } + + return true; }; diff --git a/src/plugins/inputs/join.js b/src/plugins/inputs/join.js index 57c51455..4a8f0258 100644 --- a/src/plugins/inputs/join.js +++ b/src/plugins/inputs/join.js @@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "join") { return; } + if (args.length !== 0) { var irc = network.irc; irc.join(args[0], args[1]); } + + return true; }; diff --git a/src/plugins/inputs/kick.js b/src/plugins/inputs/kick.js index c1544576..5844c8f5 100644 --- a/src/plugins/inputs/kick.js +++ b/src/plugins/inputs/kick.js @@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "kick") { return; } + if (args.length !== 0) { var irc = network.irc; irc.kick(chan.name, args[0]); } + + return true; }; diff --git a/src/plugins/inputs/mode.js b/src/plugins/inputs/mode.js index 2cd1b22c..dba13a4f 100644 --- a/src/plugins/inputs/mode.js +++ b/src/plugins/inputs/mode.js @@ -16,7 +16,7 @@ module.exports = function(network, chan, cmd, args) { "devoice": "-v" }[cmd]; } else if (args.length === 1) { - return; + return true; } else { mode = args[0]; user = args[1]; @@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) { mode, user ); + + return true; }; diff --git a/src/plugins/inputs/msg.js b/src/plugins/inputs/msg.js index 3a7c2476..d4e3b268 100644 --- a/src/plugins/inputs/msg.js +++ b/src/plugins/inputs/msg.js @@ -5,14 +5,14 @@ module.exports = function(network, chan, cmd, args) { return; } if (args.length === 0 || args[0] === "") { - return; + return true; } var irc = network.irc; var target = ""; if (cmd === "msg") { target = args.shift(); if (args.length === 0) { - return; + return true; } } else { target = chan.name; @@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) { message: msg }); } + + return true; }; diff --git a/src/plugins/inputs/nick.js b/src/plugins/inputs/nick.js index 9f8bfee0..d3729154 100644 --- a/src/plugins/inputs/nick.js +++ b/src/plugins/inputs/nick.js @@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "nick") { return; } + if (args.length !== 0) { var irc = network.irc; irc.nick(args[0]); } + + return true; }; diff --git a/src/plugins/inputs/notice.js b/src/plugins/inputs/notice.js index c910b716..291b2ca8 100644 --- a/src/plugins/inputs/notice.js +++ b/src/plugins/inputs/notice.js @@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) { chan: targetChan.id, msg: msg }); + + return true; }; diff --git a/src/plugins/inputs/part.js b/src/plugins/inputs/part.js index 191cbda6..94e99801 100644 --- a/src/plugins/inputs/part.js +++ b/src/plugins/inputs/part.js @@ -4,6 +4,7 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "part" && cmd !== "leave" && cmd !== "close") { return; } + if (chan.type !== "query") { var irc = network.irc; if (args.length === 0) { @@ -11,8 +12,11 @@ module.exports = function(network, chan, cmd, args) { } irc.part(args); } + network.channels = _.without(network.channels, chan); this.emit("part", { chan: chan.id }); + + return true; }; diff --git a/src/plugins/inputs/quit.js b/src/plugins/inputs/quit.js index 1bae1965..dd6298b7 100644 --- a/src/plugins/inputs/quit.js +++ b/src/plugins/inputs/quit.js @@ -16,4 +16,6 @@ module.exports = function(network, chan, cmd, args) { }); irc.quit(quitMessage); + + return true; }; diff --git a/src/plugins/inputs/raw.js b/src/plugins/inputs/raw.js index 6a5c1534..40f1f0bd 100644 --- a/src/plugins/inputs/raw.js +++ b/src/plugins/inputs/raw.js @@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "raw" && cmd !== "send" && cmd !== "quote") { return; } + if (args.length !== 0) { var irc = network.irc; irc.write(args.join(" ")); } + + return true; }; diff --git a/src/plugins/inputs/services.js b/src/plugins/inputs/services.js deleted file mode 100644 index 6c0db36d..00000000 --- a/src/plugins/inputs/services.js +++ /dev/null @@ -1,26 +0,0 @@ -var _ = require("lodash"); - -module.exports = function(network, chan, cmd, args) { - if (cmd !== "ns" && cmd !== "cs" && cmd !== "hs") { - return; - } - var target = ({ - "ns": "nickserv", - "cs": "chanserv", - "hs": "hostserv", - })[cmd]; - if (!target || args.length === 0 || args[0] === "") { - return; - } - var irc = network.irc; - var msg = args.join(" "); - irc.send(target, msg); - var channel = _.find(network.channels, {name: target}); - if (typeof channel !== "undefined") { - irc.emit("message", { - from: irc.me, - to: channel.name, - message: msg - }); - } -}; diff --git a/src/plugins/inputs/topic.js b/src/plugins/inputs/topic.js index 01d373b7..1e7b3c31 100644 --- a/src/plugins/inputs/topic.js +++ b/src/plugins/inputs/topic.js @@ -9,4 +9,6 @@ module.exports = function(network, chan, cmd, args) { var irc = network.irc; irc.write(msg); + + return true; }; diff --git a/src/plugins/inputs/whois.js b/src/plugins/inputs/whois.js index 4170338b..bbd7d074 100644 --- a/src/plugins/inputs/whois.js +++ b/src/plugins/inputs/whois.js @@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { if (cmd !== "whois" && cmd !== "query") { return; } + if (args.length !== 0) { var irc = network.irc; irc.whois(args[0]); } + + return true; };