Whitelist which commands are allowed while not being connected

This commit is contained in:
Pavel Djundik 2016-04-03 12:58:59 +03:00 committed by Maxime Poulin
parent 69bb003e45
commit 40a15b2676
4 changed files with 29 additions and 7 deletions

View File

@ -47,7 +47,7 @@ var inputs = [
var path = "./plugins/inputs/" + name; var path = "./plugins/inputs/" + name;
var plugin = require(path); var plugin = require(path);
plugin.commands.forEach(function(command) { plugin.commands.forEach(function(command) {
plugins[command] = plugin.input; plugins[command] = plugin;
}); });
return plugins; return plugins;
}, {}); }, {});
@ -250,10 +250,27 @@ Client.prototype.input = function(data) {
var args = text.split(" "); var args = text.split(" ");
var cmd = args.shift().toLowerCase(); var cmd = args.shift().toLowerCase();
var irc = target.network.irc;
var connected = irc && irc.connection && irc.connection.connected;
if (cmd in inputs) { if (cmd in inputs) {
inputs[cmd].apply(client, [target.network, target.chan, cmd, args]); var plugin = inputs[cmd];
} else { if (connected || plugin.allowDisconnected) {
target.network.irc.raw(text); connected = true;
plugin.input.apply(client, [target.network, target.chan, cmd, args]);
}
} else if (connected) {
irc.raw(text);
}
if (!connected) {
this.emit("msg", {
chan: target.chan.id,
msg: new Msg({
type: Msg.Type.ERROR,
text: "You are not connected to the IRC network, unable to send your command."
})
});
} }
}; };

View File

@ -1,4 +1,5 @@
exports.commands = ["connect", "server"]; exports.commands = ["connect", "server"];
exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) { exports.input = function(network, chan, cmd, args) {
if (args.length === 0) { if (args.length === 0) {

View File

@ -2,6 +2,7 @@ var _ = require("lodash");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
exports.commands = ["close", "leave", "part"]; exports.commands = ["close", "leave", "part"];
exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) { exports.input = function(network, chan, cmd, args) {
if (chan.type === "lobby") { if (chan.type === "lobby") {
@ -15,8 +16,8 @@ exports.input = function(network, chan, cmd, args) {
return; return;
} }
if (chan.type === "channel") { var irc = network.irc;
var irc = network.irc; if (irc && chan.type === "channel") {
irc.part(chan.name, args.join(" ")); irc.part(chan.name, args.join(" "));
} }

View File

@ -1,6 +1,7 @@
var _ = require("lodash"); var _ = require("lodash");
exports.commands = ["quit", "disconnect"]; exports.commands = ["quit", "disconnect"];
exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) { exports.input = function(network, chan, cmd, args) {
var client = this; var client = this;
@ -13,7 +14,9 @@ exports.input = function(network, chan, cmd, args) {
network: network.id network: network.id
}); });
irc.quit(quitMessage); if (irc) {
irc.quit(quitMessage);
}
return true; return true;
}; };