import { IS_BROWSER } from "$fresh/runtime.ts";

const eulaRegex = /(eula=false)/;
export const checkEULA = (instance = "server") => {
  try {
    return !IS_BROWSER &&
      !eulaRegex.test(Deno.readTextFileSync(`./${instance}/eula.txt`));
  } catch {
    return false;
  }
};

export const acceptEULA = (instance = "server") => {
  const eula = Deno.readTextFileSync(`./${instance}/eula.txt`);
  const mod = eula.replace(eulaRegex, "eula=true");
  !IS_BROWSER && Deno.writeTextFileSync(`./${instance}/eula.txt`, mod);
};
