autoreconnect

This commit is contained in:
Soph :3 2024-07-08 01:20:54 +03:00
parent de2fdf77ec
commit 562df25d0a
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -3,6 +3,8 @@ import { Rcon } from "./rcon";
import config from "./config.json" assert { type: "json" };
const rcon = new Rcon(config.rcon.host, config.rcon.port, config.rcon.password);
let rconReconnectTimeout: Timer | null | undefined;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
@ -19,6 +21,15 @@ rcon.on("auth", () => {
console.log("RCON authenicated.");
});
rcon.on("end", () => {
console.log("RCON ended. Reconnecting in 1000ms.")
if(rconReconnectTimeout) {
clearTimeout(rconReconnectTimeout);
}
rconReconnectTimeout = setTimeout(() => {
rcon.connect()
}, 1000)
})
client.once(Events.ClientReady, async (readyClient) => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
let playerUsernames: string[] = [];