Skip to content

Commit

Permalink
Fix adventurer search with no main character (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
man90es authored May 25, 2024
1 parent 5b749e3 commit 80e0e34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
10 changes: 10 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,17 @@
"type": "object",
"properties": {
"familyName": {
"nullable": false,
"type": "string",
"example": "Apple"
},
"profileTarget": {
"nullable": false,
"type": "string",
"example": "XXX"
},
"region": {
"nullable": false,
"type": "string",
"enum": [
"EU",
Expand All @@ -438,31 +441,38 @@
]
},
"guild": {
"nullable": true,
"properties": {
"name": {
"nullable": false,
"type": "string",
"example": "TumblrGirls"
}
}
},
"characters": {
"nullable": true,
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"nullable": false,
"type": "string",
"example": "Blue"
},
"class": {
"nullable": false,
"type": "string",
"example": "Ninja"
},
"main": {
"nullable": true,
"type": "boolean",
"example": true
},
"level": {
"nullable": false,
"type": "number",
"example": 56
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/GetStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func GetStatus(w http.ResponseWriter, r *http.Request) {
},
"proxies": len(config.GetProxyList()),
"uptime": time.Since(initTime).Round(time.Second).String(),
"version": "1.8.0",
"version": "1.8.1",
})
}
31 changes: 18 additions & 13 deletions scrapers/ScrapeAdventurerSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func ScrapeAdventurerSearch(region string, query string, searchType uint8, page
Region: region,
FamilyName: e.ChildText(".title a"),
ProfileTarget: extractProfileTarget(e.ChildAttr(".title a", "href")),
Characters: make([]models.Character, 1),
}

if region != "SA" && region != "KR" {
Expand All @@ -35,21 +34,27 @@ func ScrapeAdventurerSearch(region string, query string, searchType uint8, page
}
}

profile.Characters[0].Class = e.ChildText(".name")
profile.Characters[0].Name = e.ChildText(".text")
// Sometimes site displays text "You have not set your main character."
// instead of a character
if len(e.ChildText(".name")) > 0 {
profile.Characters = make([]models.Character, 1)

// Site displays the main character when searching by family name
// And the searched character when searching by character name
if searchType == 2 {
profile.Characters[0].Main = true
}
profile.Characters[0].Class = e.ChildText(".name")
profile.Characters[0].Name = e.ChildText(".text")

if region != "EU" && region != "NA" {
translators.TranslateClassName(&profile.Characters[0].Class)
}
// Site displays the main character when searching by family name
// And the searched character when searching by character name
if searchType == 2 {
profile.Characters[0].Main = true
}

if level, err := strconv.Atoi(e.ChildText(".level")[3:]); err == nil {
profile.Characters[0].Level = uint8(level)
if region != "EU" && region != "NA" {
translators.TranslateClassName(&profile.Characters[0].Class)
}

if level, err := strconv.Atoi(e.ChildText(".level")[3:]); err == nil {
profile.Characters[0].Level = uint8(level)
}
}

profiles = append(profiles, profile)
Expand Down

0 comments on commit 80e0e34

Please sign in to comment.