From 842b8d620caa8320589370864a0af35cce941e7e Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 6 Mar 2016 11:24:56 +0200 Subject: [PATCH] Send unknown commands to the server --- src/client.js | 27 +++++++++++++++++++-------- src/plugins/inputs/action.js | 2 ++ src/plugins/inputs/connect.js | 3 +++ src/plugins/inputs/invite.js | 2 ++ src/plugins/inputs/join.js | 3 +++ src/plugins/inputs/kick.js | 3 +++ src/plugins/inputs/mode.js | 4 +++- src/plugins/inputs/msg.js | 6 ++++-- src/plugins/inputs/nick.js | 3 +++ src/plugins/inputs/notice.js | 2 ++ src/plugins/inputs/part.js | 4 ++++ src/plugins/inputs/quit.js | 2 ++ src/plugins/inputs/raw.js | 3 +++ src/plugins/inputs/topic.js | 2 ++ src/plugins/inputs/whois.js | 3 +++ 15 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/client.js b/src/client.js index 6dff0800..46845a2e 100644 --- a/src/client.js +++ b/src/client.js @@ -33,20 +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", "topic", - "whois" ]; function Client(manager, name, config) { @@ -269,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, @@ -288,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/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; };