const fs = require('fs'); //read files databases/pokemon_games.json and databases/pokemon.json const pokemon_games = JSON.parse(fs.readFileSync('databases/pokemon_games.json')); const pokemon = JSON.parse(fs.readFileSync('databases/pokemon.json')); /*pokemon.json [ { "number": 1, "name": "Bulbasaur", "img": "https://en.wikipedia.org/wiki/Bulbasaur#/media/File:Pok%C3%A9mon_Bulbasaur_art.png", "type": [ "Grass", "Poison" ], "height": "0.7 m", "weight": "6.9 kg", "first_appeared": 1, "some_facts": [ "Bulbasaur is the first Pokémon in the National Pokédex.", "Bulbasaur is the only dual-type Pokémon in the National Pokédex that is both Poison and Grass type.", "Bulbasaur is the only Pokémon that can learn Frenzy Plant, Blast Burn, and Hydro Cannon." ] }, pokemon_games.json [ { "id": 1, "name": "Pokémon Red and Blue", "year": 1996 } */ function randomPokemon() { //connect data from pokemon.json and pokemon_games.json const randomPokemon = pokemon[Math.floor(Math.random() * pokemon.length)]; //find game id in pokemon_games.json const game = pokemon_games.find(game => game.id === randomPokemon.first_appeared); //get numbers of facts and get random fact const fact = randomPokemon.some_facts[Math.floor(Math.random() * randomPokemon.some_facts.length)]; //get types of pokemon const types = randomPokemon.type.join(', '); return `**${randomPokemon.name}**\nTypes: ${types}\nHeight: ${randomPokemon.height}\nWeight: ${randomPokemon.weight}\nFirst appeared in: ${game.name} (${game.year})\n${fact}\n${randomPokemon.img}`; } function pokemonNumber(number) { const pokemonNumber = pokemon.find(pokemon => pokemon.number === number); if (!pokemonNumber) { return 'Pokemon not found **FUNCTION NOT FINISHED**'; } const game = pokemon_games.find(game => game.id === pokemonNumber.first_appeared); const fact = pokemonNumber.some_facts[Math.floor(Math.random() * pokemonNumber.some_facts.length)]; const types = pokemonNumber.type.join(', '); return `**${pokemonNumber.name}**\nTypes: ${types}\nHeight: ${pokemonNumber.height}\nWeight: ${pokemonNumber.weight}\nFirst appeared in: ${game.name} (${game.year})\n${fact}`; } function pokemonName(name) { const pokemonName = pokemon.find(pokemon => pokemon.name.toLowerCase() === name.toLowerCase()); if (!pokemonName) { return 'Pokemon not found **FUNCTION NOT FINISHED**'; } const game = pokemon_games.find(game => game.id === pokemonName.first_appeared); const fact = pokemonName.some_facts[Math.floor(Math.random() * pokemonName.some_facts.length)]; const types = pokemonName.type.join(', '); return `**${pokemonName.name}**\nTypes: ${types}\nHeight: ${pokemonName.height}\nWeight: ${pokemonName.weight}\nFirst appeared in: ${game.name} (${game.year})\n${fact}`; } module.exports = { name: 'pokemon', description: 'Get a random pokemon. **FUNCTION NOT FINISHED**', help: 'Get a random pokemon. **FUNCTION NOT FINISHED**', arguments: [ { name: 'pokemonname', type: 'STRING', description: 'Name of the pokemon you want to get information about', required: false, }, { name: 'pokemonnumber', type: 'INTEGER', description: 'Number of the pokemon you want to get information about', required: false, }, ], options: [ { name: 'pokemonname', type: 3, // String type description: 'Name of the pokemon you want to get information about', required: false }, { name: 'pokemonnumber', type: 4, // Integer type description: 'Number of the pokemon you want to get information about', required: false } ], slash: true, text: true, admin: false, requireKick: false, requireBan: false, canBeUsedInDm: true, premium: false, contexts: ['GUILD_TEXT', 'GUILD_VOICE', 'DM'], integration_types: [0,1], execute: async (message, args) => { if(args.length === 0) { const pokemon = randomPokemon(); message.channel.send(pokemon); return; } //check if it is a number if(!isNaN(args[0])) { const pokemon = pokemonNumber(parseInt(args[0])); message.channel.send(pokemon); return; } //check if it is a string const pokemon = pokemonName(args.join(' ')); return message.channel.send(pokemon); }, executeSlash: async interaction => { const name = interaction.options.getString('pokemonname'); const number = interaction.options.getInteger('pokemonnumber'); if (!name && !number) { const pokemon = randomPokemon(); interaction.reply(pokemon); return; } if (number) { const pokemon = pokemonNumber(number); interaction.reply(pokemon); return; } const pokemon = pokemonName(name); interaction.reply(pokemon); }, };