thelounge/server/plugins/inputs/connect.ts
Reto Brunner 8ca9ee873b use the irc connected helper function
We should not mess with irc-framework internals.
Technically we shouldn't even access the connection object,
it's not part of the documented API surface
2023-03-04 18:16:28 +01:00

52 lines
814 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.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.connect({host, port, tls});
return true;
};
export default {
commands,
input,
allowDisconnected,
};