Skip to content

Commit

Permalink
Merge pull request thelounge#254 from thelounge/xpaw/auto-rc
Browse files Browse the repository at this point in the history
Enable auto reconnection
  • Loading branch information
astorije committed May 24, 2016
2 parents d31a22a + 4c39b34 commit 3b9aa94
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var inputs = [
"part",
"action",
"connect",
"disconnect",
"invite",
"kick",
"mode",
Expand Down Expand Up @@ -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,
});

Expand Down
16 changes: 16 additions & 0 deletions src/plugins/inputs/connect.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions src/plugins/inputs/disconnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports.commands = ["disconnect"];

exports.input = function(network, chan, cmd, args) {
var quitMessage = args[0] ? args.join(" ") : "";

network.irc.quit(quitMessage);
};
2 changes: 1 addition & 1 deletion src/plugins/inputs/quit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require("lodash");

exports.commands = ["quit", "disconnect"];
exports.commands = ["quit"];
exports.allowDisconnected = true;

exports.input = function(network, chan, cmd, args) {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/irc-events/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}));
});

Expand All @@ -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..."
}));
});

Expand Down

0 comments on commit 3b9aa94

Please sign in to comment.