import type { EmbedField , Guild , Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import { defaultAvatar } from "../../utils/constants" ; import { afkTimeoutFormat , contentFilterFormat , dateFormat , featureFormat , mfaLevelFormat , notificationLevelFormat , regionFormat , verificationLevelFormat , } from "../../utils/format" ; export class ServerCommand extends Command { description = "Returns info about the server." ; aliases = [ "g" , "guild" , "guildinfo" , "serverinfo" ] ; allowdisable = false ; async run ( msg , pargs ) { let guild ; pargs ?. [ 0 ] . value && this . bot . config . owners . includes ( msg . author . id ) ? ( guild = this . bot . guilds . find ( ( g ) => g . name . toLowerCase ( ) . startsWith ( pargs ?. [ 0 ] . value ) || g . id === pargs ?. [ 0 ] . value ) ) : ( guild = msg . channel . guild ) ; if ( ! guild ) return msg . channel . guild ; const fields = [ ] ; const communityChannels = [ ] ; let voice = 0 ; let text = 0 ; if ( guild . rulesChannelID ) { communityChannels . push ( { name : msg . string ( "general.SERVER_RULES_CHANNEL" ) , value : `${ msg . channel . guild . channels . get ( guild . rulesChannelID ) . mention }` , } ) ; } if ( guild . systemChannelID ) { communityChannels . push ( { name : msg . string ( "general.SERVER_SYSTEMMESSAGE_CHANNEL" ) , value : msg . channel . guild . channels . get ( guild . systemChannelID ) . mention , } ) ; } if ( guild . publicUpdatesChannelID ) { communityChannels . push ( { name : msg . string ( "general.SERVER_UPDATES_CHANNEL" ) , value : msg . channel . guild . channels . get ( guild . publicUpdatesChannelID ) . mention , } ) ; } guild . channels . forEach ( ( channel ) => { if ( channel . type === 0 ) text ++ ; if ( channel . type === 2 ) voice ++ ; } ) ; fields . push ( { name : msg . string ( "global.ID" ) , value : guild . id , } ) ; fields . push ( { name : msg . string ( "global.CREATED" ) , value : `${ dateFormat ( guild . createdAt , msg . string ) }` , } ) ; fields . push ( { name : msg . string ( "global.OWNER" ) , value : `${ msg . tagUser ( this . bot . users . get ( guild . ownerID ) ) || guild . ownerID }` , inline : true , } ) ; fields . push ( { name : msg . string ( "global.REGION" ) , value : `${ regionFormat ( guild . region ) }` , inline : true , } ) ; fields . push ( { name : msg . string ( "global.MEMBERS" ) , value : msg . string ( "general.SERVER_MEMBERS" , { members : guild . memberCount } ) , inline : true , } ) ; fields . push ( { name : msg . string ( "global.ROLES" ) , value : `${ guild . roles . size }` , inline : true , } ) ; fields . push ( { name : msg . string ( "global.CHANNELS" ) , value : msg . string ( "general.SERVER_CHANNELINFO" , { text : text , voice : voice } ) , inline : true , } ) ; if ( guild . emojis . length > 0 ) { fields . push ( { name : msg . string ( "global.EMOJIS" ) , value : `${ guild . emojis . length }` , inline : true , } ) ; } fields . push ( { name : msg . string ( "general.SERVER_MESSAGEFILTER" ) , value : `${ contentFilterFormat ( msg . string , guild . explicitContentFilter ) }` , inline : true , } ) ; fields . push ( { name : msg . string ( "general.SERVER_VERIFICATION" ) , value : `${ verificationLevelFormat ( msg . string , guild . verificationLevel ) }` , inline : true , } ) ; fields . push ( { name : msg . string ( "general.SERVER_NOTIFICATION_LEVEL" ) , value : `${ notificationLevelFormat ( msg . string , guild . defaultNotifications ) }` , inline : true , } ) ; fields . push ( { name : msg . string ( "general.SERVER_2FA" ) , value : mfaLevelFormat ( msg . string , guild . mfaLevel ) , inline : true , } ) ; if ( guild . afkChannelID ) { fields . push ( { name : msg . string ( "general.SERVER_AFK_CHANNEL" ) , value : msg . channel . guild . channels . get ( guild . afkChannelID ) . mention , inline : true , } ) ; if ( guild . afkTimeout !== 0 ) { fields . push ( { name : msg . string ( "general.SERVER_AFK_TIMEOUT" ) , value : `${ afkTimeoutFormat ( msg . string , guild . afkTimeout ) }` , inline : true , } ) ; } } if ( guild . premiumSubscriptionCount > 0 ) fields . push ( { name : msg . string ( "general.SERVER_BOOSTERS" ) , value : `${ guild . premiumSubscriptionCount }` , inline : true , } ) ; if ( guild . premiumTier > 0 ) fields . push ( { name : msg . string ( "general.SERVER_BOOSTLEVEL" ) , value : `${ guild . premiumTier }` , inline : true , } ) ; if ( guild . preferredLocale && guild . preferredLocale !== "en-US" ) fields . push ( { name : msg . string ( "general.SERVER_PREFERRED_LANGUAGE" ) , value : guild . preferredLocale , inline : true , } ) ; if ( communityChannels . length ) { fields . push ( { name : msg . string ( "general.SERVER_COMMUNITY_CHANNELS" ) , value : `${ communityChannels . map ( ( c ) => `${ c . value }: ${ c . name }` ) . join ( "\n" ) }` , inline : false , } ) ; } if ( guild . features . length ) fields . push ( { name : msg . string ( "general.SERVER_FEATURES" ) , value : featureFormat ( msg . string , guild . features ) . join ( ", " ) , inline : false , } ) ; msg . channel . createMessage ( { embed : { description : `${ guild . description ?? "" }` , color : msg . convertHex ( "general" ) , fields : fields , author : { icon_url : guild . iconURL || defaultAvatar , name : guild . name , } , thumbnail : { url : guild . iconURL || defaultAvatar , } , footer : { text : msg . string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) } ) , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) ; } }