Skip to content

Commit

Permalink
Support golbat fort update webhooks (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfberry authored Jul 19, 2023
1 parent 8841d50 commit b3f91a5
Show file tree
Hide file tree
Showing 13 changed files with 649 additions and 6 deletions.
19 changes: 19 additions & 0 deletions config/defaults/dts.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,25 @@
]
}
},
{
"id": 1,
"language": "en",
"type": "fort-update",
"default": true,
"platform": "discord",
"template": {
"embed": {
"title": "{{changeTypeText}} {{fortTypeText}} {{name}}",
"description": "{{#if description}}*{{description}}*\n\n{{/if}}{{#if isEditDescription}}**Old Description**\n> {{oldDescription}}\n\n**New Description**\n> {{newDescription}}\n\n{{/if}}{{#if isEditName}}### Old Name\n> {{oldName}}\n\n### New Name\n> {{newName}}\n\n{{/if}}\nMaps: [Google]({{{mapurl}}}) | [Apple]({{{applemap}}})",
"thumbnail": {
"url": "{{{imgUrl}}}"
},
"image": {
"url": "{{{staticMap}}}"
}
}
}
},
{
"id": 1,
"language": "en",
Expand Down
5 changes: 5 additions & 0 deletions config/defaults/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,10 @@
"type": "pokestop",
"test": "sparklylure",
"webhook": {"name":"Memorial Sculpture & Verse","pokestop_id":"0d4b26adbf24446ba893f0aa3f8de337.16","latitude":51.284727,"longitude":1.060694,"updated":1643554276,"last_modified":1643553312,"lure_expiration":1643555112,"lure_id":506,"url":"http://lh3.googleusercontent.com/Ce-yPhm1FwGNbFzaM0ToMESZ57EWx1g8dKXXgEE4o-mmdP0XdsHk2nSEXOBk88H5PIXBHud-b7m6PUUJ3N8Pe_XB98NY"}
},
{
"type": "fort_update",
"test": "edit",
"webhook": {"change_type": "edit", "edit_types": ["name", "description"], "new": {"id": "f7430347f5c34facb838be376f16adea.16", "type": "gym", "name": "Journey Through Trees And Time", "description": "A beautiful trip through time, trees, and space", "image_url": "http://lh3.googleusercontent.com/9kWjcud4Eeh4nNC6jv8zBkEr8kuQbW-QY2sKRHQqLrwnxf3drxO5AtR2qsDEjmxz3-h_eTHnQrT3AFl5Xmg2MXVqChh5", "location": {"lat": 51.268716, "lon": 1.013956}}, "old": {"id": "f7430347f5c34facb838be376f16adea.16", "type": "gym", "name": "The old walkway", "description": "An ancient trip through time and space", "image_url": "http://lh3.googleusercontent.com/9kWjcud4Eeh4nNC6jv8zBkEr8kuQbW-QY2sKRHQqLrwnxf3drxO5AtR2qsDEjmxz3-h_eTHnQrT3AFl5Xmg2MXVqChh5", "location": {"lat": 51.268716, "lon": 1.013956}}}
}
]
13 changes: 13 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,19 @@ async function processOne(hook) {
}
break
}
case 'fort_update': {
const fortId = hook.message.new?.id ?? hook.message.old?.id
if (config.general.disableFortUpdate) {
fastify.controllerLog.debug(`${fortId}: Fort update was received but set to be ignored in config`)
break
}
if (!hook.message.poracleTest) {
fastify.webhooks.info(`fort_update ${JSON.stringify(hook.message)}`)
// Caching not relevant, no duplicates
}
await processHook(hook)
break
}
case 'quest': {
if (config.general.disableQuest) {
fastify.controllerLog.debug(`${hook.message.pokestop_id}: Quest was received but set to be ignored in config`)
Expand Down
13 changes: 13 additions & 0 deletions src/controllerWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const MonsterController = require('./controllers/monster')
const RaidController = require('./controllers/raid')
const QuestController = require('./controllers/quest')
const PokestopController = require('./controllers/pokestop')
const FortUpdateController = require('./controllers/fortupdate')
const GymController = require('./controllers/gym')
const PokestopLureController = require('./controllers/pokestop_lure')
const NestController = require('./controllers/nest')
Expand Down Expand Up @@ -59,6 +60,7 @@ const questController = new QuestController(logs.controller, knex, cachingGeocod
const pokestopController = new PokestopController(logs.controller, knex, cachingGeocoder, scannerQuery, config, dts, geofence, GameData, rateLimitedUserCache, translatorFactory, mustache, controllerWeatherManager, statsData, eventParsers)
const nestController = new NestController(logs.controller, knex, cachingGeocoder, scannerQuery, config, dts, geofence, GameData, rateLimitedUserCache, translatorFactory, mustache, controllerWeatherManager, statsData, eventParsers)
const pokestopLureController = new PokestopLureController(logs.controller, knex, cachingGeocoder, scannerQuery, config, dts, geofence, GameData, rateLimitedUserCache, translatorFactory, mustache, controllerWeatherManager, statsData, eventParsers)
const fortUpdateController = new FortUpdateController(logs.controller, knex, cachingGeocoder, scannerQuery, config, dts, geofence, GameData, rateLimitedUserCache, translatorFactory, mustache, controllerWeatherManager, statsData, eventParsers)
const gymController = new GymController(logs.controller, knex, cachingGeocoder, scannerQuery, config, dts, geofence, GameData, rateLimitedUserCache, translatorFactory, mustache, controllerWeatherManager, statsData, eventParsers)

const monsterAlarmMatch = new MonsterAlarmMatch(logs.controller, knex, config)
Expand Down Expand Up @@ -113,6 +115,15 @@ async function processOne(hook) {
}
break
}
case 'fort_update': {
const result = await fortUpdateController.handle(hook.message)
if (result) {
queueAddition = result
} else {
log.error(`Worker ${workerId}: Missing result from ${hook.type} processor`, { data: hook.message })
}
break
}
case 'quest': {
const result = await questController.handle(hook.message)
if (result) {
Expand Down Expand Up @@ -187,6 +198,7 @@ function reloadDts() {
nestController.setDts(newDts)
pokestopLureController.setDts(newDts)
gymController.setDts(newDts)
fortUpdateController.setDts(newDts)
log.info('DTS reloaded')
} catch (err) {
log.error('Error reloading dts', err)
Expand All @@ -203,6 +215,7 @@ function reloadGeofence() {
nestController.setGeofence(newGeofence)
pokestopLureController.setGeofence(newGeofence)
gymController.setGeofence(newGeofence)
fortUpdateController.setGeofence(newGeofence)
log.info('Geofence reloaded')
} catch (err) {
log.error('Error reloading geofence', err)
Expand Down
Loading

0 comments on commit b3f91a5

Please sign in to comment.