From 9bcec3bea53f15e82112edf7154957b16feaaece Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 25 Aug 2018 12:11:59 +0300 Subject: [PATCH] Remember disconnected networks between server restarts --- src/client.js | 9 ++++++++- src/models/network.js | 2 ++ src/plugins/inputs/connect.js | 13 +++++++++---- src/plugins/inputs/disconnect.js | 7 +++++-- test/models/network.js | 2 ++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/client.js b/src/client.js index 0a9e7d0d..f5e9f475 100644 --- a/src/client.js +++ b/src/client.js @@ -205,6 +205,7 @@ Client.prototype.connect = function(args) { host: String(args.host || ""), port: parseInt(args.port, 10), tls: !!args.tls, + userDisconnected: !!args.userDisconnected, rejectUnauthorized: !!args.rejectUnauthorized, password: String(args.password || ""), nick: String(args.nick || ""), @@ -238,7 +239,13 @@ Client.prototype.connect = function(args) { ]); }); - network.irc.connect(); + if (network.userDisconnected) { + network.channels[0].pushMessage(client, new Msg({ + text: "You have manually disconnected from this network before, use /connect command to connect again.", + }), true); + } else { + network.irc.connect(); + } client.save(); diff --git a/src/models/network.js b/src/models/network.js index 75e1cc56..a89dc59e 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -28,6 +28,7 @@ function Network(attr) { host: "", port: 6667, tls: false, + userDisconnected: false, rejectUnauthorized: false, password: "", awayMessage: "", @@ -321,6 +322,7 @@ Network.prototype.export = function() { "host", "port", "tls", + "userDisconnected", "rejectUnauthorized", "password", "username", diff --git a/src/plugins/inputs/connect.js b/src/plugins/inputs/connect.js index 76dc19a7..8b7341c9 100644 --- a/src/plugins/inputs/connect.js +++ b/src/plugins/inputs/connect.js @@ -5,13 +5,18 @@ const Msg = require("../../models/msg"); exports.commands = ["connect", "server"]; exports.allowDisconnected = true; -exports.input = function({irc}, chan, cmd, args) { +exports.input = function(network, chan, cmd, args) { if (args.length === 0) { - if (!irc || !irc.connection) { + network.userDisconnected = false; + this.save(); + + const irc = network.irc; + + if (!irc) { return; } - if (irc.connection.connected) { + if (irc.connection && irc.connection.connected) { chan.pushMessage(this, new Msg({ type: Msg.Type.ERROR, text: "You are already connected.", @@ -19,7 +24,7 @@ exports.input = function({irc}, chan, cmd, args) { return; } - irc.connection.connect(); + irc.connect(); return; } diff --git a/src/plugins/inputs/disconnect.js b/src/plugins/inputs/disconnect.js index 729807a2..6a35be35 100644 --- a/src/plugins/inputs/disconnect.js +++ b/src/plugins/inputs/disconnect.js @@ -4,8 +4,11 @@ const Helper = require("../../helper"); exports.commands = ["disconnect"]; -exports.input = function({irc}, chan, cmd, args) { +exports.input = function(network, chan, cmd, args) { const quitMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage; - irc.quit(quitMessage); + network.irc.quit(quitMessage); + + network.userDisconnected = true; + this.save(); }; diff --git a/test/models/network.js b/test/models/network.js index b0e3da8d..14056b64 100644 --- a/test/models/network.js +++ b/test/models/network.js @@ -32,6 +32,7 @@ describe("Network", function() { host: "", port: 6667, tls: false, + userDisconnected: false, rejectUnauthorized: false, password: "", username: "", @@ -233,6 +234,7 @@ describe("Network", function() { "serverOptions", "status", "tls", + "userDisconnected", "rejectUnauthorized", "uuid", "username"