@biggy1337/discord-sbjs 1.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +147 -0
- package/package.json +80 -0
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +110 -0
- package/src/client/Client.js +1076 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +133 -0
- package/src/client/actions/ActionsManager.js +80 -0
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
- package/src/client/actions/AutoModerationActionExecution.js +27 -0
- package/src/client/actions/AutoModerationRuleCreate.js +28 -0
- package/src/client/actions/AutoModerationRuleDelete.js +32 -0
- package/src/client/actions/AutoModerationRuleUpdate.js +30 -0
- package/src/client/actions/ChannelCreate.js +23 -0
- package/src/client/actions/ChannelDelete.js +39 -0
- package/src/client/actions/ChannelUpdate.js +43 -0
- package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
- package/src/client/actions/GuildBanAdd.js +20 -0
- package/src/client/actions/GuildBanRemove.js +25 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
- package/src/client/actions/GuildDelete.js +65 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +21 -0
- package/src/client/actions/GuildEmojiUpdate.js +20 -0
- package/src/client/actions/GuildEmojisUpdate.js +34 -0
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +33 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +31 -0
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +31 -0
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
- package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
- package/src/client/actions/GuildStickerCreate.js +20 -0
- package/src/client/actions/GuildStickerDelete.js +21 -0
- package/src/client/actions/GuildStickerUpdate.js +20 -0
- package/src/client/actions/GuildStickersUpdate.js +34 -0
- package/src/client/actions/GuildUpdate.js +33 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +50 -0
- package/src/client/actions/MessageDelete.js +34 -0
- package/src/client/actions/MessageDeleteBulk.js +43 -0
- package/src/client/actions/MessagePollVoteAdd.js +33 -0
- package/src/client/actions/MessagePollVoteRemove.js +33 -0
- package/src/client/actions/MessageReactionAdd.js +71 -0
- package/src/client/actions/MessageReactionRemove.js +39 -0
- package/src/client/actions/MessageReactionRemoveAll.js +36 -0
- package/src/client/actions/MessageReactionRemoveEmoji.js +30 -0
- package/src/client/actions/MessageUpdate.js +28 -0
- package/src/client/actions/PresenceUpdate.js +55 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +33 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +32 -0
- package/src/client/actions/ThreadListSync.js +60 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +38 -0
- package/src/client/actions/TypingStart.js +31 -0
- package/src/client/actions/UserUpdate.js +35 -0
- package/src/client/actions/VoiceStateUpdate.js +63 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +162 -0
- package/src/client/voice/StreamEventRouter.js +60 -0
- package/src/client/voice/VoiceConnection.js +1173 -0
- package/src/client/voice/dispatcher/AnnexBDispatcher.js +120 -0
- package/src/client/voice/dispatcher/AudioDispatcher.js +145 -0
- package/src/client/voice/dispatcher/BaseDispatcher.js +459 -0
- package/src/client/voice/dispatcher/VPxDispatcher.js +54 -0
- package/src/client/voice/dispatcher/VideoDispatcher.js +68 -0
- package/src/client/voice/networking/VoiceUDPClient.js +187 -0
- package/src/client/voice/networking/VoiceWebSocket.js +347 -0
- package/src/client/voice/player/MediaPlayer.js +321 -0
- package/src/client/voice/player/processing/AnnexBNalSplitter.js +244 -0
- package/src/client/voice/player/processing/IvfSplitter.js +106 -0
- package/src/client/voice/player/processing/PCMInsertSilence.js +37 -0
- package/src/client/voice/receiver/PacketHandler.js +260 -0
- package/src/client/voice/receiver/Receiver.js +96 -0
- package/src/client/voice/receiver/Recorder.js +191 -0
- package/src/client/voice/util/Function.js +116 -0
- package/src/client/voice/util/PlayInterface.js +122 -0
- package/src/client/voice/util/Secretbox.js +64 -0
- package/src/client/voice/util/Silence.js +16 -0
- package/src/client/voice/util/Socket.js +62 -0
- package/src/client/voice/util/VolumeInterface.js +104 -0
- package/src/client/websocket/DispatchTable.js +7 -0
- package/src/client/websocket/GatewaySendScheduler.js +122 -0
- package/src/client/websocket/WebSocketManager.js +439 -0
- package/src/client/websocket/WebSocketShard.js +1085 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
- package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
- package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +19 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_CREATE.js +51 -0
- package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +45 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +12 -0
- package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/READY.js +156 -0
- package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +19 -0
- package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +17 -0
- package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +41 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +6 -0
- package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +82 -0
- package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +16 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +12 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/index.js +84 -0
- package/src/errors/DJSError.js +61 -0
- package/src/errors/Messages.js +218 -0
- package/src/errors/index.js +4 -0
- package/src/index.js +172 -0
- package/src/managers/ApplicationCommandManager.js +264 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +417 -0
- package/src/managers/AutoModerationRuleManager.js +296 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/BillingManager.js +66 -0
- package/src/managers/CachedManager.js +72 -0
- package/src/managers/ChannelManager.js +148 -0
- package/src/managers/ClientUserSettingManager.js +372 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/DeveloperManager.js +265 -0
- package/src/managers/GuildBanManager.js +252 -0
- package/src/managers/GuildChannelManager.js +488 -0
- package/src/managers/GuildEmojiManager.js +171 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildForumThreadManager.js +108 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +401 -0
- package/src/managers/GuildMemberManager.js +608 -0
- package/src/managers/GuildMemberRoleManager.js +195 -0
- package/src/managers/GuildScheduledEventManager.js +314 -0
- package/src/managers/GuildSettingManager.js +155 -0
- package/src/managers/GuildStickerManager.js +179 -0
- package/src/managers/GuildTextThreadManager.js +98 -0
- package/src/managers/InteractionManager.js +39 -0
- package/src/managers/MessageManager.js +457 -0
- package/src/managers/PermissionOverwriteManager.js +169 -0
- package/src/managers/PresenceManager.js +71 -0
- package/src/managers/QuestManager.js +391 -0
- package/src/managers/ReactionManager.js +67 -0
- package/src/managers/ReactionUserManager.js +73 -0
- package/src/managers/RelationshipManager.js +341 -0
- package/src/managers/RoleManager.js +448 -0
- package/src/managers/SessionManager.js +66 -0
- package/src/managers/StageInstanceManager.js +162 -0
- package/src/managers/ThreadManager.js +175 -0
- package/src/managers/ThreadMemberManager.js +186 -0
- package/src/managers/UserManager.js +274 -0
- package/src/managers/UserNoteManager.js +53 -0
- package/src/managers/VoiceStateManager.js +59 -0
- package/src/rest/APIRequest.js +198 -0
- package/src/rest/APIRouter.js +94 -0
- package/src/rest/DiscordAPIError.js +120 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +203 -0
- package/src/rest/RateLimitCoordinator.js +156 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +552 -0
- package/src/sharding/Shard.js +444 -0
- package/src/sharding/ShardClientUtil.js +279 -0
- package/src/sharding/ShardingManager.js +319 -0
- package/src/structures/AnonymousGuild.js +98 -0
- package/src/structures/ApplicationCommand.js +593 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +48 -0
- package/src/structures/AutoModerationActionExecution.js +89 -0
- package/src/structures/AutoModerationRule.js +294 -0
- package/src/structures/AutocompleteInteraction.js +107 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseCommandInteraction.js +211 -0
- package/src/structures/BaseGuild.js +124 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +191 -0
- package/src/structures/BaseGuildVoiceChannel.js +241 -0
- package/src/structures/BaseMessageComponent.js +181 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/CallState.js +63 -0
- package/src/structures/CategoryChannel.js +85 -0
- package/src/structures/Channel.js +284 -0
- package/src/structures/ClientPresence.js +77 -0
- package/src/structures/ClientUser.js +706 -0
- package/src/structures/CommandInteraction.js +41 -0
- package/src/structures/CommandInteractionOptionResolver.js +276 -0
- package/src/structures/ContainerComponent.js +68 -0
- package/src/structures/ContextMenuInteraction.js +65 -0
- package/src/structures/DMChannel.js +222 -0
- package/src/structures/DirectoryChannel.js +20 -0
- package/src/structures/Emoji.js +148 -0
- package/src/structures/FileComponent.js +49 -0
- package/src/structures/ForumChannel.js +31 -0
- package/src/structures/GroupDMChannel.js +415 -0
- package/src/structures/Guild.js +1804 -0
- package/src/structures/GuildAuditLogs.js +746 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildBoost.js +108 -0
- package/src/structures/GuildChannel.js +470 -0
- package/src/structures/GuildEmoji.js +161 -0
- package/src/structures/GuildMember.js +636 -0
- package/src/structures/GuildPreview.js +191 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +536 -0
- package/src/structures/GuildTemplate.js +236 -0
- package/src/structures/Integration.js +188 -0
- package/src/structures/IntegrationApplication.js +96 -0
- package/src/structures/Interaction.js +290 -0
- package/src/structures/InteractionCollector.js +248 -0
- package/src/structures/InteractionWebhook.js +43 -0
- package/src/structures/Invite.js +358 -0
- package/src/structures/InviteGuild.js +23 -0
- package/src/structures/InviteStageInstance.js +86 -0
- package/src/structures/MediaChannel.js +11 -0
- package/src/structures/MediaGalleryComponent.js +41 -0
- package/src/structures/MediaGalleryItem.js +47 -0
- package/src/structures/Message.js +1272 -0
- package/src/structures/MessageActionRow.js +105 -0
- package/src/structures/MessageAttachment.js +216 -0
- package/src/structures/MessageButton.js +166 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +120 -0
- package/src/structures/MessageContextMenuInteraction.js +20 -0
- package/src/structures/MessageEmbed.js +596 -0
- package/src/structures/MessageMentions.js +273 -0
- package/src/structures/MessagePayload.js +354 -0
- package/src/structures/MessageReaction.js +181 -0
- package/src/structures/MessageSelectMenu.js +141 -0
- package/src/structures/Modal.js +161 -0
- package/src/structures/ModalSubmitFieldsResolver.js +53 -0
- package/src/structures/ModalSubmitInteraction.js +119 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PermissionOverwrites.js +198 -0
- package/src/structures/Poll.js +108 -0
- package/src/structures/PollAnswer.js +88 -0
- package/src/structures/Presence.js +1165 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/Role.js +590 -0
- package/src/structures/SectionComponent.js +48 -0
- package/src/structures/SelectMenuInteraction.js +21 -0
- package/src/structures/SeparatorComponent.js +48 -0
- package/src/structures/Session.js +81 -0
- package/src/structures/StageChannel.js +104 -0
- package/src/structures/StageInstance.js +208 -0
- package/src/structures/Sticker.js +310 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StoreChannel.js +56 -0
- package/src/structures/Team.js +118 -0
- package/src/structures/TeamMember.js +80 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextDisplayComponent.js +40 -0
- package/src/structures/TextInputComponent.js +132 -0
- package/src/structures/ThreadChannel.js +605 -0
- package/src/structures/ThreadMember.js +105 -0
- package/src/structures/ThreadOnlyChannel.js +249 -0
- package/src/structures/ThumbnailComponent.js +57 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/UnfurledMediaItem.js +29 -0
- package/src/structures/User.js +992 -0
- package/src/structures/UserContextMenuInteraction.js +29 -0
- package/src/structures/VoiceChannel.js +110 -0
- package/src/structures/VoiceChannelEffect.js +69 -0
- package/src/structures/VoiceRegion.js +53 -0
- package/src/structures/VoiceState.js +354 -0
- package/src/structures/WebEmbed.js +373 -0
- package/src/structures/Webhook.js +478 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +48 -0
- package/src/structures/Widget.js +87 -0
- package/src/structures/WidgetMember.js +100 -0
- package/src/structures/interfaces/Application.js +953 -0
- package/src/structures/interfaces/Collector.js +301 -0
- package/src/structures/interfaces/InteractionResponses.js +313 -0
- package/src/structures/interfaces/TextBasedChannel.js +821 -0
- package/src/util/APITypes.js +59 -0
- package/src/util/ActivityFlags.js +44 -0
- package/src/util/ApplicationFlags.js +76 -0
- package/src/util/AttachmentFlags.js +38 -0
- package/src/util/BitField.js +170 -0
- package/src/util/ChannelFlags.js +45 -0
- package/src/util/Constants.js +1953 -0
- package/src/util/DataResolver.js +162 -0
- package/src/util/FastQueue.js +93 -0
- package/src/util/FetchUtil.js +77 -0
- package/src/util/Formatters.js +228 -0
- package/src/util/GuildMemberFlags.js +43 -0
- package/src/util/Intents.js +74 -0
- package/src/util/InviteFlags.js +34 -0
- package/src/util/LimitedCollection.js +131 -0
- package/src/util/ListenerUtil.js +12 -0
- package/src/util/MessageFlags.js +63 -0
- package/src/util/Options.js +431 -0
- package/src/util/Permissions.js +202 -0
- package/src/util/PremiumUsageFlags.js +31 -0
- package/src/util/PurchasedFlags.js +33 -0
- package/src/util/RemoteAuth.js +425 -0
- package/src/util/RoleFlags.js +37 -0
- package/src/util/SnowflakeUtil.js +92 -0
- package/src/util/Speaking.js +33 -0
- package/src/util/Sweepers.js +493 -0
- package/src/util/SystemChannelFlags.js +55 -0
- package/src/util/ThreadMemberFlags.js +30 -0
- package/src/util/UserFlags.js +104 -0
- package/src/util/Util.js +1144 -0
- package/typings/enums.d.ts +437 -0
- package/typings/index.d.ts +8857 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +403 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { setInterval } = require('node:timers');
|
|
4
|
+
const { Collection } = require('@discordjs/collection');
|
|
5
|
+
const { _cleanupSymbol } = require('./Constants.js');
|
|
6
|
+
const Sweepers = require('./Sweepers.js');
|
|
7
|
+
const { TypeError } = require('../errors/DJSError.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Function} SweepFilter
|
|
11
|
+
* @param {LimitedCollection} collection The collection being swept
|
|
12
|
+
* @returns {Function|null} Return `null` to skip sweeping, otherwise a function passed to `sweep()`,
|
|
13
|
+
* See {@link [Collection#sweep](https://discord.js.org/docs/packages/collection/stable/Collection:Class#sweep)}
|
|
14
|
+
* for the definition of this function.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Options for defining the behavior of a LimitedCollection
|
|
19
|
+
* @typedef {Object} LimitedCollectionOptions
|
|
20
|
+
* @property {?number} [maxSize=Infinity] The maximum size of the Collection
|
|
21
|
+
* @property {?Function} [keepOverLimit=null] A function, which is passed the value and key of an entry, ran to decide
|
|
22
|
+
* to keep an entry past the maximum size
|
|
23
|
+
* @property {?SweepFilter} [sweepFilter=null] DEPRECATED: There is no direct alternative to this,
|
|
24
|
+
* however most of its purpose is fulfilled by {@link Client#sweepers}
|
|
25
|
+
* A function ran every `sweepInterval` to determine how to sweep
|
|
26
|
+
* @property {?number} [sweepInterval=0] DEPRECATED: There is no direct alternative to this,
|
|
27
|
+
* however most of its purpose is fulfilled by {@link Client#sweepers}
|
|
28
|
+
* How frequently, in seconds, to sweep the collection.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A Collection which holds a max amount of entries and sweeps periodically.
|
|
33
|
+
* @extends {Collection}
|
|
34
|
+
* @param {LimitedCollectionOptions} [options={}] Options for constructing the Collection.
|
|
35
|
+
* @param {Iterable} [iterable=null] Optional entries passed to the Map constructor.
|
|
36
|
+
*/
|
|
37
|
+
class LimitedCollection extends Collection {
|
|
38
|
+
constructor(options = {}, iterable) {
|
|
39
|
+
if (typeof options !== 'object' || options === null) {
|
|
40
|
+
throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
|
41
|
+
}
|
|
42
|
+
const { maxSize = Infinity, keepOverLimit = null, sweepInterval = 0, sweepFilter = null } = options;
|
|
43
|
+
|
|
44
|
+
if (typeof maxSize !== 'number') {
|
|
45
|
+
throw new TypeError('INVALID_TYPE', 'maxSize', 'number');
|
|
46
|
+
}
|
|
47
|
+
if (keepOverLimit !== null && typeof keepOverLimit !== 'function') {
|
|
48
|
+
throw new TypeError('INVALID_TYPE', 'keepOverLimit', 'function');
|
|
49
|
+
}
|
|
50
|
+
if (typeof sweepInterval !== 'number') {
|
|
51
|
+
throw new TypeError('INVALID_TYPE', 'sweepInterval', 'number');
|
|
52
|
+
}
|
|
53
|
+
if (sweepFilter !== null && typeof sweepFilter !== 'function') {
|
|
54
|
+
throw new TypeError('INVALID_TYPE', 'sweepFilter', 'function');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
super(iterable);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The max size of the Collection.
|
|
61
|
+
* @type {number}
|
|
62
|
+
*/
|
|
63
|
+
this.maxSize = maxSize;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A function called to check if an entry should be kept when the Collection is at max size.
|
|
67
|
+
* @type {?Function}
|
|
68
|
+
*/
|
|
69
|
+
this.keepOverLimit = keepOverLimit;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A function called every sweep interval that returns a function passed to `sweep`.
|
|
73
|
+
* @deprecated in favor of {@link Client#sweepers}
|
|
74
|
+
* @type {?SweepFilter}
|
|
75
|
+
*/
|
|
76
|
+
this.sweepFilter = sweepFilter;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The id of the interval being used to sweep.
|
|
80
|
+
* @deprecated in favor of {@link Client#sweepers}
|
|
81
|
+
* @type {?Timeout}
|
|
82
|
+
*/
|
|
83
|
+
this.interval =
|
|
84
|
+
sweepInterval > 0 && sweepInterval !== Infinity && sweepFilter
|
|
85
|
+
? setInterval(() => {
|
|
86
|
+
const sweepFn = this.sweepFilter(this);
|
|
87
|
+
if (sweepFn === null) return;
|
|
88
|
+
if (typeof sweepFn !== 'function') throw new TypeError('SWEEP_FILTER_RETURN');
|
|
89
|
+
this.sweep(sweepFn);
|
|
90
|
+
}, sweepInterval * 1_000).unref()
|
|
91
|
+
: null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
set(key, value) {
|
|
95
|
+
if (this.maxSize === 0) return this;
|
|
96
|
+
if (this.size >= this.maxSize && !this.has(key)) {
|
|
97
|
+
for (const [k, v] of this.entries()) {
|
|
98
|
+
const keep = this.keepOverLimit?.(v, k, this) ?? false;
|
|
99
|
+
if (!keep) {
|
|
100
|
+
this.delete(k);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return super.set(key, value);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Create a sweepFilter function that uses a lifetime to determine sweepability.
|
|
110
|
+
* @param {LifetimeFilterOptions} [options={}] The options used to generate the filter function
|
|
111
|
+
* @deprecated Use {@link Sweepers.filterByLifetime} instead
|
|
112
|
+
* @returns {SweepFilter}
|
|
113
|
+
*/
|
|
114
|
+
static filterByLifetime({
|
|
115
|
+
lifetime = 14400,
|
|
116
|
+
getComparisonTimestamp = e => e?.createdTimestamp,
|
|
117
|
+
excludeFromSweep = () => false,
|
|
118
|
+
} = {}) {
|
|
119
|
+
return Sweepers.filterByLifetime({ lifetime, getComparisonTimestamp, excludeFromSweep });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
[_cleanupSymbol]() {
|
|
123
|
+
return this.interval ? () => clearInterval(this.interval) : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static get [Symbol.species]() {
|
|
127
|
+
return Collection;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = LimitedCollection;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function hasListener(emitter, event) {
|
|
4
|
+
if (!emitter) return false;
|
|
5
|
+
if (typeof emitter.hasListenerFast === 'function') return emitter.hasListenerFast(event);
|
|
6
|
+
if (typeof emitter.listenerCount === 'function') return emitter.listenerCount(event) > 0;
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
hasListener,
|
|
12
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const BitField = require('./BitField');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Data structure that makes it easy to interact with a {@link Message#flags} bitfield.
|
|
7
|
+
* @extends {BitField}
|
|
8
|
+
*/
|
|
9
|
+
class MessageFlags extends BitField {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @name MessageFlags
|
|
13
|
+
* @kind constructor
|
|
14
|
+
* @memberof MessageFlags
|
|
15
|
+
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Bitfield of the packed bits
|
|
20
|
+
* @type {number}
|
|
21
|
+
* @name MessageFlags#bitfield
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Numeric message flags. All available properties:
|
|
26
|
+
* * `CROSSPOSTED`
|
|
27
|
+
* * `IS_CROSSPOST`
|
|
28
|
+
* * `SUPPRESS_EMBEDS`
|
|
29
|
+
* * `SOURCE_MESSAGE_DELETED`
|
|
30
|
+
* * `URGENT`
|
|
31
|
+
* * `HAS_THREAD`
|
|
32
|
+
* * `EPHEMERAL`
|
|
33
|
+
* * `LOADING`
|
|
34
|
+
* * `FAILED_TO_MENTION_SOME_ROLES_IN_THREAD`
|
|
35
|
+
* * `GUILD_FEED_HIDDEN`
|
|
36
|
+
* * `SHOULD_SHOW_LINK_NOT_DISCORD_WARNING`
|
|
37
|
+
* * `SUPPRESS_NOTIFICATIONS`
|
|
38
|
+
* * `IS_VOICE_MESSAGE`
|
|
39
|
+
* * `HAS_SNAPSHOT`
|
|
40
|
+
* * `IS_COMPONENTS_V2`
|
|
41
|
+
* @type {Object}
|
|
42
|
+
* @see {@link https://discord.com/developers/docs/resources/channel#message-object-message-flags}
|
|
43
|
+
* @see {@link https://docs.discord.food/resources/message#message-flags}
|
|
44
|
+
*/
|
|
45
|
+
MessageFlags.FLAGS = {
|
|
46
|
+
CROSSPOSTED: 1 << 0,
|
|
47
|
+
IS_CROSSPOST: 1 << 1,
|
|
48
|
+
SUPPRESS_EMBEDS: 1 << 2,
|
|
49
|
+
SOURCE_MESSAGE_DELETED: 1 << 3,
|
|
50
|
+
URGENT: 1 << 4,
|
|
51
|
+
HAS_THREAD: 1 << 5,
|
|
52
|
+
EPHEMERAL: 1 << 6,
|
|
53
|
+
LOADING: 1 << 7,
|
|
54
|
+
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 1 << 8,
|
|
55
|
+
GUILD_FEED_HIDDEN: 1 << 9,
|
|
56
|
+
SHOULD_SHOW_LINK_NOT_DISCORD_WARNING: 1 << 10,
|
|
57
|
+
SUPPRESS_NOTIFICATIONS: 1 << 12,
|
|
58
|
+
IS_VOICE_MESSAGE: 1 << 13,
|
|
59
|
+
HAS_SNAPSHOT: 1 << 14,
|
|
60
|
+
IS_COMPONENTS_V2: 1 << 15,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = MessageFlags;
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { randomUUID } = require('node:crypto');
|
|
4
|
+
const { UserAgent } = require('./Constants');
|
|
5
|
+
const Intents = require('./Intents');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Rate limit data
|
|
9
|
+
* @typedef {Object} RateLimitData
|
|
10
|
+
* @property {number} timeout Time until this rate limit ends, in milliseconds
|
|
11
|
+
* @property {number} limit The maximum amount of requests of this endpoint
|
|
12
|
+
* @property {string} method The HTTP method of this request
|
|
13
|
+
* @property {string} path The path of the request relative to the HTTP endpoint
|
|
14
|
+
* @property {string} route The route of the request relative to the HTTP endpoint
|
|
15
|
+
* @property {boolean} global Whether this is a global rate limit
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether this rate limit should throw an Error
|
|
20
|
+
* @typedef {Function} RateLimitQueueFilter
|
|
21
|
+
* @param {RateLimitData} rateLimitData The data of this rate limit
|
|
22
|
+
* @returns {boolean|Promise<boolean>}
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {Function} CacheFactory
|
|
27
|
+
* @param {Function} manager The manager class the cache is being requested from.
|
|
28
|
+
* @param {Function} holds The class that the cache will hold.
|
|
29
|
+
* @returns {Collection} A Collection used to store the cache of the manager.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {Function} CaptchaSolver
|
|
34
|
+
* @param {Captcha} captcha Discord Captcha
|
|
35
|
+
* @param {string} UserAgent Current UserAgent
|
|
36
|
+
* @returns {Promise<string>} HCaptcha Token
|
|
37
|
+
* @example
|
|
38
|
+
* async function solveCaptcha(captcha, userAgent) {
|
|
39
|
+
* const NOPECHA_KEY = process.env.NOPECHA_KEY;
|
|
40
|
+
* if (!NOPECHA_KEY) throw new Error('Missing NOPECHA_KEY environment variable');
|
|
41
|
+
*
|
|
42
|
+
* const createPayload = {
|
|
43
|
+
* key: NOPECHA_KEY,
|
|
44
|
+
* type: 'hcaptcha',
|
|
45
|
+
* sitekey: captcha.captcha_sitekey,
|
|
46
|
+
* url: 'https://discord.com',
|
|
47
|
+
* useragent: userAgent,
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* if (captcha.captcha_rqdata) {
|
|
51
|
+
* createPayload.data = { rqdata: captcha.captcha_rqdata };
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* const createRes = await fetch('https://api.nopecha.com/token/', {
|
|
55
|
+
* method: 'POST',
|
|
56
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
57
|
+
* body: JSON.stringify(createPayload),
|
|
58
|
+
* });
|
|
59
|
+
* const createBody = await createRes.json();
|
|
60
|
+
* if (!createRes.ok || createBody?.error) {
|
|
61
|
+
* throw new Error(`NopeCHA create failed ${createBody.message}`);
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* const taskId = createBody?.data;
|
|
65
|
+
* if (typeof taskId !== 'string' || taskId.length === 0) {
|
|
66
|
+
* throw new Error('NopeCHA create failed: missing task id');
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* const timeoutMs = 60_000;
|
|
70
|
+
* const pollEveryMs = 2_500;
|
|
71
|
+
* const startedAt = Date.now();
|
|
72
|
+
*
|
|
73
|
+
* while (Date.now() - startedAt < timeoutMs) {
|
|
74
|
+
* const query = new URLSearchParams({ key: NOPECHA_KEY, id: taskId });
|
|
75
|
+
* const pollRes = await fetch(`https://api.nopecha.com/token/?${query.toString()}`);
|
|
76
|
+
* const pollBody = await pollRes.json();
|
|
77
|
+
*
|
|
78
|
+
* if (pollBody?.error === 14) {
|
|
79
|
+
* await new Promise(resolve => setTimeout(resolve, pollEveryMs));
|
|
80
|
+
* continue;
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* if (!pollRes.ok || pollBody?.error) {
|
|
84
|
+
* throw new Error(`NopeCHA poll failed ${pollBody.message}`);
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* if (typeof pollBody?.data === 'string' && pollBody.data.length > 0) return pollBody.data;
|
|
88
|
+
* throw new Error('NopeCHA poll failed: missing captcha token');
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* throw new Error(`NopeCHA solve timeout after ${timeoutMs}ms`);
|
|
92
|
+
* }
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Options for a client.
|
|
97
|
+
* @typedef {Object} ClientOptions
|
|
98
|
+
* @property {number} [DMChannelVoiceStatusSync=0] The amount of time in milliseconds that the Client to register the event with each DM channel (0=Disable)
|
|
99
|
+
* @property {number} [captchaRetryLimit=3] Captcha retry limit
|
|
100
|
+
* @property {CaptchaSolver} [captchaSolver] Captcha Solver
|
|
101
|
+
* @property {string} [TOTPKey] TOTP key / 2FA Key for two-factor authentication
|
|
102
|
+
* This is a 32-character Base32 string (excluding spaces), typically shown only once during your 2FA setup (QR code), or in the "Manual Entry" section.
|
|
103
|
+
* The library automatically removes spaces and converts the secret to uppercase.
|
|
104
|
+
* Example value: 'ftc3 uz6q 5lpw 2kew 4thr vtyp n2cu topn' or 'WSLIVE6EKYSRMVRBZLFGG2KVIVJMMQY5'
|
|
105
|
+
* @property {number} [closeTimeout=5000] The amount of time in milliseconds to wait for the close frame to be received
|
|
106
|
+
* from the WebSocket.
|
|
107
|
+
* <info>Don't have this too high/low. It's best to have it between 2000-6000 ms.</info>
|
|
108
|
+
* (e.g. recommended shard count, shard count of the ShardingManager)
|
|
109
|
+
* @property {CacheFactory} [makeCache] Function to create a cache.
|
|
110
|
+
* You can use your own function, or the {@link Options} class to customize the Collection used for the cache.
|
|
111
|
+
* <warn>Overriding the cache used in `GuildManager`, `ChannelManager`, `GuildChannelManager`, `RoleManager`,
|
|
112
|
+
* and `PermissionOverwriteManager` is unsupported and **will** break functionality</warn>
|
|
113
|
+
* @property {number} [messageCacheLifetime=0] DEPRECATED: Pass `lifetime` to `sweepers.messages` instead.
|
|
114
|
+
* How long a message should stay in the cache until it is considered sweepable (in seconds, 0 for forever)
|
|
115
|
+
* @property {number} [messageSweepInterval=0] DEPRECATED: Pass `interval` to `sweepers.messages` instead.
|
|
116
|
+
* How frequently to remove messages from the cache that are older than the message cache lifetime
|
|
117
|
+
* (in seconds, 0 for never)
|
|
118
|
+
* @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions}
|
|
119
|
+
* @property {number} [invalidRequestWarningInterval=0] The number of invalid REST requests (those that return
|
|
120
|
+
* 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings). That is, if set to 500,
|
|
121
|
+
* warnings will be emitted at invalid request number 500, 1000, 1500, and so on.
|
|
122
|
+
* @property {PartialType[]} [partials=['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'GUILD_SCHEDULED_EVENT']] Structures allowed to be partial. This means events can be emitted even when
|
|
123
|
+
* they're missing all the data for a particular structure. See the "Partial Structures" topic on the
|
|
124
|
+
* [guide](https://discordjs.guide/popular-topics/partials.html) for some
|
|
125
|
+
* important usage information, as partials require you to put checks in place when handling data.
|
|
126
|
+
* @property {number} [restWsBridgeTimeout=5000] Maximum time permitted between REST responses and their
|
|
127
|
+
* corresponding WebSocket events
|
|
128
|
+
* @property {number} [restTimeOffset=500] Extra time in milliseconds to wait before continuing to make REST
|
|
129
|
+
* requests (higher values will reduce rate-limiting errors on bad connections)
|
|
130
|
+
* @property {number} [restRequestTimeout=15000] Time to wait before cancelling a REST request, in milliseconds
|
|
131
|
+
* @property {number} [restSweepInterval=60] How frequently to delete inactive request buckets, in seconds
|
|
132
|
+
* (or 0 for never)
|
|
133
|
+
* @property {number} [restGlobalRateLimit=50] How many requests to allow sending per second (0 for unlimited, 50 for
|
|
134
|
+
* the standard global limit used by Discord)
|
|
135
|
+
* @property {string[]|RateLimitQueueFilter} [rejectOnRateLimit] Decides how rate limits and pre-emptive throttles
|
|
136
|
+
* should be handled. If this option is an array containing the prefix of the request route (e.g. /channels to match any
|
|
137
|
+
* route starting with /channels, such as /channels/222197033908436994/messages) or a function returning true, a
|
|
138
|
+
* {@link RateLimitError} will be thrown. Otherwise the request will be queued for later
|
|
139
|
+
* @property {number} [retryLimit=1] How many times to retry on 5XX errors
|
|
140
|
+
* (Infinity for an indefinite amount of retries)
|
|
141
|
+
* @property {boolean} [failIfNotExists=true] Default value for {@link ReplyMessageOptions#failIfNotExists}
|
|
142
|
+
* @property {PresenceData} [presence={ status: 'online', since: 0, activities: [], afk: false }] Presence data to use upon login
|
|
143
|
+
* @property {number} [waitGuildTimeout=15_000] Time in milliseconds that Clients with the GUILDS intent should wait for
|
|
144
|
+
* missing guilds to be received before starting the bot. If not specified, the default is 15 seconds.
|
|
145
|
+
* @property {SweeperOptions} [sweepers={}] Options for cache sweeping
|
|
146
|
+
* @property {WebsocketOptions} [ws] Options for the WebSocket
|
|
147
|
+
* @property {HTTPOptions} [http] HTTP options
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Options for {@link Sweepers} defining the behavior of cache sweeping
|
|
152
|
+
* @typedef {Object<SweeperKey, SweepOptions>} SweeperOptions
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Options for sweeping a single type of item from cache
|
|
157
|
+
* @typedef {Object} SweepOptions
|
|
158
|
+
* @property {number} interval The interval (in seconds) at which to perform sweeping of the item
|
|
159
|
+
* @property {number} [lifetime] How long an item should stay in cache until it is considered sweepable.
|
|
160
|
+
* <warn>This property is only valid for the `invites`, `messages`, and `threads` keys. The `filter` property
|
|
161
|
+
* is mutually exclusive to this property and takes priority</warn>
|
|
162
|
+
* @property {GlobalSweepFilter} filter The function used to determine the function passed to the sweep method
|
|
163
|
+
* <info>This property is optional when the key is `invites`, `messages`, or `threads` and `lifetime` is set</info>
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* WebSocket options (these are left as snake_case to match the API)
|
|
168
|
+
* @typedef {Object} WebsocketOptions
|
|
169
|
+
* @property {AgentOptions} [agent={}] HTTPS Agent options (WS Proxy)
|
|
170
|
+
* @property {boolean} [compress=false] Whether to compress data sent on the connection
|
|
171
|
+
* @property {WebSocketProperties} [properties] Properties to identify the client with
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* HTTPS Agent options.
|
|
176
|
+
* @typedef {Object} AgentOptions
|
|
177
|
+
* @see {@link https://nodejs.org/api/https.html#https_class_https_agent}
|
|
178
|
+
* @see {@link https://nodejs.org/api/http.html#http_new_agent_options}
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Proxy options compatible with Bun's fetch `proxy` setting.
|
|
183
|
+
* @typedef {Object} ProxyAgentOptions
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* HTTP options.
|
|
188
|
+
* The module is designed to be self-contained: by default it uses Bun's native fetch and WebSocket
|
|
189
|
+
* without external HTTP clients or binaries. All endpoints are configurable.
|
|
190
|
+
* @typedef {Object} HTTPOptions
|
|
191
|
+
* @property {number} [version=9] API version to use
|
|
192
|
+
* @property {ProxyAgentOptions} [agent={}] Proxy options for Bun fetch
|
|
193
|
+
* @property {Function} [fetch] Optional fetch override. Must match the standard fetch(url, options) signature.
|
|
194
|
+
* If not provided, uses Bun's native fetch. Use this to inject a custom implementation (e.g. TLS-impersonating
|
|
195
|
+
* fetch) without adding dependencies to the package.
|
|
196
|
+
* @property {boolean} [tlsFingerprint=false] Use Impit for TLS fingerprint impersonation (Chrome-like ClientHello).
|
|
197
|
+
* @property {string} [api='https://discord.com/api'] Base URL of the API
|
|
198
|
+
* @property {string} [cdn='https://cdn.discordapp.com'] Base URL of the CDN
|
|
199
|
+
* @property {string} [invite='https://discord.gg'] Base URL of invites
|
|
200
|
+
* @property {string} [template='https://discord.new'] Base URL of templates
|
|
201
|
+
* @property {Object} [headers] Additional headers to send for all API requests
|
|
202
|
+
* @property {string} [scheduledEvent='https://discord.com/events'] Base URL of guild scheduled events
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Contains various utilities for client options.
|
|
207
|
+
*/
|
|
208
|
+
class Options extends null {
|
|
209
|
+
/**
|
|
210
|
+
* The default client options.
|
|
211
|
+
* @returns {ClientOptions}
|
|
212
|
+
*/
|
|
213
|
+
static createDefault() {
|
|
214
|
+
return {
|
|
215
|
+
DMChannelVoiceStatusSync: 0,
|
|
216
|
+
captchaRetryLimit: 3,
|
|
217
|
+
captchaSolver: () => {
|
|
218
|
+
const err = new Error('CAPTCHA_SOLVER_NOT_IMPLEMENTED');
|
|
219
|
+
err.cause =
|
|
220
|
+
'You need to provide a captcha solver to use this feature\nExample: const client = new Client({ captchaSolver: yourAsyncFunction })';
|
|
221
|
+
throw err;
|
|
222
|
+
},
|
|
223
|
+
TOTPKey: null,
|
|
224
|
+
closeTimeout: 5_000,
|
|
225
|
+
waitGuildTimeout: 15_000,
|
|
226
|
+
shardCount: 1,
|
|
227
|
+
shards: [0],
|
|
228
|
+
makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings),
|
|
229
|
+
messageCacheLifetime: 0,
|
|
230
|
+
messageSweepInterval: 0,
|
|
231
|
+
invalidRequestWarningInterval: 0,
|
|
232
|
+
intents: Intents.ALL,
|
|
233
|
+
partials: ['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'GUILD_SCHEDULED_EVENT'], // Enable the partials
|
|
234
|
+
restWsBridgeTimeout: 5_000,
|
|
235
|
+
restRequestTimeout: 15_000,
|
|
236
|
+
restGlobalRateLimit: 50,
|
|
237
|
+
retryLimit: 1,
|
|
238
|
+
restTimeOffset: 500,
|
|
239
|
+
restSweepInterval: 60,
|
|
240
|
+
failIfNotExists: true,
|
|
241
|
+
presence: { status: 'online', since: 0, activities: [], afk: true },
|
|
242
|
+
sweepers: this.defaultSweeperSettings,
|
|
243
|
+
ws: {
|
|
244
|
+
capabilities: (1 << 2) | (1 << 3) | (1 << 4) | (1 << 10),
|
|
245
|
+
properties: {
|
|
246
|
+
os: 'Windows',
|
|
247
|
+
browser: 'Discord Client',
|
|
248
|
+
release_channel: 'stable',
|
|
249
|
+
client_version: '1.0.9210',
|
|
250
|
+
os_version: '10.0.19045',
|
|
251
|
+
os_arch: 'x64',
|
|
252
|
+
app_arch: 'x64',
|
|
253
|
+
system_locale: 'en-US',
|
|
254
|
+
has_client_mods: false,
|
|
255
|
+
client_launch_id: randomUUID(),
|
|
256
|
+
browser_user_agent: UserAgent,
|
|
257
|
+
browser_version: '134.0.6998.205',
|
|
258
|
+
os_sdk_version: '19045',
|
|
259
|
+
client_build_number: 471091,
|
|
260
|
+
native_build_number: 72186,
|
|
261
|
+
client_event_source: null,
|
|
262
|
+
launch_signature: randomUUID(),
|
|
263
|
+
client_heartbeat_session_id: randomUUID(),
|
|
264
|
+
client_app_state: 'focused',
|
|
265
|
+
},
|
|
266
|
+
compress: false,
|
|
267
|
+
useQosHeartbeat: true,
|
|
268
|
+
client_state: {
|
|
269
|
+
guild_versions: {},
|
|
270
|
+
},
|
|
271
|
+
version: 9,
|
|
272
|
+
agent: {},
|
|
273
|
+
},
|
|
274
|
+
http: {
|
|
275
|
+
agent: {},
|
|
276
|
+
tlsFingerprint: false,
|
|
277
|
+
headers: {
|
|
278
|
+
'User-Agent': UserAgent,
|
|
279
|
+
},
|
|
280
|
+
version: 9,
|
|
281
|
+
api: 'https://discord.com/api',
|
|
282
|
+
cdn: 'https://cdn.discordapp.com',
|
|
283
|
+
invite: 'https://discord.gg',
|
|
284
|
+
template: 'https://discord.new',
|
|
285
|
+
scheduledEvent: 'https://discord.com/events',
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Create a cache factory using predefined settings to sweep or limit.
|
|
292
|
+
* @param {Object<string, LimitedCollectionOptions|number>} [settings={}] Settings passed to the relevant constructor.
|
|
293
|
+
* If no setting is provided for a manager, it uses Collection.
|
|
294
|
+
* If a number is provided for a manager, it uses that number as the max size for a LimitedCollection.
|
|
295
|
+
* If LimitedCollectionOptions are provided for a manager, it uses those settings to form a LimitedCollection.
|
|
296
|
+
* @returns {CacheFactory}
|
|
297
|
+
* @example
|
|
298
|
+
* // Store up to 200 messages per channel and discard archived threads if they were archived more than 4 hours ago.
|
|
299
|
+
* // Note archived threads will remain in the guild and client caches with these settings
|
|
300
|
+
* Options.cacheWithLimits({
|
|
301
|
+
* MessageManager: 200,
|
|
302
|
+
* ThreadManager: {
|
|
303
|
+
* sweepInterval: 3600,
|
|
304
|
+
* sweepFilter: LimitedCollection.filterByLifetime({
|
|
305
|
+
* getComparisonTimestamp: e => e.archiveTimestamp,
|
|
306
|
+
* excludeFromSweep: e => !e.archived,
|
|
307
|
+
* }),
|
|
308
|
+
* },
|
|
309
|
+
* });
|
|
310
|
+
* @example
|
|
311
|
+
* // Sweep messages every 5 minutes, removing messages that have not been edited or created in the last 30 minutes
|
|
312
|
+
* Options.cacheWithLimits({
|
|
313
|
+
* // Keep default thread sweeping behavior
|
|
314
|
+
* ...Options.defaultMakeCacheSettings,
|
|
315
|
+
* // Override MessageManager
|
|
316
|
+
* MessageManager: {
|
|
317
|
+
* sweepInterval: 300,
|
|
318
|
+
* sweepFilter: LimitedCollection.filterByLifetime({
|
|
319
|
+
* lifetime: 1800,
|
|
320
|
+
* getComparisonTimestamp: e => e.editedTimestamp ?? e.createdTimestamp,
|
|
321
|
+
* })
|
|
322
|
+
* }
|
|
323
|
+
* });
|
|
324
|
+
*/
|
|
325
|
+
static cacheWithLimits(settings = {}) {
|
|
326
|
+
const { Collection } = require('@discordjs/collection');
|
|
327
|
+
const LimitedCollection = require('./LimitedCollection');
|
|
328
|
+
|
|
329
|
+
return manager => {
|
|
330
|
+
const setting = settings[manager.name];
|
|
331
|
+
/* eslint-disable-next-line eqeqeq */
|
|
332
|
+
if (setting == null) {
|
|
333
|
+
return new Collection();
|
|
334
|
+
}
|
|
335
|
+
if (typeof setting === 'number') {
|
|
336
|
+
if (setting === Infinity) {
|
|
337
|
+
return new Collection();
|
|
338
|
+
}
|
|
339
|
+
return new LimitedCollection({ maxSize: setting });
|
|
340
|
+
}
|
|
341
|
+
/* eslint-disable eqeqeq */
|
|
342
|
+
const noSweeping =
|
|
343
|
+
setting.sweepFilter == null ||
|
|
344
|
+
setting.sweepInterval == null ||
|
|
345
|
+
setting.sweepInterval <= 0 ||
|
|
346
|
+
setting.sweepInterval === Infinity;
|
|
347
|
+
const noLimit = setting.maxSize == null || setting.maxSize === Infinity;
|
|
348
|
+
/* eslint-enable eqeqeq */
|
|
349
|
+
if (noSweeping && noLimit) {
|
|
350
|
+
return new Collection();
|
|
351
|
+
}
|
|
352
|
+
return new LimitedCollection(setting);
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Create a cache factory that always caches everything.
|
|
358
|
+
* @returns {CacheFactory}
|
|
359
|
+
*/
|
|
360
|
+
static cacheEverything() {
|
|
361
|
+
const { Collection } = require('@discordjs/collection');
|
|
362
|
+
return () => new Collection();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The default settings passed to {@link ClientOptions.makeCache}.
|
|
367
|
+
* The caches that this changes are bounded to prevent unbounded growth.
|
|
368
|
+
* <info>If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g.
|
|
369
|
+
* `makeCache: Options.cacheWithLimits({ ...Options.defaultMakeCacheSettings, ReactionManager: 0 })`</info>
|
|
370
|
+
* @type {Object<string, LimitedCollectionOptions|number>}
|
|
371
|
+
*/
|
|
372
|
+
static get defaultMakeCacheSettings() {
|
|
373
|
+
return {
|
|
374
|
+
ApplicationCommandManager: 0,
|
|
375
|
+
AutoModerationRuleManager: 0,
|
|
376
|
+
BaseGuildEmojiManager: 0,
|
|
377
|
+
GuildEmojiManager: 0,
|
|
378
|
+
GuildMemberManager: 120,
|
|
379
|
+
GuildBanManager: 0,
|
|
380
|
+
GuildInviteManager: 0,
|
|
381
|
+
GuildScheduledEventManager: 0,
|
|
382
|
+
GuildStickerManager: 0,
|
|
383
|
+
MessageManager: 60,
|
|
384
|
+
PresenceManager: 0,
|
|
385
|
+
ReactionManager: 0,
|
|
386
|
+
ReactionUserManager: 0,
|
|
387
|
+
StageInstanceManager: 0,
|
|
388
|
+
ThreadManager: 25,
|
|
389
|
+
ThreadMemberManager: 0,
|
|
390
|
+
UserManager: 350,
|
|
391
|
+
VoiceStateManager: 0,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* The default settings passed to {@link ClientOptions.sweepers}.
|
|
398
|
+
* The sweepers that this changes are:
|
|
399
|
+
* * `threads` - Sweep archived threads every hour, removing those archived more than 4 hours ago
|
|
400
|
+
* <info>If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g.
|
|
401
|
+
* `sweepers: { ...Options.defaultSweeperSettings, messages: { interval: 300, lifetime: 600 } }`</info>
|
|
402
|
+
* @type {SweeperOptions}
|
|
403
|
+
*/
|
|
404
|
+
Options.defaultSweeperSettings = {
|
|
405
|
+
messages: {
|
|
406
|
+
interval: 180,
|
|
407
|
+
lifetime: 240,
|
|
408
|
+
},
|
|
409
|
+
users: {
|
|
410
|
+
interval: 600,
|
|
411
|
+
filter: () => user => user.id !== user.client.user?.id,
|
|
412
|
+
},
|
|
413
|
+
guildMembers: {
|
|
414
|
+
interval: 600,
|
|
415
|
+
filter: () => member => member.id !== member.client.user?.id,
|
|
416
|
+
},
|
|
417
|
+
presences: {
|
|
418
|
+
interval: 300,
|
|
419
|
+
filter: () => presence => presence.userId !== presence.client.user?.id,
|
|
420
|
+
},
|
|
421
|
+
voiceStates: {
|
|
422
|
+
interval: 300,
|
|
423
|
+
filter: () => voiceState => voiceState.id !== voiceState.client.user?.id,
|
|
424
|
+
},
|
|
425
|
+
threads: {
|
|
426
|
+
interval: 600,
|
|
427
|
+
lifetime: 1800,
|
|
428
|
+
},
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
module.exports = Options;
|