diff --git a/src/client.js b/src/client.js index 3ad82945..c0ddd323 100644 --- a/src/client.js +++ b/src/client.js @@ -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." + }) + }); } }; diff --git a/src/plugins/inputs/connect.js b/src/plugins/inputs/connect.js index 9aeba2a7..538cd4a2 100644 --- a/src/plugins/inputs/connect.js +++ b/src/plugins/inputs/connect.js @@ -1,4 +1,5 @@ exports.commands = ["connect", "server"]; +exports.allowDisconnected = true; exports.input = function(network, chan, cmd, args) { if (args.length === 0) { diff --git a/src/plugins/inputs/part.js b/src/plugins/inputs/part.js index d8701544..7c2fcf8e 100644 --- a/src/plugins/inputs/part.js +++ b/src/plugins/inputs/part.js @@ -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(" ")); } diff --git a/src/plugins/inputs/quit.js b/src/plugins/inputs/quit.js index fb208b2f..7f54fccf 100644 --- a/src/plugins/inputs/quit.js +++ b/src/plugins/inputs/quit.js @@ -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; };