diff --git a/.husky/pre-commit b/.husky/pre-commit index 449fcdee1..72c4429bc 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - npm test diff --git a/.husky/pre-push b/.husky/pre-push index 20d0d06e5..3867a0feb 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - npm run lint diff --git a/package.json b/package.json index 42e0cd3da..c625bf485 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "latest": "npm run generate latest && npm run koji && node .", "lint": "./node_modules/.bin/eslint ./src --fix", "migrateV3": "node src/init/migrateV3.js", - "prepare": "husky install", + "prepare": "husky", "start": "npm run generate && npm run koji && node .", "test": "node test/test" }, diff --git a/src/controllers/pokestop.js b/src/controllers/pokestop.js index ff5d4cfcd..696784094 100644 --- a/src/controllers/pokestop.js +++ b/src/controllers/pokestop.js @@ -322,7 +322,7 @@ class Invasion extends Controller { // Lineup 100% of encounter let gruntLineupformNormalised = '' const gruntLineupList = { confirmed: true, monsters: [] } - if (data.lineup && data.lineup != 'null') { + if (data.lineup && data.lineup !== 'null') { data.lineup.forEach((lr) => { const lineup = +lr.pokemon_id const lineupForm = +lr.form diff --git a/src/lib/pogoEventParser.js b/src/lib/pogoEventParser.js index e029ea1e5..84abd4233 100644 --- a/src/lib/pogoEventParser.js +++ b/src/lib/pogoEventParser.js @@ -9,6 +9,8 @@ const moment = require('moment-timezone') class PogoEventParser { constructor(log) { this.log = log + this.spawnEvents = [] + this.questEvents = [] } /** @@ -25,7 +27,7 @@ class PogoEventParser { // Timeout Logic }, timeoutMs) - const url = 'https://raw.githubusercontent.com/ccev/pogoinfo/v2/active/events.json' + const url = 'https://raw.githubusercontent.com/bigfoott/ScrapedDuck/data/events.json' const result = await axios({ method: 'get', url, @@ -42,7 +44,25 @@ class PogoEventParser { * @param events */ loadEvents(events) { - this.events = events + try { + // create filtered pokemon spawn event list + // for now, only filter by eventType until spawn information is available + let filteredEvents = [] + for (const event of events.filter((x) => x.eventType === 'community-day' || x.eventType === 'pokemon-spotlight-hour')) { + filteredEvents.push(event) + } + this.spawnEvents = filteredEvents + + // create filtered quest event list + // for now, only filter by eventType until field research task information is available + filteredEvents = [] + for (const event of events.filter((x) => x.eventType === 'community-day')) { + filteredEvents.push(event) + } + this.questEvents = filteredEvents + } catch (err) { + this.log.error('PogoEvents: Error creating filtered spawn and quest event lists', err) + } } /** @@ -54,26 +74,26 @@ class PogoEventParser { * @returns {{reason: string, name, time}} */ eventChangesSpawn(startTime, disappearTime, lat, lon) { - if (!this.events) return + if (!this.spawnEvents) return try { const tz = geoTz.find(lat, lon)[0].toString() - for (const event of this.events.filter((x) => (x.spawns && x.spawns.length) || x.type === 'community-day' || x.type === 'spotlight-hour')) { + for (const event of this.spawnEvents) { const eventStart = moment.tz(event.start, tz).unix() const eventEnd = moment.tz(event.end, tz).unix() if (startTime < eventStart && eventStart < disappearTime) { return { reason: 'start', name: event.name, - time: event.start.split(' ')[1], + time: moment(event.start).format('HH:mm'), } } if (startTime < eventEnd && eventEnd < disappearTime) { return { reason: 'end', name: event.name, - time: event.end.split(' ')[1], + time: moment(event.end).format('HH:mm'), } } } @@ -91,26 +111,26 @@ class PogoEventParser { * @returns {{reason: string, name, time}} */ eventChangesQuest(startTime, disappearTime, lat, lon) { - if (!this.events) return + if (!this.questEvents) return try { const tz = geoTz.find(lat, lon)[0].toString() - for (const event of this.events.filter((x) => x.has_quests)) { + for (const event of this.questEvents) { const eventStart = moment.tz(event.start, tz).unix() const eventEnd = moment.tz(event.end, tz).unix() if (startTime < eventStart && eventStart < disappearTime) { return { reason: 'start', name: event.name, - time: event.start.split(' ')[1], + time: moment(event.start).format('HH:mm'), } } if (startTime < eventEnd && eventEnd < disappearTime) { return { reason: 'end', name: event.name, - time: event.end.split(' ')[1], + time: moment(event.end).format('HH:mm'), } } } diff --git a/src/lib/poracleMessage/commands/poracle-test.js b/src/lib/poracleMessage/commands/poracle-test.js index bfc73a7fe..c65b08c1b 100644 --- a/src/lib/poracleMessage/commands/poracle-test.js +++ b/src/lib/poracleMessage/commands/poracle-test.js @@ -1,6 +1,8 @@ const stripJsonComments = require('strip-json-comments') const fs = require('fs') const path = require('path') +const geoTz = require('geo-tz') +const moment = require('moment-timezone') exports.run = async (client, msg, args, options) => { try { @@ -51,7 +53,13 @@ exports.run = async (client, msg, args, options) => { return await msg.reply(message) } - + // Create extra command argument 'disapeardt' RegEx for 'poracle-test' command. + // Added here instead of regex.js, because there is no use in other commands. + // datetime format: "YYYY-MM-DDTHH:mm:ss" e.g. 2024-08-13T23:01:00 + const disapeardtReStr = '^(disapeardt):?([2][0][0-9][0-9]-([0][0-9]|[1][0-2])-([0-2][0-9]|[3][0-1])t([0-1][0-9]|[2][0-3]):[0-5][0-9]:[0-5][0-9])' + const disapeardtRe = RegExp(disapeardtReStr, 'i') + let disapearTimeOverwrite = null + // check and handle additional arguments used by 'poracle-test' command for (let i = args.length - 1; i >= 0; i--) { if (args[i].match(client.re.templateRe)) { [, , template] = args[i].match(client.re.templateRe) @@ -59,6 +67,9 @@ exports.run = async (client, msg, args, options) => { } else if (args[i].match(client.re.languageRe)) { [, , language] = args[i].match(client.re.languageRe) args.splice(i, 1) + } else if (args[i].match(disapeardtRe)) { + [, , disapearTimeOverwrite] = args[i].match(disapeardtRe) + args.splice(i, 1) } } @@ -88,7 +99,15 @@ exports.run = async (client, msg, args, options) => { // Freshen test data switch (hookType) { case 'pokemon': { - hook.disappear_time = Date.now() / 1000 + 10 * 60 + if (disapearTimeOverwrite !== null) { + // get timezone of pokemon location + const tz = geoTz.find(hook.latitude, hook.longitude)[0].toString() + // calculate timestamp based on provided time as localtime matching to pokemon location + // disapearTimeOverwrite string was converted to lowwercase so we need to change back to upper case ('t' -> 'T') + hook.disappear_time = moment.tz(disapearTimeOverwrite.toUpperCase(), tz).unix() + } else { + hook.disappear_time = Date.now() / 1000 + 10 * 60 + } break } case 'raid': {