broken oops

This commit is contained in:
Emily 2020-11-04 21:14:58 +11:00
parent 5e98cb6c12
commit 04f4c8d141

View file

@ -67,6 +67,8 @@ module.exports = class {
const pokemon = json.data.getPokemonDetailsByFuzzy; const pokemon = json.data.getPokemonDetailsByFuzzy;
console.log(pokemon.types)
fetch('https://graphqlpokemon.favware.tech/', { fetch('https://graphqlpokemon.favware.tech/', {
method: 'POST', method: 'POST',
headers: { headers: {
@ -74,21 +76,15 @@ module.exports = class {
}, },
body: JSON.stringify({ query: ` body: JSON.stringify({ query: `
{ {
getPokemonDetailsByFuzzy(pokemon: "${query}") { getTypeMatchup(types: [water]) {
num attacking { doubleEffectiveTypes effectiveTypes resistedTypes doubleResistedTypes effectlessTypes }
species
types
sprite
shinySprite
bulbapediaPage
serebiiPage
smogonPage
} }
} }
`}) `})
}) })
.then(res => res.json()) .then(res => res.json())
.then(json => { .then(json => {
console.log(json)
if (json.errors) { if (json.errors) {
json.errors.forEach(error => { json.errors.forEach(error => {
client.logger.error('POKEMON_FETCH_ERROR', error.message); client.logger.error('POKEMON_FETCH_ERROR', error.message);
@ -98,18 +94,19 @@ module.exports = class {
} }
console.log(json.data) console.log(json.data)
const typeMatchup = json.data.getTypeMatchup.attacking; const typeMatchup = json.data.getTypeMatchup;
let doubleEffective = ''; let doubleEffective = '';
if (typeMatchup.doubleEffectiveTypes.length > 0) { if (typeMatchup.doubleEffectiveTypes && typeMatchup.doubleEffectiveTypes.length > 0) {
doubleEffective = '**' + typeMatchup.doubleEffectiveTypes.join('** **') + '**'; doubleEffective = '**' + typeMatchup.doubleEffectiveTypes.join('**, **') + '**';
doubleEffective = doubleEffective.split(' '); doubleEffective = doubleEffective.concat(typeMatchup.effectiveTypes).join(', ');
} }
let doubleResists = ''; let doubleResists = '';
if (typeMatchup.doubleResistedTypes.length > 0) { if (typeMatchup.doubleResistedTypes && typeMatchup.doubleResistedTypes.length > 0) {
doubleResists = '**' + typeMatchup.doubleResistedTypes.join('** **') + '**'; doubleResists = '**' + typeMatchup.doubleResistedTypes.join('** **') + '**';
doubleResists = doubleResists.split(' '); doubleResists = doubleResists.split(' ');
doubleResists = doubleResists.concat(typeMatchup.resistedTypes).join(', ');
} }
@ -118,8 +115,8 @@ module.exports = class {
.setTitle(`${pokemon.species.toProperCase()} (No. ${pokemon.num})`) .setTitle(`${pokemon.species.toProperCase()} (No. ${pokemon.num})`)
.setThumbnail(pokemon.sprite) .setThumbnail(pokemon.sprite)
.addField('**Types:**', pokemon.types.join(', '), true) .addField('**Types:**', pokemon.types.join(', '), true)
.addField('**Weak to:**', doubleEffective.concat(typeMatchup.effectiveTypes).join(', ')) .addField('**Weak to:**', doubleEffective)
.addField('**Strong against:**', doubleResists.concat(typeMatchup.resistedTypes).join(', ')) .addField('**Strong against:**', doubleResists)
.addField('**Immune to:**', typeMatchup.effectlessTypes.join(' ')) .addField('**Immune to:**', typeMatchup.effectlessTypes.join(' '))
.addField('**External Resources:**', `[Bulbapedia](${pokemon.bulbapediaPage}) | [Serebii](${pokemon.serebiiPage}) | [Smogon](${pokemon.smogonPage})`); .addField('**External Resources:**', `[Bulbapedia](${pokemon.bulbapediaPage}) | [Serebii](${pokemon.serebiiPage}) | [Smogon](${pokemon.smogonPage})`);
message.channel.createMessage({ embed: embed }); message.channel.createMessage({ embed: embed });