seyfert 0.1.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 +190 -0
- package/README.md +57 -0
- package/lib/api/CDN.d.ts +220 -0
- package/lib/api/CDN.js +236 -0
- package/lib/api/REST.d.ts +127 -0
- package/lib/api/REST.js +424 -0
- package/lib/api/Router.d.ts +17 -0
- package/lib/api/Router.js +63 -0
- package/lib/api/Routes/applications.d.ts +46 -0
- package/lib/api/Routes/applications.js +2 -0
- package/lib/api/Routes/cdn.d.ts +66 -0
- package/lib/api/Routes/cdn.js +2 -0
- package/lib/api/Routes/channels.d.ts +109 -0
- package/lib/api/Routes/channels.js +2 -0
- package/lib/api/Routes/gateway.d.ts +11 -0
- package/lib/api/Routes/gateway.js +2 -0
- package/lib/api/Routes/guilds.d.ts +171 -0
- package/lib/api/Routes/guilds.js +2 -0
- package/lib/api/Routes/index.d.ts +13 -0
- package/lib/api/Routes/index.js +17 -0
- package/lib/api/Routes/interactions.d.ts +14 -0
- package/lib/api/Routes/interactions.js +2 -0
- package/lib/api/Routes/invites.d.ts +9 -0
- package/lib/api/Routes/invites.js +2 -0
- package/lib/api/Routes/stage-instances.d.ts +13 -0
- package/lib/api/Routes/stage-instances.js +2 -0
- package/lib/api/Routes/stickers.d.ts +11 -0
- package/lib/api/Routes/stickers.js +2 -0
- package/lib/api/Routes/users.d.ts +35 -0
- package/lib/api/Routes/users.js +2 -0
- package/lib/api/Routes/voice.d.ts +10 -0
- package/lib/api/Routes/voice.js +2 -0
- package/lib/api/Routes/webhooks.d.ts +29 -0
- package/lib/api/Routes/webhooks.js +2 -0
- package/lib/api/errors/DiscordAPIError.d.ts +51 -0
- package/lib/api/errors/DiscordAPIError.js +81 -0
- package/lib/api/errors/HTTPError.d.ts +20 -0
- package/lib/api/errors/HTTPError.js +28 -0
- package/lib/api/errors/RateLimitError.d.ts +19 -0
- package/lib/api/errors/RateLimitError.js +37 -0
- package/lib/api/handlers/BurstHandler.d.ts +51 -0
- package/lib/api/handlers/BurstHandler.js +124 -0
- package/lib/api/handlers/SequentialHandler.d.ts +81 -0
- package/lib/api/handlers/SequentialHandler.js +365 -0
- package/lib/api/handlers/Shared.d.ts +14 -0
- package/lib/api/handlers/Shared.js +125 -0
- package/lib/api/index.d.ts +5 -0
- package/lib/api/index.js +21 -0
- package/lib/api/interfaces/Handler.d.ts +21 -0
- package/lib/api/interfaces/Handler.js +2 -0
- package/lib/api/shared.d.ts +7 -0
- package/lib/api/shared.js +27 -0
- package/lib/api/utils/constants.d.ts +39 -0
- package/lib/api/utils/constants.js +50 -0
- package/lib/api/utils/types.d.ts +335 -0
- package/lib/api/utils/types.js +14 -0
- package/lib/api/utils/utils.d.ts +52 -0
- package/lib/api/utils/utils.js +159 -0
- package/lib/builders/ActionRow.d.ts +40 -0
- package/lib/builders/ActionRow.js +58 -0
- package/lib/builders/Attachment.d.ts +106 -0
- package/lib/builders/Attachment.js +196 -0
- package/lib/builders/Base.d.ts +10 -0
- package/lib/builders/Base.js +13 -0
- package/lib/builders/Button.d.ts +59 -0
- package/lib/builders/Button.js +94 -0
- package/lib/builders/MessageEmbed.d.ts +116 -0
- package/lib/builders/MessageEmbed.js +159 -0
- package/lib/builders/Modal.d.ts +111 -0
- package/lib/builders/Modal.js +162 -0
- package/lib/builders/SelectMenu.d.ts +201 -0
- package/lib/builders/SelectMenu.js +293 -0
- package/lib/builders/index.d.ts +12 -0
- package/lib/builders/index.js +54 -0
- package/lib/builders/types.d.ts +21 -0
- package/lib/builders/types.js +2 -0
- package/lib/cache/adapters/default.d.ts +24 -0
- package/lib/cache/adapters/default.js +118 -0
- package/lib/cache/adapters/index.d.ts +4 -0
- package/lib/cache/adapters/index.js +20 -0
- package/lib/cache/adapters/redis.d.ts +35 -0
- package/lib/cache/adapters/redis.js +180 -0
- package/lib/cache/adapters/types.d.ts +25 -0
- package/lib/cache/adapters/types.js +2 -0
- package/lib/cache/adapters/workeradapter.d.ts +24 -0
- package/lib/cache/adapters/workeradapter.js +76 -0
- package/lib/cache/index.d.ts +97 -0
- package/lib/cache/index.js +394 -0
- package/lib/cache/resources/channels.d.ts +7 -0
- package/lib/cache/resources/channels.js +20 -0
- package/lib/cache/resources/default/base.d.ts +25 -0
- package/lib/cache/resources/default/base.js +75 -0
- package/lib/cache/resources/default/guild-based.d.ts +33 -0
- package/lib/cache/resources/default/guild-based.js +91 -0
- package/lib/cache/resources/default/guild-related.d.ts +32 -0
- package/lib/cache/resources/default/guild-related.js +102 -0
- package/lib/cache/resources/emojis.d.ts +7 -0
- package/lib/cache/resources/emojis.js +17 -0
- package/lib/cache/resources/guilds.d.ts +10 -0
- package/lib/cache/resources/guilds.js +117 -0
- package/lib/cache/resources/members.d.ts +10 -0
- package/lib/cache/resources/members.js +41 -0
- package/lib/cache/resources/presence.d.ts +9 -0
- package/lib/cache/resources/presence.js +14 -0
- package/lib/cache/resources/roles.d.ts +7 -0
- package/lib/cache/resources/roles.js +17 -0
- package/lib/cache/resources/stage-instances.d.ts +5 -0
- package/lib/cache/resources/stage-instances.js +8 -0
- package/lib/cache/resources/stickers.d.ts +7 -0
- package/lib/cache/resources/stickers.js +17 -0
- package/lib/cache/resources/threads.d.ts +7 -0
- package/lib/cache/resources/threads.js +17 -0
- package/lib/cache/resources/users.d.ts +7 -0
- package/lib/cache/resources/users.js +17 -0
- package/lib/cache/resources/voice-states.d.ts +9 -0
- package/lib/cache/resources/voice-states.js +13 -0
- package/lib/client/base.d.ts +244 -0
- package/lib/client/base.js +178 -0
- package/lib/client/client.d.ts +32 -0
- package/lib/client/client.js +156 -0
- package/lib/client/httpclient.d.ts +21 -0
- package/lib/client/httpclient.js +143 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +19 -0
- package/lib/client/oninteraction.d.ts +4 -0
- package/lib/client/oninteraction.js +180 -0
- package/lib/client/workerclient.d.ts +28 -0
- package/lib/client/workerclient.js +213 -0
- package/lib/collection.d.ts +233 -0
- package/lib/collection.js +371 -0
- package/lib/commands/applications/chat.d.ts +139 -0
- package/lib/commands/applications/chat.js +173 -0
- package/lib/commands/applications/chatcontext.d.ts +28 -0
- package/lib/commands/applications/chatcontext.js +53 -0
- package/lib/commands/applications/menu.d.ts +39 -0
- package/lib/commands/applications/menu.js +87 -0
- package/lib/commands/applications/menucontext.d.ts +25 -0
- package/lib/commands/applications/menucontext.js +64 -0
- package/lib/commands/applications/options.d.ts +67 -0
- package/lib/commands/applications/options.js +44 -0
- package/lib/commands/applications/shared.d.ts +35 -0
- package/lib/commands/applications/shared.js +2 -0
- package/lib/commands/decorators.d.ts +107 -0
- package/lib/commands/decorators.js +85 -0
- package/lib/commands/handler.d.ts +15 -0
- package/lib/commands/handler.js +140 -0
- package/lib/commands/index.d.ts +8 -0
- package/lib/commands/index.js +24 -0
- package/lib/commands/optionresolver.d.ts +49 -0
- package/lib/commands/optionresolver.js +146 -0
- package/lib/common/bot/watcher.d.ts +53 -0
- package/lib/common/bot/watcher.js +104 -0
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.js +30 -0
- package/lib/common/it/colors.d.ts +274 -0
- package/lib/common/it/colors.js +453 -0
- package/lib/common/it/constants.d.ts +36 -0
- package/lib/common/it/constants.js +40 -0
- package/lib/common/it/logger.d.ts +114 -0
- package/lib/common/it/logger.js +189 -0
- package/lib/common/it/utils.d.ts +107 -0
- package/lib/common/it/utils.js +275 -0
- package/lib/common/shorters/base.d.ts +5 -0
- package/lib/common/shorters/base.js +10 -0
- package/lib/common/shorters/channels.d.ts +90 -0
- package/lib/common/shorters/channels.js +95 -0
- package/lib/common/shorters/guilds.d.ts +389 -0
- package/lib/common/shorters/guilds.js +350 -0
- package/lib/common/shorters/members.d.ts +115 -0
- package/lib/common/shorters/members.js +179 -0
- package/lib/common/shorters/messages.d.ts +27 -0
- package/lib/common/shorters/messages.js +117 -0
- package/lib/common/shorters/roles.d.ts +12 -0
- package/lib/common/shorters/roles.js +51 -0
- package/lib/common/shorters/templates.d.ts +12 -0
- package/lib/common/shorters/templates.js +29 -0
- package/lib/common/shorters/users.d.ts +11 -0
- package/lib/common/shorters/users.js +42 -0
- package/lib/common/shorters/webhook.d.ts +33 -0
- package/lib/common/shorters/webhook.js +69 -0
- package/lib/common/types/options.d.ts +10 -0
- package/lib/common/types/options.js +2 -0
- package/lib/common/types/resolvables.d.ts +10 -0
- package/lib/common/types/resolvables.js +2 -0
- package/lib/common/types/util.d.ts +90 -0
- package/lib/common/types/util.js +2 -0
- package/lib/common/types/write.d.ts +21 -0
- package/lib/common/types/write.js +2 -0
- package/lib/components/ActionRow.d.ts +10 -0
- package/lib/components/ActionRow.js +13 -0
- package/lib/components/ButtonComponent.d.ts +19 -0
- package/lib/components/ButtonComponent.js +34 -0
- package/lib/components/ChannelSelectMenuComponent.d.ts +6 -0
- package/lib/components/ChannelSelectMenuComponent.js +12 -0
- package/lib/components/MentionableSelectMenuComponent.d.ts +4 -0
- package/lib/components/MentionableSelectMenuComponent.js +7 -0
- package/lib/components/RoleSelectMenuComponent.d.ts +4 -0
- package/lib/components/RoleSelectMenuComponent.js +7 -0
- package/lib/components/StringSelectMenuComponent.d.ts +6 -0
- package/lib/components/StringSelectMenuComponent.js +12 -0
- package/lib/components/TextInputComponent.d.ts +7 -0
- package/lib/components/TextInputComponent.js +14 -0
- package/lib/components/UserSelectMenuComponent.d.ts +4 -0
- package/lib/components/UserSelectMenuComponent.js +7 -0
- package/lib/components/command.d.ts +23 -0
- package/lib/components/command.js +15 -0
- package/lib/components/handler.d.ts +48 -0
- package/lib/components/handler.js +231 -0
- package/lib/components/index.d.ts +20 -0
- package/lib/components/index.js +55 -0
- package/lib/components/listener.d.ts +11 -0
- package/lib/components/listener.js +18 -0
- package/lib/events/event.d.ts +23 -0
- package/lib/events/event.js +2 -0
- package/lib/events/handler.d.ts +19 -0
- package/lib/events/handler.js +112 -0
- package/lib/events/hooks/application_command.d.ts +12 -0
- package/lib/events/hooks/application_command.js +8 -0
- package/lib/events/hooks/auto_moderation.d.ts +22 -0
- package/lib/events/hooks/auto_moderation.js +21 -0
- package/lib/events/hooks/channel.d.ts +11 -0
- package/lib/events/hooks/channel.js +24 -0
- package/lib/events/hooks/custom.d.ts +4 -0
- package/lib/events/hooks/custom.js +11 -0
- package/lib/events/hooks/dispatch.d.ts +5 -0
- package/lib/events/hooks/dispatch.js +12 -0
- package/lib/events/hooks/entitlement.d.ts +35 -0
- package/lib/events/hooks/entitlement.js +16 -0
- package/lib/events/hooks/guild.d.ts +228 -0
- package/lib/events/hooks/guild.js +101 -0
- package/lib/events/hooks/index.d.ts +23 -0
- package/lib/events/hooks/index.js +34 -0
- package/lib/events/hooks/integration.d.ts +94 -0
- package/lib/events/hooks/integration.js +27 -0
- package/lib/events/hooks/interactions.d.ts +4 -0
- package/lib/events/hooks/interactions.js +8 -0
- package/lib/events/hooks/invite.d.ts +21 -0
- package/lib/events/hooks/invite.js +12 -0
- package/lib/events/hooks/message.d.ts +69 -0
- package/lib/events/hooks/message.js +37 -0
- package/lib/events/hooks/presence.d.ts +27 -0
- package/lib/events/hooks/presence.js +8 -0
- package/lib/events/hooks/stage.d.ts +29 -0
- package/lib/events/hooks/stage.js +16 -0
- package/lib/events/hooks/thread.d.ts +198 -0
- package/lib/events/hooks/thread.js +29 -0
- package/lib/events/hooks/typing.d.ts +16 -0
- package/lib/events/hooks/typing.js +14 -0
- package/lib/events/hooks/user.d.ts +4 -0
- package/lib/events/hooks/user.js +8 -0
- package/lib/events/hooks/voice.d.ts +37 -0
- package/lib/events/hooks/voice.js +18 -0
- package/lib/events/hooks/webhook.d.ts +6 -0
- package/lib/events/hooks/webhook.js +8 -0
- package/lib/events/index.d.ts +2 -0
- package/lib/events/index.js +18 -0
- package/lib/index.d.ts +79 -0
- package/lib/index.js +104 -0
- package/lib/langs/handler.d.ts +11 -0
- package/lib/langs/handler.js +34 -0
- package/lib/langs/index.d.ts +2 -0
- package/lib/langs/index.js +18 -0
- package/lib/langs/router.d.ts +18 -0
- package/lib/langs/router.js +42 -0
- package/lib/structures/AnonymousGuild.d.ts +7 -0
- package/lib/structures/AnonymousGuild.js +11 -0
- package/lib/structures/AutoModerationRule.d.ts +22 -0
- package/lib/structures/AutoModerationRule.js +34 -0
- package/lib/structures/ClientUser.d.ts +25 -0
- package/lib/structures/ClientUser.js +52 -0
- package/lib/structures/Guild.d.ts +86 -0
- package/lib/structures/Guild.js +66 -0
- package/lib/structures/GuildEmoji.d.ts +29 -0
- package/lib/structures/GuildEmoji.js +47 -0
- package/lib/structures/GuildMember.d.ts +92 -0
- package/lib/structures/GuildMember.js +137 -0
- package/lib/structures/GuildPreview.d.ts +10 -0
- package/lib/structures/GuildPreview.js +14 -0
- package/lib/structures/GuildRole.d.ts +21 -0
- package/lib/structures/GuildRole.js +32 -0
- package/lib/structures/GuildTemplate.d.ts +23 -0
- package/lib/structures/GuildTemplate.js +36 -0
- package/lib/structures/Interaction.d.ts +152 -0
- package/lib/structures/Interaction.js +409 -0
- package/lib/structures/Message.d.ts +53 -0
- package/lib/structures/Message.js +123 -0
- package/lib/structures/Sticker.d.ts +27 -0
- package/lib/structures/Sticker.js +44 -0
- package/lib/structures/User.d.ts +20 -0
- package/lib/structures/User.js +37 -0
- package/lib/structures/Webhook.d.ts +42 -0
- package/lib/structures/Webhook.js +63 -0
- package/lib/structures/channels.d.ts +232 -0
- package/lib/structures/channels.js +366 -0
- package/lib/structures/extra/Base.d.ts +7 -0
- package/lib/structures/extra/Base.js +39 -0
- package/lib/structures/extra/BaseComponent.d.ts +9 -0
- package/lib/structures/extra/BaseComponent.js +12 -0
- package/lib/structures/extra/BaseGuild.d.ts +40 -0
- package/lib/structures/extra/BaseGuild.js +71 -0
- package/lib/structures/extra/BaseSelectMenuComponent.d.ts +9 -0
- package/lib/structures/extra/BaseSelectMenuComponent.js +13 -0
- package/lib/structures/extra/BitField.d.ts +14 -0
- package/lib/structures/extra/BitField.js +56 -0
- package/lib/structures/extra/DiscordBase.d.ts +18 -0
- package/lib/structures/extra/DiscordBase.js +28 -0
- package/lib/structures/extra/Permissions.d.ts +54 -0
- package/lib/structures/extra/Permissions.js +9 -0
- package/lib/structures/extra/functions.d.ts +11 -0
- package/lib/structures/extra/functions.js +69 -0
- package/lib/structures/index.d.ts +15 -0
- package/lib/structures/index.js +31 -0
- package/lib/websocket/SharedTypes.d.ts +128 -0
- package/lib/websocket/SharedTypes.js +2 -0
- package/lib/websocket/constants/index.d.ts +26 -0
- package/lib/websocket/constants/index.js +31 -0
- package/lib/websocket/discord/basesocket.d.ts +12 -0
- package/lib/websocket/discord/basesocket.js +37 -0
- package/lib/websocket/discord/events/memberUpdate.d.ts +16 -0
- package/lib/websocket/discord/events/memberUpdate.js +47 -0
- package/lib/websocket/discord/events/presenceUpdate.d.ts +24 -0
- package/lib/websocket/discord/events/presenceUpdate.js +46 -0
- package/lib/websocket/discord/handlemessage.d.ts +0 -0
- package/lib/websocket/discord/handlemessage.js +1 -0
- package/lib/websocket/discord/index.d.ts +4 -0
- package/lib/websocket/discord/index.js +20 -0
- package/lib/websocket/discord/memberUpdate.d.ts +16 -0
- package/lib/websocket/discord/memberUpdate.js +47 -0
- package/lib/websocket/discord/shard.d.ts +46 -0
- package/lib/websocket/discord/shard.js +278 -0
- package/lib/websocket/discord/sharder.d.ts +25 -0
- package/lib/websocket/discord/sharder.js +153 -0
- package/lib/websocket/discord/shared.d.ts +99 -0
- package/lib/websocket/discord/shared.js +8 -0
- package/lib/websocket/discord/worker.d.ts +43 -0
- package/lib/websocket/discord/worker.js +2 -0
- package/lib/websocket/discord/workermanager.d.ts +69 -0
- package/lib/websocket/discord/workermanager.js +273 -0
- package/lib/websocket/index.d.ts +3 -0
- package/lib/websocket/index.js +19 -0
- package/lib/websocket/structures/index.d.ts +117 -0
- package/lib/websocket/structures/index.js +261 -0
- package/lib/websocket/structures/timeout.d.ts +20 -0
- package/lib/websocket/structures/timeout.js +75 -0
- package/package.json +70 -0
package/lib/api/CDN.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CDN = void 0;
|
|
4
|
+
/* eslint-disable jsdoc/check-param-names */
|
|
5
|
+
const index_js_1 = require("../common/index.js");
|
|
6
|
+
const constants_js_1 = require("./utils/constants.js");
|
|
7
|
+
const utils_js_1 = require("./utils/utils.js");
|
|
8
|
+
let deprecationEmittedForEmoji = false;
|
|
9
|
+
/**
|
|
10
|
+
* The CDN link builder
|
|
11
|
+
*/
|
|
12
|
+
class CDN {
|
|
13
|
+
base;
|
|
14
|
+
constructor(base = index_js_1.CDN_URL) {
|
|
15
|
+
this.base = base;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates an app asset URL for a client's asset.
|
|
19
|
+
*
|
|
20
|
+
* @param clientId - The client id that has the asset
|
|
21
|
+
* @param assetHash - The hash provided by Discord for this asset
|
|
22
|
+
* @param options - Optional options for the asset
|
|
23
|
+
*/
|
|
24
|
+
appAsset(clientId, assetHash, options) {
|
|
25
|
+
return this.makeURL(`/app-assets/${clientId}/${assetHash}`, options);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generates an app icon URL for a client's icon.
|
|
29
|
+
*
|
|
30
|
+
* @param clientId - The client id that has the icon
|
|
31
|
+
* @param iconHash - The hash provided by Discord for this icon
|
|
32
|
+
* @param options - Optional options for the icon
|
|
33
|
+
*/
|
|
34
|
+
appIcon(clientId, iconHash, options) {
|
|
35
|
+
return this.makeURL(`/app-icons/${clientId}/${iconHash}`, options);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generates an avatar URL, e.g. for a user or a webhook.
|
|
39
|
+
*
|
|
40
|
+
* @param id - The id that has the icon
|
|
41
|
+
* @param avatarHash - The hash provided by Discord for this avatar
|
|
42
|
+
* @param options - Optional options for the avatar
|
|
43
|
+
*/
|
|
44
|
+
avatar(id, avatarHash, options) {
|
|
45
|
+
return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generates a user avatar decoration URL.
|
|
49
|
+
*
|
|
50
|
+
* @param userId - The id of the user
|
|
51
|
+
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
|
52
|
+
* @param options - Optional options for the avatar decoration
|
|
53
|
+
*/
|
|
54
|
+
avatarDecoration(userId, userAvatarDecoration, options) {
|
|
55
|
+
return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generates a banner URL, e.g. for a user or a guild.
|
|
59
|
+
*
|
|
60
|
+
* @param id - The id that has the banner splash
|
|
61
|
+
* @param bannerHash - The hash provided by Discord for this banner
|
|
62
|
+
* @param options - Optional options for the banner
|
|
63
|
+
*/
|
|
64
|
+
banner(id, bannerHash, options) {
|
|
65
|
+
return this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generates an icon URL for a channel, e.g. a group DM.
|
|
69
|
+
*
|
|
70
|
+
* @param channelId - The channel id that has the icon
|
|
71
|
+
* @param iconHash - The hash provided by Discord for this channel
|
|
72
|
+
* @param options - Optional options for the icon
|
|
73
|
+
*/
|
|
74
|
+
channelIcon(channelId, iconHash, options) {
|
|
75
|
+
return this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generates a default avatar URL
|
|
79
|
+
*
|
|
80
|
+
* @param index - The default avatar index
|
|
81
|
+
* @remarks
|
|
82
|
+
* To calculate the index for a user do `(userId >> 22) % 6`,
|
|
83
|
+
* or `discriminator % 5` if they're using the legacy username system.
|
|
84
|
+
*/
|
|
85
|
+
defaultAvatar(index) {
|
|
86
|
+
return this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Generates a discovery splash URL for a guild's discovery splash.
|
|
90
|
+
*
|
|
91
|
+
* @param guildId - The guild id that has the discovery splash
|
|
92
|
+
* @param splashHash - The hash provided by Discord for this splash
|
|
93
|
+
* @param options - Optional options for the splash
|
|
94
|
+
*/
|
|
95
|
+
discoverySplash(guildId, splashHash, options) {
|
|
96
|
+
return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);
|
|
97
|
+
}
|
|
98
|
+
emoji(emojiId, options) {
|
|
99
|
+
let resolvedOptions;
|
|
100
|
+
if (typeof options === 'string') {
|
|
101
|
+
if (!deprecationEmittedForEmoji) {
|
|
102
|
+
(0, utils_js_1.deprecationWarning)('Passing a string for the second parameter of CDN#emoji() is deprecated. Use an object instead.');
|
|
103
|
+
deprecationEmittedForEmoji = true;
|
|
104
|
+
}
|
|
105
|
+
resolvedOptions = { extension: options };
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
resolvedOptions = options;
|
|
109
|
+
}
|
|
110
|
+
return this.makeURL(`/emojis/${emojiId}`, resolvedOptions);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Generates a guild member avatar URL.
|
|
114
|
+
*
|
|
115
|
+
* @param guildId - The id of the guild
|
|
116
|
+
* @param userId - The id of the user
|
|
117
|
+
* @param avatarHash - The hash provided by Discord for this avatar
|
|
118
|
+
* @param options - Optional options for the avatar
|
|
119
|
+
*/
|
|
120
|
+
guildMemberAvatar(guildId, userId, avatarHash, options) {
|
|
121
|
+
return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Generates a guild member banner URL.
|
|
125
|
+
*
|
|
126
|
+
* @param guildId - The id of the guild
|
|
127
|
+
* @param userId - The id of the user
|
|
128
|
+
* @param bannerHash - The hash provided by Discord for this banner
|
|
129
|
+
* @param options - Optional options for the banner
|
|
130
|
+
*/
|
|
131
|
+
guildMemberBanner(guildId, userId, bannerHash, options) {
|
|
132
|
+
return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Generates an icon URL, e.g. for a guild.
|
|
136
|
+
*
|
|
137
|
+
* @param id - The id that has the icon splash
|
|
138
|
+
* @param iconHash - The hash provided by Discord for this icon
|
|
139
|
+
* @param options - Optional options for the icon
|
|
140
|
+
*/
|
|
141
|
+
icon(id, iconHash, options) {
|
|
142
|
+
return this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Generates a URL for the icon of a role
|
|
146
|
+
*
|
|
147
|
+
* @param roleId - The id of the role that has the icon
|
|
148
|
+
* @param roleIconHash - The hash provided by Discord for this role icon
|
|
149
|
+
* @param options - Optional options for the role icon
|
|
150
|
+
*/
|
|
151
|
+
roleIcon(roleId, roleIconHash, options) {
|
|
152
|
+
return this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Generates a guild invite splash URL for a guild's invite splash.
|
|
156
|
+
*
|
|
157
|
+
* @param guildId - The guild id that has the invite splash
|
|
158
|
+
* @param splashHash - The hash provided by Discord for this splash
|
|
159
|
+
* @param options - Optional options for the splash
|
|
160
|
+
*/
|
|
161
|
+
splash(guildId, splashHash, options) {
|
|
162
|
+
return this.makeURL(`/splashes/${guildId}/${splashHash}`, options);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Generates a sticker URL.
|
|
166
|
+
*
|
|
167
|
+
* @param stickerId - The sticker id
|
|
168
|
+
* @param extension - The extension of the sticker
|
|
169
|
+
* @privateRemarks
|
|
170
|
+
* Stickers cannot have a `.webp` extension, so we default to a `.png`
|
|
171
|
+
*/
|
|
172
|
+
sticker(stickerId, extension = 'png') {
|
|
173
|
+
return this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: constants_js_1.ALLOWED_STICKER_EXTENSIONS, extension });
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Generates a sticker pack banner URL.
|
|
177
|
+
*
|
|
178
|
+
* @param bannerId - The banner id
|
|
179
|
+
* @param options - Optional options for the banner
|
|
180
|
+
*/
|
|
181
|
+
stickerPackBanner(bannerId, options) {
|
|
182
|
+
return this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Generates a team icon URL for a team's icon.
|
|
186
|
+
*
|
|
187
|
+
* @param teamId - The team id that has the icon
|
|
188
|
+
* @param iconHash - The hash provided by Discord for this icon
|
|
189
|
+
* @param options - Optional options for the icon
|
|
190
|
+
*/
|
|
191
|
+
teamIcon(teamId, iconHash, options) {
|
|
192
|
+
return this.makeURL(`/team-icons/${teamId}/${iconHash}`, options);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Generates a cover image for a guild scheduled event.
|
|
196
|
+
*
|
|
197
|
+
* @param scheduledEventId - The scheduled event id
|
|
198
|
+
* @param coverHash - The hash provided by discord for this cover image
|
|
199
|
+
* @param options - Optional options for the cover image
|
|
200
|
+
*/
|
|
201
|
+
guildScheduledEventCover(scheduledEventId, coverHash, options) {
|
|
202
|
+
return this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
|
|
206
|
+
*
|
|
207
|
+
* @param route - The base cdn route
|
|
208
|
+
* @param hash - The hash provided by Discord for this icon
|
|
209
|
+
* @param options - Optional options for the link
|
|
210
|
+
*/
|
|
211
|
+
dynamicMakeURL(route, hash, { forceStatic = false, ...options } = {}) {
|
|
212
|
+
return this.makeURL(route, !forceStatic && hash.startsWith('a_') ? { ...options, extension: 'gif' } : options);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Constructs the URL for the resource
|
|
216
|
+
*
|
|
217
|
+
* @param route - The base cdn route
|
|
218
|
+
* @param options - The extension/size options for the link
|
|
219
|
+
*/
|
|
220
|
+
makeURL(route, { allowedExtensions = constants_js_1.ALLOWED_EXTENSIONS, extension = 'webp', size } = {}) {
|
|
221
|
+
// eslint-disable-next-line no-param-reassign
|
|
222
|
+
extension = String(extension).toLowerCase();
|
|
223
|
+
if (!allowedExtensions.includes(extension)) {
|
|
224
|
+
throw new RangeError(`Invalid extension provided: ${extension}\nMust be one of: ${allowedExtensions.join(', ')}`);
|
|
225
|
+
}
|
|
226
|
+
if (size && !constants_js_1.ALLOWED_SIZES.includes(size)) {
|
|
227
|
+
throw new RangeError(`Invalid size provided: ${size}\nMust be one of: ${constants_js_1.ALLOWED_SIZES.join(', ')}`);
|
|
228
|
+
}
|
|
229
|
+
const url = new URL(`${this.base}${route}.${extension}`);
|
|
230
|
+
if (size) {
|
|
231
|
+
url.searchParams.set('size', String(size));
|
|
232
|
+
}
|
|
233
|
+
return url.toString();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.CDN = CDN;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { Dispatcher } from 'undici-types';
|
|
2
|
+
import { Collection } from '../collection';
|
|
3
|
+
import { Logger } from '../common/it/logger';
|
|
4
|
+
import { CDN } from './CDN';
|
|
5
|
+
import type { ProxyRequestMethod } from './Router';
|
|
6
|
+
import type { IHandler } from './interfaces/Handler';
|
|
7
|
+
import type { HashData, InternalRequest, RESTConstructorOptions, RESTOptions, RawFile, RequestData, ResponseLike } from './utils/types';
|
|
8
|
+
/**
|
|
9
|
+
* Represents the class that manages handlers for endpoints
|
|
10
|
+
*/
|
|
11
|
+
export declare class REST {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests
|
|
15
|
+
* performed by this manager.
|
|
16
|
+
*/
|
|
17
|
+
agent: Dispatcher | null;
|
|
18
|
+
/**
|
|
19
|
+
* The number of requests remaining in the global bucket
|
|
20
|
+
*/
|
|
21
|
+
globalRemaining: number;
|
|
22
|
+
/**
|
|
23
|
+
* The promise used to wait out the global rate limit
|
|
24
|
+
*/
|
|
25
|
+
globalDelay: Promise<void> | null;
|
|
26
|
+
/**
|
|
27
|
+
* The timestamp at which the global bucket resets
|
|
28
|
+
*/
|
|
29
|
+
globalReset: number;
|
|
30
|
+
/**
|
|
31
|
+
* API bucket hashes that are cached from provided routes
|
|
32
|
+
*/
|
|
33
|
+
readonly hashes: Collection<string, HashData>;
|
|
34
|
+
/**
|
|
35
|
+
* Request handlers created from the bucket hash and the major parameters
|
|
36
|
+
*/
|
|
37
|
+
readonly handlers: Collection<string, IHandler>;
|
|
38
|
+
readonly cdn: CDN;
|
|
39
|
+
private hashTimer;
|
|
40
|
+
private handlerTimer;
|
|
41
|
+
readonly options: RESTOptions;
|
|
42
|
+
debugger?: Logger;
|
|
43
|
+
constructor(options: RESTConstructorOptions);
|
|
44
|
+
private setupSweepers;
|
|
45
|
+
/**
|
|
46
|
+
* Runs a get request from the api
|
|
47
|
+
*
|
|
48
|
+
* @param route - The full route to query
|
|
49
|
+
* @param options - Optional request options
|
|
50
|
+
*/
|
|
51
|
+
get<T>(route: string, options?: RequestObject<ProxyRequestMethod.Get>): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Runs a delete request from the api
|
|
54
|
+
*
|
|
55
|
+
* @param route - The full route to query
|
|
56
|
+
* @param options - Optional request options
|
|
57
|
+
*/
|
|
58
|
+
delete<T>(route: string, options?: RequestObject<ProxyRequestMethod.Delete>): Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Runs a post request from the api
|
|
61
|
+
*
|
|
62
|
+
* @param route - The full route to query
|
|
63
|
+
* @param options - Optional request options
|
|
64
|
+
*/
|
|
65
|
+
post<T>(route: string, body?: RequestObject<ProxyRequestMethod.Post>): Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Runs a put request from the api
|
|
68
|
+
*
|
|
69
|
+
* @param route - The full route to query
|
|
70
|
+
* @param options - Optional request options
|
|
71
|
+
*/
|
|
72
|
+
put<T>(route: string, body?: RequestObject<ProxyRequestMethod.Put>): Promise<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Runs a patch request from the api
|
|
75
|
+
*
|
|
76
|
+
* @param route - The full route to query
|
|
77
|
+
* @param options - Optional request options
|
|
78
|
+
*/
|
|
79
|
+
patch<T>(route: string, body?: RequestObject<ProxyRequestMethod.Patch>): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* Runs a request from the api
|
|
82
|
+
*
|
|
83
|
+
* @param options - Request options
|
|
84
|
+
*/
|
|
85
|
+
request(options: InternalRequest): Promise<unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the default agent to use for requests performed by this manager
|
|
88
|
+
*
|
|
89
|
+
* @param agent - The agent to use
|
|
90
|
+
*/
|
|
91
|
+
setAgent(agent: Dispatcher): this;
|
|
92
|
+
/**
|
|
93
|
+
* Sets the authorization token that should be used for requests
|
|
94
|
+
*
|
|
95
|
+
* @param token - The authorization token to use
|
|
96
|
+
*/
|
|
97
|
+
setToken(token: string): this;
|
|
98
|
+
/**
|
|
99
|
+
* Queues a request to be sent
|
|
100
|
+
*
|
|
101
|
+
* @param request - All the information needed to make a request
|
|
102
|
+
* @returns The response from the api request
|
|
103
|
+
*/
|
|
104
|
+
queueRequest(request: InternalRequest): Promise<ResponseLike>;
|
|
105
|
+
/**
|
|
106
|
+
* Formats the request data to a usable format for fetch
|
|
107
|
+
*
|
|
108
|
+
* @param request - The request data
|
|
109
|
+
*/
|
|
110
|
+
private resolveRequest;
|
|
111
|
+
/**
|
|
112
|
+
* Stops the hash sweeping interval
|
|
113
|
+
*/
|
|
114
|
+
clearHashSweeper(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Stops the request handler sweeping interval
|
|
117
|
+
*/
|
|
118
|
+
clearHandlerSweeper(): void;
|
|
119
|
+
}
|
|
120
|
+
export type RequestOptions = Pick<RequestData, 'passThroughBody' | 'reason' | 'auth' | 'appendToFormData'>;
|
|
121
|
+
export type RequestObject<M extends ProxyRequestMethod, B = Record<string, any>, Q = Record<string, any>, F extends RawFile[] = RawFile[]> = {
|
|
122
|
+
query?: Q;
|
|
123
|
+
} & RequestOptions & (M extends `${ProxyRequestMethod.Get}` ? unknown : {
|
|
124
|
+
body?: B;
|
|
125
|
+
files?: F;
|
|
126
|
+
});
|
|
127
|
+
export type RestArguments<M extends ProxyRequestMethod, B = any, Q extends never | Record<string, any> = any, F extends RawFile[] = RawFile[]> = M extends ProxyRequestMethod.Get ? Q extends never ? RequestObject<M, never, B, never> : never : RequestObject<M, B, Q, F>;
|