chapterjs 0.1.2 → 0.1.4
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/dist/assets/asset.d.ts +46 -0
- package/dist/assets/asset.js +86 -0
- package/dist/assets/public.d.ts +19 -0
- package/dist/assets/public.js +120 -0
- package/dist/cache/cache.d.ts +62 -0
- package/dist/cache/cache.js +80 -0
- package/dist/cache/store.d.ts +45 -0
- package/dist/cache/store.js +53 -0
- package/dist/cli/build.d.ts +41 -0
- package/dist/cli/build.js +206 -0
- package/dist/cli/cli.js +108 -25
- package/dist/cli/cluster.d.ts +70 -0
- package/dist/cli/cluster.js +213 -0
- package/dist/cli/dev.d.ts +18 -1
- package/dist/cli/dev.js +252 -198
- package/dist/cli/env.d.ts +31 -0
- package/dist/cli/env.js +93 -0
- package/dist/cli/log.d.ts +13 -0
- package/dist/cli/log.js +17 -0
- package/dist/cli/node-version.d.ts +8 -0
- package/dist/cli/node-version.js +13 -0
- package/dist/cli/preflight.d.ts +36 -0
- package/dist/cli/preflight.js +122 -0
- package/dist/cli/project.d.ts +122 -0
- package/dist/cli/project.js +452 -0
- package/dist/cli/start.d.ts +25 -0
- package/dist/cli/start.js +225 -0
- package/dist/commands/autocomplete.d.ts +13 -0
- package/dist/commands/autocomplete.js +159 -0
- package/dist/commands/command.d.ts +346 -0
- package/dist/commands/command.js +28 -0
- package/dist/commands/convention.d.ts +64 -0
- package/dist/commands/convention.js +464 -0
- package/dist/commands/register.d.ts +18 -0
- package/dist/commands/register.js +42 -0
- package/dist/commands/router.d.ts +20 -0
- package/dist/commands/router.js +228 -0
- package/dist/commands/tree.d.ts +43 -0
- package/dist/commands/tree.js +206 -0
- package/dist/commands/twins.d.ts +15 -0
- package/dist/commands/twins.js +78 -0
- package/dist/components/button.d.ts +79 -0
- package/dist/components/button.js +108 -0
- package/dist/components/component.d.ts +140 -0
- package/dist/components/component.js +39 -0
- package/dist/components/convention.d.ts +35 -0
- package/dist/components/convention.js +339 -0
- package/dist/components/custom-id.d.ts +72 -0
- package/dist/components/custom-id.js +128 -0
- package/dist/components/embed.d.ts +28 -0
- package/dist/components/embed.js +11 -0
- package/dist/components/file.d.ts +30 -0
- package/dist/components/file.js +52 -0
- package/dist/components/instance.d.ts +100 -0
- package/dist/components/instance.js +86 -0
- package/dist/components/layout.d.ts +103 -0
- package/dist/components/layout.js +279 -0
- package/dist/components/modal.d.ts +244 -0
- package/dist/components/modal.js +399 -0
- package/dist/components/options.d.ts +41 -0
- package/dist/components/options.js +101 -0
- package/dist/components/render.d.ts +12 -0
- package/dist/components/render.js +58 -0
- package/dist/components/router.d.ts +18 -0
- package/dist/components/router.js +256 -0
- package/dist/components/select.d.ts +144 -0
- package/dist/components/select.js +179 -0
- package/dist/core/bot.d.ts +99 -0
- package/dist/core/bot.js +174 -0
- package/dist/core/memory.d.ts +66 -0
- package/dist/core/memory.js +115 -0
- package/dist/discord/api.d.ts +112 -0
- package/dist/discord/api.js +115 -0
- package/dist/discord/cdn.d.ts +67 -0
- package/dist/discord/cdn.js +100 -0
- package/dist/discord/codes.d.ts +171 -0
- package/dist/discord/codes.js +421 -0
- package/dist/discord/endpoint.d.ts +56 -0
- package/dist/discord/endpoint.js +53 -0
- package/dist/discord/endpoints.d.ts +1529 -0
- package/dist/discord/endpoints.js +1139 -0
- package/dist/discord/formatting.d.ts +67 -0
- package/dist/discord/formatting.js +87 -0
- package/dist/discord/index.d.ts +10 -0
- package/dist/discord/index.js +13 -0
- package/dist/discord/intents.d.ts +48 -0
- package/dist/discord/intents.js +128 -0
- package/dist/discord/permissions.d.ts +94 -0
- package/dist/discord/permissions.js +185 -0
- package/dist/discord/snowflake.d.ts +21 -0
- package/dist/discord/snowflake.js +36 -0
- package/dist/discord/types/application-command.d.ts +332 -0
- package/dist/discord/types/application-command.js +48 -0
- package/dist/discord/types/application-role-connection-metadata.d.ts +42 -0
- package/dist/discord/types/application-role-connection-metadata.js +22 -0
- package/dist/discord/types/application.d.ts +208 -0
- package/dist/discord/types/application.js +48 -0
- package/dist/discord/types/audit-log.d.ts +255 -0
- package/dist/discord/types/audit-log.js +144 -0
- package/dist/discord/types/auto-moderation.d.ts +167 -0
- package/dist/discord/types/auto-moderation.js +52 -0
- package/dist/discord/types/channel.d.ts +557 -0
- package/dist/discord/types/channel.js +88 -0
- package/dist/discord/types/common.d.ts +54 -0
- package/dist/discord/types/common.js +38 -0
- package/dist/discord/types/component.d.ts +775 -0
- package/dist/discord/types/component.js +76 -0
- package/dist/discord/types/emoji.d.ts +74 -0
- package/dist/discord/types/emoji.js +1 -0
- package/dist/discord/types/entitlement.d.ts +84 -0
- package/dist/discord/types/entitlement.js +22 -0
- package/dist/discord/types/gateway-events.d.ts +1148 -0
- package/dist/discord/types/gateway-events.js +54 -0
- package/dist/discord/types/gateway.d.ts +38 -0
- package/dist/discord/types/gateway.js +1 -0
- package/dist/discord/types/guild-scheduled-event.d.ts +257 -0
- package/dist/discord/types/guild-scheduled-event.js +68 -0
- package/dist/discord/types/guild-template.d.ts +51 -0
- package/dist/discord/types/guild-template.js +1 -0
- package/dist/discord/types/guild.d.ts +910 -0
- package/dist/discord/types/guild.js +153 -0
- package/dist/discord/types/index.d.ts +31 -0
- package/dist/discord/types/index.js +31 -0
- package/dist/discord/types/interaction.d.ts +321 -0
- package/dist/discord/types/interaction.js +47 -0
- package/dist/discord/types/invite.d.ts +158 -0
- package/dist/discord/types/invite.js +39 -0
- package/dist/discord/types/message.d.ts +834 -0
- package/dist/discord/types/message.js +159 -0
- package/dist/discord/types/oauth2.d.ts +22 -0
- package/dist/discord/types/oauth2.js +1 -0
- package/dist/discord/types/permissions.d.ts +183 -0
- package/dist/discord/types/permissions.js +118 -0
- package/dist/discord/types/poll.d.ts +106 -0
- package/dist/discord/types/poll.js +8 -0
- package/dist/discord/types/sku.d.ts +47 -0
- package/dist/discord/types/sku.js +26 -0
- package/dist/discord/types/soundboard.d.ts +71 -0
- package/dist/discord/types/soundboard.js +1 -0
- package/dist/discord/types/stage-instance.d.ts +58 -0
- package/dist/discord/types/stage-instance.js +10 -0
- package/dist/discord/types/sticker.d.ts +115 -0
- package/dist/discord/types/sticker.js +20 -0
- package/dist/discord/types/subscription.d.ts +54 -0
- package/dist/discord/types/subscription.js +12 -0
- package/dist/discord/types/team.d.ts +55 -0
- package/dist/discord/types/team.js +21 -0
- package/dist/discord/types/user.d.ts +273 -0
- package/dist/discord/types/user.js +83 -0
- package/dist/discord/types/voice.d.ts +72 -0
- package/dist/discord/types/voice.js +1 -0
- package/dist/discord/types/webhook.d.ts +184 -0
- package/dist/discord/types/webhook.js +12 -0
- package/dist/events/convention.d.ts +25 -0
- package/dist/events/convention.js +97 -0
- package/dist/events/event.d.ts +8 -0
- package/dist/events/event.js +20 -0
- package/dist/events/registry.d.ts +706 -0
- package/dist/events/registry.js +839 -0
- package/dist/events/router.d.ts +45 -0
- package/dist/events/router.js +133 -0
- package/dist/events/types.d.ts +7 -0
- package/dist/events/types.js +48 -0
- package/dist/gateway/errors.d.ts +18 -0
- package/dist/gateway/errors.js +47 -0
- package/dist/gateway/gateway.d.ts +64 -0
- package/dist/gateway/gateway.js +117 -0
- package/dist/gateway/identify-queue.d.ts +25 -0
- package/dist/gateway/identify-queue.js +29 -0
- package/dist/gateway/shard.d.ts +94 -0
- package/dist/gateway/shard.js +414 -0
- package/dist/gateway/state.d.ts +11 -0
- package/dist/gateway/state.js +184 -0
- package/dist/index.d.ts +55 -18
- package/dist/index.js +38 -12
- package/dist/interactions/cooldown.d.ts +33 -0
- package/dist/interactions/cooldown.js +74 -0
- package/dist/interactions/dispatch.d.ts +91 -0
- package/dist/interactions/dispatch.js +110 -0
- package/dist/loader/generated.d.ts +37 -0
- package/dist/loader/generated.js +114 -0
- package/dist/loader/hot.d.ts +13 -0
- package/dist/loader/hot.js +85 -0
- package/dist/loader/loader.d.ts +72 -0
- package/dist/loader/loader.js +135 -0
- package/dist/loader/locate.d.ts +10 -0
- package/dist/loader/locate.js +36 -0
- package/dist/loader/watch.d.ts +17 -0
- package/dist/loader/watch.js +66 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +6 -0
- package/dist/messages/commands.d.ts +23 -0
- package/dist/messages/commands.js +123 -0
- package/dist/messages/convention.d.ts +89 -0
- package/dist/messages/convention.js +347 -0
- package/dist/messages/messages.d.ts +219 -0
- package/dist/messages/messages.js +30 -0
- package/dist/messages/phrases.d.ts +23 -0
- package/dist/messages/phrases.js +44 -0
- package/dist/messages/translate.d.ts +100 -0
- package/dist/messages/translate.js +249 -0
- package/dist/presence/convention.d.ts +26 -0
- package/dist/presence/convention.js +133 -0
- package/dist/presence/presence.d.ts +57 -0
- package/dist/presence/presence.js +27 -0
- package/dist/rest/errors.d.ts +55 -0
- package/dist/rest/errors.js +92 -0
- package/dist/rest/rate-limiter.d.ts +46 -0
- package/dist/rest/rate-limiter.js +153 -0
- package/dist/rest/rest.d.ts +63 -0
- package/dist/rest/rest.js +194 -0
- package/dist/structures/base.d.ts +48 -0
- package/dist/structures/base.js +84 -0
- package/dist/structures/channel.d.ts +380 -0
- package/dist/structures/channel.js +627 -0
- package/dist/structures/context.d.ts +30 -0
- package/dist/structures/context.js +7 -0
- package/dist/structures/emoji.d.ts +46 -0
- package/dist/structures/emoji.js +65 -0
- package/dist/structures/entities.d.ts +62 -0
- package/dist/structures/entities.js +226 -0
- package/dist/structures/guild.d.ts +348 -0
- package/dist/structures/guild.js +466 -0
- package/dist/structures/interaction.d.ts +197 -0
- package/dist/structures/interaction.js +396 -0
- package/dist/structures/invite.d.ts +38 -0
- package/dist/structures/invite.js +57 -0
- package/dist/structures/known.d.ts +28 -0
- package/dist/structures/known.js +58 -0
- package/dist/structures/member.d.ts +140 -0
- package/dist/structures/member.js +260 -0
- package/dist/structures/message.d.ts +197 -0
- package/dist/structures/message.js +268 -0
- package/dist/structures/payload.d.ts +91 -0
- package/dist/structures/payload.js +184 -0
- package/dist/structures/role.d.ts +69 -0
- package/dist/structures/role.js +112 -0
- package/dist/structures/user.d.ts +59 -0
- package/dist/structures/user.js +94 -0
- package/dist/structures/webhook.d.ts +46 -0
- package/dist/structures/webhook.js +79 -0
- package/dist/tasks/convention.d.ts +26 -0
- package/dist/tasks/convention.js +78 -0
- package/dist/tasks/schedule.d.ts +54 -0
- package/dist/tasks/schedule.js +236 -0
- package/dist/tasks/scheduler.d.ts +33 -0
- package/dist/tasks/scheduler.js +107 -0
- package/dist/tasks/task.d.ts +76 -0
- package/dist/tasks/task.js +28 -0
- package/dist/util/case.d.ts +13 -0
- package/dist/util/case.js +54 -0
- package/dist/util/duration.d.ts +8 -0
- package/dist/util/duration.js +29 -0
- package/dist/util/websocket.d.ts +9 -0
- package/dist/util/websocket.js +31 -0
- package/dist/voice/connection.d.ts +90 -0
- package/dist/voice/connection.js +494 -0
- package/dist/voice/dave.d.ts +109 -0
- package/dist/voice/dave.js +245 -0
- package/dist/voice/opus.d.ts +19 -0
- package/dist/voice/opus.js +273 -0
- package/dist/voice/session.d.ts +55 -0
- package/dist/voice/session.js +405 -0
- package/dist/voice/source.d.ts +22 -0
- package/dist/voice/source.js +195 -0
- package/dist/voice/transport.d.ts +43 -0
- package/dist/voice/transport.js +140 -0
- package/dist/voice/usage.d.ts +4 -0
- package/dist/voice/usage.js +33 -0
- package/package.json +26 -7
- package/vendor/dave/LICENSE +231 -0
- package/vendor/dave/libdave.d.mts +99 -0
- package/vendor/dave/libdave.mjs +2 -0
- package/vendor/dave/libdave.wasm +0 -0
- package/dist/components.d.ts +0 -97
- package/dist/components.js +0 -260
- package/dist/context.d.ts +0 -72
- package/dist/context.js +0 -273
- package/dist/discord/client.d.ts +0 -35
- package/dist/discord/client.js +0 -66
- package/dist/discord/constants.d.ts +0 -49
- package/dist/discord/constants.js +0 -61
- package/dist/discord/events.d.ts +0 -129
- package/dist/discord/events.js +0 -102
- package/dist/discord/gateway.d.ts +0 -61
- package/dist/discord/gateway.js +0 -320
- package/dist/discord/payloads.d.ts +0 -275
- package/dist/discord/payloads.js +0 -3
- package/dist/discord/presence.d.ts +0 -42
- package/dist/discord/presence.js +0 -51
- package/dist/discord/rest.d.ts +0 -49
- package/dist/discord/rest.js +0 -271
- package/dist/discord/types.d.ts +0 -334
- package/dist/discord/types.js +0 -4
- package/dist/events.d.ts +0 -94
- package/dist/events.js +0 -255
- package/dist/presence.d.ts +0 -92
- package/dist/presence.js +0 -250
- package/dist/structures/Channel.d.ts +0 -110
- package/dist/structures/Channel.js +0 -171
- package/dist/structures/Guild.d.ts +0 -70
- package/dist/structures/Guild.js +0 -105
- package/dist/structures/Interaction.d.ts +0 -113
- package/dist/structures/Interaction.js +0 -274
- package/dist/structures/Member.d.ts +0 -70
- package/dist/structures/Member.js +0 -124
- package/dist/structures/Message.d.ts +0 -87
- package/dist/structures/Message.js +0 -182
- package/dist/structures/Reaction.d.ts +0 -38
- package/dist/structures/Reaction.js +0 -64
- package/dist/structures/Role.d.ts +0 -43
- package/dist/structures/Role.js +0 -77
- package/dist/structures/User.d.ts +0 -41
- package/dist/structures/User.js +0 -79
- package/dist/structures/utils.d.ts +0 -72
- package/dist/structures/utils.js +0 -59
- package/dist/utils/errors.d.ts +0 -5
- package/dist/utils/errors.js +0 -28
- package/dist/utils/modules.d.ts +0 -39
- package/dist/utils/modules.js +0 -156
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
// Opcodes and status codes, as listed by the official documentation.
|
|
2
|
+
// https://docs.discord.com/developers/topics/opcodes-and-status-codes
|
|
3
|
+
/**
|
|
4
|
+
* Gateway Opcodes
|
|
5
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#gateway-gateway-opcodes
|
|
6
|
+
*/
|
|
7
|
+
export const GatewayOpcode = {
|
|
8
|
+
/** An event was dispatched. */
|
|
9
|
+
Dispatch: 0,
|
|
10
|
+
/** Fired periodically by the client to keep the connection alive. */
|
|
11
|
+
Heartbeat: 1,
|
|
12
|
+
/** Starts a new session during the initial handshake. */
|
|
13
|
+
Identify: 2,
|
|
14
|
+
/** Update the client's presence. */
|
|
15
|
+
PresenceUpdate: 3,
|
|
16
|
+
/** Used to join/leave or move between voice channels. */
|
|
17
|
+
VoiceStateUpdate: 4,
|
|
18
|
+
/** Resume a previous session that was disconnected. */
|
|
19
|
+
Resume: 6,
|
|
20
|
+
/** You should attempt to reconnect and resume immediately. */
|
|
21
|
+
Reconnect: 7,
|
|
22
|
+
/** Request information about offline guild members in a large guild. */
|
|
23
|
+
RequestGuildMembers: 8,
|
|
24
|
+
/** The session has been invalidated. You should reconnect and identify/resume accordingly. */
|
|
25
|
+
InvalidSession: 9,
|
|
26
|
+
/** Sent immediately after connecting, contains the `heartbeat_interval` to use. */
|
|
27
|
+
Hello: 10,
|
|
28
|
+
/** Sent in response to receiving a heartbeat to acknowledge that it has been received. */
|
|
29
|
+
HeartbeatAck: 11,
|
|
30
|
+
/** Request information about soundboard sounds in a set of guilds. */
|
|
31
|
+
RequestSoundboardSounds: 31,
|
|
32
|
+
/** Request ephemeral channel data for channels in a guild. */
|
|
33
|
+
RequestChannelInfo: 43,
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Gateway Close Event Codes
|
|
37
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes
|
|
38
|
+
*/
|
|
39
|
+
export const GatewayCloseCode = {
|
|
40
|
+
UnknownError: 4000,
|
|
41
|
+
UnknownOpcode: 4001,
|
|
42
|
+
DecodeError: 4002,
|
|
43
|
+
NotAuthenticated: 4003,
|
|
44
|
+
AuthenticationFailed: 4004,
|
|
45
|
+
AlreadyAuthenticated: 4005,
|
|
46
|
+
InvalidSeq: 4007,
|
|
47
|
+
RateLimited: 4008,
|
|
48
|
+
SessionTimedOut: 4009,
|
|
49
|
+
InvalidShard: 4010,
|
|
50
|
+
ShardingRequired: 4011,
|
|
51
|
+
InvalidApiVersion: 4012,
|
|
52
|
+
InvalidIntents: 4013,
|
|
53
|
+
DisallowedIntents: 4014,
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Close codes after which reconnecting is pointless: the "Reconnect" column
|
|
57
|
+
* of the table says `false`.
|
|
58
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes
|
|
59
|
+
*/
|
|
60
|
+
export const FATAL_GATEWAY_CLOSE_CODES = new Set([
|
|
61
|
+
GatewayCloseCode.AuthenticationFailed,
|
|
62
|
+
GatewayCloseCode.InvalidShard,
|
|
63
|
+
GatewayCloseCode.ShardingRequired,
|
|
64
|
+
GatewayCloseCode.InvalidApiVersion,
|
|
65
|
+
GatewayCloseCode.InvalidIntents,
|
|
66
|
+
GatewayCloseCode.DisallowedIntents,
|
|
67
|
+
]);
|
|
68
|
+
/**
|
|
69
|
+
* Voice Opcodes
|
|
70
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#voice-voice-opcodes
|
|
71
|
+
*/
|
|
72
|
+
export const VoiceOpcode = {
|
|
73
|
+
/** Begin a voice websocket connection. */
|
|
74
|
+
Identify: 0,
|
|
75
|
+
/** Select the voice protocol. */
|
|
76
|
+
SelectProtocol: 1,
|
|
77
|
+
/** Complete the websocket handshake. */
|
|
78
|
+
Ready: 2,
|
|
79
|
+
/** Keep the websocket connection alive. */
|
|
80
|
+
Heartbeat: 3,
|
|
81
|
+
/** Describe the session. */
|
|
82
|
+
SessionDescription: 4,
|
|
83
|
+
/** Indicate which users are speaking. */
|
|
84
|
+
Speaking: 5,
|
|
85
|
+
/** Sent to acknowledge a received client heartbeat. */
|
|
86
|
+
HeartbeatAck: 6,
|
|
87
|
+
/** Resume a connection. */
|
|
88
|
+
Resume: 7,
|
|
89
|
+
/** Time to wait between sending heartbeats in milliseconds. */
|
|
90
|
+
Hello: 8,
|
|
91
|
+
/** Acknowledge a successful session resume. */
|
|
92
|
+
Resumed: 9,
|
|
93
|
+
/** One or more clients have connected to the voice channel */
|
|
94
|
+
ClientsConnect: 11,
|
|
95
|
+
/** A client has disconnected from the voice channel */
|
|
96
|
+
ClientDisconnect: 13,
|
|
97
|
+
/** A downgrade from the DAVE protocol is upcoming */
|
|
98
|
+
DavePrepareTransition: 21,
|
|
99
|
+
/** Execute a previously announced protocol transition */
|
|
100
|
+
DaveExecuteTransition: 22,
|
|
101
|
+
/** Acknowledge readiness previously announced transition */
|
|
102
|
+
DaveTransitionReady: 23,
|
|
103
|
+
/** A DAVE protocol version or group change is upcoming */
|
|
104
|
+
DavePrepareEpoch: 24,
|
|
105
|
+
/** Credential and public key for MLS external sender */
|
|
106
|
+
DaveMlsExternalSender: 25,
|
|
107
|
+
/** MLS Key Package for pending group member */
|
|
108
|
+
DaveMlsKeyPackage: 26,
|
|
109
|
+
/** MLS Proposals to be appended or revoked */
|
|
110
|
+
DaveMlsProposals: 27,
|
|
111
|
+
/** MLS Commit with optional MLS Welcome messages */
|
|
112
|
+
DaveMlsCommitWelcome: 28,
|
|
113
|
+
/** MLS Commit to be processed for upcoming transition */
|
|
114
|
+
DaveMlsAnnounceCommitTransition: 29,
|
|
115
|
+
/** MLS Welcome to group for upcoming transition */
|
|
116
|
+
DaveMlsWelcome: 30,
|
|
117
|
+
/** Flag invalid commit or welcome, request re-add */
|
|
118
|
+
DaveMlsInvalidCommitWelcome: 31,
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Voice Close Event Codes
|
|
122
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#voice-voice-close-event-codes
|
|
123
|
+
*/
|
|
124
|
+
export const VoiceCloseCode = {
|
|
125
|
+
UnknownOpcode: 4001,
|
|
126
|
+
FailedToDecodePayload: 4002,
|
|
127
|
+
NotAuthenticated: 4003,
|
|
128
|
+
AuthenticationFailed: 4004,
|
|
129
|
+
AlreadyAuthenticated: 4005,
|
|
130
|
+
SessionNoLongerValid: 4006,
|
|
131
|
+
SessionTimeout: 4009,
|
|
132
|
+
ServerNotFound: 4011,
|
|
133
|
+
UnknownProtocol: 4012,
|
|
134
|
+
Disconnected: 4014,
|
|
135
|
+
VoiceServerCrashed: 4015,
|
|
136
|
+
UnknownEncryptionMode: 4016,
|
|
137
|
+
E2eeDaveProtocolRequired: 4017,
|
|
138
|
+
BadRequest: 4020,
|
|
139
|
+
DisconnectedRateLimited: 4021,
|
|
140
|
+
DisconnectedCallTerminated: 4022,
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* HTTP Response Codes
|
|
144
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#http-http-response-codes
|
|
145
|
+
*/
|
|
146
|
+
export const HttpStatus = {
|
|
147
|
+
/** The request completed successfully. */
|
|
148
|
+
Ok: 200,
|
|
149
|
+
/** The entity was created successfully. */
|
|
150
|
+
Created: 201,
|
|
151
|
+
/** The request completed successfully but returned no content. */
|
|
152
|
+
NoContent: 204,
|
|
153
|
+
/** The entity was not modified (no action was taken). */
|
|
154
|
+
NotModified: 304,
|
|
155
|
+
/** The request was improperly formatted, or the server couldn't understand it. */
|
|
156
|
+
BadRequest: 400,
|
|
157
|
+
/** The `Authorization` header was missing or invalid. */
|
|
158
|
+
Unauthorized: 401,
|
|
159
|
+
/** The `Authorization` token you passed did not have permission to the resource. */
|
|
160
|
+
Forbidden: 403,
|
|
161
|
+
/** The resource at the location specified doesn't exist. */
|
|
162
|
+
NotFound: 404,
|
|
163
|
+
/** The HTTP method used is not valid for the location specified. */
|
|
164
|
+
MethodNotAllowed: 405,
|
|
165
|
+
/** You are being rate limited, see Rate Limits. */
|
|
166
|
+
TooManyRequests: 429,
|
|
167
|
+
/** There was not a gateway available to process your request. Wait a bit and retry. */
|
|
168
|
+
GatewayUnavailable: 502,
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* JSON Error Codes: the `code` of an error response, with what Discord says
|
|
172
|
+
* it means.
|
|
173
|
+
* @see https://docs.discord.com/developers/topics/opcodes-and-status-codes#json-json-error-codes
|
|
174
|
+
*/
|
|
175
|
+
export const JSON_ERROR_CODES = {
|
|
176
|
+
0: 'General error (such as a malformed request body, amongst other things)',
|
|
177
|
+
10001: 'Unknown account',
|
|
178
|
+
10002: 'Unknown application',
|
|
179
|
+
10003: 'Unknown channel',
|
|
180
|
+
10004: 'Unknown guild',
|
|
181
|
+
10005: 'Unknown integration',
|
|
182
|
+
10006: 'Unknown invite',
|
|
183
|
+
10007: 'Unknown member',
|
|
184
|
+
10008: 'Unknown message',
|
|
185
|
+
10009: 'Unknown permission overwrite',
|
|
186
|
+
10010: 'Unknown provider',
|
|
187
|
+
10011: 'Unknown role',
|
|
188
|
+
10012: 'Unknown token',
|
|
189
|
+
10013: 'Unknown user',
|
|
190
|
+
10014: 'Unknown emoji',
|
|
191
|
+
10015: 'Unknown webhook',
|
|
192
|
+
10016: 'Unknown webhook service',
|
|
193
|
+
10020: 'Unknown session',
|
|
194
|
+
10021: 'Unknown Asset',
|
|
195
|
+
10026: 'Unknown ban',
|
|
196
|
+
10027: 'Unknown SKU',
|
|
197
|
+
10028: 'Unknown Store Listing',
|
|
198
|
+
10029: 'Unknown entitlement',
|
|
199
|
+
10030: 'Unknown build',
|
|
200
|
+
10031: 'Unknown lobby',
|
|
201
|
+
10032: 'Unknown branch',
|
|
202
|
+
10033: 'Unknown store directory layout',
|
|
203
|
+
10036: 'Unknown redistributable',
|
|
204
|
+
10038: 'Unknown gift code',
|
|
205
|
+
10049: 'Unknown stream',
|
|
206
|
+
10050: 'Unknown premium server subscribe cooldown',
|
|
207
|
+
10057: 'Unknown guild template',
|
|
208
|
+
10059: 'Unknown discoverable server category',
|
|
209
|
+
10060: 'Unknown sticker',
|
|
210
|
+
10061: 'Unknown sticker pack',
|
|
211
|
+
10062: 'Unknown interaction',
|
|
212
|
+
10063: 'Unknown application command',
|
|
213
|
+
10065: 'Unknown voice state',
|
|
214
|
+
10066: 'Unknown application command permissions',
|
|
215
|
+
10067: 'Unknown Stage Instance',
|
|
216
|
+
10068: 'Unknown Guild Member Verification Form',
|
|
217
|
+
10069: 'Unknown Guild Welcome Screen',
|
|
218
|
+
10070: 'Unknown Guild Scheduled Event',
|
|
219
|
+
10071: 'Unknown Guild Scheduled Event User',
|
|
220
|
+
10087: 'Unknown Tag',
|
|
221
|
+
10097: 'Unknown sound',
|
|
222
|
+
10124: 'Unknown invite target users job (invite exists but has no target users)',
|
|
223
|
+
10129: 'Unknown invite target users (invite exists but has no target users)',
|
|
224
|
+
20001: 'Bots cannot use this endpoint',
|
|
225
|
+
20002: 'Only bots can use this endpoint',
|
|
226
|
+
20009: 'Explicit content cannot be sent to the desired recipient(s)',
|
|
227
|
+
20012: 'You are not authorized to perform this action on this application',
|
|
228
|
+
20015: 'This action requires a premium subscription',
|
|
229
|
+
20016: 'This action cannot be performed due to slowmode rate limit',
|
|
230
|
+
20018: 'Only the owner of this account can perform this action',
|
|
231
|
+
20022: 'This message cannot be edited due to announcement rate limits',
|
|
232
|
+
20024: 'Under minimum age',
|
|
233
|
+
20028: 'The write action you are performing on the channel has hit the write rate limit',
|
|
234
|
+
20029: 'The write action you are performing on the server has hit the write rate limit',
|
|
235
|
+
20031: 'Your Stage topic, server name, server description, or channel names contain words that are not allowed',
|
|
236
|
+
20035: 'Guild premium subscription level too low',
|
|
237
|
+
30001: 'Maximum number of guilds reached (100)',
|
|
238
|
+
30002: 'Maximum number of friends reached (1000)',
|
|
239
|
+
30003: 'Maximum number of pins reached for the channel (250)',
|
|
240
|
+
30004: 'Maximum number of recipients reached (10)',
|
|
241
|
+
30005: 'Maximum number of guild roles reached (250)',
|
|
242
|
+
30007: 'Maximum number of webhooks reached (15)',
|
|
243
|
+
30008: 'Maximum number of emojis reached',
|
|
244
|
+
30010: 'Maximum number of reactions reached (20)',
|
|
245
|
+
30011: 'Maximum number of group DMs reached (10)',
|
|
246
|
+
30013: 'Maximum number of guild channels reached (500)',
|
|
247
|
+
30015: 'Maximum number of attachments in a message reached (10)',
|
|
248
|
+
30016: 'Maximum number of invites reached (1000)',
|
|
249
|
+
30018: 'Maximum number of animated emojis reached',
|
|
250
|
+
30019: 'Maximum number of server members reached',
|
|
251
|
+
30030: 'Maximum number of server categories has been reached (5)',
|
|
252
|
+
30031: 'Guild already has a template',
|
|
253
|
+
30032: 'Maximum number of application commands reached',
|
|
254
|
+
30033: 'Maximum number of thread participants has been reached (1000)',
|
|
255
|
+
30034: 'Maximum number of daily application command creates has been reached (200)',
|
|
256
|
+
30035: 'Maximum number of bans for non-guild members have been exceeded',
|
|
257
|
+
30037: 'Maximum number of bans fetches has been reached',
|
|
258
|
+
30038: 'Maximum number of uncompleted guild scheduled events reached (100)',
|
|
259
|
+
30039: 'Maximum number of stickers reached',
|
|
260
|
+
30040: 'Maximum number of prune requests has been reached. Try again later',
|
|
261
|
+
30042: 'Maximum number of guild widget settings updates has been reached. Try again later',
|
|
262
|
+
30045: 'Maximum number of soundboard sounds reached',
|
|
263
|
+
30046: 'Maximum number of edits to messages older than 1 hour reached. Try again later',
|
|
264
|
+
30047: 'Maximum number of pinned threads in a forum channel has been reached',
|
|
265
|
+
30048: 'Maximum number of tags in a forum channel has been reached',
|
|
266
|
+
30052: 'Bitrate is too high for channel of this type',
|
|
267
|
+
30056: 'Maximum number of premium emojis reached (25)',
|
|
268
|
+
30058: 'Maximum number of webhooks per guild reached (1000)',
|
|
269
|
+
30060: 'Maximum number of channel permission overwrites reached (1000)',
|
|
270
|
+
30061: 'The channels for this guild are too large',
|
|
271
|
+
30084: 'Target users limit for this guild reached',
|
|
272
|
+
40001: 'Unauthorized. Provide a valid token and try again',
|
|
273
|
+
40002: 'You need to verify your account in order to perform this action',
|
|
274
|
+
40003: 'You are opening direct messages too fast',
|
|
275
|
+
40004: 'Send messages has been temporarily disabled',
|
|
276
|
+
40005: 'Request entity too large. Try sending something smaller in size',
|
|
277
|
+
40006: 'This feature has been temporarily disabled server-side',
|
|
278
|
+
40007: 'The user is banned from this guild',
|
|
279
|
+
40009: 'Only one channel can have a parent_id modified at a time',
|
|
280
|
+
40012: 'Connection has been revoked',
|
|
281
|
+
40018: 'Only consumable SKUs can be consumed',
|
|
282
|
+
40019: 'You can only delete sandbox entitlements.',
|
|
283
|
+
40032: 'Target user is not connected to voice',
|
|
284
|
+
40033: 'This message has already been crossposted',
|
|
285
|
+
40041: 'An application command with that name already exists',
|
|
286
|
+
40043: 'Application interaction failed to send',
|
|
287
|
+
40058: 'Cannot send a message in a forum channel',
|
|
288
|
+
40060: 'Interaction has already been acknowledged',
|
|
289
|
+
40061: 'Tag names must be unique',
|
|
290
|
+
40062: 'Service resource is being rate limited',
|
|
291
|
+
40066: 'There are no tags available that can be set by non-moderators',
|
|
292
|
+
40067: 'A tag is required to create a forum post in this channel',
|
|
293
|
+
40074: 'An entitlement has already been granted for this resource',
|
|
294
|
+
40094: 'This interaction has hit the maximum number of follow up messages',
|
|
295
|
+
40114: 'Target users are already being processed for this invite',
|
|
296
|
+
40115: 'Target users file has not been processed',
|
|
297
|
+
40333: 'Cloudflare is blocking your request. This can often be resolved by setting a proper User Agent',
|
|
298
|
+
50001: 'Missing access',
|
|
299
|
+
50002: 'Invalid account type',
|
|
300
|
+
50003: 'Cannot execute action on a DM channel',
|
|
301
|
+
50004: 'Guild widget disabled',
|
|
302
|
+
50005: 'Cannot edit a message authored by another user',
|
|
303
|
+
50006: 'Cannot send an empty message',
|
|
304
|
+
50007: 'Cannot send messages to this user',
|
|
305
|
+
50008: 'Cannot send messages in a non-text channel',
|
|
306
|
+
50009: 'Channel verification level is too high for you to gain access',
|
|
307
|
+
50010: 'OAuth2 application does not have a bot',
|
|
308
|
+
50011: 'OAuth2 application limit reached',
|
|
309
|
+
50012: 'Invalid OAuth2 state',
|
|
310
|
+
50013: 'You lack permissions to perform that action',
|
|
311
|
+
50014: 'Invalid authentication token provided',
|
|
312
|
+
50015: 'Note was too long',
|
|
313
|
+
50016: 'Provided too few or too many messages to delete. Must provide at least 2 and fewer than 100 messages to delete',
|
|
314
|
+
50017: 'Invalid MFA Level',
|
|
315
|
+
50019: 'A message can only be pinned to the channel it was sent in',
|
|
316
|
+
50020: 'Invite code was either invalid or taken',
|
|
317
|
+
50021: 'Cannot execute action on a system message',
|
|
318
|
+
50024: 'Cannot execute action on this channel type',
|
|
319
|
+
50025: 'Invalid OAuth2 access token provided',
|
|
320
|
+
50026: 'Missing required OAuth2 scope',
|
|
321
|
+
50027: 'Invalid webhook token provided',
|
|
322
|
+
50028: 'Invalid role',
|
|
323
|
+
50033: 'Invalid Recipient(s)',
|
|
324
|
+
50034: 'A message provided was too old to bulk delete',
|
|
325
|
+
50035: 'Invalid form body (returned for both `application/json` and `multipart/form-data` bodies), or invalid `Content-Type` provided',
|
|
326
|
+
50036: "An invite was accepted to a guild the application's bot is not in",
|
|
327
|
+
50039: 'Invalid Activity Action',
|
|
328
|
+
50041: 'Invalid API version provided',
|
|
329
|
+
50045: 'File uploaded exceeds the maximum size',
|
|
330
|
+
50046: 'Invalid file uploaded',
|
|
331
|
+
50054: 'Cannot self-redeem this gift',
|
|
332
|
+
50055: 'Invalid Guild',
|
|
333
|
+
50057: 'Invalid SKU',
|
|
334
|
+
50067: 'Invalid request origin',
|
|
335
|
+
50068: 'Invalid message type',
|
|
336
|
+
50070: 'Payment source required to redeem gift',
|
|
337
|
+
50073: 'Cannot modify a system webhook',
|
|
338
|
+
50074: 'Cannot delete a channel required for Community guilds',
|
|
339
|
+
50080: 'Cannot edit stickers within a message',
|
|
340
|
+
50081: 'Invalid sticker sent',
|
|
341
|
+
50083: 'Tried to perform an operation on an archived thread, such as editing a message or adding a user to the thread',
|
|
342
|
+
50084: 'Invalid thread notification settings',
|
|
343
|
+
50085: '`before` value is earlier than the thread creation date',
|
|
344
|
+
50086: 'Community server channels must be text channels',
|
|
345
|
+
50091: 'The entity type of the event is different from the entity you are trying to start the event for',
|
|
346
|
+
50095: 'This server is not available in your location',
|
|
347
|
+
50097: 'This server needs monetization enabled in order to perform this action',
|
|
348
|
+
50101: 'This server needs more boosts to perform this action',
|
|
349
|
+
50109: 'The request body contains invalid JSON.',
|
|
350
|
+
50110: 'The provided file is invalid.',
|
|
351
|
+
50123: 'The provided file type is invalid.',
|
|
352
|
+
50124: 'The provided file duration exceeds maximum of 5.2 seconds.',
|
|
353
|
+
50131: 'Owner cannot be pending member',
|
|
354
|
+
50132: 'Ownership cannot be transferred to a bot user',
|
|
355
|
+
50138: 'Failed to resize asset below the maximum size: 262144',
|
|
356
|
+
50144: 'Cannot mix subscription and non subscription roles for an emoji',
|
|
357
|
+
50145: 'Cannot convert between premium emoji and normal emoji',
|
|
358
|
+
50146: 'Uploaded file not found.',
|
|
359
|
+
50151: 'The specified emoji is invalid',
|
|
360
|
+
50159: 'Voice messages do not support additional content.',
|
|
361
|
+
50160: 'Voice messages must have a single audio attachment.',
|
|
362
|
+
50161: 'Voice messages must have supporting metadata.',
|
|
363
|
+
50162: 'Voice messages cannot be edited.',
|
|
364
|
+
50163: 'Cannot delete guild subscription integration',
|
|
365
|
+
50167: 'Cannot send voice effect when user is server muted, deafened, or suppressed',
|
|
366
|
+
50173: 'You cannot send voice messages in this channel.',
|
|
367
|
+
50178: 'The user account must first be verified',
|
|
368
|
+
50192: 'The provided file does not have a valid duration.',
|
|
369
|
+
50278: 'Cannot send messages to this user due to having no mutual guilds',
|
|
370
|
+
50600: 'You do not have permission to send this sticker.',
|
|
371
|
+
60003: 'Two factor is required for this operation',
|
|
372
|
+
80004: 'No users with DiscordTag exist',
|
|
373
|
+
90001: 'Reaction was blocked',
|
|
374
|
+
90002: 'User cannot use burst reactions',
|
|
375
|
+
110000: 'Index not yet available. Try again later',
|
|
376
|
+
110001: 'Application not yet available. Try again later',
|
|
377
|
+
130000: 'API resource is currently overloaded. Try again a little later',
|
|
378
|
+
150006: 'The Stage is already open',
|
|
379
|
+
160002: 'Cannot reply without permission to read message history',
|
|
380
|
+
160004: 'A thread has already been created for this message',
|
|
381
|
+
160005: 'Thread is locked',
|
|
382
|
+
160006: 'Maximum number of active threads reached',
|
|
383
|
+
160007: 'Maximum number of active announcement threads reached',
|
|
384
|
+
160009: 'Cannot reference a message without permission to read message history',
|
|
385
|
+
160010: 'NSFW channel message reference not allowed',
|
|
386
|
+
160014: 'You cannot forward a message whose content you cannot read',
|
|
387
|
+
170001: 'Invalid JSON for uploaded Lottie file',
|
|
388
|
+
170002: 'Uploaded Lotties cannot contain rasterized images such as PNG or JPEG',
|
|
389
|
+
170003: 'Sticker maximum framerate exceeded',
|
|
390
|
+
170004: 'Sticker frame count exceeds maximum of 1000 frames',
|
|
391
|
+
170005: 'Lottie animation maximum dimensions exceeded',
|
|
392
|
+
170006: 'Sticker frame rate is either too small or too large',
|
|
393
|
+
170007: 'Sticker animation duration exceeds maximum of 5 seconds',
|
|
394
|
+
180000: 'Cannot update a finished event',
|
|
395
|
+
180002: 'Failed to create stage needed for stage event',
|
|
396
|
+
200000: 'Message was blocked by automatic moderation',
|
|
397
|
+
200001: 'Title was blocked by automatic moderation',
|
|
398
|
+
220001: 'Webhooks posted to forum channels must have a thread_name or thread_id',
|
|
399
|
+
220002: 'Webhooks posted to forum channels cannot have both a thread_name and thread_id',
|
|
400
|
+
220003: 'Webhooks can only create threads in forum channels',
|
|
401
|
+
220004: 'Webhook services cannot be used in forum channels',
|
|
402
|
+
240000: 'Message blocked by harmful links filter',
|
|
403
|
+
340015: 'Access to joining new servers has been limited for the user',
|
|
404
|
+
350000: 'Cannot enable onboarding, requirements are not met',
|
|
405
|
+
350001: 'Cannot update onboarding while below requirements',
|
|
406
|
+
400001: 'Access to file uploads has been limited for this guild',
|
|
407
|
+
500000: 'Failed to ban users',
|
|
408
|
+
520000: 'Poll voting blocked',
|
|
409
|
+
520001: 'Poll expired',
|
|
410
|
+
520002: 'Invalid channel type for poll creation',
|
|
411
|
+
520003: 'Cannot edit a poll message',
|
|
412
|
+
520004: 'Cannot use an emoji included with the poll',
|
|
413
|
+
520006: 'Cannot expire a non-poll message',
|
|
414
|
+
530000: 'Your Discord application has not been granted the permission to use provisional accounts.',
|
|
415
|
+
530001: 'The ID token JWT you have provided is expired. You will need to get another one issued from the identity provider.',
|
|
416
|
+
530002: 'The issuer in the ID token JWT you have provided does not match what you have configured.',
|
|
417
|
+
530003: 'The audience in the ID token JWT you have provided does not match the audience you specified in your OIDC configuration. Either update your configuration or pass in an ID token that was issued to your application.',
|
|
418
|
+
530004: 'The ID token you provided was issued too long ago. Discord will not accept ID tokens issued beyond a week ago. You will need to get a new ID token issued from the identity provider.',
|
|
419
|
+
530006: 'Discord failed to generate a unique username within the allotted time. This is not a terminal error, and should resolve itself upon a retry.',
|
|
420
|
+
530007: 'Your client secret is invalid. Double check what you are sending or regenerate your client secret.',
|
|
421
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Snowflake } from './types/common.js';
|
|
2
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
3
|
+
/** What an endpoint takes and returns; a missing key means "nothing". */
|
|
4
|
+
export interface EndpointTypes {
|
|
5
|
+
/** The JSON body of the request. */
|
|
6
|
+
body?: unknown;
|
|
7
|
+
/** The query string parameters. */
|
|
8
|
+
query?: unknown;
|
|
9
|
+
/** The JSON body of the response. */
|
|
10
|
+
result?: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One REST endpoint: its method and its path as written in the official
|
|
14
|
+
* documentation (`/guilds/{guild.id}/members/{user.id}`). The types of its
|
|
15
|
+
* body, query and result only exist for the compiler.
|
|
16
|
+
*/
|
|
17
|
+
export interface Endpoint<Path extends string = string, Types extends EndpointTypes = EndpointTypes> {
|
|
18
|
+
readonly method: HttpMethod;
|
|
19
|
+
readonly path: Path;
|
|
20
|
+
/** Never set: only carries the types of the endpoint. */
|
|
21
|
+
readonly types?: Types;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The values that fill the `{placeholders}` of a path, in order:
|
|
25
|
+
* `'/guilds/{guild.id}/members/{user.id}'` takes `[guildId, userId]`.
|
|
26
|
+
*/
|
|
27
|
+
export type PathParams<Path extends string> = Path extends `${string}{${string}}${infer Rest}` ? [Snowflake, ...PathParams<Rest>] : [];
|
|
28
|
+
export type EndpointBody<E extends Endpoint> = NonNullable<E['types']> extends {
|
|
29
|
+
body: infer Body;
|
|
30
|
+
} ? Body : undefined;
|
|
31
|
+
export type EndpointQuery<E extends Endpoint> = NonNullable<E['types']> extends {
|
|
32
|
+
query: infer Query;
|
|
33
|
+
} ? Query : undefined;
|
|
34
|
+
export type EndpointResult<E extends Endpoint> = NonNullable<E['types']> extends {
|
|
35
|
+
result: infer Result;
|
|
36
|
+
} ? Result : void;
|
|
37
|
+
/**
|
|
38
|
+
* Declares an endpoint. Called in two steps so the types are given by hand
|
|
39
|
+
* while the path keeps its literal type:
|
|
40
|
+
* `endpoint<{ result: RawUser }>()('GET', '/users/{user.id}')`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function endpoint<Types extends EndpointTypes>(): <Path extends string>(method: HttpMethod, path: Path) => Endpoint<Path, Types>;
|
|
43
|
+
/** The names of the `{placeholders}` of a path, in order. */
|
|
44
|
+
export declare function pathParamNames(path: string): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Replaces the `{placeholders}` of a path with the given values, URL-encoded
|
|
47
|
+
* (an emoji in a reaction path, for example, is not URL-safe).
|
|
48
|
+
*/
|
|
49
|
+
export declare function fillPath(path: string, params: readonly string[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* The part of a request that Discord counts rate limits by, besides the
|
|
52
|
+
* endpoint itself: the top-level resource of the path (a channel, a guild,
|
|
53
|
+
* or a webhook with its token).
|
|
54
|
+
* @see https://docs.discord.com/developers/topics/rate-limits#rate-limits
|
|
55
|
+
*/
|
|
56
|
+
export declare function majorParameter(path: string, params: readonly string[]): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declares an endpoint. Called in two steps so the types are given by hand
|
|
3
|
+
* while the path keeps its literal type:
|
|
4
|
+
* `endpoint<{ result: RawUser }>()('GET', '/users/{user.id}')`.
|
|
5
|
+
*/
|
|
6
|
+
export function endpoint() {
|
|
7
|
+
return (method, path) => Object.freeze({ method, path });
|
|
8
|
+
}
|
|
9
|
+
const PLACEHOLDER = /\{([^}]+)\}/g;
|
|
10
|
+
/** The names of the `{placeholders}` of a path, in order. */
|
|
11
|
+
export function pathParamNames(path) {
|
|
12
|
+
return Array.from(path.matchAll(PLACEHOLDER), match => match[1]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Replaces the `{placeholders}` of a path with the given values, URL-encoded
|
|
16
|
+
* (an emoji in a reaction path, for example, is not URL-safe).
|
|
17
|
+
*/
|
|
18
|
+
export function fillPath(path, params) {
|
|
19
|
+
const names = pathParamNames(path);
|
|
20
|
+
if (names.length !== params.length) {
|
|
21
|
+
throw new TypeError(`"${path}" takes ${names.length} value(s) (${names.join(', ') || 'none'}), got ${params.length}.`);
|
|
22
|
+
}
|
|
23
|
+
let index = 0;
|
|
24
|
+
return path.replace(PLACEHOLDER, (_, name) => {
|
|
25
|
+
const value = params[index++];
|
|
26
|
+
if (typeof value !== 'string' || value === '') {
|
|
27
|
+
throw new TypeError(`"${path}" needs a non-empty text for {${name}}, got ${JSON.stringify(value)}.`);
|
|
28
|
+
}
|
|
29
|
+
return encodeURIComponent(value);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The part of a request that Discord counts rate limits by, besides the
|
|
34
|
+
* endpoint itself: the top-level resource of the path (a channel, a guild,
|
|
35
|
+
* or a webhook with its token).
|
|
36
|
+
* @see https://docs.discord.com/developers/topics/rate-limits#rate-limits
|
|
37
|
+
*/
|
|
38
|
+
export function majorParameter(path, params) {
|
|
39
|
+
const names = pathParamNames(path);
|
|
40
|
+
const first = names[0];
|
|
41
|
+
if (first === 'channel.id' || first === 'guild.id')
|
|
42
|
+
return params[0];
|
|
43
|
+
if (first === 'webhook.id') {
|
|
44
|
+
return names[1] === 'webhook.token'
|
|
45
|
+
? `${params[0]}/${params[1]}`
|
|
46
|
+
: params[0];
|
|
47
|
+
}
|
|
48
|
+
// Interaction endpoints are webhooks named after the application.
|
|
49
|
+
if (first === 'application.id' && names[1] === 'interaction.token') {
|
|
50
|
+
return `${params[0]}/${params[1]}`;
|
|
51
|
+
}
|
|
52
|
+
return '';
|
|
53
|
+
}
|