Skip to content

Commit

Permalink
Merge branch 'main' into morewebhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio1988 committed Jul 27, 2023
2 parents abdc4f4 + a31d5a5 commit e2fb68a
Show file tree
Hide file tree
Showing 17 changed files with 176,500 additions and 121,243 deletions.
1 change: 1 addition & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
port = 9001 # Listening port for golbat
#grpc_port = 50001 # Listening port for grpc
raw_bearer = "" # Raw bearer (password) required
api_secret = "golbat" # Golbat secret required on api calls (blank for none)

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "golbat/geo"

type configDefinition struct {
Port int `koanf:"port"`
GrpcPort int `koanf:"grpc_port"`
Webhooks []webhook `koanf:"webhooks"`
Database database `koanf:"database"`
Stats bool `koanf:"stats"`
Expand Down
47 changes: 30 additions & 17 deletions decoder/fort.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"golbat/pogo"
"golbat/webhooks"
"net/url"
"strings"
)

type Location struct {
Expand Down Expand Up @@ -141,31 +142,36 @@ func CreateFortWebHooks(old *FortWebhook, new *FortWebhook, change FortChange) {
} else if change == EDIT {
areas := MatchStatsGeofence(new.Location.Latitude, new.Location.Longitude)
var editTypes []string
if !(old.Name == nil && new.Name == nil) &&
(old.Name == nil || new.Name == nil || *old.Name != *new.Name) {

// Check if Name has changed
if old.Name == nil {
if new.Name != nil && *new.Name != "" {
editTypes = append(editTypes, "name")
}
} else if new.Name != nil && *old.Name != *new.Name {
editTypes = append(editTypes, "name")
}
if !(old.Description == nil && new.Description == nil) &&
(old.Description == nil || new.Description == nil || *old.Description != *new.Description) {

// Check if Description has changed
if old.Description == nil {
if new.Description != nil && *new.Description != "" {
editTypes = append(editTypes, "description")
}
} else if new.Description != nil && *old.Description != *new.Description {
editTypes = append(editTypes, "description")
}
if !(old.ImageUrl == nil && new.ImageUrl == nil) &&
(old.ImageUrl == nil || new.ImageUrl == nil || *old.ImageUrl != *new.ImageUrl) {
var newPath, oldPath string
newUrl, err := url.Parse(*new.ImageUrl)
if err == nil && newUrl != nil {
newPath = newUrl.Path
}
if old.ImageUrl != nil {
oldUrl, err2 := url.Parse(*old.ImageUrl)
if err2 == nil && oldUrl != nil {
oldPath = oldUrl.Path
}
}

// Check if ImageUrl has changed
if old.ImageUrl != nil && new.ImageUrl != nil && *old.ImageUrl != *new.ImageUrl {
oldPath := getPathFromURL(*old.ImageUrl)
newPath := getPathFromURL(*new.ImageUrl)
if oldPath != newPath {
editTypes = append(editTypes, "image_url")
}
} else if (old.ImageUrl == nil || *old.ImageUrl == "") && new.ImageUrl != nil && *new.ImageUrl != "" {
editTypes = append(editTypes, "image_url")
}
// Check if location has changed
if !floatAlmostEqual(old.Location.Latitude, new.Location.Latitude, floatTolerance) ||
!floatAlmostEqual(old.Location.Longitude, new.Location.Longitude, floatTolerance) {
editTypes = append(editTypes, "location")
Expand All @@ -182,6 +188,13 @@ func CreateFortWebHooks(old *FortWebhook, new *FortWebhook, change FortChange) {
}
}

func getPathFromURL(u string) string {
parsedURL, err := url.Parse(u)
if err != nil {
return ""
}
return strings.TrimPrefix(parsedURL.Path, "/")
}
func UpdateFortRecordWithGetMapFortsOutProto(ctx context.Context, db db.DbDetails, mapFort *pogo.GetMapFortsOutProto_FortProto) (bool, string) {
// when we miss, we check the gym, if again, we save it in cache for 5 minutes (in gym part)
status, output := UpdatePokestopRecordWithGetMapFortsOutProto(ctx, db, mapFort)
Expand Down
7 changes: 6 additions & 1 deletion decoder/gym.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) *
gym.Url = null.StringFrom(gymData.Url)
}
gym.Name = null.StringFrom(gymData.Name)
gym.Description = null.StringFrom(gymData.Description)

if gymData.Description == "" {
gym.Description = null.NewString("", false)
} else {
gym.Description = null.StringFrom(gymData.Description)
}

return gym
}
Expand Down
5 changes: 3 additions & 2 deletions decoder/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func savePokemonRecordAsAtTime(ctx context.Context, db db.DbDetails, pokemon *Po
if err != nil {
log.Errorf("insert pokemon: [%s] %s", pokemon.Id, err)
log.Errorf("Full structure: %+v", pokemon)
pokemonCache.Delete(pokemon.Id) // Force reload of pokemon from database
return
}

Expand Down Expand Up @@ -360,12 +361,12 @@ func savePokemonRecordAsAtTime(ctx context.Context, db db.DbDetails, pokemon *Po
if err != nil {
log.Errorf("Update pokemon [%s] %s", pokemon.Id, err)
log.Errorf("Full structure: %+v", pokemon)
pokemonCache.Delete(pokemon.Id) // Force reload of pokemon from database

return
}
rows, rowsErr := res.RowsAffected()
log.Debugf("Updating pokemon [%s] after update res = %d %v", pokemon.Id, rows, rowsErr)

_, _ = res, err
}
}

Expand Down
7 changes: 6 additions & 1 deletion decoder/pokestop.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,12 @@ func (stop *Pokestop) updatePokestopFromFortDetailsProto(fortData *pogo.FortDeta
stop.Url = null.StringFrom(fortData.ImageUrl[0])
}
stop.Name = null.StringFrom(fortData.Name)
stop.Description = null.StringFrom(fortData.Description)

if fortData.Description == "" {
stop.Description = null.NewString("", false)
} else {
stop.Description = null.StringFrom(fortData.Description)
}

if fortData.Modifier != nil && len(fortData.Modifier) > 0 {
// DeployingPlayerCodename contains the name of the player if we want that
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- GOLBAT.API_SECRET=golbat

- GOLBAT.STATS=false
- GOLBAT.IN_MEMORY=false
- GOLBAT.POKEMON_MEMORY_ONLY=false

- GOLBAT.KOJI.URL=http://{koji_url}/api/v1/geofence/feature-collection/{golbat_project}
- GOLBAT.KOJI.BEARER_TOKEN=secret
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/tidwall/rtree v1.10.0
github.com/toorop/gin-logrus v0.0.0-20210225092905-2c785434f26f
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.30.0
gopkg.in/guregu/null.v4 v4.0.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand All @@ -42,6 +43,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down Expand Up @@ -70,6 +72,7 @@ require (
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/golang-migrate/migrate/v4 v4.16.2/go.mod h1:pfcJX4nPHaVdc5nmdCikFBWtm
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 h1:HKlyj6in2JV6wVkmQ4XmG/EIm+SCYlPZ+V4GWit7Z+I=
github.com/golang/geo v0.0.0-20230421003525-6adc56603217/go.mod h1:8wI0hitZ3a1IxZfeH3/5I97CI8i5cLGsYe7xNhQGs9U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -251,7 +253,12 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Expand Down
Loading

0 comments on commit e2fb68a

Please sign in to comment.