Send unknown commands to the server

This commit is contained in:
Pavel Djundik 2016-03-06 11:24:56 +02:00
parent 42a7c54c0a
commit 842b8d620c
15 changed files with 58 additions and 11 deletions

View File

@ -33,20 +33,21 @@ var events = [
"whois" "whois"
]; ];
var inputs = [ var inputs = [
// These inputs are sorted in order that is most likely to be used
"msg",
"whois",
"part",
"action", "action",
"connect", "connect",
"invite", "invite",
"join", "join",
"kick", "kick",
"mode", "mode",
"msg",
"nick", "nick",
"notice", "notice",
"part",
"quit", "quit",
"raw", "raw",
"topic", "topic",
"whois"
]; ];
function Client(manager, name, config) { function Client(manager, name, config) {
@ -269,16 +270,22 @@ Client.prototype.input = function(data) {
var client = this; var client = this;
var text = data.text.trim(); var text = data.text.trim();
var target = client.find(data.target); 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 args = text.split(" ");
var cmd = args.shift().replace("/", "").toLowerCase(); var cmd = args.shift().toLowerCase();
_.each(inputs, function(plugin) {
var result = inputs.some(function(plugin) {
try { try {
var path = "./plugins/inputs/" + plugin; var path = "./plugins/inputs/" + plugin;
var fn = require(path); var fn = require(path);
fn.apply(client, [ return fn.apply(client, [
target.network, target.network,
target.chan, target.chan,
cmd, cmd,
@ -288,6 +295,10 @@ Client.prototype.input = function(data) {
console.log(path + ": " + e); console.log(path + ": " + e);
} }
}); });
if (result !== true) {
target.network.irc.write(text);
}
}; };
Client.prototype.more = function(data) { Client.prototype.more = function(data) {

View File

@ -26,4 +26,6 @@ module.exports = function(network, chan, cmd, args) {
}); });
break; break;
} }
return true;
}; };

View File

@ -2,10 +2,13 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "connect" && cmd !== "server") { if (cmd !== "connect" && cmd !== "server") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var client = this; var client = this;
client.connect({ client.connect({
host: args[0] host: args[0]
}); });
} }
return true;
}; };

View File

@ -10,4 +10,6 @@ module.exports = function(network, chan, cmd, args) {
} else if (args.length === 1 && chan.type === "channel") { } else if (args.length === 1 && chan.type === "channel") {
irc.invite(args[0], chan.name); // Current channel irc.invite(args[0], chan.name); // Current channel
} }
return true;
}; };

View File

@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "join") { if (cmd !== "join") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var irc = network.irc; var irc = network.irc;
irc.join(args[0], args[1]); irc.join(args[0], args[1]);
} }
return true;
}; };

View File

@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "kick") { if (cmd !== "kick") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var irc = network.irc; var irc = network.irc;
irc.kick(chan.name, args[0]); irc.kick(chan.name, args[0]);
} }
return true;
}; };

View File

@ -16,7 +16,7 @@ module.exports = function(network, chan, cmd, args) {
"devoice": "-v" "devoice": "-v"
}[cmd]; }[cmd];
} else if (args.length === 1) { } else if (args.length === 1) {
return; return true;
} else { } else {
mode = args[0]; mode = args[0];
user = args[1]; user = args[1];
@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) {
mode, mode,
user user
); );
return true;
}; };

View File

@ -5,14 +5,14 @@ module.exports = function(network, chan, cmd, args) {
return; return;
} }
if (args.length === 0 || args[0] === "") { if (args.length === 0 || args[0] === "") {
return; return true;
} }
var irc = network.irc; var irc = network.irc;
var target = ""; var target = "";
if (cmd === "msg") { if (cmd === "msg") {
target = args.shift(); target = args.shift();
if (args.length === 0) { if (args.length === 0) {
return; return true;
} }
} else { } else {
target = chan.name; target = chan.name;
@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) {
message: msg message: msg
}); });
} }
return true;
}; };

View File

@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "nick") { if (cmd !== "nick") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var irc = network.irc; var irc = network.irc;
irc.nick(args[0]); irc.nick(args[0]);
} }
return true;
}; };

View File

@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) {
chan: targetChan.id, chan: targetChan.id,
msg: msg msg: msg
}); });
return true;
}; };

View File

@ -4,6 +4,7 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "part" && cmd !== "leave" && cmd !== "close") { if (cmd !== "part" && cmd !== "leave" && cmd !== "close") {
return; return;
} }
if (chan.type !== "query") { if (chan.type !== "query") {
var irc = network.irc; var irc = network.irc;
if (args.length === 0) { if (args.length === 0) {
@ -11,8 +12,11 @@ module.exports = function(network, chan, cmd, args) {
} }
irc.part(args); irc.part(args);
} }
network.channels = _.without(network.channels, chan); network.channels = _.without(network.channels, chan);
this.emit("part", { this.emit("part", {
chan: chan.id chan: chan.id
}); });
return true;
}; };

View File

@ -16,4 +16,6 @@ module.exports = function(network, chan, cmd, args) {
}); });
irc.quit(quitMessage); irc.quit(quitMessage);
return true;
}; };

View File

@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "raw" && cmd !== "send" && cmd !== "quote") { if (cmd !== "raw" && cmd !== "send" && cmd !== "quote") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var irc = network.irc; var irc = network.irc;
irc.write(args.join(" ")); irc.write(args.join(" "));
} }
return true;
}; };

View File

@ -9,4 +9,6 @@ module.exports = function(network, chan, cmd, args) {
var irc = network.irc; var irc = network.irc;
irc.write(msg); irc.write(msg);
return true;
}; };

View File

@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) {
if (cmd !== "whois" && cmd !== "query") { if (cmd !== "whois" && cmd !== "query") {
return; return;
} }
if (args.length !== 0) { if (args.length !== 0) {
var irc = network.irc; var irc = network.irc;
irc.whois(args[0]); irc.whois(args[0]);
} }
return true;
}; };