mirror of
https://github.com/thelounge/thelounge
synced 2024-11-23 12:33:07 +00:00
Whitelist which commands are allowed while not being connected
This commit is contained in:
parent
69bb003e45
commit
40a15b2676
4 changed files with 29 additions and 7 deletions
|
@ -47,7 +47,7 @@ var inputs = [
|
|||
var path = "./plugins/inputs/" + name;
|
||||
var plugin = require(path);
|
||||
plugin.commands.forEach(function(command) {
|
||||
plugins[command] = plugin.input;
|
||||
plugins[command] = plugin;
|
||||
});
|
||||
return plugins;
|
||||
}, {});
|
||||
|
@ -250,10 +250,27 @@ Client.prototype.input = function(data) {
|
|||
var args = text.split(" ");
|
||||
var cmd = args.shift().toLowerCase();
|
||||
|
||||
var irc = target.network.irc;
|
||||
var connected = irc && irc.connection && irc.connection.connected;
|
||||
|
||||
if (cmd in inputs) {
|
||||
inputs[cmd].apply(client, [target.network, target.chan, cmd, args]);
|
||||
} else {
|
||||
target.network.irc.raw(text);
|
||||
var plugin = inputs[cmd];
|
||||
if (connected || plugin.allowDisconnected) {
|
||||
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."
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
exports.commands = ["connect", "server"];
|
||||
exports.allowDisconnected = true;
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (args.length === 0) {
|
||||
|
|
|
@ -2,6 +2,7 @@ var _ = require("lodash");
|
|||
var Msg = require("../../models/msg");
|
||||
|
||||
exports.commands = ["close", "leave", "part"];
|
||||
exports.allowDisconnected = true;
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
if (chan.type === "lobby") {
|
||||
|
@ -15,8 +16,8 @@ exports.input = function(network, chan, cmd, args) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (chan.type === "channel") {
|
||||
var irc = network.irc;
|
||||
var irc = network.irc;
|
||||
if (irc && chan.type === "channel") {
|
||||
irc.part(chan.name, args.join(" "));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var _ = require("lodash");
|
||||
|
||||
exports.commands = ["quit", "disconnect"];
|
||||
exports.allowDisconnected = true;
|
||||
|
||||
exports.input = function(network, chan, cmd, args) {
|
||||
var client = this;
|
||||
|
@ -13,7 +14,9 @@ exports.input = function(network, chan, cmd, args) {
|
|||
network: network.id
|
||||
});
|
||||
|
||||
irc.quit(quitMessage);
|
||||
if (irc) {
|
||||
irc.quit(quitMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue