From cde5e0dff582fd9e07a6ad3d53061d6c4eaed588 Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 19 Apr 2023 11:23:45 -0400 Subject: [PATCH 1/2] Remove unnecessary check before sending webhook --- decoder/pokemon.go | 111 ++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 58 deletions(-) diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 2dd6f708..e83afd99 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -401,65 +401,60 @@ func createPokemonWebhooks(old *Pokemon, new *Pokemon, areas []geo.AreaName) { // return v.ValueOrZero() //} - if old == nil || - old.PokemonId != new.PokemonId || - old.Weather != new.Weather || - old.Cp != new.Cp { - pokemonHook := map[string]interface{}{ - "spawnpoint_id": func() string { - if !new.SpawnId.Valid { - return "None" - } - return strconv.FormatInt(new.SpawnId.ValueOrZero(), 16) - }(), - "pokestop_id": func() string { - if !new.PokestopId.Valid { - return "None" - } else { - return new.PokestopId.ValueOrZero() - } - }(), - "encounter_id": new.Id, - "pokemon_id": new.PokemonId, - "latitude": new.Lat, - "longitude": new.Lon, - "disappear_time": new.ExpireTimestamp.ValueOrZero(), - "disappear_time_verified": new.ExpireTimestampVerified, - "first_seen": new.FirstSeenTimestamp, - "last_modified_time": new.Updated, - "gender": new.Gender, - "cp": new.Cp, - "form": new.Form, - "costume": new.Costume, - "individual_attack": new.AtkIv, - "individual_defense": new.DefIv, - "individual_stamina": new.StaIv, - "pokemon_level": new.Level, - "move_1": new.Move1, - "move_2": new.Move2, - "weight": new.Weight, - "size": new.Size, - "height": new.Height, - "weather": new.Weather, - "capture_1": new.Capture1.ValueOrZero(), - "capture_2": new.Capture2.ValueOrZero(), - "capture_3": new.Capture3.ValueOrZero(), - "shiny": new.Shiny, - "username": new.Username, - "display_pokemon_id": new.DisplayPokemonId, - "is_event": new.IsEvent, - "seen_type": new.SeenType, - "pvp": func() interface{} { - if !new.Pvp.Valid { - return nil - } else { - return json.RawMessage(new.Pvp.ValueOrZero()) - } - }(), - } - - webhooks.AddMessage(webhooks.Pokemon, pokemonHook, areas) + pokemonHook := map[string]interface{}{ + "spawnpoint_id": func() string { + if !new.SpawnId.Valid { + return "None" + } + return strconv.FormatInt(new.SpawnId.ValueOrZero(), 16) + }(), + "pokestop_id": func() string { + if !new.PokestopId.Valid { + return "None" + } else { + return new.PokestopId.ValueOrZero() + } + }(), + "encounter_id": new.Id, + "pokemon_id": new.PokemonId, + "latitude": new.Lat, + "longitude": new.Lon, + "disappear_time": new.ExpireTimestamp.ValueOrZero(), + "disappear_time_verified": new.ExpireTimestampVerified, + "first_seen": new.FirstSeenTimestamp, + "last_modified_time": new.Updated, + "gender": new.Gender, + "cp": new.Cp, + "form": new.Form, + "costume": new.Costume, + "individual_attack": new.AtkIv, + "individual_defense": new.DefIv, + "individual_stamina": new.StaIv, + "pokemon_level": new.Level, + "move_1": new.Move1, + "move_2": new.Move2, + "weight": new.Weight, + "size": new.Size, + "height": new.Height, + "weather": new.Weather, + "capture_1": new.Capture1.ValueOrZero(), + "capture_2": new.Capture2.ValueOrZero(), + "capture_3": new.Capture3.ValueOrZero(), + "shiny": new.Shiny, + "username": new.Username, + "display_pokemon_id": new.DisplayPokemonId, + "is_event": new.IsEvent, + "seen_type": new.SeenType, + "pvp": func() interface{} { + if !new.Pvp.Valid { + return nil + } else { + return json.RawMessage(new.Pvp.ValueOrZero()) + } + }(), } + + webhooks.AddMessage(webhooks.Pokemon, pokemonHook, areas) } func (pokemon *Pokemon) isNewRecord() bool { From 1779343843e7e03261bea2e1016cdee37c7be2fb Mon Sep 17 00:00:00 2001 From: Fabio1988 <35898099+Fabio1988@users.noreply.github.com> Date: Sun, 31 Mar 2024 12:21:52 +0200 Subject: [PATCH 2/2] fix resolving conflicts --- decoder/pokemon.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 8aae1a79..f78733ea 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -476,8 +476,6 @@ func createPokemonWebhooks(ctx context.Context, db db.DbDetails, old *Pokemon, n } else { webhooksSender.AddMessage(webhooks.PokemonNoIV, pokemonHook, areas) } - - webhooks.AddMessage(webhooks.Pokemon, pokemonHook, areas) } func (pokemon *Pokemon) isNewRecord() bool {