Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions decoder/fort.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ type FortWebhook struct {
Location Location `json:"location"`
}

type FortChangeWebhook struct {
ChangeType string `json:"change_type"`
EditTypes []string `json:"edit_types,omitempty"`
Old *FortWebhook `json:"old,omitempty"`
New *FortWebhook `json:"new,omitempty"`
}

type FortChange string
type FortType string

Expand Down Expand Up @@ -129,17 +136,17 @@ func CreateFortWebhooks(ctx context.Context, dbDetails db.DbDetails, ids []strin
func CreateFortWebHooks(old *FortWebhook, new *FortWebhook, change FortChange) {
if change == NEW {
areas := MatchStatsGeofence(new.Location.Latitude, new.Location.Longitude)
hook := map[string]interface{}{
"change_type": change.String(),
"new": new,
hook := FortChangeWebhook{
ChangeType: change.String(),
New: new,
}
webhooksSender.AddMessage(webhooks.FortUpdate, hook, areas)
statsCollector.UpdateFortCount(areas, new.Type, "addition")
} else if change == REMOVAL {
areas := MatchStatsGeofence(old.Location.Latitude, old.Location.Longitude)
hook := map[string]interface{}{
"change_type": change.String(),
"old": old,
hook := FortChangeWebhook{
ChangeType: change.String(),
Old: old,
}
webhooksSender.AddMessage(webhooks.FortUpdate, hook, areas)
statsCollector.UpdateFortCount(areas, new.Type, "removal")
Expand Down Expand Up @@ -181,11 +188,11 @@ func CreateFortWebHooks(old *FortWebhook, new *FortWebhook, change FortChange) {
editTypes = append(editTypes, "location")
}
if len(editTypes) > 0 {
hook := map[string]interface{}{
"change_type": change.String(),
"edit_types": editTypes,
"old": old,
"new": new,
hook := FortChangeWebhook{
ChangeType: change.String(),
EditTypes: editTypes,
Old: old,
New: new,
}
webhooksSender.AddMessage(webhooks.FortUpdate, hook, areas)
statsCollector.UpdateFortCount(areas, new.Type, "edit")
Expand Down
126 changes: 69 additions & 57 deletions decoder/gym.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,23 +505,37 @@ type GymDetailsWebhook struct {
PowerUpEndTimestamp int64 `json:"power_up_end_timestamp"`
ArScanEligible int64 `json:"ar_scan_eligible"`
Defenders any `json:"defenders"`
}

//"id": id,
//"name": name ?? "Unknown",
//"url": url ?? "",
//"latitude": lat,
//"longitude": lon,
//"team": teamId ?? 0,
//"guard_pokemon_id": guardPokemonId ?? 0,
//"slots_available": availableSlots ?? 6,
//"ex_raid_eligible": exRaidEligible ?? 0,
//"in_battle": inBattle ?? false,
//"sponsor_id": sponsorId ?? 0,
//"partner_id": partnerId ?? 0,
//"power_up_points": powerUpPoints ?? 0,
//"power_up_level": powerUpLevel ?? 0,
//"power_up_end_timestamp": powerUpEndTimestamp ?? 0,
//"ar_scan_eligible": arScanEligible ?? 0
type RaidWebhook struct {
GymId string `json:"gym_id"`
GymName string `json:"gym_name"`
GymUrl string `json:"gym_url"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
TeamId int64 `json:"team_id"`
Spawn int64 `json:"spawn"`
Start int64 `json:"start"`
End int64 `json:"end"`
Level int64 `json:"level"`
PokemonId int64 `json:"pokemon_id"`
Cp int64 `json:"cp"`
Gender int64 `json:"gender"`
Form int64 `json:"form"`
Alignment int64 `json:"alignment"`
Costume int64 `json:"costume"`
Evolution int64 `json:"evolution"`
Move1 int64 `json:"move_1"`
Move2 int64 `json:"move_2"`
ExRaidEligible int64 `json:"ex_raid_eligible"`
IsExclusive int64 `json:"is_exclusive"`
SponsorId int64 `json:"sponsor_id"`
PartnerId string `json:"partner_id"`
PowerUpPoints int64 `json:"power_up_points"`
PowerUpLevel int64 `json:"power_up_level"`
PowerUpEndTimestamp int64 `json:"power_up_end_timestamp"`
ArScanEligible int64 `json:"ar_scan_eligible"`
Rsvps json.RawMessage `json:"rsvps"`
}

func createGymFortWebhooks(oldGym *Gym, gym *Gym) {
Expand Down Expand Up @@ -576,47 +590,45 @@ func createGymWebhooks(oldGym *Gym, gym *Gym, areas []geo.AreaName) {

if (raidBattleTime > now && gym.RaidLevel.ValueOrZero() > 0) ||
(raidEndTime > now && gym.RaidPokemonId.ValueOrZero() > 0) {
raidHook := map[string]any{
"gym_id": gym.Id,
"gym_name": func() string {
if !gym.Name.Valid {
return "Unknown"
} else {
return gym.Name.String
}
}(),
"gym_url": gym.Url.ValueOrZero(),
"latitude": gym.Lat,
"longitude": gym.Lon,
"team_id": gym.TeamId.ValueOrZero(),
"spawn": gym.RaidSpawnTimestamp.ValueOrZero(),
"start": gym.RaidBattleTimestamp.ValueOrZero(),
"end": gym.RaidEndTimestamp.ValueOrZero(),
"level": gym.RaidLevel.ValueOrZero(),
"pokemon_id": gym.RaidPokemonId.ValueOrZero(),
"cp": gym.RaidPokemonCp.ValueOrZero(),
"gender": gym.RaidPokemonGender.ValueOrZero(),
"form": gym.RaidPokemonForm.ValueOrZero(),
"alignment": gym.RaidPokemonAlignment.ValueOrZero(),
"costume": gym.RaidPokemonCostume.ValueOrZero(),
"evolution": gym.RaidPokemonEvolution.ValueOrZero(),
"move_1": gym.RaidPokemonMove1.ValueOrZero(),
"move_2": gym.RaidPokemonMove2.ValueOrZero(),
"ex_raid_eligible": gym.ExRaidEligible.ValueOrZero(),
"is_exclusive": gym.RaidIsExclusive.ValueOrZero(),
"sponsor_id": gym.SponsorId.ValueOrZero(),
"partner_id": gym.PartnerId.ValueOrZero(),
"power_up_points": gym.PowerUpPoints.ValueOrZero(),
"power_up_level": gym.PowerUpLevel.ValueOrZero(),
"power_up_end_timestamp": gym.PowerUpEndTimestamp.ValueOrZero(),
"ar_scan_eligible": gym.ArScanEligible.ValueOrZero(),
"rsvps": func() any {
if !gym.Rsvps.Valid {
return nil
} else {
return json.RawMessage(gym.Rsvps.ValueOrZero())
}
}(),
gymName := "Unknown"
if gym.Name.Valid {
gymName = gym.Name.String
}

var rsvps json.RawMessage
if gym.Rsvps.Valid {
rsvps = json.RawMessage(gym.Rsvps.ValueOrZero())
}

raidHook := RaidWebhook{
GymId: gym.Id,
GymName: gymName,
GymUrl: gym.Url.ValueOrZero(),
Latitude: gym.Lat,
Longitude: gym.Lon,
TeamId: gym.TeamId.ValueOrZero(),
Spawn: gym.RaidSpawnTimestamp.ValueOrZero(),
Start: gym.RaidBattleTimestamp.ValueOrZero(),
End: gym.RaidEndTimestamp.ValueOrZero(),
Level: gym.RaidLevel.ValueOrZero(),
PokemonId: gym.RaidPokemonId.ValueOrZero(),
Cp: gym.RaidPokemonCp.ValueOrZero(),
Gender: gym.RaidPokemonGender.ValueOrZero(),
Form: gym.RaidPokemonForm.ValueOrZero(),
Alignment: gym.RaidPokemonAlignment.ValueOrZero(),
Costume: gym.RaidPokemonCostume.ValueOrZero(),
Evolution: gym.RaidPokemonEvolution.ValueOrZero(),
Move1: gym.RaidPokemonMove1.ValueOrZero(),
Move2: gym.RaidPokemonMove2.ValueOrZero(),
ExRaidEligible: gym.ExRaidEligible.ValueOrZero(),
IsExclusive: gym.RaidIsExclusive.ValueOrZero(),
SponsorId: gym.SponsorId.ValueOrZero(),
PartnerId: gym.PartnerId.ValueOrZero(),
PowerUpPoints: gym.PowerUpPoints.ValueOrZero(),
PowerUpLevel: gym.PowerUpLevel.ValueOrZero(),
PowerUpEndTimestamp: gym.PowerUpEndTimestamp.ValueOrZero(),
ArScanEligible: gym.ArScanEligible.ValueOrZero(),
Rsvps: rsvps,
}

webhooksSender.AddMessage(webhooks.Raid, raidHook, areas)
Expand Down
71 changes: 46 additions & 25 deletions decoder/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ type webhookLineup struct {
Form null.Int `json:"form"`
}

type IncidentWebhook struct {
Id string `json:"id"`
PokestopId string `json:"pokestop_id"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
PokestopName string `json:"pokestop_name"`
Url string `json:"url"`
Enabled bool `json:"enabled"`
Start int64 `json:"start"`
IncidentExpireTimestamp int64 `json:"incident_expire_timestamp"`
Expiration int64 `json:"expiration"`
DisplayType int16 `json:"display_type"`
Style int16 `json:"style"`
GruntType int16 `json:"grunt_type"`
Character int16 `json:"character"`
Updated int64 `json:"updated"`
Confirmed bool `json:"confirmed"`
Lineup []webhookLineup `json:"lineup"`
}

//-> `id` varchar(35) NOT NULL,
//-> `pokestop_id` varchar(35) NOT NULL,
//-> `start` int unsigned NOT NULL,
Expand Down Expand Up @@ -160,34 +180,14 @@ func createIncidentWebhooks(ctx context.Context, db db.DbDetails, oldIncident *I
stop = &Pokestop{}
}

incidentHook := map[string]interface{}{
"id": incident.Id,
"pokestop_id": incident.PokestopId,
"latitude": stop.Lat,
"longitude": stop.Lon,
"pokestop_name": func() string {
if stop.Name.Valid {
return stop.Name.String
} else {
return "Unknown"
}
}(),
"url": stop.Url.ValueOrZero(),
"enabled": stop.Enabled.ValueOrZero(),
"start": incident.StartTime,
"incident_expire_timestamp": incident.ExpirationTime, // deprecated, remove old key in the future
"expiration": incident.ExpirationTime,
"display_type": incident.DisplayType,
"style": incident.Style,
"grunt_type": incident.Character, // deprecated, remove old key in the future
"character": incident.Character,
"updated": incident.Updated,
"confirmed": incident.Confirmed,
"lineup": nil,
pokestopName := "Unknown"
if stop.Name.Valid {
pokestopName = stop.Name.String
}

var lineup []webhookLineup
if incident.Slot1PokemonId.Valid {
incidentHook["lineup"] = []webhookLineup{
lineup = []webhookLineup{
{
Slot: 1,
PokemonId: incident.Slot1PokemonId,
Expand All @@ -205,6 +205,27 @@ func createIncidentWebhooks(ctx context.Context, db db.DbDetails, oldIncident *I
},
}
}

incidentHook := IncidentWebhook{
Id: incident.Id,
PokestopId: incident.PokestopId,
Latitude: stop.Lat,
Longitude: stop.Lon,
PokestopName: pokestopName,
Url: stop.Url.ValueOrZero(),
Enabled: stop.Enabled.ValueOrZero(),
Start: incident.StartTime,
IncidentExpireTimestamp: incident.ExpirationTime,
Expiration: incident.ExpirationTime,
DisplayType: incident.DisplayType,
Style: incident.Style,
GruntType: incident.Character,
Character: incident.Character,
Updated: incident.Updated,
Confirmed: incident.Confirmed,
Lineup: lineup,
}

areas := MatchStatsGeofence(stop.Lat, stop.Lon)
webhooksSender.AddMessage(webhooks.Invasion, incidentHook, areas)
statsCollector.UpdateIncidentCount(areas)
Expand Down
Loading