const { startAuthServer } = require("./twitch/authServer");
const { connect } = require("./twitch/websocket");
const { initFromDisk } = require("./twitch/token");

const restored = initFromDisk();

if (restored) {
  console.log("🚀 Using saved token, skipping login...");
  connect();
} else {
  const auth = startAuthServer();

  const wait = setInterval(() => {
    const token = auth.getToken();

    if (!token) return;

    clearInterval(wait);
    connect();
  }, 1000);
}