Skip to content

Commit

Permalink
fix: update cry updater to handle forms
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Mar 2, 2024
1 parent c3b2d74 commit 206aa9e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
import { pokedex } from '#assets/pokedex.js';
import { FetchResultTypes, fetch } from '@sapphire/fetch';
import { eachLimit } from 'async';
import { green, yellow } from 'colorette';
import { toLowerSingleWordCase } from '../../../../src/lib/utils/utils';
import { green } from 'colorette';
import { inspectData, replaceEnumLikeValues, writeDataToFileAndPrettify } from '../../../utils';
import { generations } from '../classification-updater/constants';
import { getModulePathForGeneration, getPokemonGenerationForDexNumber } from '../classification-updater/utils';
import { pokedexAppendContent, pokedexPrependContent } from '../utils/pokedex-constants';
import { MegaSpriteRegex, baseUrl } from './constants';
import { getCryUrl } from './get-cry-url';
import { log } from './log-wrapper';

await eachLimit(pokedex.values(), 10, async (pokemon) => {
const logPrefix = `${pokemon.species} (${pokemon.num}${pokemon.forme ?? ''}) - `;

await log({ msg: `${logPrefix}Started processing`, color: yellow, isBold: false, isIndent: true, bypassCiCheck: true });

let nameToUse = pokemon.baseSpecies ? pokemon.species : toLowerSingleWordCase(pokemon.species);

if (nameToUse.match(MegaSpriteRegex)) {
nameToUse = nameToUse.replace(MegaSpriteRegex, '$1$2');
}

const urlToFetch = `${baseUrl}/${nameToUse}.mp3` as const;
await log({ msg: `${logPrefix}Fetching URL ${urlToFetch}`, color: yellow, isBold: false, isIndent: true });

const mapEntry = pokedex.get(pokemon.key);
try {
const result = await fetch(urlToFetch, FetchResultTypes.Result);
if (result.status === 200) {
mapEntry.cry = urlToFetch;
await log({ msg: `${logPrefix}Set cry on the map object`, color: yellow, isBold: false, isIndent: true });
}
} catch {
// Ignore entry
}
});
await eachLimit(pokedex.values(), 100, async (pokemon) => getCryUrl(pokemon));

for (const generation of generations) {
const mapForGeneration = pokedex.filter((poke) => getPokemonGenerationForDexNumber(poke.num) === generation);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { pokedex } from '#assets/pokedex.js';
import type { PokemonTypes } from '#assets/pokemon-source';
import { FetchResultTypes, fetch } from '@sapphire/fetch';
import { yellow } from 'colorette';
import { toLowerSingleWordCase } from '../../../../src/lib/utils/utils';
import { MegaSpriteRegex, baseUrl } from './constants';
import { log } from './log-wrapper';

export async function getCryUrl(pokemon: PokemonTypes.DexEntry, recursivePokemon?: PokemonTypes.DexEntry) {
const logPrefix = `${pokemon.species} (${pokemon.num}${pokemon.forme ?? ''}) - `;

await log({ msg: `${logPrefix}Started processing`, color: yellow, isBold: false, isIndent: true, bypassCiCheck: true });

let nameToUse = pokemon.baseSpecies ? pokemon.species : toLowerSingleWordCase(pokemon.species);

if (nameToUse.match(MegaSpriteRegex)) {
nameToUse = nameToUse.replace(MegaSpriteRegex, '$1$2');
}

const urlToFetch = `${baseUrl}/${nameToUse}.mp3` as const;
await log({ msg: `${logPrefix}Fetching URL ${urlToFetch}`, color: yellow, isBold: false, isIndent: true });

try {
const result = await fetch(urlToFetch, FetchResultTypes.Result);
if (result.status === 200) {
if (recursivePokemon) {
recursivePokemon.cry = urlToFetch;
await log({ msg: `${logPrefix}Set cry on the recursive object`, color: yellow, isBold: false, isIndent: true });
} else {
pokemon.cry = urlToFetch;
await log({ msg: `${logPrefix}Set cry on the map object`, color: yellow, isBold: false, isIndent: true });
}
}
} catch {
if (pokemon.baseSpecies) {
const baseSpecies = pokedex.get(pokemon.baseSpecies);
if (baseSpecies) {
await getCryUrl(baseSpecies, pokemon);
}
}
}
}

0 comments on commit 206aa9e

Please sign in to comment.