diff --git a/src/client.js b/src/client.js index 4ad1bf93..98653ba7 100644 --- a/src/client.js +++ b/src/client.js @@ -36,6 +36,7 @@ var inputs = [ "part", "action", "connect", + "disconnect", "invite", "kick", "mode", @@ -211,7 +212,7 @@ Client.prototype.connect = function(args) { tls: network.tls, localAddress: config.bind, rejectUnauthorized: false, - auto_reconnect: false, // TODO: Enable auto reconnection + auto_reconnect: true, webirc: webirc, }); diff --git a/src/plugins/inputs/connect.js b/src/plugins/inputs/connect.js index 538cd4a2..04296247 100644 --- a/src/plugins/inputs/connect.js +++ b/src/plugins/inputs/connect.js @@ -1,8 +1,24 @@ +var Msg = require("../../models/msg"); + exports.commands = ["connect", "server"]; exports.allowDisconnected = true; exports.input = function(network, chan, cmd, args) { if (args.length === 0) { + if (!network.irc || !network.irc.connection) { + return; + } + + if (network.irc.connection.connected) { + chan.pushMessage(this, new Msg({ + type: Msg.Type.ERROR, + text: "You are already connected." + })); + return; + } + + network.irc.connection.connect(); + return; } diff --git a/src/plugins/inputs/disconnect.js b/src/plugins/inputs/disconnect.js new file mode 100644 index 00000000..a0ad99fb --- /dev/null +++ b/src/plugins/inputs/disconnect.js @@ -0,0 +1,7 @@ +exports.commands = ["disconnect"]; + +exports.input = function(network, chan, cmd, args) { + var quitMessage = args[0] ? args.join(" ") : ""; + + network.irc.quit(quitMessage); +}; diff --git a/src/plugins/inputs/quit.js b/src/plugins/inputs/quit.js index 7f54fccf..9039c704 100644 --- a/src/plugins/inputs/quit.js +++ b/src/plugins/inputs/quit.js @@ -1,6 +1,6 @@ var _ = require("lodash"); -exports.commands = ["quit", "disconnect"]; +exports.commands = ["quit"]; exports.allowDisconnected = true; exports.input = function(network, chan, cmd, args) { diff --git a/src/plugins/irc-events/connection.js b/src/plugins/irc-events/connection.js index 26676297..597e1db3 100644 --- a/src/plugins/irc-events/connection.js +++ b/src/plugins/irc-events/connection.js @@ -19,9 +19,9 @@ module.exports = function(irc, network) { })); }); - irc.on("socket close", function() { + irc.on("close", function() { network.channels[0].pushMessage(client, new Msg({ - text: "Disconnected from the network." + text: "Disconnected from the network, and will not reconnect." })); }); @@ -35,7 +35,7 @@ module.exports = function(irc, network) { irc.on("reconnecting", function() { network.channels[0].pushMessage(client, new Msg({ - text: "Reconnecting..." + text: "Disconnected from the network. Reconnecting..." })); });