Skip to content

Commit c698900

Browse files
committed
fix: add fallback to resolve boosted creature
1 parent 8bb6b3b commit c698900

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/TibiaCreaturesOverview.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type CreaturesOverviewResponse struct {
3232
var (
3333
BoostedCreatureNameAndRaceRegex = regexp.MustCompile(`<a.*race=(.*)".*?>(.*)</a>`)
3434
BoostedCreatureImageRegex = regexp.MustCompile(`<img[^>]+\bsrc=["']([^"']+)["']`)
35+
BoostedCreatureRaceRegex = regexp.MustCompile(`monsters\/(.*).gif`)
3536
CreatureInformationRegex = regexp.MustCompile(`.*race=(.*)"><img src="(.*)" border.*div>(.*)<\/div>`)
3637
)
3738

@@ -67,6 +68,23 @@ func TibiaCreaturesOverviewImpl(BoxContentHTML string, url string) (CreaturesOve
6768
BoostedCreatureImage = subma2b[0][1]
6869
}
6970

71+
// Fallback if boosted creature is not in creature list
72+
if len(BoostedCreatureName) == 0 {
73+
74+
// Find boosted creature
75+
boostedMonsterTitle, boostedCreatureFound := ReaderHTML.Find("#Monster").First().Attr("title")
76+
77+
if boostedCreatureFound {
78+
boostedCreatureRace := boostedMonsterTitle[strings.Index(boostedMonsterTitle, ": ")+2:]
79+
80+
subma3b := BoostedCreatureRaceRegex.FindStringSubmatch(BoostedCreatureImage)
81+
if len(subma3b) > 0 {
82+
BoostedCreatureName = boostedCreatureRace
83+
BoostedCreatureRace = subma3b[1]
84+
}
85+
}
86+
}
87+
7088
var (
7189
// Creating empty CreaturesData var
7290
CreaturesData []OverviewCreature

0 commit comments

Comments
 (0)