Widiskel / initia-daily-bot

An Initia daily routine bot, for automatically doing daily quest
30 stars 24 forks source link

npm run schedule #16

Open retrunv0id opened 3 months ago

retrunv0id commented 3 months ago

Maybe there's a part here that goes on too long with 38 I tried changing it. You can check and the results are quicker to redo the work

 import { Twisters } from "twisters";
import { CronJob } from "cron";
import { doQuest } from "./index.js";
import { account } from "./account.js"; // Ensure this matches the actual export

(async () => {
  try {
    const twisters = new Twisters();

    twisters.put("title", {
      active: false,
      text: `
        Initia Task Runner!
    `,
    });

    const job = new CronJob(
      "* * * * *", // Run the job every minute
      async () => {
        while (true) {
          twisters.put("title", {
            active: false,
            text: `
              Retrying...
          `,
          });

          for (const acc of account) {
            const [walletAddress, privateKey] = acc;
            try {
              await doQuest(walletAddress, privateKey);
            } catch (error) {
              console.error(error);
            }
          }

          // Wait for 5 seconds before starting the tasks again
          await new Promise((resolve) => setTimeout(resolve, 5000));
        }
      },
      null,
      true
    );
    job.start();
  } catch (error) {
    console.error("Error During executing bot", error);
  }
})();