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"
];
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) {

View File

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

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};

View File

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

View File

@ -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;
};

View File

@ -16,4 +16,6 @@ module.exports = function(network, chan, cmd, args) {
});
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") {
return;
}
if (args.length !== 0) {
var irc = network.irc;
irc.write(args.join(" "));
}
return true;
};

View File

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

View File

@ -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;
};