hardlounge/server/plugins/inputs/connect.ts
Val Lorentz a049a01aeb Client: move socket connection out of the constructor
It will make it easier to write tests for what used to be in
the connect() method
2023-03-15 08:40:53 +01:00

52 lines
852 B
TypeScript

import Msg, {MessageType} from "../../models/msg";
import {PluginInputHandler} from "./index";
const commands = ["connect", "server"];
const allowDisconnected = true;
const input: PluginInputHandler = function (network, chan, cmd, args) {
if (args.length === 0) {
network.userDisconnected = false;
this.save();
const irc = network.irc;
if (!irc) {
return;
}
if (irc.connection && irc.connection.connected) {
chan.pushMessage(
this,
new Msg({
type: MessageType.ERROR,
text: "You are already connected.",
})
);
return;
}
irc.connect();
return;
}
let port = args[1] || "";
const tls = port[0] === "+";
if (tls) {
port = port.substring(1);
}
const host = args[0];
this.connectToNetwork({host, port, tls});
return true;
};
export default {
commands,
input,
allowDisconnected,
};