diff --git a/package-lock.json b/package-lock.json index cf075fc..2beaf32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2549,7 +2549,7 @@ "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, "pogo-translations": { - "version": "git+https://github.com/bschultz/pogo-translations.git#b17c44cb6fb3a91bb57f35791b79f692d0082fd1", + "version": "git+https://github.com/bschultz/pogo-translations.git#96d3303807b34601698319d8225c89b84de90ee4", "from": "git+https://github.com/bschultz/pogo-translations.git" }, "point-in-polygon": { diff --git a/package.json b/package.json index 4887ef9..2c7f646 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "start": "node src/index.js", "create-locales": "node src/createLocales.js", "test": "npx eslint src/**/*.js", - "test-fix": "npx eslint src/**/*.js --fix" + "test-fix": "npx eslint src/**/*.js --fix", + "update": "npm install && npm update pogo-translations && npm run create-locales" }, "repository": { "type": "git", diff --git a/src/controllers/instances/auto.js b/src/controllers/instances/auto.js index 8550607..b60a7d9 100644 --- a/src/controllers/instances/auto.js +++ b/src/controllers/instances/auto.js @@ -8,8 +8,6 @@ const Account = require('../../models/account.js'); const Cell = require('../../models/cell.js'); const Pokestop = require('../../models/pokestop.js'); -const ClearQuestsInterval = 60 * 1000; // every minute - const AutoType = { Quest: 'quest' }; @@ -91,9 +89,22 @@ class AutoInstanceController { this.bootstrap() .then(x => x) .catch(err => { - console.error('[AutoInstanceController] Failed to bootstrap instance:', this.name, err); + console.error('[AutoInstanceController] Failed to bootstrap instance:', this.name, err); }); - this.clearQuestsTimer = setInterval(() => this.clearQuests(), ClearQuestsInterval); + this.setClearQuestsTimer(); + } + + setClearQuestsTimer() { + let date = new Date(); + // TODO: timeZone + let hour = date.getHours(); + let minute = date.getMinutes(); + let second = date.getSeconds(); + let timeLeftSeconds = (23 - hour) * 3600 + (59 - minute) * 60 + (60 - second); + let at = new Date(date.getTime() + (timeLeftSeconds * 1000)); + console.debug(`[AutoInstanceController] [${this.name}] Clearing Quests in ${timeLeftSeconds.toLocaleString()}s at ${at.toLocaleString()} (Currently: ${date.toLocaleString()})`); + + this.clearQuestsTimer = setInterval(() => this.clearQuests(), timeLeftSeconds * 1000); } async bootstrap() { @@ -455,37 +466,29 @@ class AutoInstanceController { } async clearQuests() { - let date = new Date(); - // TODO: timeZone - let hour = date.getHours(); - let minute = date.getMinutes(); - let second = date.getSeconds(); - let timeLeft = (23 - hour) * 3600 + (59 - minute) * 60 + (60 - second); - let at = new Date(date.getTime() + (timeLeft * 1000)); - console.debug(`[AutoInstanceController] [${this.name}] Clearing Quests in ${timeLeft.toLocaleString()}s at ${at.toLocaleString()} (Currently: ${date.toLocaleString()})`); + clearInterval(this.clearQuestsTimer); + this.setClearQuestsTimer(); - if (timeLeft <= 0) { + if (this.shouldExit) { + return; + } + if (!this.allStops || this.allStops.length === 0) { + console.warn(`[AutoInstanceController] [${this.name}] Tried clearing quests but no pokestops.`); + return; + } + console.debug(`[AutoInstanceController] [${this.name}] Getting pokestop ids`); + let ids = this.allStops.map(x => x.id); + console.debug(`[AutoInstanceController] [${this.name}] Clearing Quests for ids: ${ids}.`); + try { + await Pokestop.clearQuests(ids); + } catch (err) { + console.error(`[AutoInstanceController] [${this.name} Failed to clear quests:`, err); if (this.shouldExit) { return; } - if (!this.allStops || this.allStops.length === 0) { - console.warn(`[AutoInstanceController] [${this.name}] Tried clearing quests but no pokestops.`); - return; - } - console.debug(`[AutoInstanceController] [${this.name}] Getting pokestop ids`); - let ids = this.allStops.map(x => x.id); - console.debug(`[AutoInstanceController] [${this.name}] Clearing Quests for ids: ${ids}.`); - try { - await Pokestop.clearQuests(ids); - } catch (err) { - console.error(`[AutoInstanceController] [${this.name} Failed to clear quests:`, err); - if (this.shouldExit) { - return; - } - } - this.update(); } + await this.update(); } } -module.exports = { AutoType, CooldownTimes, AutoInstanceController }; \ No newline at end of file +module.exports = { AutoType, CooldownTimes, AutoInstanceController };