import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import axios from "axios" ; export class FactCommand extends Command { description = "Posts a cat, dog, or random fact." ; args = "[cat:string] | [dog:string] | [useless:string]" ; aliases = [ "catfact" , "dogfact" , "randomfact" , "uselessfact" ] ; cooldown = 3000 ; allowdms = true ; async run ( msg , _pargs , args ) { const apis = [ "https://catfact.ninja/fact" , "https://dog-api.kinduff.com/api/facts" , "https://useless-facts.sameerkumar.website/api" ] ; const apinames = [ "cat" , "dog" , "useless" ] ; const apilabels = [ `🐱 ${ msg . string ( "fun.FACT_CAT" ) }` , `🐶 ${ msg . string ( "fun.FACT_DOG" ) }` , `🍀 ${ msg . string ( "fun.FACT_USELESS" ) }` ] ; let index = Math . floor ( Math . random ( ) * apis . length ) ; if ( args . length > 0 && apinames . filter ( ( api ) => api . includes ( args . join ( " " ) ) ) . length ) { index = apinames . indexOf ( apinames . filter ( ( api ) => api . includes ( args . join ( " " ) ) ) [ 0 ] ) ; } const api = apis [ index ] ; const apiname = apinames [ index ] ; const apilabel = apilabels [ index ] ; let fact = "" ; const body = await axios . get ( api ) . catch ( ( ) => { } ) ; if ( ! body || ! body . data ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "fun.FACT_ERROR" ) , "error" ) ; if ( apiname === "cat" ) fact = body . data . fact ; else if ( apiname === "dog" ) fact = body . data . facts [ 0 ] ; else if ( apiname === "useless" ) fact = body . data . data ; msg . createEmbed ( apilabel , fact ) ; } }