mini-interactions 0.0.0-stage → 0.15.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 +253 -2
- package/dist/bot.d.ts +58 -0
- package/dist/bot.js +217 -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/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 +90 -4
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|