Skip to content

Commit de5f526

Browse files
use 'flavor_text_entry' when 'short_effect' is null (#117)
1 parent d82c086 commit de5f526

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

cmd/ability.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,34 @@ func AbilityCommand() {
6969
}
7070
}
7171

72-
capitalizedEffect := cases.Title(language.English).String(strings.Replace(abilityName, "-", " ", -1))
73-
fmt.Println(styling.StyleBold.Render(capitalizedEffect))
74-
fmt.Println("Effect:", englishShortEffect)
72+
// Extract English flavor_text_entries
73+
var englishFlavorEntry string
74+
for _, entry := range abilitiesStruct.FlavorEntries {
75+
if entry.Language.Name == "en" {
76+
englishFlavorEntry = entry.FlavorText
77+
break
78+
}
79+
}
80+
81+
capitalizedAbility := cases.Title(language.English).String(strings.Replace(abilityName, "-", " ", -1))
82+
fmt.Println(styling.StyleBold.Render(capitalizedAbility))
83+
84+
// API is missing some data for the short_effect for abilities from Generation 9.
85+
// If short_effect is empty, fallback to the move's flavor_text_entry.
86+
if englishShortEffect == "" {
87+
fmt.Println("Effect:", englishFlavorEntry)
88+
} else {
89+
fmt.Println("Effect:", englishShortEffect)
90+
}
91+
92+
// Print the generation where the move was first introduced.
93+
generationParts := strings.Split(abilitiesStruct.Generation.Name, "-")
94+
if len(generationParts) > 1 {
95+
generationUpper := strings.ToUpper(generationParts[1])
96+
fmt.Println("Generation:", generationUpper)
97+
} else {
98+
fmt.Println("Generation: Unknown")
99+
}
75100

76101
if *pokemonFlag || *shortPokemonFlag {
77102
if err := flags.PokemonFlag(endpoint, abilityName); err != nil {

structs/structs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ type AbilityJSONStruct struct {
1010
} `json:"language"`
1111
ShortEffect string `json:"short_effect"`
1212
} `json:"effect_entries"`
13+
FlavorEntries []struct {
14+
FlavorText string `json:"flavor_text"`
15+
Language struct {
16+
Name string `json:"name"`
17+
URL string `json:"url"`
18+
} `json:"language"`
19+
VersionGroup struct {
20+
Name string `json:"name"`
21+
URL string `json:"url"`
22+
} `json:"version_group"`
23+
} `json:"flavor_text_entries"`
24+
Generation struct {
25+
Name string `json:"name"`
26+
URL string `json:"url"`
27+
} `json:"generation"`
1328
Pokemon []struct {
1429
Hidden bool `json:"hidden"`
1530
PokemonName struct {

0 commit comments

Comments
 (0)