Merge pull request #2718 from thelounge/xpaw/remember-disconnect

Remember disconnected networks between server restarts
This commit is contained in:
Al McKinlay 2018-08-26 21:50:02 +01:00 committed by GitHub
commit 0a35000cb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 7 deletions

View File

@ -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();

View File

@ -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",

View File

@ -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;
}

View File

@ -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();
};

View File

@ -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"