Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily disable on player join #41

Open
SeasonalFerret opened this issue Apr 20, 2023 · 1 comment
Open

Temporarily disable on player join #41

SeasonalFerret opened this issue Apr 20, 2023 · 1 comment

Comments

@SeasonalFerret
Copy link

SeasonalFerret commented Apr 20, 2023

When the player logs into hypixel, we get kicked with this message:

info:  Kicked for {"extra":[{"color":"red","text":"You logged in from another location!"}],"text":""}

When that happens, wait 5 minutes and check hypixel API for player online status.
https://api.hypixel.net/#tag/Player-Data/paths/~1status/get

If the user is online, just wait another 5 minutes.
If it says the user is offline, we can reconnect and continue.

logger.info(`Kicked for ${reason}`);

@WhyClove
Copy link

WhyClove commented Feb 5, 2024

Mines, a bit inefficient, but it gets the job done

// add this to near top to allow request module to be added
const request = require('request')

// put the  two variables below autotipSession

// Make sure to replace "INSERT_YOUR_UUID_HERE" with the uuid you want to check if they're online
const apiEndpoint = `https://api.hypixel.net/status?uuid=INSERT_YOUR_UUID_HERE`;
// i created a variable called hypixelKey in credentials.json but you can just put it in here
const apiKey = credentials.hypixelKey;

// put the below under onMessage() function

async function checkSessionStatus() {
  return new Promise((resolve) => {
    request.get({
      url: apiEndpoint,
      headers: { 'Api-Key': apiKey },
      json: true
    }, (error, response, body) => {
      if (error) {
        console.error('Error:', error);
        resolve(false);
      }

      const session = body.session;

      if (session && session.online) {
        console.log('Player is online. Waiting for 5 minutes...');
        resolve(true);
      } else {
        console.log('Player is offline. Logging in to the server...');
        resolve(false);
      }
    });
  });
}

You'd also want to replace the init function.

async function main() {
// Checks if player is online
  online = await checkSessionStatus()
  if (online == false) {
  bot = mineflayer.createBot(options);
  bot._client.once('session', session => options.session = session);
  bot.once('login', onLogin);
  bot.on('message', onMessage);
  bot.on('kicked', (reason) => {
    logger.info(`Kicked for ${reason}`);
  });
  bot.once('end', () => {
    // Schedule the main function to run again after 3 minutes of bot exiting
    setTimeout(main, 3 * 60 * 1000);
  });
} else {
  // If the player is not online, recheck after 5 minutes
  setTimeout(main, 5 * 60 * 1000);
}
}

Above the process.on stuff just put main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants