import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import axios from "axios" ; export class XKCDCommand extends Command { description = "Sends a random or specified comic from XKCD." ; args = "[id:string] | [today:string]" ; cooldown = 3000 ; allowdms = true ; async run ( msg , _pargs , args ) { const comic = encodeURIComponent ( args . join ( "" ) ) ; let api = "" ; if ( comic === "today" || comic === "daily" ) api = "https://xkcd.com/info.0.json" ; else if ( args . length ) api = `https://xkcd.com/${ comic }/info.0.json` ; else { const body = await axios . get ( "https://xkcd.com/info.0.json" ) . catch ( ( ) => { } ) ; if ( ! body || ! body . data . num ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "fun.XKCD_ERROR" ) , "error" ) ; const random = Math . floor ( Math . random ( ) * body . data . num ) + 1 ; api = `https://xkcd.com/${ random }/info.0.json` ; } const body = await axios . get ( api ) . catch ( ( ) => { } ) ; if ( ! body || ! body . data . num ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "fun.XKCD_ERROR" ) , "error" ) ; msg . channel . createMessage ( { embed : { title : `💬 ${ body . data . safe_title }` , description : `${ body . data . alt }` , color : msg . convertHex ( "general" ) , image : { url : body . data . img , } , footer : { text : msg . string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) , extra : `${ body . data . month }/${ body . data . day }/${ body . data . year }` , } ) , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) ; } }