Skip to content

Commit

Permalink
commands(pokemon): use pokedex API v2 (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtraction authored Aug 27, 2023
2 parents a2e647d + 879eeac commit 928e461
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions src/commands/search/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,44 @@ import * as requests from "../../utils/requests.js";
import { COLORS } from "../../utils/constants.js";

interface Pokemon {
number?: string;
number?: number;
name?: string;
description?: string;
codename?: string;
gen?: number;
starter?: boolean;
mega?: boolean;
ultraBeast?: boolean;
legendary?: boolean;
mythical?: boolean;
species?: string;
types?: string[];
types?: string[],
abilities?: {
normal: string[];
hidden: string[];
};
eggGroups?: string[];
gender?: [ number, number ] | [];
name: string;
description: string;
hidden: boolean;
}[];
height?: string;
weight?: string;
sprite?: string;
family?: {
evolutionLine: string[];
mega?: boolean | {
stone: string;
sprite: string;
};
baseStats?: {
hp: number;
attack: number;
defense: number;
spAtk: number;
spDef: number;
speed: number;
};
training?: {
evYield: string;
catchRate: string;
baseFriendship: string;
baseExp: string;
growthRate: string;
};
breeding?: {
gender: string;
eggGroups: string[];
eggCycles: string;
};
sprite?: string;
}

class PokemonCommand extends Command {
Expand All @@ -55,7 +70,7 @@ class PokemonCommand extends Command {
const name = interaction.options.getString("name");

// fetch pokemon
const { body } = await requests.get(`https://pokeapi.glitch.me/v1/pokemon/${ encodeURIComponent(name) }`);
const { body } = await requests.get(`https://ex.traction.one/pokedex/pokemon/${ encodeURIComponent(name) }`);
const pokemon: Pokemon[] = await body.json() as unknown[];

if (pokemon?.length) {
Expand All @@ -64,19 +79,19 @@ class PokemonCommand extends Command {
{
color: COLORS.PRIMARY,
author: {
name: (pokemon[0].mythical ? "Mythical " : "") + (pokemon[0].legendary ? "Legendary " : "") + (pokemon[0].mega ? "Mega" : "") + (pokemon[0].ultraBeast ? "Ultra Beast" : "") + (pokemon[0].starter ? "Starter " : "") + "Pokémon",
name: (pokemon[0].codename ? "Ultra Beast" : "") + "Pokémon",
},
title: pokemon[0].name,
description: "Discovered in generation " + pokemon[0].gen,
description: pokemon[0].species,
fields: [
{
name: "Number",
value: pokemon[0].number,
value: "#" + pokemon[0].number?.toString(),
inline: true,
},
{
name: "Species",
value: pokemon[0].species,
name: "Generation",
value: pokemon[0].gen?.toString(),
inline: true,
},
{
Expand All @@ -86,17 +101,17 @@ class PokemonCommand extends Command {
},
{
name: "Abilities",
value: `Normal: ${pokemon[0].abilities.normal.join(", ") || "-"}\nHidden: ${pokemon[0].abilities.hidden.join(", ") || "-"}`,
value: pokemon[0].abilities.map(a => a.name).join("\n") || "Undiscovered",
inline: true,
},
{
name: "Egg Groups",
value: pokemon[0].eggGroups.join("\n"),
value: pokemon[0].breeding?.eggGroups.join("\n"),
inline: true,
},
{
name: "Gender Ratio",
value: pokemon[0].gender.length ? `${pokemon[0].gender[0]}:${pokemon[0].gender[1]}` : "Genderless",
value: pokemon[0].breeding?.gender || "Undiscovered",
inline: true,
},
{
Expand All @@ -109,14 +124,6 @@ class PokemonCommand extends Command {
value: pokemon[0].weight,
inline: true,
},
{
name: "Evolution Line",
value: pokemon[0].family.evolutionLine.join(" -> "),
},
{
name: "Description",
value: pokemon[0].description,
},
],
thumbnail: {
url: pokemon[0].sprite,
Expand Down

0 comments on commit 928e461

Please sign in to comment.