Skip to content

Commit

Permalink
feat: add tibia_urls field into information-section (#398)
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Lindberg <[email protected]>
  • Loading branch information
Kai-Animator and tobiasehlert authored Nov 21, 2024
1 parent b59bc38 commit 30cb2f7
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 107 deletions.
3 changes: 2 additions & 1 deletion src/TibiaBoostableBossesOverview.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type BoostableBossesOverviewResponse struct {
Information Information `json:"information"`
}

func TibiaBoostableBossesOverviewImpl(BoxContentHTML string) (BoostableBossesOverviewResponse, error) {
func TibiaBoostableBossesOverviewImpl(BoxContentHTML string, url string) (BoostableBossesOverviewResponse, error) {
const (
bodyIndexer = `<body`
endBodyIndexer = `</body>`
Expand Down Expand Up @@ -151,6 +151,7 @@ func TibiaBoostableBossesOverviewImpl(BoxContentHTML string) (BoostableBossesOve
Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
TibiaURLs: []string{url},
Status: Status{
HTTPCode: http.StatusOK,
},
Expand Down
6 changes: 4 additions & 2 deletions src/TibiaBoostableBossesOverview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ func TestBoostableBossesOverview(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

boostableBossesJson, _ := TibiaBoostableBossesOverviewImpl(string(data))
boostableBossesJson, _ := TibiaBoostableBossesOverviewImpl(string(data), "https://www.tibia.com/library/?subtopic=boostablebosses")
assert := assert.New(t)
boosted := boostableBossesJson.BoostableBosses.Boosted
bosses := boostableBossesJson.BoostableBosses.BoostableBosses
information := boostableBossesJson.Information

assert.Equal("https://www.tibia.com/library/?subtopic=boostablebosses", information.TibiaURLs[0])
assert.Equal(95, len(bosses))
assert.Equal("Ragiaz", boosted.Name)
assert.Equal(
Expand Down Expand Up @@ -107,6 +109,6 @@ func BenchmarkTibiaBoostableBossesOverviewImpl(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
bossSink, _ = TibiaBoostableBossesOverviewImpl(data)
bossSink, _ = TibiaBoostableBossesOverviewImpl(data, "https://www.tibia.com/library/?subtopic=boostablebosses")
}
}
3 changes: 2 additions & 1 deletion src/TibiaCharactersCharacter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type CharacterResponse struct {
const Br = 0x202

// TibiaCharactersCharacter func
func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, error) {
func TibiaCharactersCharacterImpl(BoxContentHTML string, url string) (CharacterResponse, error) {
var (
// local strings used in this function
localDivQueryString = ".TableContentContainer tr"
Expand Down Expand Up @@ -725,6 +725,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
TibiaURLs: []string{url},
Status: Status{
HTTPCode: http.StatusOK,
},
Expand Down
33 changes: 18 additions & 15 deletions src/TibiaCharactersCharacter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ func TestNumber1(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "https://www.tibia.com/community/?subtopic=characters&name=Darkside+Rafa")
if err != nil {
t.Fatal(err)
}

assert := assert.New(t)
character := characterJson.Character.CharacterInfo
information := characterJson.Information

assert.Equal("Darkside Rafa", character.Name)
assert.Nil(character.FormerNames)
Expand All @@ -54,6 +55,8 @@ func TestNumber1(t *testing.T) {
assert.Equal("2022-01-05T21:23:32Z", character.LastLogin)
assert.Equal("Premium Account", character.AccountStatus)
assert.Empty(character.Comment)

assert.Equal("https://www.tibia.com/community/?subtopic=characters&name=Darkside+Rafa", information.TibiaURLs[0])
}

func TestNumber2(t *testing.T) {
Expand All @@ -68,7 +71,7 @@ func TestNumber2(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -134,7 +137,7 @@ func TestNumber3(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -169,7 +172,7 @@ func TestNumber4(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2784,7 +2787,7 @@ func TestNumber5(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2838,7 +2841,7 @@ func TestNumber6(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2888,7 +2891,7 @@ func TestNumber7(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -2913,7 +2916,7 @@ func TestNumber8(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3073,7 +3076,7 @@ func TestNumber9(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3175,7 +3178,7 @@ func TestNumber10(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3204,7 +3207,7 @@ func TestNumber11(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3285,7 +3288,7 @@ func TestNumber12(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -3310,7 +3313,7 @@ func TestNumber13(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

characterJson, err := TibiaCharactersCharacterImpl(string(data))
characterJson, err := TibiaCharactersCharacterImpl(string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3401,7 +3404,7 @@ func BenchmarkNumber1(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
characterJson, _ := TibiaCharactersCharacterImpl(string(data))
characterJson, _ := TibiaCharactersCharacterImpl(string(data), "")

assert.Equal(b, "Darkside Rafa", characterJson.Character.CharacterInfo.Name)
}
Expand All @@ -3422,7 +3425,7 @@ func BenchmarkNumber2(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
characterJson, _ := TibiaCharactersCharacterImpl(string(data))
characterJson, _ := TibiaCharactersCharacterImpl(string(data), "")

assert.Equal(b, "Riley No Hands", characterJson.Character.CharacterInfo.Name)
}
Expand Down
7 changes: 4 additions & 3 deletions src/TibiaCreaturesCreature.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ var (
CreatureLootRegex = regexp.MustCompile(`.*yield (.*) experience.*carry (.*)with them.`)
)

func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string) (CreatureResponse, error) {
func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string, url string) (CreatureResponse, error) {
// local strings used in this function
var localDamageString = " damage"
localDamageString := " damage"

// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
Expand All @@ -79,7 +79,7 @@ func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string) (CreatureRes
CreatureBeParalysed, CreatureBeSummoned, CreatureBeConvinced, CreatureSeeInvisible, CreatureIsLootable, CreatureIsBoosted bool
)

//Find boosted creature
// Find boosted creature
boostedMonsterTitle, boostedCreatureFound := ReaderHTML.Find("#Monster").First().Attr("title")

if boostedCreatureFound {
Expand Down Expand Up @@ -192,6 +192,7 @@ func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string) (CreatureRes
Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
TibiaURLs: []string{url},
Status: Status{
HTTPCode: http.StatusOK,
},
Expand Down
14 changes: 8 additions & 6 deletions src/TibiaCreaturesCreature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ func TestDemon(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

demonJson, err := TibiaCreaturesCreatureImpl("Demon", string(data))
demonJson, err := TibiaCreaturesCreatureImpl("Demon", string(data), "https://www.tibia.com/library/?subtopic=creatures&race=demon")
if err != nil {
t.Fatal(err)
}

assert := assert.New(t)
information := demonJson.Information

assert.Equal("https://www.tibia.com/library/?subtopic=creatures&race=demon", information.TibiaURLs[0])
assert.Equal("Demons", demonJson.Creature.Name)
assert.Equal("Demon", demonJson.Creature.Race)
assert.Equal("https://static.tibia.com/images/library/demon.gif", demonJson.Creature.ImageURL)
Expand Down Expand Up @@ -76,7 +78,7 @@ func TestQuaraPredatorFeatured(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

quaraPredatorJson, err := TibiaCreaturesCreatureImpl("Quara Predator", string(data))
quaraPredatorJson, err := TibiaCreaturesCreatureImpl("Quara Predator", string(data), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -128,7 +130,7 @@ func TestCentipede(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

centipedeJson, _ := TibiaCreaturesCreatureImpl("Centipede", string(data))
centipedeJson, _ := TibiaCreaturesCreatureImpl("Centipede", string(data), "")
assert := assert.New(t)

assert.Equal("Centipedes", centipedeJson.Creature.Name)
Expand All @@ -152,7 +154,7 @@ func TestHunter(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

hunterJson, _ := TibiaCreaturesCreatureImpl("Hunter", string(data))
hunterJson, _ := TibiaCreaturesCreatureImpl("Hunter", string(data), "")
assert := assert.New(t)

assert.Equal("Hunters", hunterJson.Creature.Name)
Expand All @@ -176,7 +178,7 @@ func TestSkunk(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

skunkJson, _ := TibiaCreaturesCreatureImpl("Skunk", string(data))
skunkJson, _ := TibiaCreaturesCreatureImpl("Skunk", string(data), "")
assert := assert.New(t)

assert.Equal("Skunks", skunkJson.Creature.Name)
Expand All @@ -200,7 +202,7 @@ func TestLavaLurkers(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

lavalurkersJson, _ := TibiaCreaturesCreatureImpl("Lava Lurkers", string(data))
lavalurkersJson, _ := TibiaCreaturesCreatureImpl("Lava Lurkers", string(data), "")
assert := assert.New(t)

assert.Equal("Lava Lurkers", lavalurkersJson.Creature.Name)
Expand Down
7 changes: 3 additions & 4 deletions src/TibiaCreaturesOverview.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ var (
CreatureInformationRegex = regexp.MustCompile(`.*race=(.*)"><img src="(.*)" border.*div>(.*)<\/div>`)
)

func TibiaCreaturesOverviewImpl(BoxContentHTML string) (CreaturesOverviewResponse, error) {
var (
BoostedCreatureName, BoostedCreatureRace, BoostedCreatureImage string
)
func TibiaCreaturesOverviewImpl(BoxContentHTML string, url string) (CreaturesOverviewResponse, error) {
var BoostedCreatureName, BoostedCreatureRace, BoostedCreatureImage string

// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
Expand Down Expand Up @@ -127,6 +125,7 @@ func TibiaCreaturesOverviewImpl(BoxContentHTML string) (CreaturesOverviewRespons
Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
TibiaURLs: []string{url},
Status: Status{
HTTPCode: http.StatusOK,
},
Expand Down
4 changes: 3 additions & 1 deletion src/TibiaCreaturesOverview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ func TestOverview(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

creaturesJson, err := TibiaCreaturesOverviewImpl(string(data))
creaturesJson, err := TibiaCreaturesOverviewImpl(string(data), "https://www.tibia.com/library/?subtopic=creatures")
if err != nil {
t.Fatal(err)
}

assert := assert.New(t)
information := creaturesJson.Information

assert.Equal("https://www.tibia.com/library/?subtopic=creatures", information.TibiaURLs[0])
assert.Equal("Minotaur Amazon", creaturesJson.Creatures.Boosted.Name)
assert.Equal("minotauramazon", creaturesJson.Creatures.Boosted.Race)
assert.Equal("https://static.tibia.com/images/global/header/monsters/minotauramazon.gif", creaturesJson.Creatures.Boosted.ImageURL)
Expand Down
3 changes: 2 additions & 1 deletion src/TibiaFansites.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var (
FansiteAnchorRegex = regexp.MustCompile(`.*src="(.*)" alt=".*`)
)

func TibiaFansitesImpl(BoxContentHTML string) (FansitesResponse, error) {
func TibiaFansitesImpl(BoxContentHTML string, url string) (FansitesResponse, error) {
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
Expand Down Expand Up @@ -97,6 +97,7 @@ func TibiaFansitesImpl(BoxContentHTML string) (FansitesResponse, error) {
Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
TibiaURLs: []string{url},
Status: Status{
HTTPCode: http.StatusOK,
},
Expand Down
5 changes: 4 additions & 1 deletion src/TibiaFansites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestFansites(t *testing.T) {
t.Fatalf("File reading error: %s", err)
}

fansitesJson, err := TibiaFansitesImpl(string(data))
fansitesJson, err := TibiaFansitesImpl(string(data), "https://www.tibia.com/community/?subtopic=fansites")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -86,4 +86,7 @@ func TestFansites(t *testing.T) {
assert.Equal("Upload, browse, like and share pictures.", tibiaGalleryFansite.Specials[0])
assert.True(tibiaGalleryFansite.FansiteItem)
assert.Equal("https://static.tibia.com/images/community/fansiteitems/TibiaGallery.com.gif", tibiaGalleryFansite.FansiteItemURL)

information := fansitesJson.Information
assert.Equal("https://www.tibia.com/community/?subtopic=fansites", information.TibiaURLs[0])
}
3 changes: 2 additions & 1 deletion src/TibiaGuildsGuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
GuildMemberInvitesInformationRegex = regexp.MustCompile(`<td><a.*">(.*)<\/a><\/td><td>(.*)<\/td>`)
)

func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (GuildResponse, error) {
func TibiaGuildsGuildImpl(guild string, BoxContentHTML string, url string) (GuildResponse, error) {
// Creating empty vars
var (
MembersData []GuildMember
Expand Down Expand Up @@ -282,6 +282,7 @@ func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (GuildResponse, e
Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
TibiaURLs: []string{url},
Status: Status{
HTTPCode: http.StatusOK,
},
Expand Down
Loading

0 comments on commit 30cb2f7

Please sign in to comment.