2022-03-19 10:37:45 +00:00
'use strict' ;
const process = require ( 'node:process' ) ;
const { ChannelType , MessageType } = require ( 'discord-api-types/v9' ) ;
const Package = ( exports . Package = require ( '../../package.json' ) ) ;
exports . UserAgent = ` Mozilla/5.0 (iPhone; CPU iPhone OS 15_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1 ` ;
/ * *
* The name of an item to be swept in Sweepers
* * ` applicationCommands ` - both global and guild commands
* * ` bans `
* * ` emojis `
* * ` invites ` - accepts the ` lifetime ` property , using it will sweep based on expires timestamp
* * ` guildMembers `
* * ` messages ` - accepts the ` lifetime ` property , using it will sweep based on edited or created timestamp
* * ` presences `
* * ` reactions `
* * ` stageInstances `
* * ` stickers `
* * ` threadMembers `
* * ` threads ` - accepts the ` lifetime ` property , using it will sweep archived threads based on archived timestamp
* * ` users `
* * ` voiceStates `
* @ typedef { string } SweeperKey
* /
exports . SweeperKeys = [
'applicationCommands' ,
'bans' ,
'emojis' ,
'invites' ,
'guildMembers' ,
'messages' ,
'presences' ,
'reactions' ,
'stageInstances' ,
'stickers' ,
'threadMembers' ,
'threads' ,
'users' ,
'voiceStates' ,
] ;
/ * *
* The types of messages that are not ` System ` . The available types are :
* * { @ link MessageType . Default }
* * { @ link MessageType . Reply }
* * { @ link MessageType . ChatInputCommand }
* * { @ link MessageType . ContextMenuCommand }
* @ typedef { MessageType [ ] } NonSystemMessageTypes
* /
exports . NonSystemMessageTypes = [
MessageType . Default ,
MessageType . Reply ,
MessageType . ChatInputCommand ,
MessageType . ContextMenuCommand ,
] ;
/ * *
* The channels that are text - based .
* * DMChannel
* * TextChannel
* * NewsChannel
* * ThreadChannel
* @ typedef { DMChannel | TextChannel | NewsChannel | ThreadChannel } TextBasedChannels
* /
/ * *
* The types of channels that are text - based . The available types are :
* * { @ link ChannelType . DM }
* * { @ link ChannelType . GuildText }
* * { @ link ChannelType . GuildNews }
* * { @ link ChannelType . GuildNewsThread }
* * { @ link ChannelType . GuildPublicThread }
* * { @ link ChannelType . GuildPrivateThread }
* @ typedef { ChannelType } TextBasedChannelTypes
* /
exports . TextBasedChannelTypes = [
ChannelType . DM ,
ChannelType . GuildText ,
ChannelType . GuildNews ,
ChannelType . GuildNewsThread ,
ChannelType . GuildPublicThread ,
ChannelType . GuildPrivateThread ,
] ;
/ * *
* The types of channels that are threads . The available types are :
* * { @ link ChannelType . GuildNewsThread }
* * { @ link ChannelType . GuildPublicThread }
* * { @ link ChannelType . GuildPrivateThread }
* @ typedef { ChannelType [ ] } ThreadChannelTypes
* /
exports . ThreadChannelTypes = [
ChannelType . GuildNewsThread ,
ChannelType . GuildPublicThread ,
ChannelType . GuildPrivateThread ,
] ;
/ * *
* The types of channels that are voice - based . The available types are :
* * { @ link ChannelType . GuildVoice }
* * { @ link ChannelType . GuildStageVoice }
* @ typedef { ChannelType [ ] } VoiceBasedChannelTypes
* /
exports . VoiceBasedChannelTypes = [ ChannelType . GuildVoice , ChannelType . GuildStageVoice ] ;
/* eslint-enable max-len */
/ * *
* @ typedef { Object } Constants Constants that can be used in an enum or object - like way .
* @ property { Status } Status The available statuses of the client .
* /
exports . Events = {
RATE _LIMIT : 'rateLimit' ,
INVALID _REQUEST _WARNING : 'invalidRequestWarning' ,
API _RESPONSE : 'apiResponse' ,
API _REQUEST : 'apiRequest' ,
CLIENT _READY : 'ready' ,
/ * *
* @ deprecated See { @ link https : //github.com/discord/discord-api-docs/issues/3690 this issue} for more information.
* /
APPLICATION _COMMAND _CREATE : 'applicationCommandCreate' ,
/ * *
* @ deprecated See { @ link https : //github.com/discord/discord-api-docs/issues/3690 this issue} for more information.
* /
APPLICATION _COMMAND _DELETE : 'applicationCommandDelete' ,
/ * *
* @ deprecated See { @ link https : //github.com/discord/discord-api-docs/issues/3690 this issue} for more information.
* /
APPLICATION _COMMAND _UPDATE : 'applicationCommandUpdate' ,
GUILD _CREATE : 'guildCreate' ,
GUILD _DELETE : 'guildDelete' ,
GUILD _UPDATE : 'guildUpdate' ,
GUILD _UNAVAILABLE : 'guildUnavailable' ,
GUILD _MEMBER _ADD : 'guildMemberAdd' ,
GUILD _MEMBER _REMOVE : 'guildMemberRemove' ,
GUILD _MEMBER _UPDATE : 'guildMemberUpdate' ,
GUILD _MEMBER _AVAILABLE : 'guildMemberAvailable' ,
GUILD _MEMBERS _CHUNK : 'guildMembersChunk' ,
GUILD _INTEGRATIONS _UPDATE : 'guildIntegrationsUpdate' ,
GUILD _ROLE _CREATE : 'roleCreate' ,
GUILD _ROLE _DELETE : 'roleDelete' ,
INVITE _CREATE : 'inviteCreate' ,
INVITE _DELETE : 'inviteDelete' ,
GUILD _ROLE _UPDATE : 'roleUpdate' ,
GUILD _EMOJI _CREATE : 'emojiCreate' ,
GUILD _EMOJI _DELETE : 'emojiDelete' ,
GUILD _EMOJI _UPDATE : 'emojiUpdate' ,
GUILD _BAN _ADD : 'guildBanAdd' ,
GUILD _BAN _REMOVE : 'guildBanRemove' ,
CHANNEL _CREATE : 'channelCreate' ,
CHANNEL _DELETE : 'channelDelete' ,
CHANNEL _UPDATE : 'channelUpdate' ,
CHANNEL _PINS _UPDATE : 'channelPinsUpdate' ,
MESSAGE _CREATE : 'messageCreate' ,
MESSAGE _DELETE : 'messageDelete' ,
MESSAGE _UPDATE : 'messageUpdate' ,
MESSAGE _BULK _DELETE : 'messageDeleteBulk' ,
MESSAGE _REACTION _ADD : 'messageReactionAdd' ,
MESSAGE _REACTION _REMOVE : 'messageReactionRemove' ,
MESSAGE _REACTION _REMOVE _ALL : 'messageReactionRemoveAll' ,
MESSAGE _REACTION _REMOVE _EMOJI : 'messageReactionRemoveEmoji' ,
THREAD _CREATE : 'threadCreate' ,
THREAD _DELETE : 'threadDelete' ,
THREAD _UPDATE : 'threadUpdate' ,
THREAD _LIST _SYNC : 'threadListSync' ,
THREAD _MEMBER _UPDATE : 'threadMemberUpdate' ,
THREAD _MEMBERS _UPDATE : 'threadMembersUpdate' ,
USER _UPDATE : 'userUpdate' ,
PRESENCE _UPDATE : 'presenceUpdate' ,
VOICE _SERVER _UPDATE : 'voiceServerUpdate' ,
VOICE _STATE _UPDATE : 'voiceStateUpdate' ,
TYPING _START : 'typingStart' ,
WEBHOOKS _UPDATE : 'webhookUpdate' ,
INTERACTION _CREATE : 'interactionCreate' ,
ERROR : 'error' ,
WARN : 'warn' ,
DEBUG : 'debug' ,
CACHE _SWEEP : 'cacheSweep' ,
SHARD _DISCONNECT : 'shardDisconnect' ,
SHARD _ERROR : 'shardError' ,
SHARD _RECONNECTING : 'shardReconnecting' ,
SHARD _READY : 'shardReady' ,
SHARD _RESUME : 'shardResume' ,
INVALIDATED : 'invalidated' ,
RAW : 'raw' ,
STAGE _INSTANCE _CREATE : 'stageInstanceCreate' ,
STAGE _INSTANCE _UPDATE : 'stageInstanceUpdate' ,
STAGE _INSTANCE _DELETE : 'stageInstanceDelete' ,
GUILD _STICKER _CREATE : 'stickerCreate' ,
GUILD _STICKER _DELETE : 'stickerDelete' ,
GUILD _STICKER _UPDATE : 'stickerUpdate' ,
GUILD _SCHEDULED _EVENT _CREATE : 'guildScheduledEventCreate' ,
GUILD _SCHEDULED _EVENT _UPDATE : 'guildScheduledEventUpdate' ,
GUILD _SCHEDULED _EVENT _DELETE : 'guildScheduledEventDelete' ,
GUILD _SCHEDULED _EVENT _USER _ADD : 'guildScheduledEventUserAdd' ,
GUILD _SCHEDULED _EVENT _USER _REMOVE : 'guildScheduledEventUserRemove' ,
} ;
2022-03-23 11:36:58 +00:00
const AllowedImageFormats = [ 'webp' , 'png' , 'jpg' , 'jpeg' , 'gif' ] ;
const AllowedImageSizes = [
16 , 32 , 56 , 64 , 96 , 128 , 256 , 300 , 512 , 600 , 1024 , 2048 , 4096 ,
] ;
2022-03-19 10:37:45 +00:00
function makeImageUrl ( root , { format = 'webp' , size } = { } ) {
if ( ! [ 'undefined' , 'number' ] . includes ( typeof size ) ) throw new TypeError ( 'INVALID_TYPE' , 'size' , 'number' ) ;
if ( format && ! AllowedImageFormats . includes ( format ) ) throw new Error ( 'IMAGE_FORMAT' , format ) ;
if ( size && ! AllowedImageSizes . includes ( size ) ) throw new RangeError ( 'IMAGE_SIZE' , size ) ;
return ` ${ root } . ${ format } ${ size ? ` ?size= ${ size } ` : '' } ` ;
}
/ * *
* Options for Image URLs .
* @ typedef { StaticImageURLOptions } ImageURLOptions
* @ property { boolean } [ dynamic = false ] If true , the format will dynamically change to ` gif ` for animated avatars .
* /
/ * *
* Options for static Image URLs .
* @ typedef { Object } StaticImageURLOptions
* @ property { string } [ format = 'webp' ] One of ` webp ` , ` png ` , ` jpg ` , ` jpeg ` .
* @ property { number } [ size ] One of ` 16 ` , ` 32 ` , ` 56 ` , ` 64 ` , ` 96 ` , ` 128 ` , ` 256 ` , ` 300 ` , ` 512 ` , ` 600 ` , ` 1024 ` , ` 2048 ` ,
* ` 4096 `
* /
// https://discord.com/developers/docs/reference#image-formatting-cdn-endpoints
exports . Endpoints = {
CDN ( root ) {
return {
Emoji : ( emojiId , format = 'webp' ) => ` ${ root } /emojis/ ${ emojiId } . ${ format } ` ,
Asset : name => ` ${ root } /assets/ ${ name } ` ,
DefaultAvatar : discriminator => ` ${ root } /embed/avatars/ ${ discriminator } .png ` ,
Avatar : ( userId , hash , format , size , dynamic = false ) => {
if ( dynamic && hash . startsWith ( 'a_' ) ) format = 'gif' ;
return makeImageUrl ( ` ${ root } /avatars/ ${ userId } / ${ hash } ` , { format , size } ) ;
} ,
GuildMemberAvatar : ( guildId , memberId , hash , format = 'webp' , size , dynamic = false ) => {
if ( dynamic && hash . startsWith ( 'a_' ) ) format = 'gif' ;
return makeImageUrl ( ` ${ root } /guilds/ ${ guildId } /users/ ${ memberId } /avatars/ ${ hash } ` , { format , size } ) ;
} ,
Banner : ( id , hash , format , size , dynamic = false ) => {
if ( dynamic && hash . startsWith ( 'a_' ) ) format = 'gif' ;
return makeImageUrl ( ` ${ root } /banners/ ${ id } / ${ hash } ` , { format , size } ) ;
} ,
Icon : ( guildId , hash , format , size , dynamic = false ) => {
if ( dynamic && hash . startsWith ( 'a_' ) ) format = 'gif' ;
return makeImageUrl ( ` ${ root } /icons/ ${ guildId } / ${ hash } ` , { format , size } ) ;
} ,
AppIcon : ( appId , hash , options ) => makeImageUrl ( ` ${ root } /app-icons/ ${ appId } / ${ hash } ` , options ) ,
AppAsset : ( appId , hash , options ) => makeImageUrl ( ` ${ root } /app-assets/ ${ appId } / ${ hash } ` , options ) ,
StickerPackBanner : ( bannerId , format , size ) =>
makeImageUrl ( ` ${ root } /app-assets/710982414301790216/store/ ${ bannerId } ` , { size , format } ) ,
GDMIcon : ( channelId , hash , format , size ) =>
makeImageUrl ( ` ${ root } /channel-icons/ ${ channelId } / ${ hash } ` , { size , format } ) ,
Splash : ( guildId , hash , format , size ) => makeImageUrl ( ` ${ root } /splashes/ ${ guildId } / ${ hash } ` , { size , format } ) ,
DiscoverySplash : ( guildId , hash , format , size ) =>
makeImageUrl ( ` ${ root } /discovery-splashes/ ${ guildId } / ${ hash } ` , { size , format } ) ,
TeamIcon : ( teamId , hash , options ) => makeImageUrl ( ` ${ root } /team-icons/ ${ teamId } / ${ hash } ` , options ) ,
Sticker : ( stickerId , stickerFormat ) =>
` ${ root } /stickers/ ${ stickerId } . ${ stickerFormat === 'LOTTIE' ? 'json' : 'png' } ` ,
RoleIcon : ( roleId , hash , format = 'webp' , size ) =>
makeImageUrl ( ` ${ root } /role-icons/ ${ roleId } / ${ hash } ` , { size , format } ) ,
} ;
} ,
invite : ( root , code , eventId ) => ( eventId ? ` ${ root } / ${ code } ?event= ${ eventId } ` : ` ${ root } / ${ code } ` ) ,
scheduledEvent : ( root , guildId , eventId ) => ` ${ root } / ${ guildId } / ${ eventId } ` ,
botGateway : '/gateway/bot' ,
} ;