Skip to content

Commit

Permalink
fixed bug where multi part named pokemon werent found
Browse files Browse the repository at this point in the history
  • Loading branch information
caquillo07 committed Oct 24, 2020
1 parent bd2a812 commit a62b4bd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.5.1
v1.5.2
7 changes: 4 additions & 3 deletions bot/cmd_pokedex.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ func (b *Bot) handlePokedexCmd(

externalPokedexLinks := fmt.Sprintf(
"[Bulbapedia Entry](https://bulbapedia.bulbagarden.net/wiki/%s_(Pokémon))\n",
strings.ToLower(urlPkmName),
strings.ReplaceAll(urlPkmName, " ", "_"),
)

if len(pkm.Dens.Shield) > 0 || len(pkm.Dens.Sword) > 0 || pkm.Generation == "SwordShield" {
externalPokedexLinks += fmt.Sprintf(
"[Serebii Sword & Shield Pokédex](https://serebii.net/pokedex-swsh/%s/)",
strings.ToLower(urlPkmName),
strings.ReplaceAll(strings.ToLower(urlPkmName), " ", ""),
)
} else {
externalPokedexLinks += fmt.Sprintf(
Expand Down Expand Up @@ -90,7 +91,7 @@ func (b *Bot) handlePokedexCmd(

embed.URL = fmt.Sprintf(
"https://bulbapedia.bulbagarden.net/wiki/%s_(Pokémon)",
strings.ToLower(urlPkmName),
strings.ReplaceAll(urlPkmName, " ", "_"),
)

embed.Fields = []*discordgo.MessageEmbedField{
Expand Down
39 changes: 25 additions & 14 deletions bot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,10 @@ func parsePokemonCommand(command string, args []string) pokemonArg {

// now check if its a pokemon with a two-part name and its not the last
// element in the slice
cleanArg := strings.ReplaceAll(arg, "*", "")
if (cleanArg == "mr" || cleanArg == "mr." || cleanArg == "mime") && i != len(args)-1 {
secondPart := args[i+1]
cleanSecondPart := strings.ReplaceAll(secondPart, "*", "")
if strings.Contains(arg, "mr") && (cleanSecondPart == "rime" || cleanSecondPart == "mime") {
pkmArgs.name = "mr " + cleanSecondPart
pkmArgs.isShiny = strings.Contains(arg, "*") || strings.Contains(secondPart, "*")
skipIndex = true
continue
}

if cleanArg == "mime" && strings.Contains(cleanSecondPart, "jr") {
pkmArgs.name = "mime jr"
pkmArgs.isShiny = strings.Contains(arg, "*") || strings.Contains(secondPart, "*")
if i != len(args)-1 {
if name, shiny := handleMultiPartName(arg, args[i+1]); name != "" {
pkmArgs.name = name
pkmArgs.isShiny = shiny
skipIndex = true
continue
}
Expand All @@ -279,6 +269,7 @@ func parsePokemonCommand(command string, args []string) pokemonArg {
// pokemon has two forms, the which are 3 words long so we have to
// threat it a bit differently by only checking the first one, and
// manually adding the rest of the name.
cleanArg := strings.ReplaceAll(arg, "*", "")
if cleanArg == "urshifu" {

// first check if the form is before the name in the command.
Expand Down Expand Up @@ -376,3 +367,23 @@ func parsePokemonCommand(command string, args []string) pokemonArg {

return pkmArgs
}

func handleMultiPartName(first, second string) (string, bool) {
cleanedFirst := strings.ReplaceAll(first, "*", "")
cleanedSecond := strings.ReplaceAll(second, "*", "")
var name string
shiny := strings.Contains(first, "*") || strings.Contains(second, "*")
switch n := cleanedFirst + " " + cleanedSecond; n {
case "tapu koko", "tapu lele", "tapu bulu", "tapu fini", "mr mime", "mr rime",
"mime jr", "type: null":
name = n
case "mime jr.", "mr. rime", "mr. mime":
name = strings.ReplaceAll(n, ".", "")
case "type null":
name = "type: null"
default:
// none
}

return name, shiny
}
4 changes: 3 additions & 1 deletion repository/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (p *Pokemon) SpriteImage(shiny bool, form string) string {
}

cleanName := strings.ReplaceAll(p.Name, "-", "")
cleanName = strings.ReplaceAll(p.Name, ":", "")

// kind of hacky here, but if the pokemon is a galar one we need to
// remove the form from the name, else we wont get the right sprite.
Expand All @@ -94,7 +95,8 @@ func (p *Pokemon) SpriteImage(shiny bool, form string) string {
}

// the dumb mr mime line has special sprite names. I. hate. this.
if p.DexID == 439 || p.DexID == 122 || p.DexID == 866 {
if p.DexID == 439 || p.DexID == 122 || p.DexID == 866 || p.DexID == 785 ||
p.DexID == 786 || p.DexID == 787 || p.DexID == 788 || p.DexID == 772 {
cleanName = strings.ReplaceAll(cleanName, " ", "-")
}

Expand Down

0 comments on commit a62b4bd

Please sign in to comment.