GeorgeCiesinski / poke-guesser-bot

Discord bot that lets you guess pokemon
MIT License
0 stars 3 forks source link

Add support for other languages #5

Closed GeorgeCiesinski closed 3 years ago

GeorgeCiesinski commented 3 years ago

Describe the new feature

The bot currently only accepts English answers. Functionality should be added to take advantage of pokeApi's multi language support so that pokemon names can be guessed in any supported language.

Planning

fetchNames-Implementation

function fetchNames(nameOrId) {
  return fetch('https://pokeapi.co/api/v2/pokemon-species/' + nameOrId + '/')
  // Parse to json
  .then(res => res.json())
  // Get names as array
  .then(json => json.names)
  // Format names
  .then(names => {
    let resultNames = []
    for (let i = 0; i < names.length; i++) {
      resultNames.push({
        languageName: names[i].language.name,
        languageUrl: names[i].language.url,
        name: names[i].name
      })
    }
    return resultNames
  })
}

Guess-Check

pokeFetch.fetchNames(pokemonArray[0].toLowerCase()).then(names => {
        console.log('Guess:' + guess)
        for (let i = 0; i < names.length; i++) {
          if (names[i].name.toLowerCase() === guess.toLowerCase()) {
            addScore(msg.author.username)
            // Send message that guess is correct
            msg.channel.send(`${msg.author} correctly guessed ${guess}`)
            break; // To avoid scoring multiple times
          }
        }
      })

Useful links

  1. Dominik's example
Wissididom commented 3 years ago

The addScore here should also be updated like mentioned in #6 when we switch over to ids. Just so that we don't forget.

GeorgeCiesinski commented 3 years ago

Fixed in Pull Request #10

As the addScore change has been added to #6 I will proceed to close this issue.