mini-interactions 0.0.0-stage → 0.16.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 +21 -0
- package/MIGRATION.md +126 -0
- package/README.md +303 -2
- package/dist/bot.d.ts +113 -0
- package/dist/bot.js +293 -0
- package/dist/builders/ActionRowBuilder.d.ts +22 -0
- package/dist/builders/ActionRowBuilder.js +33 -0
- package/dist/builders/AutomodRuleBuilder.d.ts +45 -0
- package/dist/builders/AutomodRuleBuilder.js +151 -0
- package/dist/builders/ButtonBuilder.d.ts +53 -0
- package/dist/builders/ButtonBuilder.js +124 -0
- package/dist/builders/ChannelSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ChannelSelectMenuBuilder.js +105 -0
- package/dist/builders/CheckboxBuilder.d.ts +20 -0
- package/dist/builders/CheckboxBuilder.js +20 -0
- package/dist/builders/CheckboxGroupBuilder.d.ts +25 -0
- package/dist/builders/CheckboxGroupBuilder.js +48 -0
- package/dist/builders/EmbedBuilder.d.ts +33 -0
- package/dist/builders/EmbedBuilder.js +103 -0
- package/dist/builders/FileUploadBuilder.d.ts +17 -0
- package/dist/builders/FileUploadBuilder.js +22 -0
- package/dist/builders/LabelBuilder.d.ts +16 -0
- package/dist/builders/LabelBuilder.js +21 -0
- package/dist/builders/MiniContainerBuilder.d.ts +131 -0
- package/dist/builders/MiniContainerBuilder.js +347 -0
- package/dist/builders/ModalBuilder.d.ts +16 -0
- package/dist/builders/ModalBuilder.js +36 -0
- package/dist/builders/ModalChannelSelectMenuBuilder.d.ts +29 -0
- package/dist/builders/ModalChannelSelectMenuBuilder.js +25 -0
- package/dist/builders/ModalMentionableSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ModalMentionableSelectMenuBuilder.js +87 -0
- package/dist/builders/ModalRoleSelectMenuBuilder.d.ts +27 -0
- package/dist/builders/ModalRoleSelectMenuBuilder.js +24 -0
- package/dist/builders/ModalStringSelectMenuBuilder.d.ts +62 -0
- package/dist/builders/ModalStringSelectMenuBuilder.js +120 -0
- package/dist/builders/ModalUserSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ModalUserSelectMenuBuilder.js +96 -0
- package/dist/builders/RadioBuilder.d.ts +22 -0
- package/dist/builders/RadioBuilder.js +36 -0
- package/dist/builders/RoleSelectMenuBuilder.d.ts +47 -0
- package/dist/builders/RoleSelectMenuBuilder.js +92 -0
- package/dist/builders/StringSelectMenuBuilder.d.ts +52 -0
- package/dist/builders/StringSelectMenuBuilder.js +104 -0
- package/dist/builders/StringSelectMenuOptionBuilder.d.ts +46 -0
- package/dist/builders/StringSelectMenuOptionBuilder.js +106 -0
- package/dist/builders/TextInputBuilder.d.ts +23 -0
- package/dist/builders/TextInputBuilder.js +26 -0
- package/dist/builders/index.d.ts +44 -0
- package/dist/builders/index.js +22 -0
- package/dist/builders/shared.d.ts +8 -0
- package/dist/builders/shared.js +11 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +71 -0
- package/dist/commands/CommandBuilder.d.ts +278 -0
- package/dist/commands/CommandBuilder.js +687 -0
- package/dist/commands/ContextMenuCommandBuilder.d.ts +94 -0
- package/dist/commands/ContextMenuCommandBuilder.js +145 -0
- package/dist/core/http/DiscordRestClient.d.ts +400 -0
- package/dist/core/http/DiscordRestClient.js +988 -0
- package/dist/core/interactions/InteractionContext.d.ts +33 -0
- package/dist/core/interactions/InteractionContext.js +61 -0
- package/dist/core/interactions/InteractionVerifier.d.ts +8 -0
- package/dist/core/interactions/InteractionVerifier.js +9 -0
- package/dist/core/messages/DiscordSentMessage.d.ts +32 -0
- package/dist/core/messages/DiscordSentMessage.js +64 -0
- package/dist/core/messages/message-payloads.d.ts +94 -0
- package/dist/core/messages/message-payloads.js +99 -0
- package/dist/core/webhooks/DiscordWebhook.d.ts +14 -0
- package/dist/core/webhooks/DiscordWebhook.js +69 -0
- package/dist/database/MiniDataBuilder.d.ts +61 -0
- package/dist/database/MiniDataBuilder.js +98 -0
- package/dist/database/MiniDatabase.d.ts +67 -0
- package/dist/database/MiniDatabase.js +222 -0
- package/dist/database/MiniDatabaseBuilder.d.ts +58 -0
- package/dist/database/MiniDatabaseBuilder.js +84 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.js +3 -0
- package/dist/identity/ApplicationIdentityProfile.d.ts +188 -0
- package/dist/identity/ApplicationIdentityProfile.js +207 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +34 -0
- package/dist/lobby/Lobby.d.ts +150 -0
- package/dist/lobby/Lobby.js +90 -0
- package/dist/node/MiniInteraction.d.ts +199 -0
- package/dist/node/MiniInteraction.js +861 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/oauth2/DiscordOAuth.d.ts +49 -0
- package/dist/oauth2/DiscordOAuth.js +113 -0
- package/dist/oauth2/OAuth2Builder.d.ts +296 -0
- package/dist/oauth2/OAuth2Builder.js +435 -0
- package/dist/oauth2/OAuth2Scopes.d.ts +285 -0
- package/dist/oauth2/OAuth2Scopes.js +438 -0
- package/dist/oauth2/OAuthTokenStorage.d.ts +37 -0
- package/dist/oauth2/OAuthTokenStorage.js +109 -0
- package/dist/oauth2/index.d.ts +8 -0
- package/dist/oauth2/index.js +4 -0
- package/dist/router/AutocompleteContext.d.ts +36 -0
- package/dist/router/AutocompleteContext.js +82 -0
- package/dist/router/InteractionRouter.d.ts +82 -0
- package/dist/router/InteractionRouter.js +225 -0
- package/dist/types/ButtonStyle.d.ts +16 -0
- package/dist/types/ButtonStyle.js +17 -0
- package/dist/types/ChannelType.d.ts +2 -0
- package/dist/types/ChannelType.js +2 -0
- package/dist/types/Commands.d.ts +35 -0
- package/dist/types/Commands.js +1 -0
- package/dist/types/ComponentTypes.d.ts +19 -0
- package/dist/types/ComponentTypes.js +1 -0
- package/dist/types/InteractionFlags.d.ts +5 -0
- package/dist/types/InteractionFlags.js +6 -0
- package/dist/types/PermissionFlags.d.ts +56 -0
- package/dist/types/PermissionFlags.js +5 -0
- package/dist/types/RoleConnectionMetadata.d.ts +14 -0
- package/dist/types/RoleConnectionMetadata.js +1 -0
- package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
- package/dist/types/RoleConnectionMetadataTypes.js +12 -0
- package/dist/types/SeparatorSpacingSize.d.ts +2 -0
- package/dist/types/SeparatorSpacingSize.js +2 -0
- package/dist/types/checkbox.d.ts +16 -0
- package/dist/types/checkbox.js +12 -0
- package/dist/types/discord.d.ts +2 -0
- package/dist/types/discord.js +1 -0
- package/dist/types/radio.d.ts +12 -0
- package/dist/types/radio.js +10 -0
- package/dist/types/validation.d.ts +14 -0
- package/dist/types/validation.js +40 -0
- package/dist/utils/CommandInteractionOptions.d.ts +66 -0
- package/dist/utils/CommandInteractionOptions.js +364 -0
- package/dist/utils/ContextMenuInteraction.d.ts +76 -0
- package/dist/utils/ContextMenuInteraction.js +152 -0
- package/dist/utils/MessageComponentInteraction.d.ts +148 -0
- package/dist/utils/MessageComponentInteraction.js +259 -0
- package/dist/utils/ModalSubmitInteraction.d.ts +86 -0
- package/dist/utils/ModalSubmitInteraction.js +267 -0
- package/dist/utils/cdn.d.ts +30 -0
- package/dist/utils/cdn.js +60 -0
- package/dist/utils/formatting.d.ts +76 -0
- package/dist/utils/formatting.js +132 -0
- package/dist/utils/interactionMessageHelpers.d.ts +40 -0
- package/dist/utils/interactionMessageHelpers.js +118 -0
- package/dist/utils/localization.d.ts +25 -0
- package/dist/utils/localization.js +38 -0
- package/dist/utils/snowflake.d.ts +19 -0
- package/dist/utils/snowflake.js +32 -0
- package/dist/webhooks/WebhookEvent.d.ts +229 -0
- package/dist/webhooks/WebhookEvent.js +59 -0
- package/dist/webhooks/WebhookEventRouter.d.ts +123 -0
- package/dist/webhooks/WebhookEventRouter.js +160 -0
- package/dist/webhooks/WebhookEventVerifier.d.ts +33 -0
- package/dist/webhooks/WebhookEventVerifier.js +37 -0
- package/dist/webhooks/index.d.ts +6 -0
- package/dist/webhooks/index.js +3 -0
- package/package.json +93 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ComponentType, } from "discord-api-types/v10";
|
|
2
|
+
import { ButtonStyle } from "../types/ButtonStyle.js";
|
|
3
|
+
/** Builder for Discord button components. */
|
|
4
|
+
export class ButtonBuilder {
|
|
5
|
+
data;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new button builder with optional seed data.
|
|
8
|
+
*/
|
|
9
|
+
constructor(data = {}) {
|
|
10
|
+
this.data = {
|
|
11
|
+
style: data.style ?? ButtonStyle.Secondary,
|
|
12
|
+
label: data.label,
|
|
13
|
+
emoji: data.emoji ? { ...data.emoji } : undefined,
|
|
14
|
+
customId: data.customId,
|
|
15
|
+
url: data.url,
|
|
16
|
+
disabled: data.disabled,
|
|
17
|
+
skuId: data.skuId,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets the visual style of the button.
|
|
22
|
+
*/
|
|
23
|
+
setStyle(style) {
|
|
24
|
+
this.data.style = style;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sets or clears the button label text.
|
|
29
|
+
*/
|
|
30
|
+
setLabel(label) {
|
|
31
|
+
this.data.label = label ?? undefined;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets or clears the emoji displayed on the button.
|
|
36
|
+
*/
|
|
37
|
+
setEmoji(emoji) {
|
|
38
|
+
this.data.emoji = emoji ? { ...emoji } : undefined;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configures the button as an interaction component with the provided custom identifier.
|
|
43
|
+
*/
|
|
44
|
+
setCustomId(customId) {
|
|
45
|
+
this.data.customId = customId;
|
|
46
|
+
if (this.data.style === ButtonStyle.Link) {
|
|
47
|
+
this.data.style = ButtonStyle.Secondary;
|
|
48
|
+
}
|
|
49
|
+
this.data.url = undefined;
|
|
50
|
+
this.data.skuId = undefined;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Configures the button as a link button.
|
|
55
|
+
*/
|
|
56
|
+
setURL(url) {
|
|
57
|
+
this.data.url = url;
|
|
58
|
+
this.data.customId = undefined;
|
|
59
|
+
this.data.skuId = undefined;
|
|
60
|
+
this.data.style = ButtonStyle.Link;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Configures the button as a premium purchase button.
|
|
65
|
+
*/
|
|
66
|
+
setSKUId(skuId) {
|
|
67
|
+
this.data.skuId = skuId;
|
|
68
|
+
this.data.customId = undefined;
|
|
69
|
+
this.data.url = undefined;
|
|
70
|
+
this.data.style = ButtonStyle.Premium;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Toggles whether the button is disabled.
|
|
75
|
+
*/
|
|
76
|
+
setDisabled(disabled) {
|
|
77
|
+
this.data.disabled = disabled;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serialises the builder into an API compatible button payload.
|
|
82
|
+
*/
|
|
83
|
+
toJSON() {
|
|
84
|
+
const { style, label, emoji, disabled } = this.data;
|
|
85
|
+
if (style === ButtonStyle.Link) {
|
|
86
|
+
const url = this.data.url;
|
|
87
|
+
if (!url) {
|
|
88
|
+
throw new Error("[ButtonBuilder] Link buttons must have a URL.");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
type: ComponentType.Button,
|
|
92
|
+
style,
|
|
93
|
+
label,
|
|
94
|
+
emoji: emoji ? { ...emoji } : undefined,
|
|
95
|
+
disabled,
|
|
96
|
+
url,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (style === ButtonStyle.Premium) {
|
|
100
|
+
const skuId = this.data.skuId;
|
|
101
|
+
if (!skuId) {
|
|
102
|
+
throw new Error("[ButtonBuilder] Premium buttons must have an SKU id.");
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
type: ComponentType.Button,
|
|
106
|
+
style,
|
|
107
|
+
disabled,
|
|
108
|
+
sku_id: skuId,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const customId = this.data.customId;
|
|
112
|
+
if (!customId) {
|
|
113
|
+
throw new Error("[ButtonBuilder] Non-link buttons must have a custom id.");
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type: ComponentType.Button,
|
|
117
|
+
style,
|
|
118
|
+
label,
|
|
119
|
+
emoji: emoji ? { ...emoji } : undefined,
|
|
120
|
+
disabled,
|
|
121
|
+
custom_id: customId,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SelectMenuDefaultValueType, type APIChannelSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
|
|
2
|
+
import { ChannelType } from "../types/ChannelType.js";
|
|
3
|
+
import type { JSONEncodable } from "./shared.js";
|
|
4
|
+
/** Shape describing initial channel select menu data accepted by the builder. */
|
|
5
|
+
export type ChannelSelectMenuBuilderData = {
|
|
6
|
+
customId?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
minValues?: number;
|
|
9
|
+
maxValues?: number;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
channelTypes?: ChannelType[];
|
|
12
|
+
defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>[];
|
|
13
|
+
};
|
|
14
|
+
/** Builder for Discord channel select menu components. */
|
|
15
|
+
export declare class ChannelSelectMenuBuilder implements JSONEncodable<APIChannelSelectComponent> {
|
|
16
|
+
private data;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new channel select menu builder with optional seed data.
|
|
19
|
+
*/
|
|
20
|
+
constructor(data?: ChannelSelectMenuBuilderData);
|
|
21
|
+
/**
|
|
22
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
23
|
+
*/
|
|
24
|
+
setCustomId(customId: string): this;
|
|
25
|
+
/**
|
|
26
|
+
* Sets or clears the placeholder text displayed when no channel is selected.
|
|
27
|
+
*/
|
|
28
|
+
setPlaceholder(placeholder: string | null | undefined): this;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the minimum number of channels that must be selected.
|
|
31
|
+
*/
|
|
32
|
+
setMinValues(minValues: number | null | undefined): this;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the maximum number of channels that can be selected.
|
|
35
|
+
*/
|
|
36
|
+
setMaxValues(maxValues: number | null | undefined): this;
|
|
37
|
+
/**
|
|
38
|
+
* Toggles whether the select menu is disabled.
|
|
39
|
+
*/
|
|
40
|
+
setDisabled(disabled: boolean): this;
|
|
41
|
+
/**
|
|
42
|
+
* Filters selectable channels by the provided channel types.
|
|
43
|
+
*/
|
|
44
|
+
setChannelTypes(channelTypes: Iterable<ChannelType>): this;
|
|
45
|
+
/**
|
|
46
|
+
* Replaces the default channel selections displayed when the menu renders.
|
|
47
|
+
*/
|
|
48
|
+
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Serialises the builder into an API compatible channel select menu payload.
|
|
51
|
+
*/
|
|
52
|
+
toJSON(): APIChannelSelectComponent;
|
|
53
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ComponentType, SelectMenuDefaultValueType, } from "discord-api-types/v10";
|
|
2
|
+
/** Builder for Discord channel select menu components. */
|
|
3
|
+
export class ChannelSelectMenuBuilder {
|
|
4
|
+
data;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new channel select menu builder with optional seed data.
|
|
7
|
+
*/
|
|
8
|
+
constructor(data = {}) {
|
|
9
|
+
this.data = {
|
|
10
|
+
customId: data.customId,
|
|
11
|
+
placeholder: data.placeholder,
|
|
12
|
+
minValues: data.minValues,
|
|
13
|
+
maxValues: data.maxValues,
|
|
14
|
+
disabled: data.disabled,
|
|
15
|
+
channelTypes: data.channelTypes
|
|
16
|
+
? [...data.channelTypes]
|
|
17
|
+
: undefined,
|
|
18
|
+
defaultValues: data.defaultValues
|
|
19
|
+
? data.defaultValues.map((value) => ({
|
|
20
|
+
...value,
|
|
21
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
22
|
+
}))
|
|
23
|
+
: undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
28
|
+
*/
|
|
29
|
+
setCustomId(customId) {
|
|
30
|
+
this.data.customId = customId;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets or clears the placeholder text displayed when no channel is selected.
|
|
35
|
+
*/
|
|
36
|
+
setPlaceholder(placeholder) {
|
|
37
|
+
this.data.placeholder = placeholder ?? undefined;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the minimum number of channels that must be selected.
|
|
42
|
+
*/
|
|
43
|
+
setMinValues(minValues) {
|
|
44
|
+
this.data.minValues = minValues ?? undefined;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the maximum number of channels that can be selected.
|
|
49
|
+
*/
|
|
50
|
+
setMaxValues(maxValues) {
|
|
51
|
+
this.data.maxValues = maxValues ?? undefined;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Toggles whether the select menu is disabled.
|
|
56
|
+
*/
|
|
57
|
+
setDisabled(disabled) {
|
|
58
|
+
this.data.disabled = disabled;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Filters selectable channels by the provided channel types.
|
|
63
|
+
*/
|
|
64
|
+
setChannelTypes(channelTypes) {
|
|
65
|
+
this.data.channelTypes = Array.from(channelTypes);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Replaces the default channel selections displayed when the menu renders.
|
|
70
|
+
*/
|
|
71
|
+
setDefaultValues(defaultValues) {
|
|
72
|
+
this.data.defaultValues = Array.from(defaultValues, (value) => ({
|
|
73
|
+
...value,
|
|
74
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
75
|
+
}));
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Serialises the builder into an API compatible channel select menu payload.
|
|
80
|
+
*/
|
|
81
|
+
toJSON() {
|
|
82
|
+
const { customId } = this.data;
|
|
83
|
+
if (!customId) {
|
|
84
|
+
throw new Error("[ChannelSelectMenuBuilder] custom id is required.");
|
|
85
|
+
}
|
|
86
|
+
if (this.data.placeholder && this.data.placeholder.length > 150) {
|
|
87
|
+
throw new Error("[ChannelSelectMenuBuilder] placeholder must be 150 characters or less.");
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: ComponentType.ChannelSelect,
|
|
91
|
+
custom_id: customId,
|
|
92
|
+
placeholder: this.data.placeholder,
|
|
93
|
+
min_values: this.data.minValues,
|
|
94
|
+
max_values: this.data.maxValues,
|
|
95
|
+
disabled: this.data.disabled,
|
|
96
|
+
channel_types: this.data.channelTypes
|
|
97
|
+
? [...this.data.channelTypes]
|
|
98
|
+
: undefined,
|
|
99
|
+
default_values: this.data.defaultValues?.map((value) => ({
|
|
100
|
+
...value,
|
|
101
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
102
|
+
})),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JSONEncodable } from './shared.js';
|
|
2
|
+
import { APICheckboxComponent } from '../types/checkbox.js';
|
|
3
|
+
export type CheckboxBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
default?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Builder for Discord's modal-only single Checkbox component (type 23).
|
|
9
|
+
* A single checkbox holds no options; use {@link CheckboxGroupBuilder} for
|
|
10
|
+
* multi-option checkbox groups.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox}
|
|
13
|
+
*/
|
|
14
|
+
export declare class CheckboxBuilder implements JSONEncodable<APICheckboxComponent> {
|
|
15
|
+
private readonly data;
|
|
16
|
+
constructor(data?: CheckboxBuilderData);
|
|
17
|
+
setCustomId(customId: string): this;
|
|
18
|
+
setDefault(isDefault: boolean): this;
|
|
19
|
+
toJSON(): APICheckboxComponent;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CHECKBOX_COMPONENT_TYPE } from '../types/checkbox.js';
|
|
2
|
+
import { assertDefined, assertStringLength } from '../types/validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builder for Discord's modal-only single Checkbox component (type 23).
|
|
5
|
+
* A single checkbox holds no options; use {@link CheckboxGroupBuilder} for
|
|
6
|
+
* multi-option checkbox groups.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox}
|
|
9
|
+
*/
|
|
10
|
+
export class CheckboxBuilder {
|
|
11
|
+
data;
|
|
12
|
+
constructor(data = {}) { this.data = { ...data }; }
|
|
13
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
14
|
+
setDefault(isDefault) { this.data.default = isDefault; return this; }
|
|
15
|
+
toJSON() {
|
|
16
|
+
const customId = assertDefined('CheckboxBuilder', 'custom_id', this.data.customId);
|
|
17
|
+
assertStringLength('CheckboxBuilder', 'custom_id', customId, 1, 100);
|
|
18
|
+
return { type: CHECKBOX_COMPONENT_TYPE, custom_id: customId, default: this.data.default };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JSONEncodable } from './shared.js';
|
|
2
|
+
import type { APICheckboxGroupComponent, APICheckboxGroupOption } from '../types/checkbox.js';
|
|
3
|
+
export type CheckboxGroupBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
minValues?: number;
|
|
6
|
+
maxValues?: number;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
options?: APICheckboxGroupOption[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builder for Discord's modal-only CheckboxGroup component (type 22).
|
|
12
|
+
* Groups hold up to 10 options and support multiple pre-selected defaults.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox-group}
|
|
15
|
+
*/
|
|
16
|
+
export declare class CheckboxGroupBuilder implements JSONEncodable<APICheckboxGroupComponent> {
|
|
17
|
+
private readonly data;
|
|
18
|
+
constructor(data?: CheckboxGroupBuilderData);
|
|
19
|
+
setCustomId(customId: string): this;
|
|
20
|
+
setRequired(required: boolean): this;
|
|
21
|
+
setMinValues(minValues: number): this;
|
|
22
|
+
setMaxValues(maxValues: number): this;
|
|
23
|
+
addOptions(...options: APICheckboxGroupOption[]): this;
|
|
24
|
+
toJSON(): APICheckboxGroupComponent;
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CHECKBOX_GROUP_COMPONENT_TYPE } from '../types/checkbox.js';
|
|
2
|
+
import { assertDefined, assertRange, assertStringLength, ValidationError } from '../types/validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builder for Discord's modal-only CheckboxGroup component (type 22).
|
|
5
|
+
* Groups hold up to 10 options and support multiple pre-selected defaults.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox-group}
|
|
8
|
+
*/
|
|
9
|
+
export class CheckboxGroupBuilder {
|
|
10
|
+
data;
|
|
11
|
+
constructor(data = {}) { this.data = { ...data, options: data.options ? [...data.options] : [] }; }
|
|
12
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
13
|
+
setRequired(required) { this.data.required = required; return this; }
|
|
14
|
+
setMinValues(minValues) { this.data.minValues = minValues; return this; }
|
|
15
|
+
setMaxValues(maxValues) { this.data.maxValues = maxValues; return this; }
|
|
16
|
+
addOptions(...options) { this.data.options = [...(this.data.options ?? []), ...options]; return this; }
|
|
17
|
+
toJSON() {
|
|
18
|
+
const customId = assertDefined('CheckboxGroupBuilder', 'custom_id', this.data.customId);
|
|
19
|
+
assertStringLength('CheckboxGroupBuilder', 'custom_id', customId, 1, 100);
|
|
20
|
+
if (this.data.minValues !== undefined)
|
|
21
|
+
assertRange('CheckboxGroupBuilder', 'min_values', this.data.minValues, 0, 10);
|
|
22
|
+
if (this.data.maxValues !== undefined)
|
|
23
|
+
assertRange('CheckboxGroupBuilder', 'max_values', this.data.maxValues, 1, 10);
|
|
24
|
+
if (this.data.minValues !== undefined &&
|
|
25
|
+
this.data.maxValues !== undefined &&
|
|
26
|
+
this.data.minValues > this.data.maxValues) {
|
|
27
|
+
throw new ValidationError('CheckboxGroupBuilder', 'min_values', 'cannot be greater than max_values');
|
|
28
|
+
}
|
|
29
|
+
const options = [...(this.data.options ?? [])];
|
|
30
|
+
if (options.length < 2 || options.length > 10) {
|
|
31
|
+
throw new ValidationError('CheckboxGroupBuilder', 'options', 'must contain between 2 and 10 options');
|
|
32
|
+
}
|
|
33
|
+
for (const [index, option] of options.entries()) {
|
|
34
|
+
assertStringLength('CheckboxGroupBuilder', `options[${index}].label`, option.label, 1, 100);
|
|
35
|
+
assertStringLength('CheckboxGroupBuilder', `options[${index}].value`, option.value, 1, 100);
|
|
36
|
+
if (option.description)
|
|
37
|
+
assertStringLength('CheckboxGroupBuilder', `options[${index}].description`, option.description, 1, 100);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type: CHECKBOX_GROUP_COMPONENT_TYPE,
|
|
41
|
+
custom_id: customId,
|
|
42
|
+
min_values: this.data.minValues,
|
|
43
|
+
max_values: this.data.maxValues,
|
|
44
|
+
required: this.data.required,
|
|
45
|
+
options,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type APIEmbed, type APIEmbedAuthor, type APIEmbedField, type APIEmbedFooter, type APIEmbedImage, type APIEmbedThumbnail } from "discord-api-types/v10";
|
|
2
|
+
import { type JSONEncodable } from "./shared.js";
|
|
3
|
+
/** Shape describing data used to seed an embed builder instance. */
|
|
4
|
+
export type EmbedBuilderData = Partial<APIEmbed>;
|
|
5
|
+
/** Builder for Discord embed payloads. */
|
|
6
|
+
export declare class EmbedBuilder implements JSONEncodable<APIEmbed> {
|
|
7
|
+
private data;
|
|
8
|
+
constructor(data?: EmbedBuilderData);
|
|
9
|
+
/** Sets or clears the embed title. */
|
|
10
|
+
setTitle(title: string | null | undefined): this;
|
|
11
|
+
/** Sets or clears the embed description. */
|
|
12
|
+
setDescription(description: string | null | undefined): this;
|
|
13
|
+
/** Sets or clears the embed URL. */
|
|
14
|
+
setURL(url: string | null | undefined): this;
|
|
15
|
+
/** Sets or clears the embed color. */
|
|
16
|
+
setColor(color: number | null | undefined): this;
|
|
17
|
+
/** Sets the timestamp value using either a Date or ISO string. */
|
|
18
|
+
setTimestamp(timestamp: Date | number | string | null | undefined): this;
|
|
19
|
+
/** Sets or clears the footer. */
|
|
20
|
+
setFooter(footer: APIEmbedFooter | null | undefined): this;
|
|
21
|
+
/** Sets or clears the image. */
|
|
22
|
+
setImage(image: APIEmbedImage | null | undefined): this;
|
|
23
|
+
/** Sets or clears the thumbnail. */
|
|
24
|
+
setThumbnail(thumbnail: APIEmbedThumbnail | null | undefined): this;
|
|
25
|
+
/** Sets or clears the author. */
|
|
26
|
+
setAuthor(author: APIEmbedAuthor | null | undefined): this;
|
|
27
|
+
/** Replaces the embed fields with the provided values. */
|
|
28
|
+
setFields(fields: APIEmbedField[]): this;
|
|
29
|
+
/** Appends fields to the embed. */
|
|
30
|
+
addFields(...fields: APIEmbedField[]): this;
|
|
31
|
+
/** Serialises the builder into an API compatible embed payload. */
|
|
32
|
+
toJSON(): APIEmbed;
|
|
33
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { resolveJSONEncodable } from "./shared.js";
|
|
2
|
+
/** Builder for Discord embed payloads. */
|
|
3
|
+
export class EmbedBuilder {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data = {}) {
|
|
6
|
+
this.data = {
|
|
7
|
+
...data,
|
|
8
|
+
footer: data.footer ? { ...data.footer } : undefined,
|
|
9
|
+
image: data.image ? { ...data.image } : undefined,
|
|
10
|
+
thumbnail: data.thumbnail ? { ...data.thumbnail } : undefined,
|
|
11
|
+
author: data.author ? { ...data.author } : undefined,
|
|
12
|
+
fields: data.fields ? data.fields.map((field) => ({ ...field })) : [],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Sets or clears the embed title. */
|
|
16
|
+
setTitle(title) {
|
|
17
|
+
this.data.title = title ?? undefined;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
/** Sets or clears the embed description. */
|
|
21
|
+
setDescription(description) {
|
|
22
|
+
this.data.description = description ?? undefined;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/** Sets or clears the embed URL. */
|
|
26
|
+
setURL(url) {
|
|
27
|
+
this.data.url = url ?? undefined;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/** Sets or clears the embed color. */
|
|
31
|
+
setColor(color) {
|
|
32
|
+
this.data.color = color ?? undefined;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/** Sets the timestamp value using either a Date or ISO string. */
|
|
36
|
+
setTimestamp(timestamp) {
|
|
37
|
+
if (timestamp === null || timestamp === undefined) {
|
|
38
|
+
this.data.timestamp = undefined;
|
|
39
|
+
}
|
|
40
|
+
else if (timestamp instanceof Date) {
|
|
41
|
+
this.data.timestamp = timestamp.toISOString();
|
|
42
|
+
}
|
|
43
|
+
else if (typeof timestamp === "number") {
|
|
44
|
+
this.data.timestamp = new Date(timestamp).toISOString();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.data.timestamp = new Date(timestamp).toISOString();
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/** Sets or clears the footer. */
|
|
52
|
+
setFooter(footer) {
|
|
53
|
+
this.data.footer = footer ? { ...footer } : undefined;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/** Sets or clears the image. */
|
|
57
|
+
setImage(image) {
|
|
58
|
+
this.data.image = image ? { ...image } : undefined;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/** Sets or clears the thumbnail. */
|
|
62
|
+
setThumbnail(thumbnail) {
|
|
63
|
+
this.data.thumbnail = thumbnail ? { ...thumbnail } : undefined;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/** Sets or clears the author. */
|
|
67
|
+
setAuthor(author) {
|
|
68
|
+
this.data.author = author ? { ...author } : undefined;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/** Replaces the embed fields with the provided values. */
|
|
72
|
+
setFields(fields) {
|
|
73
|
+
this.data.fields = fields.map((field) => ({ ...field }));
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/** Appends fields to the embed. */
|
|
77
|
+
addFields(...fields) {
|
|
78
|
+
if (!this.data.fields) {
|
|
79
|
+
this.data.fields = [];
|
|
80
|
+
}
|
|
81
|
+
this.data.fields.push(...fields.map((field) => ({ ...field })));
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/** Serialises the builder into an API compatible embed payload. */
|
|
85
|
+
toJSON() {
|
|
86
|
+
return {
|
|
87
|
+
...this.data,
|
|
88
|
+
footer: this.data.footer
|
|
89
|
+
? resolveJSONEncodable(this.data.footer)
|
|
90
|
+
: undefined,
|
|
91
|
+
image: this.data.image
|
|
92
|
+
? resolveJSONEncodable(this.data.image)
|
|
93
|
+
: undefined,
|
|
94
|
+
thumbnail: this.data.thumbnail
|
|
95
|
+
? resolveJSONEncodable(this.data.thumbnail)
|
|
96
|
+
: undefined,
|
|
97
|
+
author: this.data.author
|
|
98
|
+
? resolveJSONEncodable(this.data.author)
|
|
99
|
+
: undefined,
|
|
100
|
+
fields: this.data.fields?.map((field) => resolveJSONEncodable(field)),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type APIFileUploadComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { type JSONEncodable } from './shared.js';
|
|
3
|
+
export type FileUploadBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
minValues?: number;
|
|
6
|
+
maxValues?: number;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare class FileUploadBuilder implements JSONEncodable<APIFileUploadComponent> {
|
|
10
|
+
private readonly data;
|
|
11
|
+
constructor(data?: FileUploadBuilderData);
|
|
12
|
+
setCustomId(customId: string): this;
|
|
13
|
+
setMinValues(minValues: number): this;
|
|
14
|
+
setMaxValues(maxValues: number): this;
|
|
15
|
+
setRequired(required: boolean): this;
|
|
16
|
+
toJSON(): APIFileUploadComponent;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentType } from 'discord-api-types/v10';
|
|
2
|
+
import { assertDefined, assertRange, assertStringLength, ValidationError } from '../types/validation.js';
|
|
3
|
+
export class FileUploadBuilder {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data = {}) { this.data = { ...data }; }
|
|
6
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
7
|
+
setMinValues(minValues) { this.data.minValues = minValues; return this; }
|
|
8
|
+
setMaxValues(maxValues) { this.data.maxValues = maxValues; return this; }
|
|
9
|
+
setRequired(required) { this.data.required = required; return this; }
|
|
10
|
+
toJSON() {
|
|
11
|
+
const customId = assertDefined('FileUploadBuilder', 'custom_id', this.data.customId);
|
|
12
|
+
assertStringLength('FileUploadBuilder', 'custom_id', customId, 1, 100);
|
|
13
|
+
if (this.data.minValues !== undefined)
|
|
14
|
+
assertRange('FileUploadBuilder', 'min_values', this.data.minValues, 0, 10);
|
|
15
|
+
if (this.data.maxValues !== undefined)
|
|
16
|
+
assertRange('FileUploadBuilder', 'max_values', this.data.maxValues, 1, 10);
|
|
17
|
+
if (this.data.minValues !== undefined && this.data.maxValues !== undefined && this.data.minValues > this.data.maxValues) {
|
|
18
|
+
throw new ValidationError('FileUploadBuilder', 'min_values', 'cannot be greater than max_values');
|
|
19
|
+
}
|
|
20
|
+
return { type: ComponentType.FileUpload, custom_id: customId, min_values: this.data.minValues, max_values: this.data.maxValues, required: this.data.required };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type APIComponentInLabel, type APILabelComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { type JSONEncodable } from './shared.js';
|
|
3
|
+
export type LabelComponentLike = JSONEncodable<APIComponentInLabel> | APIComponentInLabel;
|
|
4
|
+
export type LabelBuilderData = {
|
|
5
|
+
label?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
component?: LabelComponentLike;
|
|
8
|
+
};
|
|
9
|
+
export declare class LabelBuilder implements JSONEncodable<APILabelComponent> {
|
|
10
|
+
private readonly data;
|
|
11
|
+
constructor(data?: LabelBuilderData);
|
|
12
|
+
setLabel(label: string): this;
|
|
13
|
+
setDescription(description: string): this;
|
|
14
|
+
setComponent(component: LabelComponentLike): this;
|
|
15
|
+
toJSON(): APILabelComponent;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentType } from 'discord-api-types/v10';
|
|
2
|
+
import { resolveJSONEncodable } from './shared.js';
|
|
3
|
+
import { ValidationError, assertDefined, assertStringLength } from '../types/validation.js';
|
|
4
|
+
export class LabelBuilder {
|
|
5
|
+
data;
|
|
6
|
+
constructor(data = {}) { this.data = { ...data }; }
|
|
7
|
+
setLabel(label) { this.data.label = label; return this; }
|
|
8
|
+
setDescription(description) { this.data.description = description; return this; }
|
|
9
|
+
setComponent(component) { this.data.component = component; return this; }
|
|
10
|
+
toJSON() {
|
|
11
|
+
const label = assertDefined('LabelBuilder', 'label', this.data.label);
|
|
12
|
+
const component = assertDefined('LabelBuilder', 'component', this.data.component);
|
|
13
|
+
assertStringLength('LabelBuilder', 'label', label, 1, 45);
|
|
14
|
+
if (this.data.description)
|
|
15
|
+
assertStringLength('LabelBuilder', 'description', this.data.description, 1, 100);
|
|
16
|
+
const resolved = resolveJSONEncodable(component);
|
|
17
|
+
if (!('type' in resolved))
|
|
18
|
+
throw new ValidationError('LabelBuilder', 'component', 'must contain a valid component payload');
|
|
19
|
+
return { type: ComponentType.Label, label, description: this.data.description, component: resolved };
|
|
20
|
+
}
|
|
21
|
+
}
|