Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary check before sending webhook #106

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
146 changes: 70 additions & 76 deletions decoder/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,82 +406,76 @@ func createPokemonWebhooks(ctx context.Context, db db.DbDetails, old *Pokemon, n
// }
// 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()
}
}(),
"pokestop_name": func() *string {
if !new.PokestopId.Valid {
return nil
} else {
pokestop, _ := GetPokestopRecord(ctx, db, new.PokestopId.String)
name := "Unknown"
if pokestop != nil {
name = pokestop.Name.ValueOrZero()
}
return &name
}
}(),
"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())
}
}(),
}

if new.AtkIv.Valid && new.DefIv.Valid && new.StaIv.Valid {
webhooksSender.AddMessage(webhooks.PokemonIV, pokemonHook, areas)
} else {
webhooksSender.AddMessage(webhooks.PokemonNoIV, 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()
}
}(),
"pokestop_name": func() *string {
if !new.PokestopId.Valid {
return nil
} else {
pokestop, _ := GetPokestopRecord(ctx, db, new.PokestopId.String)
name := "Unknown"
if pokestop != nil {
name = pokestop.Name.ValueOrZero()
}
return &name
}
}(),
"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())
}
}(),
}

if new.AtkIv.Valid && new.DefIv.Valid && new.StaIv.Valid {
webhooksSender.AddMessage(webhooks.PokemonIV, pokemonHook, areas)
} else {
webhooksSender.AddMessage(webhooks.PokemonNoIV, pokemonHook, areas)
}
}

func (pokemon *Pokemon) isNewRecord() bool {
Expand Down