torikushiii / hoyolab-auto

Auto check-in and others for any Hoyoverse games
https://ko-fi.com/torikushiii
GNU Affero General Public License v3.0
75 stars 17 forks source link

"No default or custom configuration found." #32

Closed Deathfairy27 closed 1 month ago

Deathfairy27 commented 1 month ago

Followed all the usual steps after updating to the latest commit and I keep getting this error, even if I were to leave the config on 'default.config.js' it pushes this same error. image

torikushiii commented 1 month ago

can you open index.js and replace the whole code into this one:

This new code is using path to access to config file

const Command = require("./classes/command.js");
const Config = require("./classes/config.js");
const Got = require("./classes/got.js");

const Cache = require("./singleton/cache.js");
const Logger = require("./singleton/logger.js");
const Utils = require("./singleton/utils.js");

const HoyoLab = require("./hoyolab-modules/template.js");
const Platform = require("./platforms/template.js");

const Error = require("./object/error.js");

const path = require("path");
let config;
try {
    config = require(path.resolve(process.cwd(), "config.js"));
}
catch (e) {
    console.error({
        message: e.message,
        cwd: process.cwd()
    });

    try {
        config = require(path.resolve(process.cwd(), "default.config.js"));
    }
    catch (err) {
        console.error({
            message: err.message,
            cwd: process.cwd()
        });
        throw new Error({ message: "No default or custom configuration found." });
    }
}

(async () => {
    const start = process.hrtime.bigint();

    const platformsConfig = config.platforms;
    if (!platformsConfig || platformsConfig.length === 0) {
        console.warn("No platforms configured! Exiting.");
        process.exit(0);
    }

    globalThis.app = {
        Error,

        Config,
        Command,

        Got: await Got.initialize(),
        Cache: new Cache(),
        Logger: new Logger(config.loglevel),
        Utils: new Utils()
    };

    app.Logger.info("Client", "Loading configuration data");
    Config.load(config);
    app.Logger.info("Client", `Loaded ${Config.data.size} configuration entries`);

    const platforms = new Set();
    for (const definition of platformsConfig) {
        if (!definition.active) {
            app.Logger.warn("Client", `Skipping ${definition.type} platform (inactive)`);
            continue;
        }

        platforms.add(Platform.create(definition.type, definition));
    }

    const { loadCommands } = require("./commands/index.js");
    const commands = await loadCommands();
    await Command.importData(commands.definitions);

    const { initCrons } = require("./crons/index.js");
    initCrons();

    const accountsConfig = config.accounts;
    if (!accountsConfig || accountsConfig.length === 0) {
        app.Logger.warn("Client", "No accounts configured! Exiting.");
        process.exit(0);
    }

    const accounts = new Set();
    for (const definition of accountsConfig) {
        if (!definition.active) {
            app.Logger.warn("Client", `Skipping ${definition.type} account (inactive)`);
            continue;
        }

        accounts.add(HoyoLab.create(definition.type, definition));
    }

    const definitions = require("./gots/index.js");
    await app.Got.importData(definitions);

    globalThis.app = {
        ...app,
        Platform,
        HoyoLab
    };

    const promises = [];
    for (const platform of platforms) {
        promises.push(platform.connect());
    }

    const hoyoPromises = [];
    for (const account of accounts) {
        hoyoPromises.push(account.login());
    }

    await Promise.all(promises);
    await Promise.all(hoyoPromises);

    const end = process.hrtime.bigint();
    app.Logger.info("Client", `Initialize completed (${Number(end - start) / 1e6}ms)`);

    process.on("unhandledRejection", (reason) => {
        if (!(reason instanceof Error)) {
            return;
        }

        app.Logger.log("Client", {
            message: "Unhandled promise rejection",
            args: { reason }
        });
    });
})();
Deathfairy27 commented 1 month ago

Edit: New copy of repo, still same error as below screenshot. After replacing the whole index.js file with the code you gave I havent replaced it on a new copy of the repo, I will report back with an edit after I try with a new copy of the repo. image

torikushiii commented 1 month ago

That error could be a missing comma "," or there's a new line at one of the cookie, could you re-check your configuration file again.

// config.js (incorrect)
{ 
  loglevel: "info" // Missing semicolon
  platforms: [
    { 
      type: "platformType1",
      active: true
    } 
  ] 
}
// config.js (correct)
{
  loglevel: "info", 
  platforms: [
    {
      type: "platformType1",
      active: true
    }
  ]
}

i suggest you to use a code editor or look for online JSON validator to spot the error, because it can be annoying to look for it one-by-one

Deathfairy27 commented 1 month ago

Guess somewhere along the line something got lost in that config as you are right, was able to find the missing bit in my config.js and that fixed it right up. Thank you and appreciate the guidance.