import type { EmbedField , Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import axios from "axios" ; export class IPInfoCommand extends Command { description = "Returns info about an IP address." ; requiredkeys = [ "ipinfo" ] ; args = "<ip:string>" ; aliases = [ "aboutip" , "geolocation" , "ip" , "ipinformation" ] ; cooldown = 3000 ; allowdms = true ; async run ( msg , _pargs , args ) { const query = encodeURIComponent ( args . join ( " " ) ) ; const body = await axios . get ( `https://ipinfo.io/${ query }/json?token=${ encodeURIComponent ( this . bot . config . keys . ipinfo ) }` ) . catch ( ( ) => { } ) ; const abuseinfo = await axios . get ( `https://api.abuseipdb.com/api/v2/check?ipAddress=${ query }` , { headers : { "Key" : encodeURIComponent ( this . bot . config . keys . abuseipdb ) , "Accept" : "application/json" , "User-Agent" : "hibiki" , } , } ) . catch ( ( ) => { } ) ; if ( ! body || ! body . data || body . data . error || ! body . data . ip || ! body . data . org ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.IPINFO_INVALID" ) , "error" ) ; } const fields = [ ] ; let regionString = "" ; if ( body . data . country ) regionString = body . data . country ; if ( body . data . country && body . data . region ) regionString = `${ body . data . region }, ${ body . data . country }` ; if ( body . data . city && body . data . region && body . data . country ) { regionString = `${ body . data . city }, ${ body . data . region }, ${ body . data . country }` ; } if ( body . data . hostname ) { fields . push ( { name : msg . string ( "utility.IPINFO_HOSTNAME" ) , value : body . data . hostname , inline : true , } ) ; } if ( body . data . org ) { fields . push ( { name : msg . string ( "utility.IPINFO_ORG" ) , value : body . data . org , inline : true , } ) ; } if ( body . data . loc ) { fields . push ( { name : msg . string ( "utility.IPINFO_GEOLOCATION" ) , value : body . data . loc , inline : true , } ) ; } if ( regionString ) { fields . push ( { name : msg . string ( "utility.LOCATION" ) , value : `${ regionString }` , inline : false , } ) ; } if ( abuseinfo && abuseinfo . data ?. data ) { if ( ! abuseinfo . data . data . errors ) { fields . push ( { name : msg . string ( "utility.IPINFO_ABUSEINFO" ) , value : msg . string ( "utility.IPINFO_ABUSEDATA" , { reports : abuseinfo . data . data . totalReports , confidence : abuseinfo . data . data . abuseConfidenceScore , } ) , } ) ; } } let image ; if ( body . data . loc && this . bot . config . keys . maps ) { image = `https://maps.googleapis.com/maps/api/staticmap?center=${ body . data . loc }&zoom=10&size=250x150&sensor=false&key=${ this . bot . config . keys . maps }` ; } msg . channel . createMessage ( { embed : { title : `🌐 ${ body . data . ip }` , description : msg . string ( "utility.IPINFO_DESCRIPTION" ) , color : msg . convertHex ( "general" ) , image : { url : image || "" , } , fields : fields , footer : { text : msg . string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) , poweredBy : "ipinfo.io" , } ) , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) ; } }