Skip to content

Commit 641427e

Browse files
adding character truncated deaths list indicator (#276)
* add AreDeathsTruncated to the Character struct * add tests * renaming AreDeathsTruncated to DeathsTruncated * fix v3 characters documentation --------- Co-authored-by: Tobias Lindberg <tobias.ehlert@gmail.com>
1 parent 675937b commit 641427e

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/TIbiaDataDocsV3.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ func tibiaCharactersCharacterV3() bool {
4040
return false
4141
}
4242

43+
type CharacterV3 struct {
44+
CharacterInfo CharacterInfo `json:"character"` // The character's information.
45+
AccountBadges []AccountBadges `json:"account_badges,omitempty"` // The account's badges.
46+
Achievements []Achievements `json:"achievements,omitempty"` // The character's achievements.
47+
Deaths []Deaths `json:"deaths,omitempty"` // The character's deaths.
48+
AccountInformation AccountInformation `json:"account_information,omitempty"` // The account information.
49+
OtherCharacters []OtherCharacters `json:"other_characters,omitempty"` // The account's other characters.
50+
}
4351
type CharacterResponseV3 struct {
44-
Characters Character `json:"characters"`
52+
Characters CharacterV3 `json:"characters"`
4553
Information InformationV3 `json:"information"`
4654
}
4755

src/TibiaCharactersCharacter.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type Character struct {
105105
AccountBadges []AccountBadges `json:"account_badges,omitempty"` // The account's badges.
106106
Achievements []Achievements `json:"achievements,omitempty"` // The character's achievements.
107107
Deaths []Deaths `json:"deaths,omitempty"` // The character's deaths.
108+
DeathsTruncated bool `json:"deaths_truncated"` // Whether the character's deaths were truncated or not.
108109
AccountInformation AccountInformation `json:"account_information,omitempty"` // The account information.
109110
OtherCharacters []OtherCharacters `json:"other_characters,omitempty"` // The account's other characters.
110111
}
@@ -135,6 +136,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
135136
DeathsData []Deaths
136137
AccountInformationData AccountInformation
137138
OtherCharactersData []OtherCharacters
139+
DeathsTruncated bool
138140

139141
// Errors
140142
characterNotFound bool
@@ -229,7 +231,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
229231
AnchorQuery := s.Find("a")
230232
HouseName := AnchorQuery.Nodes[0].FirstChild.Data
231233
HouseHref := AnchorQuery.Nodes[0].Attr[0].Val
232-
//substring from houseid= to &character in the href for the house
234+
// substring from houseid= to &character in the href for the house
233235
HouseId := HouseHref[strings.Index(HouseHref, "houseid")+8 : strings.Index(HouseHref, "&character")]
234236
HouseRawData := RowNameQuery.Nodes[0].NextSibling.LastChild.Data
235237
HouseTown := HouseRawData[strings.Index(HouseRawData, "(")+1 : strings.Index(HouseRawData, ")")]
@@ -244,7 +246,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
244246
case "Guild Membership:":
245247
CharacterInfoData.Guild.Rank = strings.TrimSuffix(RowData, " of the ")
246248

247-
//TODO: I don't understand why the unicode nbsp is there...
249+
// TODO: I don't understand why the unicode nbsp is there...
248250
CharacterInfoData.Guild.GuildName = TibiaDataSanitizeStrings(RowNameQuery.Nodes[0].NextSibling.LastChild.LastChild.Data)
249251
case "Last Login:":
250252
if RowData != "never logged in" {
@@ -256,8 +258,8 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
256258
stringBuilder := strings.Builder{}
257259
for node != nil {
258260
if node.DataAtom == Br {
259-
//It appears we can ignore br because either the encoding or goquery adds an \n for us
260-
//stringBuilder.WriteString("\n")
261+
// It appears we can ignore br because either the encoding or goquery adds an \n for us
262+
// stringBuilder.WriteString("\n")
261263
} else {
262264
stringBuilder.WriteString(node.Data)
263265
}
@@ -388,6 +390,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
388390
dataNoTags := RemoveHtmlTag(CharacterListHTML)
389391

390392
if strings.HasPrefix(dataNoTags, "There happened more character deaths in the last 30 days than we can display here.") {
393+
DeathsTruncated = true
391394
return false
392395
}
393396

@@ -609,6 +612,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, err
609612
AccountBadgesData,
610613
AchievementsData,
611614
DeathsData,
615+
DeathsTruncated,
612616
AccountInformationData,
613617
OtherCharactersData,
614618
}

src/TibiaCharactersCharacter_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestNumber2(t *testing.T) {
101101
assert.Equal("Testa de Ferro do Lejonhjartat ;)", character.Comment)
102102
assert.Equal("Premium Account", character.AccountStatus)
103103

104-
//validate other characters
104+
// validate other characters
105105
assert.Equal(7, len(characterJson.Character.OtherCharacters))
106106

107107
onlineMainCharacter := characterJson.Character.OtherCharacters[3]
@@ -179,14 +179,14 @@ func TestNumber4(t *testing.T) {
179179

180180
assert.Equal("Riley No Hands", character.Name)
181181

182-
//validate former names
182+
// validate former names
183183
assert.Equal(4, len(character.FormerNames))
184184
assert.Equal("Dura Malandro", character.FormerNames[0])
185185
assert.Equal("Letsgo Brandon", character.FormerNames[1])
186-
assert.Equal("Letsgo Brandon", character.FormerNames[2]) //yes, this name is listed twice
186+
assert.Equal("Letsgo Brandon", character.FormerNames[2]) // yes, this name is listed twice
187187
assert.Equal("Nataraya Soldrac", character.FormerNames[3])
188188

189-
//validate death data
189+
// validate death data
190190
assert.Equal(79, len(characterJson.Character.Deaths))
191191

192192
firstDeath := characterJson.Character.Deaths[0]
@@ -327,7 +327,6 @@ func TestNumber4(t *testing.T) {
327327
{Name: "Suprldo", Player: true, Traded: false, Summon: ""},
328328
},
329329
Killers: []Killers{
330-
331330
{Name: "Jupa Infinity", Player: true, Traded: false, Summon: ""},
332331
{Name: "Okiba Kay", Player: true, Traded: false, Summon: ""},
333332
{Name: "Jahziel Hardcori", Player: true, Traded: false, Summon: ""},
@@ -364,7 +363,6 @@ func TestNumber4(t *testing.T) {
364363
},
365364
{
366365
Assists: []Killers{
367-
368366
{Name: "May Thirtieth", Player: true, Traded: false, Summon: ""},
369367
{Name: "Guichin Killzejk Boom", Player: true, Traded: false, Summon: ""},
370368
{Name: "Kanabionoia", Player: true, Traded: false, Summon: ""},
@@ -2815,7 +2813,7 @@ func TestNumber5(t *testing.T) {
28152813
assert.Empty(characterJson.Character.Achievements)
28162814
assert.Empty(characterJson.Character.AccountInformation.LoyaltyTitle)
28172815

2818-
//validate other characters
2816+
// validate other characters
28192817
assert.Equal(4, len(characterJson.Character.OtherCharacters))
28202818

28212819
positionCharacter := characterJson.Character.OtherCharacters[1]
@@ -3055,8 +3053,9 @@ func TestNumber11(t *testing.T) {
30553053
character := characterJson.Character.CharacterInfo
30563054

30573055
assert.Equal("Orca Kaoksh", character.Name)
3056+
assert.False(characterJson.Character.DeathsTruncated)
30583057

3059-
//validate death data
3058+
// validate death data
30603059
assert.Equal(2, len(characterJson.Character.Deaths))
30613060
deaths := characterJson.Character.Deaths
30623061

@@ -3112,7 +3111,6 @@ func TestNumber11(t *testing.T) {
31123111
idx, tc.Time, deaths[idx].Time,
31133112
)
31143113
}
3115-
31163114
}
31173115

31183116
func TestNumber12(t *testing.T) {
@@ -3136,6 +3134,7 @@ func TestNumber12(t *testing.T) {
31363134
character := characterJson.Character.CharacterInfo
31373135

31383136
assert.Equal("Stalone Matador", character.Name)
3137+
assert.True(characterJson.Character.DeathsTruncated)
31393138
assert.Equal(55, len(characterJson.Character.Deaths))
31403139
}
31413140

0 commit comments

Comments
 (0)