2020-11-10 03:31:49 +00:00
const { typeArray , colours } = require ( '../../assets/pokemon.json' ) ;
2020-11-04 07:17:31 +00:00
const fetch = require ( 'node-fetch' ) ;
module . exports = class {
constructor ( name , category ) {
this . name = name ,
this . category = category ,
this . enabled = true ,
this . devOnly = false ,
2020-11-06 23:42:25 +00:00
this . aliases = [ 'type' , 'typematchup' ] ,
2020-11-04 07:17:31 +00:00
this . userPerms = [ ] ,
this . botPerms = [ ] ,
this . cooldown = 5000 ,
this . help = {
2020-11-06 23:42:25 +00:00
description : 'Get the strengths and weaknesses of a pokemon type/type combination' ,
arguments : '<pokemon/type> [type2]' ,
details : 'The type2 argument is only needed if you are submitting two types, not a pokemon or singular type.' ,
examples : '`effective ghost dragon`\n`effective ribombee`'
2020-11-04 07:17:31 +00:00
} ;
}
async run ( client , message , args , data ) { //eslint-disable-line no-unused-vars
2021-07-15 02:39:19 +00:00
if ( ! args [ 0 ] ) return message . channel . send (
2021-07-15 02:26:42 +00:00
` ${ client . config . emojis . userError } You didn't give me a pokemon or type combination to look up! Usage: \` ${ message . prefix + this . name + ' ' + this . help . arguments } \` `
2020-11-04 07:17:31 +00:00
) ;
2021-07-17 05:55:18 +00:00
const editMessage = await message . channel . send ( ` ${ client . config . emojis . loading } Please wait... ` ) ;
2020-11-04 07:17:31 +00:00
2020-11-06 03:42:52 +00:00
let types ;
if ( ! typeArray . includes ( args [ 0 ] . toProperCase ( ) ) ) {
const res = await fetch ( 'https://graphqlpokemon.favware.tech/' , {
method : 'POST' ,
headers : {
2021-02-26 02:16:47 +00:00
'Content-Type' : 'application/json' ,
'User-Agent' : client . config . userAgent
2020-11-06 03:42:52 +00:00
} ,
body : JSON . stringify ( { query : `
{
getPokemonDetailsByFuzzy ( pokemon : "${args.join(' ').toLowerCase()}" ) {
types
}
}
` })
} ) ;
const json = await res . json ( ) ;
if ( json . errors ) {
json . errors . forEach ( error => {
if ( error . message . startsWith ( 'No Pokémon found' ) ) {
2021-07-15 02:39:19 +00:00
message . channel . send (
2021-07-15 02:26:42 +00:00
` ${ client . config . emojis . userError } I couldn't find any Pokemon with names similar to ${ args . join ( ' ' ) . toLowerCase ( ) } . Check your spelling, maybe? `
2020-11-06 03:42:52 +00:00
) ;
} else {
2020-11-11 23:55:35 +00:00
client . logger . error ( 'MATCHUP_API_ERROR' , error . message ) ;
2020-11-06 03:42:52 +00:00
}
} ) ;
return ;
}
2020-11-06 08:31:03 +00:00
types = json . data . getPokemonDetailsByFuzzy . types . map ( type => type . toLowerCase ( ) ) ;
2020-11-06 03:42:52 +00:00
} else {
2020-11-06 08:31:03 +00:00
types = args . map ( type => type . toLowerCase ( ) ) ;
2020-11-06 03:42:52 +00:00
}
2020-11-04 07:17:31 +00:00
fetch ( 'https://graphqlpokemon.favware.tech/' , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json'
} ,
body : JSON . stringify ( { query : `
{
2020-11-06 08:31:03 +00:00
getTypeMatchup ( types : [ $ { types . join ( ', ' ) } ] ) {
2020-11-06 03:42:52 +00:00
attacking { doubleEffectiveTypes effectiveTypes normalTypes resistedTypes doubleResistedTypes effectlessTypes }
defending { doubleEffectiveTypes effectiveTypes normalTypes resistedTypes doubleResistedTypes effectlessTypes }
2020-11-04 07:17:31 +00:00
}
}
` })
} )
. then ( res => res . json ( ) )
. then ( json => {
if ( json . errors ) {
json . errors . forEach ( error => {
2020-11-06 08:31:03 +00:00
if ( error . message . includes ( 'does not exist in "Types' ) ) {
2021-07-15 02:39:19 +00:00
message . channel . send (
2021-07-15 02:26:42 +00:00
` ${ client . config . emojis . userError } One or more of the types you gave me are invalid. Check your spelling, maybe? `
2020-11-04 07:17:31 +00:00
) ;
} else {
2020-11-06 08:31:03 +00:00
client . logger . error ( 'MATCHUP_FETCH_ERROR' , error . message ) ;
2020-11-04 07:17:31 +00:00
}
} ) ;
return ;
}
2020-11-06 03:42:52 +00:00
const typeMatchup = json . data . getTypeMatchup ;
2020-11-06 05:48:01 +00:00
let effectless = '' ;
if ( typeMatchup . attacking . effectlessTypes . length > 0 ) effectless = `
* * Doesn ' t effect : * *
$ { typeMatchup . attacking . effectlessTypes . map ( type => ` \` ${ type . toProperCase ( ) } \` ` ) . join ( ' ' ) }
` ;
let immune = '' ;
if ( typeMatchup . defending . effectlessTypes . length > 0 ) immune = `
2020-11-06 08:31:03 +00:00
* * Immunities : * *
2020-11-06 05:48:01 +00:00
$ { typeMatchup . defending . effectlessTypes . map ( type => ` \` ${ type . toProperCase ( ) } \` ` ) . join ( ' ' ) }
` ;
2021-07-17 05:55:18 +00:00
const embed = new client . MessageEmbed ( )
. setColor ( colours [ types [ 0 ] . toProperCase ( ) ] )
2020-11-06 08:31:03 +00:00
. setTitle ( 'Type effectiveness of ' + types . map ( type => type . toProperCase ( ) ) . join ( ' and ' ) )
2020-11-06 05:48:01 +00:00
. addField ( 'Offensive:' , `
* * Super - effective : * *
$ { this . parseEffectiveTypes ( typeMatchup . attacking . effectiveTypes , typeMatchup . attacking . doubleEffectiveTypes ) }
* * Not very effective : * *
$ { this . parseResistedTypes ( typeMatchup . attacking . resistedTypes , typeMatchup . attacking . doubleResistedTypes ) } $ { effectless }
` )
. addField ( 'Defensive:' , `
2020-11-06 08:31:03 +00:00
* * Weaknesses : * *
2020-11-06 05:48:01 +00:00
$ { this . parseEffectiveTypes ( typeMatchup . defending . effectiveTypes , typeMatchup . defending . doubleEffectiveTypes ) }
2020-11-06 08:31:03 +00:00
* * Resistances : * *
2020-11-06 05:48:01 +00:00
$ { this . parseResistedTypes ( typeMatchup . defending . resistedTypes , typeMatchup . defending . doubleResistedTypes ) } $ { immune }
` );
2021-07-17 05:55:18 +00:00
editMessage . edit ( { content : null , embeds : [ embed ] } ) ;
2020-11-06 08:31:03 +00:00
} ) ;
2020-11-06 03:42:52 +00:00
}
2020-11-04 07:17:31 +00:00
2020-11-06 03:42:52 +00:00
parseEffectiveTypes ( effective , doubleEffective ) {
2020-11-06 05:48:01 +00:00
return doubleEffective
. map ( type => ` \` ${ type . toProperCase ( ) } (x4) \` ` )
. concat ( effective . map ( type => ` \` ${ type . toProperCase ( ) } (x2) \` ` ) )
. join ( ' ' ) ;
2020-11-06 03:42:52 +00:00
}
2020-11-04 07:17:31 +00:00
2020-11-06 05:48:01 +00:00
parseResistedTypes ( resisted , doubleResisted ) {
return doubleResisted
. map ( type => ` \` ${ type . toProperCase ( ) } (x0.25) \` ` )
. concat ( resisted . map ( type => ` \` ${ type . toProperCase ( ) } (x0.5) \` ` ) )
. join ( ' ' ) ;
2020-11-06 03:42:52 +00:00
}
2020-11-04 07:17:31 +00:00
} ;