discord-sb.js 1.0.0
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 +2 -0
- package/package.json +91 -0
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +86 -0
- package/src/client/Client.js +978 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +116 -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 +32 -0
- package/src/client/actions/MessageDeleteBulk.js +46 -0
- package/src/client/actions/MessagePollVoteAdd.js +33 -0
- package/src/client/actions/MessagePollVoteRemove.js +33 -0
- package/src/client/actions/MessageReactionAdd.js +68 -0
- package/src/client/actions/MessageReactionRemove.js +50 -0
- package/src/client/actions/MessageReactionRemoveAll.js +33 -0
- package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
- package/src/client/actions/MessageUpdate.js +26 -0
- package/src/client/actions/PresenceUpdate.js +50 -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 +59 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +34 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +35 -0
- package/src/client/actions/VoiceStateUpdate.js +50 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +151 -0
- package/src/client/voice/VoiceConnection.js +1249 -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 +173 -0
- package/src/client/voice/networking/VoiceWebSocket.js +286 -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 +173 -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/WebSocketManager.js +392 -0
- package/src/client/websocket/WebSocketShard.js +907 -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 +52 -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 +39 -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 +121 -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 +78 -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 +6 -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 +217 -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 +71 -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 +254 -0
- package/src/managers/GuildBanManager.js +250 -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 +338 -0
- package/src/managers/GuildMemberManager.js +599 -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 +423 -0
- package/src/managers/PermissionOverwriteManager.js +164 -0
- package/src/managers/PresenceManager.js +71 -0
- package/src/managers/QuestManager.js +353 -0
- package/src/managers/ReactionManager.js +67 -0
- package/src/managers/ReactionUserManager.js +73 -0
- package/src/managers/RelationshipManager.js +278 -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 +136 -0
- package/src/managers/UserNoteManager.js +53 -0
- package/src/managers/VoiceStateManager.js +59 -0
- package/src/rest/APIRequest.js +154 -0
- package/src/rest/APIRouter.js +53 -0
- package/src/rest/DiscordAPIError.js +119 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +67 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +466 -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 +116 -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 +655 -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 +219 -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 +394 -0
- package/src/structures/Guild.js +1791 -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 +1252 -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 +1157 -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 +640 -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 +99 -0
- package/src/structures/interfaces/Application.js +953 -0
- package/src/structures/interfaces/Collector.js +300 -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 +1914 -0
- package/src/util/DataResolver.js +146 -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/MessageFlags.js +63 -0
- package/src/util/Options.js +358 -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 +415 -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 +466 -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 +1048 -0
- package/typings/enums.d.ts +439 -0
- package/typings/index.d.ts +8505 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +403 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Buffer } = require('node:buffer');
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const EventEmitter = require('node:events');
|
|
6
|
+
const { setTimeout } = require('node:timers');
|
|
7
|
+
const { fetch } = require('undici');
|
|
8
|
+
const { UserAgent } = require('./Constants');
|
|
9
|
+
const Options = require('./Options');
|
|
10
|
+
const { WebSocket } = require('../WebSocket');
|
|
11
|
+
|
|
12
|
+
const defaultClientOptions = Options.createDefault();
|
|
13
|
+
const superPropertiesBase64 = Buffer.from(JSON.stringify(defaultClientOptions.ws.properties), 'ascii').toString(
|
|
14
|
+
'base64',
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const baseURL = 'https://discord.com/ra/';
|
|
18
|
+
|
|
19
|
+
const wsURL = 'wss://remote-auth-gateway.discord.gg/?v=2';
|
|
20
|
+
|
|
21
|
+
const receiveEvent = {
|
|
22
|
+
HELLO: 'hello',
|
|
23
|
+
NONCE_PROOF: 'nonce_proof',
|
|
24
|
+
PENDING_REMOTE_INIT: 'pending_remote_init',
|
|
25
|
+
HEARTBEAT_ACK: 'heartbeat_ack',
|
|
26
|
+
PENDING_TICKET: 'pending_ticket',
|
|
27
|
+
CANCEL: 'cancel',
|
|
28
|
+
PENDING_LOGIN: 'pending_login',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const sendEvent = {
|
|
32
|
+
INIT: 'init',
|
|
33
|
+
NONCE_PROOF: 'nonce_proof',
|
|
34
|
+
HEARTBEAT: 'heartbeat',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const Event = {
|
|
38
|
+
READY: 'ready',
|
|
39
|
+
ERROR: 'error',
|
|
40
|
+
CANCEL: 'cancel',
|
|
41
|
+
WAIT_SCAN: 'pending',
|
|
42
|
+
FINISH: 'finish',
|
|
43
|
+
CLOSED: 'closed',
|
|
44
|
+
DEBUG: 'debug',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Discord Auth QR
|
|
49
|
+
* @extends {EventEmitter}
|
|
50
|
+
* @abstract
|
|
51
|
+
*/
|
|
52
|
+
class DiscordAuthWebsocket extends EventEmitter {
|
|
53
|
+
#ws = null;
|
|
54
|
+
#heartbeatTimeout = null;
|
|
55
|
+
#heartbeatInterval = null;
|
|
56
|
+
#expire = null;
|
|
57
|
+
#publicKey = null;
|
|
58
|
+
#privateKey = null;
|
|
59
|
+
#encodedPublicKey = null;
|
|
60
|
+
#ticket = null;
|
|
61
|
+
#fingerprint = '';
|
|
62
|
+
#userDecryptString = '';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new DiscordAuthWebsocket instance.
|
|
66
|
+
*/
|
|
67
|
+
constructor() {
|
|
68
|
+
super();
|
|
69
|
+
this.token = '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @type {string}
|
|
74
|
+
*/
|
|
75
|
+
get AuthURL() {
|
|
76
|
+
return baseURL + this.#fingerprint;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @type {Date}
|
|
81
|
+
*/
|
|
82
|
+
get exprire() {
|
|
83
|
+
return this.#expire;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @type {UserRaw}
|
|
88
|
+
*/
|
|
89
|
+
get user() {
|
|
90
|
+
return DiscordAuthWebsocket.decryptUser(this.#userDecryptString);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#createWebSocket(url) {
|
|
94
|
+
this.#ws = new WebSocket(url, {
|
|
95
|
+
headers: {
|
|
96
|
+
Origin: 'https://discord.com',
|
|
97
|
+
'User-Agent': UserAgent,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
this.#handleWebSocket();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#clearHeartbeatTimer() {
|
|
104
|
+
if (!this.#heartbeatTimeout) return;
|
|
105
|
+
clearTimeout(this.#heartbeatTimeout);
|
|
106
|
+
this.#heartbeatTimeout = null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#parseMessage(message) {
|
|
110
|
+
try {
|
|
111
|
+
const payload =
|
|
112
|
+
typeof message === 'string'
|
|
113
|
+
? message
|
|
114
|
+
: Buffer.isBuffer(message)
|
|
115
|
+
? message.toString('utf8')
|
|
116
|
+
: message?.data instanceof ArrayBuffer
|
|
117
|
+
? Buffer.from(message.data).toString('utf8')
|
|
118
|
+
: Buffer.isBuffer(message?.data)
|
|
119
|
+
? message.data.toString('utf8')
|
|
120
|
+
: message?.data ?? message;
|
|
121
|
+
const serialized = typeof payload === 'string' ? payload : String(payload);
|
|
122
|
+
return JSON.parse(serialized);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
this.emit(Event.ERROR, error);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#handleWebSocket() {
|
|
130
|
+
this.#ws.on('error', error => {
|
|
131
|
+
/**
|
|
132
|
+
* WS Error
|
|
133
|
+
* @event DiscordAuthWebsocket#error
|
|
134
|
+
* @param {Error} error Error
|
|
135
|
+
*/
|
|
136
|
+
this.emit(Event.ERROR, error);
|
|
137
|
+
});
|
|
138
|
+
this.#ws.on('open', () => {
|
|
139
|
+
/**
|
|
140
|
+
* Debug Event
|
|
141
|
+
* @event DiscordAuthWebsocket#debug
|
|
142
|
+
* @param {string} msg Debug msg
|
|
143
|
+
*/
|
|
144
|
+
this.emit(Event.DEBUG, '[WS] Client Connected');
|
|
145
|
+
});
|
|
146
|
+
this.#ws.on('close', () => {
|
|
147
|
+
this.#clearHeartbeatTimer();
|
|
148
|
+
this.emit(Event.DEBUG, '[WS] Connection closed');
|
|
149
|
+
});
|
|
150
|
+
this.#ws.on('message', this.#handleMessage.bind(this));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#handleMessage(message) {
|
|
154
|
+
const payload = this.#parseMessage(message);
|
|
155
|
+
if (!payload) return;
|
|
156
|
+
switch (payload.op) {
|
|
157
|
+
case receiveEvent.HELLO: {
|
|
158
|
+
this.#ready(payload);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
case receiveEvent.NONCE_PROOF: {
|
|
163
|
+
this.#receiveNonceProof(payload);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
case receiveEvent.PENDING_REMOTE_INIT: {
|
|
168
|
+
this.#fingerprint = payload.fingerprint;
|
|
169
|
+
/**
|
|
170
|
+
* Ready Event
|
|
171
|
+
* @event DiscordAuthWebsocket#ready
|
|
172
|
+
* @param {DiscordAuthWebsocket} client WS
|
|
173
|
+
*/
|
|
174
|
+
this.emit(Event.READY, this);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
case receiveEvent.HEARTBEAT_ACK: {
|
|
179
|
+
this.emit(Event.DEBUG, `Heartbeat acknowledged.`);
|
|
180
|
+
this.#heartbeatAck();
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
case receiveEvent.PENDING_TICKET: {
|
|
185
|
+
this.#pendingLogin(payload);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
case receiveEvent.CANCEL: {
|
|
190
|
+
/**
|
|
191
|
+
* Cancel
|
|
192
|
+
* @event DiscordAuthWebsocket#cancel
|
|
193
|
+
* @param {DiscordAuthWebsocket} client WS
|
|
194
|
+
*/
|
|
195
|
+
this.emit(Event.CANCEL, this);
|
|
196
|
+
this.destroy();
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
case receiveEvent.PENDING_LOGIN: {
|
|
201
|
+
this.#ticket = payload.ticket;
|
|
202
|
+
this.#findRealToken();
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#send(op, data) {
|
|
209
|
+
if (!this.#ws || this.#ws.readyState !== WebSocket.OPEN) return;
|
|
210
|
+
let payload = { op: op };
|
|
211
|
+
if (data !== null) payload = { ...payload, ...data };
|
|
212
|
+
this.#ws.send(JSON.stringify(payload));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#heartbeatAck() {
|
|
216
|
+
this.#clearHeartbeatTimer();
|
|
217
|
+
this.#heartbeatTimeout = setTimeout(() => {
|
|
218
|
+
this.#send(sendEvent.HEARTBEAT);
|
|
219
|
+
}, this.#heartbeatInterval);
|
|
220
|
+
if (typeof this.#heartbeatTimeout.unref === 'function') {
|
|
221
|
+
this.#heartbeatTimeout.unref();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#ready(data) {
|
|
226
|
+
this.emit(Event.DEBUG, 'Attempting server handshake...');
|
|
227
|
+
this.#expire = new Date(Date.now() + data.timeout_ms);
|
|
228
|
+
this.#heartbeatInterval = data.heartbeat_interval;
|
|
229
|
+
this.#createKey();
|
|
230
|
+
this.#heartbeatAck();
|
|
231
|
+
this.#init();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
#createKey() {
|
|
235
|
+
const key = crypto.generateKeyPairSync('rsa', {
|
|
236
|
+
modulusLength: 2048,
|
|
237
|
+
publicKeyEncoding: {
|
|
238
|
+
type: 'spki',
|
|
239
|
+
format: 'pem',
|
|
240
|
+
},
|
|
241
|
+
privateKeyEncoding: {
|
|
242
|
+
type: 'pkcs1',
|
|
243
|
+
format: 'pem',
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
this.#privateKey = typeof key.privateKey === 'string' ? key.privateKey : key.privateKey.toString('utf8');
|
|
247
|
+
this.#publicKey = typeof key.publicKey === 'string' ? key.publicKey : key.publicKey.toString('utf8');
|
|
248
|
+
this.#encodedPublicKey = this.#encodePublicKey();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
#encodePublicKey() {
|
|
252
|
+
return this.#publicKey
|
|
253
|
+
.replace('-----BEGIN PUBLIC KEY-----\n', '')
|
|
254
|
+
.replace('\n-----END PUBLIC KEY-----\n', '')
|
|
255
|
+
.replace(/\n/g, '');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#init() {
|
|
259
|
+
this.#send(sendEvent.INIT, { encoded_public_key: this.#encodedPublicKey });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
#receiveNonceProof(data) {
|
|
263
|
+
const nonce = data.encrypted_nonce;
|
|
264
|
+
const decrypted_nonce = this.#decryptPayload(nonce);
|
|
265
|
+
const proof = crypto.createHash('sha256').update(decrypted_nonce).digest('base64url');
|
|
266
|
+
this.#send(sendEvent.NONCE_PROOF, { proof: proof });
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
#decryptPayload(encrypted_payload) {
|
|
270
|
+
const payload = Buffer.from(encrypted_payload, 'base64');
|
|
271
|
+
const data = crypto.privateDecrypt(
|
|
272
|
+
{
|
|
273
|
+
key: this.#privateKey,
|
|
274
|
+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
|
275
|
+
oaepHash: 'sha256',
|
|
276
|
+
},
|
|
277
|
+
payload,
|
|
278
|
+
);
|
|
279
|
+
return data;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#pendingLogin(data) {
|
|
283
|
+
const user_data = this.#decryptPayload(data.encrypted_user_payload);
|
|
284
|
+
this.#userDecryptString = user_data.toString('utf8');
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @typedef {Object} UserRaw
|
|
288
|
+
* @property {Snowflake} id
|
|
289
|
+
* @property {string} username
|
|
290
|
+
* @property {number} discriminator
|
|
291
|
+
* @property {string} avatar
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Emitted whenever a user is scan QR Code.
|
|
296
|
+
* @event DiscordAuthWebsocket#pending
|
|
297
|
+
* @param {UserRaw} user Discord User Raw
|
|
298
|
+
*/
|
|
299
|
+
this.emit(Event.WAIT_SCAN, this.user);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
#awaitLogin(client) {
|
|
303
|
+
return new Promise(r => {
|
|
304
|
+
this.once(Event.FINISH, token => {
|
|
305
|
+
r(client.login(token));
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Connect WS
|
|
312
|
+
* @param {Client} [client] DiscordJS Client
|
|
313
|
+
* @returns {Promise<void>}
|
|
314
|
+
*/
|
|
315
|
+
connect(client) {
|
|
316
|
+
this.#createWebSocket(wsURL);
|
|
317
|
+
if (client) {
|
|
318
|
+
return this.#awaitLogin(client);
|
|
319
|
+
} else {
|
|
320
|
+
return Promise.resolve();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Destroy client
|
|
326
|
+
* @returns {void}
|
|
327
|
+
*/
|
|
328
|
+
destroy() {
|
|
329
|
+
if (!this.#ws) return;
|
|
330
|
+
this.#clearHeartbeatTimer();
|
|
331
|
+
this.#ws.close();
|
|
332
|
+
this.#ws = null;
|
|
333
|
+
this.emit(Event.DEBUG, 'WebSocket closed.');
|
|
334
|
+
/**
|
|
335
|
+
* Emitted whenever a connection is closed.
|
|
336
|
+
* @event DiscordAuthWebsocket#closed
|
|
337
|
+
*/
|
|
338
|
+
this.emit(Event.CLOSED);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Generate QR code for user to scan (Terminal)
|
|
343
|
+
* @returns {void}
|
|
344
|
+
*/
|
|
345
|
+
generateQR() {
|
|
346
|
+
if (!this.#fingerprint) return;
|
|
347
|
+
require('qrcode').toString(this.AuthURL, { type: 'utf8', errorCorrectionLevel: 'L' }, (err, url) => {
|
|
348
|
+
if (err) {
|
|
349
|
+
//
|
|
350
|
+
}
|
|
351
|
+
console.log(url);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async #findRealToken() {
|
|
356
|
+
try {
|
|
357
|
+
const response = await fetch(`https://discord.com/api/v9/users/@me/remote-auth/login`, {
|
|
358
|
+
method: 'POST',
|
|
359
|
+
headers: {
|
|
360
|
+
Accept: '*/*',
|
|
361
|
+
'Accept-Language': 'en-US',
|
|
362
|
+
'Content-Type': 'application/json',
|
|
363
|
+
'Sec-Fetch-Dest': 'empty',
|
|
364
|
+
'Sec-Fetch-Mode': 'cors',
|
|
365
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
366
|
+
'X-Debug-Options': 'bugReporterEnabled',
|
|
367
|
+
'X-Super-Properties': superPropertiesBase64,
|
|
368
|
+
'X-Discord-Locale': 'en-US',
|
|
369
|
+
'User-Agent': UserAgent,
|
|
370
|
+
Referer: 'https://discord.com/channels/@me',
|
|
371
|
+
Connection: 'keep-alive',
|
|
372
|
+
Origin: 'https://discord.com',
|
|
373
|
+
},
|
|
374
|
+
body: JSON.stringify({
|
|
375
|
+
ticket: this.#ticket,
|
|
376
|
+
}),
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
if (!response.ok) {
|
|
380
|
+
throw new Error(`Remote auth exchange failed with status ${response.status}`);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const res = await response.json();
|
|
384
|
+
if (res.encrypted_token) {
|
|
385
|
+
this.token = this.#decryptPayload(res.encrypted_token).toString('utf8');
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Emitted whenever a real token is found.
|
|
389
|
+
* @event DiscordAuthWebsocket#finish
|
|
390
|
+
* @param {string} token Discord Token
|
|
391
|
+
*/
|
|
392
|
+
this.emit(Event.FINISH, this.token);
|
|
393
|
+
} catch (error) {
|
|
394
|
+
this.emit(Event.ERROR, error);
|
|
395
|
+
} finally {
|
|
396
|
+
this.destroy();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
static decryptUser(payload) {
|
|
401
|
+
const values = payload.split(':');
|
|
402
|
+
const id = values[0];
|
|
403
|
+
const username = values[3];
|
|
404
|
+
const discriminator = values[1];
|
|
405
|
+
const avatar = values[2];
|
|
406
|
+
return {
|
|
407
|
+
id,
|
|
408
|
+
username,
|
|
409
|
+
discriminator,
|
|
410
|
+
avatar,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
module.exports = DiscordAuthWebsocket;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const BitField = require('./BitField');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Data structure that makes it easy to interact with an {@link GuildMember#flags} bitfield.
|
|
7
|
+
* @extends {BitField}
|
|
8
|
+
*/
|
|
9
|
+
class RoleFlags extends BitField {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @name RoleFlags
|
|
13
|
+
* @kind constructor
|
|
14
|
+
* @memberof RoleFlags
|
|
15
|
+
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Numeric guild member flags. All available properties:
|
|
20
|
+
* * `IN_PROMPT`
|
|
21
|
+
* @type {Object}
|
|
22
|
+
* @see {@link https://discord.com/developers/docs/topics/permissions#role-object-role-flags}
|
|
23
|
+
*/
|
|
24
|
+
RoleFlags.FLAGS = {
|
|
25
|
+
IN_PROMPT: 1 << 0,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Data that can be resolved to give a role flag bitfield. This can be:
|
|
30
|
+
* * A string (see {@link RoleFlags.FLAGS})
|
|
31
|
+
* * A role flag
|
|
32
|
+
* * An instance of RoleFlags
|
|
33
|
+
* * An Array of RoleFlagsResolvable
|
|
34
|
+
* @typedef {string|number|RoleFlags|RoleFlagsResolvable[]} RoleFlagsResolvable
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
module.exports = RoleFlags;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Discord epoch (2015-01-01T00:00:00.000Z)
|
|
4
|
+
const EPOCH = 1_420_070_400_000;
|
|
5
|
+
let INCREMENT = BigInt(0);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A container for useful snowflake-related methods.
|
|
9
|
+
*/
|
|
10
|
+
class SnowflakeUtil extends null {
|
|
11
|
+
/**
|
|
12
|
+
* A {@link https://docs.x.com/resources/fundamentals/x-ids Twitter snowflake},
|
|
13
|
+
* except the epoch is 2015-01-01T00:00:00.000Z.
|
|
14
|
+
*
|
|
15
|
+
* If we have a snowflake '266241948824764416' we can represent it as binary:
|
|
16
|
+
* ```
|
|
17
|
+
* 64 22 17 12 0
|
|
18
|
+
* 000000111011000111100001101001000101000000 00001 00000 000000000000
|
|
19
|
+
* number of milliseconds since Discord epoch worker pid increment
|
|
20
|
+
* ```
|
|
21
|
+
* @typedef {string} Snowflake
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generates a Discord snowflake.
|
|
26
|
+
* <info>This hardcodes the worker's id as 1 and the process's id as 0.</info>
|
|
27
|
+
* @param {number|Date} [timestamp=Date.now()] Timestamp or date of the snowflake to generate
|
|
28
|
+
* @returns {Snowflake} The generated snowflake
|
|
29
|
+
*/
|
|
30
|
+
static generate(timestamp = Date.now()) {
|
|
31
|
+
if (timestamp instanceof Date) timestamp = timestamp.getTime();
|
|
32
|
+
if (typeof timestamp !== 'number' || isNaN(timestamp)) {
|
|
33
|
+
throw new TypeError(
|
|
34
|
+
`"timestamp" argument must be a number (received ${isNaN(timestamp) ? 'NaN' : typeof timestamp})`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (INCREMENT >= 4095n) INCREMENT = BigInt(0);
|
|
38
|
+
|
|
39
|
+
// Assign WorkerId as 1 and ProcessId as 0:
|
|
40
|
+
return ((BigInt(timestamp - EPOCH) << 22n) | (1n << 17n) | INCREMENT++).toString();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A deconstructed snowflake.
|
|
45
|
+
* @typedef {Object} DeconstructedSnowflake
|
|
46
|
+
* @property {number} timestamp Timestamp the snowflake was created
|
|
47
|
+
* @property {Date} date Date the snowflake was created
|
|
48
|
+
* @property {number} workerId The worker's id in the snowflake
|
|
49
|
+
* @property {number} processId The process's id in the snowflake
|
|
50
|
+
* @property {number} increment Increment in the snowflake
|
|
51
|
+
* @property {string} binary Binary representation of the snowflake
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Deconstructs a Discord snowflake.
|
|
56
|
+
* @param {Snowflake} snowflake Snowflake to deconstruct
|
|
57
|
+
* @returns {DeconstructedSnowflake}
|
|
58
|
+
*/
|
|
59
|
+
static deconstruct(snowflake) {
|
|
60
|
+
const bigIntSnowflake = BigInt(snowflake);
|
|
61
|
+
return {
|
|
62
|
+
timestamp: Number(bigIntSnowflake >> 22n) + EPOCH,
|
|
63
|
+
get date() {
|
|
64
|
+
return new Date(this.timestamp);
|
|
65
|
+
},
|
|
66
|
+
workerId: Number((bigIntSnowflake >> 17n) & 0b11111n),
|
|
67
|
+
processId: Number((bigIntSnowflake >> 12n) & 0b11111n),
|
|
68
|
+
increment: Number(bigIntSnowflake & 0b111111111111n),
|
|
69
|
+
binary: bigIntSnowflake.toString(2).padStart(64, '0'),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves the timestamp field's value from a Discord snowflake.
|
|
75
|
+
* @param {Snowflake} snowflake Snowflake to get the timestamp value from
|
|
76
|
+
* @returns {number}
|
|
77
|
+
*/
|
|
78
|
+
static timestampFrom(snowflake) {
|
|
79
|
+
return Number(BigInt(snowflake) >> 22n) + EPOCH;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Discord's epoch value (2015-01-01T00:00:00.000Z).
|
|
84
|
+
* @type {number}
|
|
85
|
+
* @readonly
|
|
86
|
+
*/
|
|
87
|
+
static get EPOCH() {
|
|
88
|
+
return EPOCH;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = SnowflakeUtil;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const BitField = require('./BitField');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Data structure that makes it easy to interact with a {@link VoiceConnection#speaking}
|
|
7
|
+
* and {@link guildMemberSpeaking} event bitfields.
|
|
8
|
+
* @extends {BitField}
|
|
9
|
+
*/
|
|
10
|
+
class Speaking extends BitField {}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @name Speaking
|
|
14
|
+
* @kind constructor
|
|
15
|
+
* @memberof Speaking
|
|
16
|
+
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Numeric speaking flags. All available properties:
|
|
21
|
+
* * `SPEAKING`
|
|
22
|
+
* * `SOUNDSHARE`
|
|
23
|
+
* * `PRIORITY_SPEAKING`
|
|
24
|
+
* @type {Object}
|
|
25
|
+
* @see {@link https://discord.com/developers/docs/topics/voice-connections#speaking}
|
|
26
|
+
*/
|
|
27
|
+
Speaking.FLAGS = {
|
|
28
|
+
SPEAKING: 1 << 0,
|
|
29
|
+
SOUNDSHARE: 1 << 1,
|
|
30
|
+
PRIORITY_SPEAKING: 1 << 2,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = Speaking;
|