Hi! I’m trying to make a command that takes a query from the user, and uses it to search an array, and print the line identified with the query. Specifically, I want a “Pokedex”, where the query would be the name of a pokemon, and the result would be the line from my JSON about that pokemon.
I currently have this command, which I got from this thread:
$(eval a=$(urlfetch json https://gist.githubusercontent.com/webcamcals/8daa9da5679173ad7c915a86231a7d99/raw/67fc6d499638614df14d857ee079af7ebed5f3cb/pokedex3.json);a[parseInt(decodeURIComponent(`$(querystring)`))-1]||a[Math.floor(Math.random()*a.length)])
This works using numbers (eg !dex 1
prints the first line, which contains information for Pokemon #1, Bulbasaur, etc). And with no input from the user after the command, it outputs a random line. That’s pretty good! But ideally, it would function using Pokemon names as input (ignoring case), eg !dex bulbasaur would return line number 001, containing information about Bulbasaur.
The JSON I’m working with was exported out of a spreadsheet and edited in Notepad++, so I am able to format it differently, which might help if it’s necessary to do something else to demarcate specifically where the pokemon’s name is in the line; I think that some pokedex entries contain the names of other pokemon, which could complicate searching the whole document, unless it’s possible to identify names that are in their own column / bounded by separator characters, as they are here.
Or, if it’s possible to do two lookups with one command, pokemon names could be converted to numbers using a different, simpler list containing only names, and then the line number containing a match for the query could be pulled from the full json, as they are currently.
Any help with this would be massively appreciated!