duck-dynasty / duckbot

A Discord bot for personal friend group
GNU General Public License v3.0
9 stars 10 forks source link

add pokemon of the day #699

Open twentylemon opened 1 year ago

twentylemon commented 1 year ago

Or something that gives a random pokemon (like /pokemon). Some random stats about it would be nice, like it's type and some nonsense about the LORE.

I wholeheartedly stole this idea from my alexas.

jameshughes89 commented 1 year ago

I support this idea

Chippers255 commented 1 year ago

Excellent idea! It would also be good to give it a pokedex like ability such a /pokemon bulbasaur to get stats for a particular one.

twentylemon commented 1 year ago

For the command portion, https://pokeapi.co/ looks pretty good. It's free too.
https://pokeapi.co/api/v2/pokemon/* supports both ID and name which is nice, it includes things like base stats so duckbot can pass judgement on whether or not the pokemon is useless garbage. It also includes flavour text, eg for bulbasaur,

a snip from https://pokeapi.co/api/v2/pokemon/1

"species": {
  "name": "bulbasaur",
  "url": "https://pokeapi.co/api/v2/pokemon-species/1/"
},

then a snip from https://pokeapi.co/api/v2/pokemon-species/1/ gives

"flavor_text_entries": [
  {
    "flavor_text": "A strange seed was\nplanted on its\nback at birth.\fThe plant sprouts\nand grows with\nthis POKéMON.",
    "language": {
      "name": "en",
      "url": "https://pokeapi.co/api/v2/language/9/"
    },
    "version": {
      "name": "red",
      "url": "https://pokeapi.co/api/v2/version/1/"
    }
  },
  {
  "flavor_text": "A strange seed was\nplanted on its\nback at birth.\fThe plant sprouts\nand grows with\nthis POKéMON.",
  "language": {
    "name": "en",
    "url": "https://pokeapi.co/api/v2/language/9/"
  },
  "version": {
    "name": "blue",
    "url": "https://pokeapi.co/api/v2/version/2/"
  }
},

Some weird artifacts with \n and \f (I imagine these are directly from the games) which we'd want to remove, but otherwise, pog.

Wrapper libraries also exist, check the docs.

twentylemon commented 1 year ago

For pokemon of the day, we could use a deterministic shuffle of the list range(1, n) where n is the number of pokemon (ie, a random list of all pokemon ids), then pick some anchor date which we offset from (maybe duckbot's inception day) to be the first index in that new list. Then todaysPokemon = shuffle(range(1, n))[(today() - anchor()).days % n]

I'm not sure where to get n though. I'd rather not hard code it.
https://pokeapi.co/api/v2/pokemon?limit=100000&offset=0 is almost it. The end of it is outta whack though, it lists a bunch of utility IDs, see https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_National_Pok%C3%A9dex_number

jameshughes89 commented 1 year ago

Why have a shuffle though? Does having them come out of numeric order matter?

twentylemon commented 1 year ago

I'd say randomness matters. It'd be boring if you could trivially predict the next pokemon of the day.

Either method though, you'd still need to know n.

twentylemon commented 1 year ago

So, looking closer at https://pokeapi.co/api/v2/pokemon?limit=100000&offset=0
The last IDs are all 10000+, so we could use that to find n, filtering out the utility IDs and that's it.

jameshughes89 commented 1 year ago

The numbering is a little unclear.

First line value is "count":1281 and then the URL numbering goes 1 -- 1009 and then 10001 -- 10271. So, the count seems correct, but the numbering is throwing me off.

twentylemon commented 1 year ago

count is the size of the list. Each element has an ID embedded in the url though.

twentylemon commented 1 year ago

Maybe relevant is the API also does pagination by default, so count might be less if there are multiple pages. It's semi-typical to include such data in a single page of results.

The query there though says "screw you, I want one page only."