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,131 @@
|
|
|
1
|
+
import type { APIComponentInContainer, APIContainerComponent, APIMediaGalleryComponent, APIMediaGalleryItem, APISectionAccessoryComponent, APISectionComponent, APISeparatorComponent, APITextDisplayComponent, APIThumbnailComponent, APIUnfurledMediaItem } from "discord-api-types/v10";
|
|
2
|
+
import { SeparatorSpacingSize } from "discord-api-types/v10";
|
|
3
|
+
import type { JSONEncodable } from "./shared.js";
|
|
4
|
+
/** Structured message container payload. */
|
|
5
|
+
export type MiniContainerComponent = APIContainerComponent;
|
|
6
|
+
/** Section within a structured message container. */
|
|
7
|
+
export type MiniSectionComponent = APISectionComponent;
|
|
8
|
+
/** Text display structured message component. */
|
|
9
|
+
export type MiniTextDisplayComponent = APITextDisplayComponent;
|
|
10
|
+
/** Separator structured message component. */
|
|
11
|
+
export type MiniSeparatorComponent = APISeparatorComponent;
|
|
12
|
+
/** Thumbnail payload used within sections. */
|
|
13
|
+
export type MiniThumbnailComponent = APIThumbnailComponent;
|
|
14
|
+
/** Gallery item payload. */
|
|
15
|
+
export type MiniGalleryItemComponent = APIMediaGalleryItem;
|
|
16
|
+
/** Gallery structured message component. */
|
|
17
|
+
export type MiniGalleryComponent = APIMediaGalleryComponent;
|
|
18
|
+
/** Union of supported components within a container. */
|
|
19
|
+
export type MiniContentComponent = APIComponentInContainer;
|
|
20
|
+
/** Union of supported section accessory components. */
|
|
21
|
+
export type MiniSectionAccessoryComponent = APISectionAccessoryComponent;
|
|
22
|
+
/** Data accepted by the container builder constructor. */
|
|
23
|
+
export type ContainerBuilderData = Partial<Omit<MiniContainerComponent, "components">> & {
|
|
24
|
+
components?: Array<MiniContentComponent | JSONEncodable<MiniContentComponent>>;
|
|
25
|
+
};
|
|
26
|
+
/** Data accepted by the section builder constructor. */
|
|
27
|
+
export type SectionBuilderData = Partial<Omit<MiniSectionComponent, "components" | "accessory">> & {
|
|
28
|
+
components?: Array<MiniTextDisplayComponent | JSONEncodable<MiniTextDisplayComponent>>;
|
|
29
|
+
accessory?: MiniSectionAccessoryComponent | JSONEncodable<MiniSectionAccessoryComponent>;
|
|
30
|
+
};
|
|
31
|
+
/** Data accepted by the text display builder constructor. */
|
|
32
|
+
export type TextDisplayBuilderData = Partial<MiniTextDisplayComponent>;
|
|
33
|
+
/** Data accepted by the separator builder constructor. */
|
|
34
|
+
export type SeparatorBuilderData = Partial<MiniSeparatorComponent>;
|
|
35
|
+
/** Data accepted by the gallery builder constructor. */
|
|
36
|
+
export type GalleryBuilderData = Partial<Omit<MiniGalleryComponent, "items">> & {
|
|
37
|
+
items?: Array<MiniGalleryItemComponent | JSONEncodable<MiniGalleryItemComponent>>;
|
|
38
|
+
};
|
|
39
|
+
/** Data accepted by the gallery item builder constructor. */
|
|
40
|
+
export type GalleryItemBuilderData = Partial<MiniGalleryItemComponent>;
|
|
41
|
+
/** Data accepted by the thumbnail builder constructor. */
|
|
42
|
+
export type ThumbnailBuilderData = Partial<MiniThumbnailComponent>;
|
|
43
|
+
/** Builder for structured message container payloads. */
|
|
44
|
+
export declare class ContainerBuilder implements JSONEncodable<MiniContainerComponent> {
|
|
45
|
+
private data;
|
|
46
|
+
constructor(data?: ContainerBuilderData);
|
|
47
|
+
/** Replaces the components contained in the container. */
|
|
48
|
+
setComponents(components: Array<MiniContentComponent | JSONEncodable<MiniContentComponent>>): this;
|
|
49
|
+
/** Replaces the sections contained in the container. */
|
|
50
|
+
setSections(sections: Array<MiniSectionComponent | JSONEncodable<MiniSectionComponent>>): this;
|
|
51
|
+
/** Adds a component to the container. */
|
|
52
|
+
addComponent(component: MiniContentComponent | JSONEncodable<MiniContentComponent>): this;
|
|
53
|
+
/** Adds a section to the container. */
|
|
54
|
+
addSection(section: MiniSectionComponent | JSONEncodable<MiniSectionComponent>): this;
|
|
55
|
+
/** Sets or clears the accent colour on the container. */
|
|
56
|
+
setAccentColor(color: number | null | undefined): this;
|
|
57
|
+
/** Marks the container as a spoiler. */
|
|
58
|
+
setSpoiler(spoiler: boolean | null | undefined): this;
|
|
59
|
+
/** Serialises the container into a structured message payload. */
|
|
60
|
+
toJSON(): MiniContainerComponent;
|
|
61
|
+
}
|
|
62
|
+
/** Builder for structured message sections. */
|
|
63
|
+
export declare class SectionBuilder implements JSONEncodable<MiniSectionComponent> {
|
|
64
|
+
private data;
|
|
65
|
+
constructor(data?: SectionBuilderData);
|
|
66
|
+
/** Replaces the text components within the section. */
|
|
67
|
+
setComponents(components: Array<MiniTextDisplayComponent | JSONEncodable<MiniTextDisplayComponent>>): this;
|
|
68
|
+
/** Adds a text component to the section. */
|
|
69
|
+
addComponent(component: MiniTextDisplayComponent | JSONEncodable<MiniTextDisplayComponent>): this;
|
|
70
|
+
/** Sets or clears the accessory component. */
|
|
71
|
+
setAccessory(accessory: MiniSectionAccessoryComponent | JSONEncodable<MiniSectionAccessoryComponent> | null | undefined): this;
|
|
72
|
+
/** Serialises the section into a structured message payload. */
|
|
73
|
+
toJSON(): MiniSectionComponent;
|
|
74
|
+
}
|
|
75
|
+
/** Builder for structured message text display components. */
|
|
76
|
+
export declare class TextDisplayBuilder implements JSONEncodable<MiniTextDisplayComponent> {
|
|
77
|
+
private data;
|
|
78
|
+
constructor(data?: TextDisplayBuilderData);
|
|
79
|
+
/** Sets or clears the primary text content. */
|
|
80
|
+
setContent(content: string | null | undefined): this;
|
|
81
|
+
/** Serialises the component into a structured message payload. */
|
|
82
|
+
toJSON(): MiniTextDisplayComponent;
|
|
83
|
+
}
|
|
84
|
+
/** Builder for structured message separator components. */
|
|
85
|
+
export declare class SeparatorBuilder implements JSONEncodable<MiniSeparatorComponent> {
|
|
86
|
+
private data;
|
|
87
|
+
constructor(data?: SeparatorBuilderData);
|
|
88
|
+
/** Sets whether the separator should render a divider. */
|
|
89
|
+
setDivider(divider: boolean | null | undefined): this;
|
|
90
|
+
/** Sets the separator spacing value. */
|
|
91
|
+
setSpacing(spacing: SeparatorSpacingSize | null | undefined): this;
|
|
92
|
+
/** Serialises the separator payload. */
|
|
93
|
+
toJSON(): MiniSeparatorComponent;
|
|
94
|
+
}
|
|
95
|
+
/** Builder for structured message thumbnails. */
|
|
96
|
+
export declare class ThumbnailBuilder implements JSONEncodable<MiniThumbnailComponent> {
|
|
97
|
+
private data;
|
|
98
|
+
constructor(data?: ThumbnailBuilderData);
|
|
99
|
+
/** Sets the media payload for the thumbnail. */
|
|
100
|
+
setMedia(media: APIUnfurledMediaItem | null | undefined): this;
|
|
101
|
+
/** Sets the thumbnail description. */
|
|
102
|
+
setDescription(description: string | null | undefined): this;
|
|
103
|
+
/** Marks the thumbnail as a spoiler. */
|
|
104
|
+
setSpoiler(spoiler: boolean | null | undefined): this;
|
|
105
|
+
/** Serialises the thumbnail payload. */
|
|
106
|
+
toJSON(): MiniThumbnailComponent;
|
|
107
|
+
}
|
|
108
|
+
/** Builder for structured message gallery items. */
|
|
109
|
+
export declare class GalleryItemBuilder implements JSONEncodable<MiniGalleryItemComponent> {
|
|
110
|
+
private data;
|
|
111
|
+
constructor(data?: GalleryItemBuilderData);
|
|
112
|
+
/** Sets the media item payload. */
|
|
113
|
+
setMedia(media: APIUnfurledMediaItem | null | undefined): this;
|
|
114
|
+
/** Sets the media description. */
|
|
115
|
+
setDescription(description: string | null | undefined): this;
|
|
116
|
+
/** Marks the media item as a spoiler. */
|
|
117
|
+
setSpoiler(spoiler: boolean | null | undefined): this;
|
|
118
|
+
/** Serialises the gallery item payload. */
|
|
119
|
+
toJSON(): MiniGalleryItemComponent;
|
|
120
|
+
}
|
|
121
|
+
/** Builder for structured message gallery components. */
|
|
122
|
+
export declare class GalleryBuilder implements JSONEncodable<MiniGalleryComponent> {
|
|
123
|
+
private data;
|
|
124
|
+
constructor(data?: GalleryBuilderData);
|
|
125
|
+
/** Replaces the gallery items. */
|
|
126
|
+
setItems(items: Array<MiniGalleryItemComponent | JSONEncodable<MiniGalleryItemComponent>>): this;
|
|
127
|
+
/** Adds a gallery item to the payload. */
|
|
128
|
+
addItem(item: MiniGalleryItemComponent | JSONEncodable<MiniGalleryItemComponent>): this;
|
|
129
|
+
/** Serialises the gallery payload. */
|
|
130
|
+
toJSON(): MiniGalleryComponent;
|
|
131
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { ComponentType } from "discord-api-types/v10";
|
|
2
|
+
import { resolveJSONEncodable } from "./shared.js";
|
|
3
|
+
function cloneContainerComponent(component) {
|
|
4
|
+
const resolved = resolveJSONEncodable(component);
|
|
5
|
+
return { ...resolved };
|
|
6
|
+
}
|
|
7
|
+
function cloneAccessory(accessory) {
|
|
8
|
+
const resolved = resolveJSONEncodable(accessory);
|
|
9
|
+
return { ...resolved };
|
|
10
|
+
}
|
|
11
|
+
/** Builder for structured message container payloads. */
|
|
12
|
+
export class ContainerBuilder {
|
|
13
|
+
data;
|
|
14
|
+
constructor(data = {}) {
|
|
15
|
+
const components = data.components
|
|
16
|
+
? data.components.map((component) => cloneContainerComponent(component))
|
|
17
|
+
: [];
|
|
18
|
+
this.data = {
|
|
19
|
+
...data,
|
|
20
|
+
type: ComponentType.Container,
|
|
21
|
+
components,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Replaces the components contained in the container. */
|
|
25
|
+
setComponents(components) {
|
|
26
|
+
this.data.components = components.map((component) => cloneContainerComponent(component));
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/** Replaces the sections contained in the container. */
|
|
30
|
+
setSections(sections) {
|
|
31
|
+
return this.setComponents(sections);
|
|
32
|
+
}
|
|
33
|
+
/** Adds a component to the container. */
|
|
34
|
+
addComponent(component) {
|
|
35
|
+
this.data.components ??= [];
|
|
36
|
+
this.data.components.push(cloneContainerComponent(component));
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/** Adds a section to the container. */
|
|
40
|
+
addSection(section) {
|
|
41
|
+
return this.addComponent(section);
|
|
42
|
+
}
|
|
43
|
+
/** Sets or clears the accent colour on the container. */
|
|
44
|
+
setAccentColor(color) {
|
|
45
|
+
if (color === undefined) {
|
|
46
|
+
delete this.data.accent_color;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.data.accent_color = color ?? null;
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/** Marks the container as a spoiler. */
|
|
54
|
+
setSpoiler(spoiler) {
|
|
55
|
+
if (spoiler === null || spoiler === undefined) {
|
|
56
|
+
delete this.data.spoiler;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.data.spoiler = spoiler;
|
|
60
|
+
}
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/** Serialises the container into a structured message payload. */
|
|
64
|
+
toJSON() {
|
|
65
|
+
const components = this.data.components ?? [];
|
|
66
|
+
return {
|
|
67
|
+
...this.data,
|
|
68
|
+
type: ComponentType.Container,
|
|
69
|
+
components: components.map((component) => resolveJSONEncodable(component)),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Builder for structured message sections. */
|
|
74
|
+
export class SectionBuilder {
|
|
75
|
+
data;
|
|
76
|
+
constructor(data = {}) {
|
|
77
|
+
const components = data.components
|
|
78
|
+
? data.components.map((component) => cloneTextDisplayComponent(component))
|
|
79
|
+
: [];
|
|
80
|
+
const rawAccessory = data.accessory;
|
|
81
|
+
const accessory = rawAccessory === undefined || rawAccessory === null
|
|
82
|
+
? undefined
|
|
83
|
+
: cloneAccessory(rawAccessory);
|
|
84
|
+
this.data = {
|
|
85
|
+
...data,
|
|
86
|
+
type: ComponentType.Section,
|
|
87
|
+
components,
|
|
88
|
+
accessory,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Replaces the text components within the section. */
|
|
92
|
+
setComponents(components) {
|
|
93
|
+
this.data.components = components.map((component) => cloneTextDisplayComponent(component));
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
/** Adds a text component to the section. */
|
|
97
|
+
addComponent(component) {
|
|
98
|
+
this.data.components ??= [];
|
|
99
|
+
this.data.components.push(cloneTextDisplayComponent(component));
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
/** Sets or clears the accessory component. */
|
|
103
|
+
setAccessory(accessory) {
|
|
104
|
+
if (accessory === null || accessory === undefined) {
|
|
105
|
+
this.data.accessory = undefined;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.data.accessory = cloneAccessory(accessory);
|
|
109
|
+
}
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/** Serialises the section into a structured message payload. */
|
|
113
|
+
toJSON() {
|
|
114
|
+
const components = this.data.components ?? [];
|
|
115
|
+
const accessory = this.data.accessory
|
|
116
|
+
? resolveJSONEncodable(this.data.accessory)
|
|
117
|
+
: undefined;
|
|
118
|
+
if (!accessory) {
|
|
119
|
+
throw new Error("[SectionBuilder] accessory is required for sections");
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
...this.data,
|
|
123
|
+
type: ComponentType.Section,
|
|
124
|
+
components: components.map((component) => resolveJSONEncodable(component)),
|
|
125
|
+
accessory,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function cloneTextDisplayComponent(component) {
|
|
130
|
+
const resolved = resolveJSONEncodable(component);
|
|
131
|
+
return { ...resolved };
|
|
132
|
+
}
|
|
133
|
+
/** Builder for structured message text display components. */
|
|
134
|
+
export class TextDisplayBuilder {
|
|
135
|
+
data;
|
|
136
|
+
constructor(data = {}) {
|
|
137
|
+
this.data = {
|
|
138
|
+
...data,
|
|
139
|
+
type: ComponentType.TextDisplay,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Sets or clears the primary text content. */
|
|
143
|
+
setContent(content) {
|
|
144
|
+
if (content === null || content === undefined) {
|
|
145
|
+
delete this.data.content;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.data.content = content;
|
|
149
|
+
}
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
/** Serialises the component into a structured message payload. */
|
|
153
|
+
toJSON() {
|
|
154
|
+
if (!this.data.content) {
|
|
155
|
+
throw new Error("[TextDisplayBuilder] content is required for text displays");
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...this.data,
|
|
159
|
+
type: ComponentType.TextDisplay,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Builder for structured message separator components. */
|
|
164
|
+
export class SeparatorBuilder {
|
|
165
|
+
data;
|
|
166
|
+
constructor(data = {}) {
|
|
167
|
+
this.data = {
|
|
168
|
+
...data,
|
|
169
|
+
type: ComponentType.Separator,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** Sets whether the separator should render a divider. */
|
|
173
|
+
setDivider(divider) {
|
|
174
|
+
if (divider === null || divider === undefined) {
|
|
175
|
+
delete this.data.divider;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.data.divider = divider;
|
|
179
|
+
}
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
/** Sets the separator spacing value. */
|
|
183
|
+
setSpacing(spacing) {
|
|
184
|
+
if (spacing === null || spacing === undefined) {
|
|
185
|
+
delete this.data.spacing;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.data.spacing = spacing;
|
|
189
|
+
}
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/** Serialises the separator payload. */
|
|
193
|
+
toJSON() {
|
|
194
|
+
return {
|
|
195
|
+
...this.data,
|
|
196
|
+
type: ComponentType.Separator,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Builder for structured message thumbnails. */
|
|
201
|
+
export class ThumbnailBuilder {
|
|
202
|
+
data;
|
|
203
|
+
constructor(data = {}) {
|
|
204
|
+
this.data = {
|
|
205
|
+
...data,
|
|
206
|
+
type: ComponentType.Thumbnail,
|
|
207
|
+
media: data.media ? { ...data.media } : undefined,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** Sets the media payload for the thumbnail. */
|
|
211
|
+
setMedia(media) {
|
|
212
|
+
if (media === null || media === undefined) {
|
|
213
|
+
delete this.data.media;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
this.data.media = { ...media };
|
|
217
|
+
}
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
/** Sets the thumbnail description. */
|
|
221
|
+
setDescription(description) {
|
|
222
|
+
if (description === null || description === undefined) {
|
|
223
|
+
delete this.data.description;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this.data.description = description;
|
|
227
|
+
}
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
/** Marks the thumbnail as a spoiler. */
|
|
231
|
+
setSpoiler(spoiler) {
|
|
232
|
+
if (spoiler === null || spoiler === undefined) {
|
|
233
|
+
delete this.data.spoiler;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
this.data.spoiler = spoiler;
|
|
237
|
+
}
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
/** Serialises the thumbnail payload. */
|
|
241
|
+
toJSON() {
|
|
242
|
+
if (!this.data.media) {
|
|
243
|
+
throw new Error("[ThumbnailBuilder] media is required for thumbnails");
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
...this.data,
|
|
247
|
+
type: ComponentType.Thumbnail,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** Builder for structured message gallery items. */
|
|
252
|
+
export class GalleryItemBuilder {
|
|
253
|
+
data;
|
|
254
|
+
constructor(data = {}) {
|
|
255
|
+
this.data = {
|
|
256
|
+
...data,
|
|
257
|
+
media: data.media ? { ...data.media } : undefined,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Sets the media item payload. */
|
|
261
|
+
setMedia(media) {
|
|
262
|
+
if (media === null || media === undefined) {
|
|
263
|
+
delete this.data.media;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
this.data.media = { ...media };
|
|
267
|
+
}
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
/** Sets the media description. */
|
|
271
|
+
setDescription(description) {
|
|
272
|
+
if (description === null || description === undefined) {
|
|
273
|
+
delete this.data.description;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this.data.description = description;
|
|
277
|
+
}
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
/** Marks the media item as a spoiler. */
|
|
281
|
+
setSpoiler(spoiler) {
|
|
282
|
+
if (spoiler === null || spoiler === undefined) {
|
|
283
|
+
delete this.data.spoiler;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
this.data.spoiler = spoiler;
|
|
287
|
+
}
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
/** Serialises the gallery item payload. */
|
|
291
|
+
toJSON() {
|
|
292
|
+
if (!this.data.media) {
|
|
293
|
+
throw new Error("[GalleryItemBuilder] media is required for gallery items");
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
...this.data,
|
|
297
|
+
media: { ...this.data.media },
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/** Builder for structured message gallery components. */
|
|
302
|
+
export class GalleryBuilder {
|
|
303
|
+
data;
|
|
304
|
+
constructor(data = {}) {
|
|
305
|
+
const items = data.items
|
|
306
|
+
? data.items.map((item) => resolveGalleryItem(item))
|
|
307
|
+
: [];
|
|
308
|
+
this.data = {
|
|
309
|
+
...data,
|
|
310
|
+
type: ComponentType.MediaGallery,
|
|
311
|
+
items,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/** Replaces the gallery items. */
|
|
315
|
+
setItems(items) {
|
|
316
|
+
this.data.items = items.map((item) => resolveGalleryItem(item));
|
|
317
|
+
return this;
|
|
318
|
+
}
|
|
319
|
+
/** Adds a gallery item to the payload. */
|
|
320
|
+
addItem(item) {
|
|
321
|
+
this.data.items ??= [];
|
|
322
|
+
this.data.items.push(resolveGalleryItem(item));
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
/** Serialises the gallery payload. */
|
|
326
|
+
toJSON() {
|
|
327
|
+
const items = this.data.items ?? [];
|
|
328
|
+
if (items.length === 0) {
|
|
329
|
+
throw new Error("[GalleryBuilder] at least one gallery item is required");
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
...this.data,
|
|
333
|
+
type: ComponentType.MediaGallery,
|
|
334
|
+
items: items.map((item) => resolveJSONEncodable(item)),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function resolveGalleryItem(item) {
|
|
339
|
+
const resolved = resolveJSONEncodable(item);
|
|
340
|
+
if (!resolved.media) {
|
|
341
|
+
throw new Error("[GalleryBuilder] gallery items require media");
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
...resolved,
|
|
345
|
+
media: { ...resolved.media },
|
|
346
|
+
};
|
|
347
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type APIModalInteractionResponseCallbackData, type APIModalInteractionResponseCallbackComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { type JSONEncodable } from './shared.js';
|
|
3
|
+
export type ModalComponentLike = JSONEncodable<APIModalInteractionResponseCallbackComponent> | APIModalInteractionResponseCallbackComponent;
|
|
4
|
+
export type ModalBuilderData = {
|
|
5
|
+
customId?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
components?: Iterable<ModalComponentLike>;
|
|
8
|
+
};
|
|
9
|
+
export declare class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {
|
|
10
|
+
private readonly data;
|
|
11
|
+
constructor(data?: ModalBuilderData);
|
|
12
|
+
setCustomId(customId: string): this;
|
|
13
|
+
setTitle(title: string): this;
|
|
14
|
+
addComponents(...components: ModalComponentLike[]): this;
|
|
15
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 ModalBuilder {
|
|
5
|
+
data;
|
|
6
|
+
constructor(data = {}) {
|
|
7
|
+
this.data = { ...data, components: data.components ? Array.from(data.components) : [] };
|
|
8
|
+
}
|
|
9
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
10
|
+
setTitle(title) { this.data.title = title; return this; }
|
|
11
|
+
addComponents(...components) {
|
|
12
|
+
this.data.components = [...(this.data.components ?? []), ...components];
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
toJSON() {
|
|
16
|
+
const customId = assertDefined('ModalBuilder', 'custom_id', this.data.customId);
|
|
17
|
+
const title = assertDefined('ModalBuilder', 'title', this.data.title);
|
|
18
|
+
assertStringLength('ModalBuilder', 'custom_id', customId, 1, 100);
|
|
19
|
+
assertStringLength('ModalBuilder', 'title', title, 1, 45);
|
|
20
|
+
const components = Array.from(this.data.components ?? []).map((c) => resolveJSONEncodable(c));
|
|
21
|
+
if (components.length === 0 || components.length > 5) {
|
|
22
|
+
throw new ValidationError('ModalBuilder', 'components', 'must contain between 1 and 5 components');
|
|
23
|
+
}
|
|
24
|
+
for (const component of components) {
|
|
25
|
+
const allowedTypes = [
|
|
26
|
+
ComponentType.ActionRow, // deprecated in modals, still accepted for legacy rows
|
|
27
|
+
ComponentType.TextDisplay,
|
|
28
|
+
ComponentType.Label,
|
|
29
|
+
];
|
|
30
|
+
if (!allowedTypes.includes(component.type)) {
|
|
31
|
+
throw new ValidationError('ModalBuilder', 'components', `invalid modal top-level component type ${component.type}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { custom_id: customId, title, components };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChannelType, SelectMenuDefaultValueType, type APIChannelSelectComponent, type APISelectMenuDefaultValue } from 'discord-api-types/v10';
|
|
2
|
+
import type { JSONEncodable } from './shared.js';
|
|
3
|
+
export type ModalChannelSelectMenuBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
minValues?: number;
|
|
7
|
+
maxValues?: number;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
channelTypes?: ChannelType[];
|
|
11
|
+
defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>[];
|
|
12
|
+
};
|
|
13
|
+
export declare class ModalChannelSelectMenuBuilder implements JSONEncodable<APIChannelSelectComponent> {
|
|
14
|
+
private readonly data;
|
|
15
|
+
constructor(data?: ModalChannelSelectMenuBuilderData);
|
|
16
|
+
setCustomId(customId: string): this;
|
|
17
|
+
setPlaceholder(placeholder?: string): this;
|
|
18
|
+
setMinValues(minValues?: number): this;
|
|
19
|
+
setMaxValues(maxValues?: number): this;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Discord does not accept `disabled` on modal select menus; the
|
|
22
|
+
* value is ignored during serialisation.
|
|
23
|
+
*/
|
|
24
|
+
setDisabled(disabled: boolean): this;
|
|
25
|
+
setRequired(required: boolean): this;
|
|
26
|
+
setChannelTypes(channelTypes: ChannelType[]): this;
|
|
27
|
+
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>>): this;
|
|
28
|
+
toJSON(): APIChannelSelectComponent;
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10';
|
|
2
|
+
import { assertSelectMenuConstraints } from '../types/validation.js';
|
|
3
|
+
export class ModalChannelSelectMenuBuilder {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data = {}) { this.data = { ...data }; }
|
|
6
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
7
|
+
setPlaceholder(placeholder) { this.data.placeholder = placeholder; return this; }
|
|
8
|
+
setMinValues(minValues) { this.data.minValues = minValues; return this; }
|
|
9
|
+
setMaxValues(maxValues) { this.data.maxValues = maxValues; return this; }
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Discord does not accept `disabled` on modal select menus; the
|
|
12
|
+
* value is ignored during serialisation.
|
|
13
|
+
*/
|
|
14
|
+
setDisabled(disabled) { this.data.disabled = disabled; return this; }
|
|
15
|
+
setRequired(required) { this.data.required = required; return this; }
|
|
16
|
+
setChannelTypes(channelTypes) { this.data.channelTypes = [...channelTypes]; return this; }
|
|
17
|
+
setDefaultValues(defaultValues) {
|
|
18
|
+
this.data.defaultValues = Array.from(defaultValues, (v) => ({ ...v, type: SelectMenuDefaultValueType.Channel }));
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
const customId = assertSelectMenuConstraints('ModalChannelSelectMenuBuilder', this.data);
|
|
23
|
+
return { type: ComponentType.ChannelSelect, custom_id: customId, placeholder: this.data.placeholder, min_values: this.data.minValues, max_values: this.data.maxValues, required: this.data.required, channel_types: this.data.channelTypes, default_values: this.data.defaultValues };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SelectMenuDefaultValueType, type APIMentionableSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
/** Shape describing initial modal mentionable select menu data accepted by the builder. */
|
|
4
|
+
export type ModalMentionableSelectMenuBuilderData = {
|
|
5
|
+
customId?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
minValues?: number;
|
|
8
|
+
maxValues?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
defaultValues?: (APISelectMenuDefaultValue<SelectMenuDefaultValueType.User> | APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role>)[];
|
|
12
|
+
};
|
|
13
|
+
/** Builder for Discord mentionable select menu components in modals. */
|
|
14
|
+
export declare class ModalMentionableSelectMenuBuilder implements JSONEncodable<APIMentionableSelectComponent> {
|
|
15
|
+
private data;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new modal mentionable select menu builder with optional seed data.
|
|
18
|
+
*/
|
|
19
|
+
constructor(data?: ModalMentionableSelectMenuBuilderData);
|
|
20
|
+
/**
|
|
21
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
22
|
+
*/
|
|
23
|
+
setCustomId(customId: string): this;
|
|
24
|
+
/**
|
|
25
|
+
* Sets or clears the placeholder text displayed when no mentionable is selected.
|
|
26
|
+
*/
|
|
27
|
+
setPlaceholder(placeholder: string | null | undefined): this;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the minimum number of mentionables that must be selected.
|
|
30
|
+
*/
|
|
31
|
+
setMinValues(minValues: number | null | undefined): this;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the maximum number of mentionables that can be selected.
|
|
34
|
+
*/
|
|
35
|
+
setMaxValues(maxValues: number | null | undefined): this;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Discord does not accept `disabled` on modal select menus; the
|
|
38
|
+
* value is ignored during serialisation.
|
|
39
|
+
*/
|
|
40
|
+
setDisabled(disabled: boolean): this;
|
|
41
|
+
/**
|
|
42
|
+
* Marks the select menu as required in the modal.
|
|
43
|
+
*/
|
|
44
|
+
setRequired(required: boolean): this;
|
|
45
|
+
/**
|
|
46
|
+
* Replaces the default mentionable selections displayed when the menu renders.
|
|
47
|
+
*/
|
|
48
|
+
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.User> | APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role>>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Serialises the builder into an API compatible mentionable select menu payload.
|
|
51
|
+
*/
|
|
52
|
+
toJSON(): APIMentionableSelectComponent;
|
|
53
|
+
}
|