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,52 @@
|
|
|
1
|
+
import { type APISelectMenuOption, type APIStringSelectComponent } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
import type { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
4
|
+
/** Shape describing initial string select menu data accepted by the builder. */
|
|
5
|
+
export type StringSelectMenuBuilderData = {
|
|
6
|
+
customId?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
minValues?: number;
|
|
9
|
+
maxValues?: number;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
options?: APISelectMenuOption[];
|
|
12
|
+
};
|
|
13
|
+
/** Builder for Discord string select menu components. */
|
|
14
|
+
export declare class StringSelectMenuBuilder implements JSONEncodable<APIStringSelectComponent> {
|
|
15
|
+
private data;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new string select menu builder with optional seed data.
|
|
18
|
+
*/
|
|
19
|
+
constructor(data?: StringSelectMenuBuilderData);
|
|
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 option is selected.
|
|
26
|
+
*/
|
|
27
|
+
setPlaceholder(placeholder: string | null | undefined): this;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the minimum number of options that must be selected.
|
|
30
|
+
*/
|
|
31
|
+
setMinValues(minValues: number | null | undefined): this;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the maximum number of options that can be selected.
|
|
34
|
+
*/
|
|
35
|
+
setMaxValues(maxValues: number | null | undefined): this;
|
|
36
|
+
/**
|
|
37
|
+
* Toggles whether the select menu is disabled.
|
|
38
|
+
*/
|
|
39
|
+
setDisabled(disabled: boolean): this;
|
|
40
|
+
/**
|
|
41
|
+
* Appends new option entries to the select menu.
|
|
42
|
+
*/
|
|
43
|
+
addOptions(...options: (APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>)[]): this;
|
|
44
|
+
/**
|
|
45
|
+
* Replaces the current option set with the provided iterable.
|
|
46
|
+
*/
|
|
47
|
+
setOptions(options: Iterable<APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>>): this;
|
|
48
|
+
/**
|
|
49
|
+
* Serialises the builder into an API compatible string select menu payload.
|
|
50
|
+
*/
|
|
51
|
+
toJSON(): APIStringSelectComponent;
|
|
52
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ComponentType, } from "discord-api-types/v10";
|
|
2
|
+
/** Builder for Discord string select menu components. */
|
|
3
|
+
export class StringSelectMenuBuilder {
|
|
4
|
+
data;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new string 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
|
+
options: data.options ? [...data.options] : [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
20
|
+
*/
|
|
21
|
+
setCustomId(customId) {
|
|
22
|
+
this.data.customId = customId;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sets or clears the placeholder text displayed when no option is selected.
|
|
27
|
+
*/
|
|
28
|
+
setPlaceholder(placeholder) {
|
|
29
|
+
this.data.placeholder = placeholder ?? undefined;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets the minimum number of options that must be selected.
|
|
34
|
+
*/
|
|
35
|
+
setMinValues(minValues) {
|
|
36
|
+
this.data.minValues = minValues ?? undefined;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the maximum number of options that can be selected.
|
|
41
|
+
*/
|
|
42
|
+
setMaxValues(maxValues) {
|
|
43
|
+
this.data.maxValues = maxValues ?? undefined;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Toggles whether the select menu is disabled.
|
|
48
|
+
*/
|
|
49
|
+
setDisabled(disabled) {
|
|
50
|
+
this.data.disabled = disabled;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Appends new option entries to the select menu.
|
|
55
|
+
*/
|
|
56
|
+
addOptions(...options) {
|
|
57
|
+
this.data.options.push(...options.map((option) => {
|
|
58
|
+
if ("toJSON" in option && typeof option.toJSON === "function") {
|
|
59
|
+
return { ...option.toJSON() };
|
|
60
|
+
}
|
|
61
|
+
return { ...option };
|
|
62
|
+
}));
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Replaces the current option set with the provided iterable.
|
|
67
|
+
*/
|
|
68
|
+
setOptions(options) {
|
|
69
|
+
this.data.options = Array.from(options, (option) => {
|
|
70
|
+
if ("toJSON" in option && typeof option.toJSON === "function") {
|
|
71
|
+
return { ...option.toJSON() };
|
|
72
|
+
}
|
|
73
|
+
return { ...option };
|
|
74
|
+
});
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Serialises the builder into an API compatible string select menu payload.
|
|
79
|
+
*/
|
|
80
|
+
toJSON() {
|
|
81
|
+
const { customId, options } = this.data;
|
|
82
|
+
if (!customId) {
|
|
83
|
+
throw new Error("[StringSelectMenuBuilder] custom id is required.");
|
|
84
|
+
}
|
|
85
|
+
if (this.data.placeholder && this.data.placeholder.length > 150) {
|
|
86
|
+
throw new Error("[StringSelectMenuBuilder] placeholder must be 150 characters or less.");
|
|
87
|
+
}
|
|
88
|
+
if (options.length === 0) {
|
|
89
|
+
throw new Error("[StringSelectMenuBuilder] at least one option is required.");
|
|
90
|
+
}
|
|
91
|
+
if (options.length > 25) {
|
|
92
|
+
throw new Error("[StringSelectMenuBuilder] no more than 25 options can be provided.");
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
type: ComponentType.StringSelect,
|
|
96
|
+
custom_id: customId,
|
|
97
|
+
placeholder: this.data.placeholder,
|
|
98
|
+
min_values: this.data.minValues,
|
|
99
|
+
max_values: this.data.maxValues,
|
|
100
|
+
disabled: this.data.disabled,
|
|
101
|
+
options: options.map((option) => ({ ...option })),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { APIMessageComponentEmoji, APISelectMenuOption } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
/** Shape describing initial string select menu option data accepted by the builder. */
|
|
4
|
+
export type StringSelectMenuOptionBuilderData = {
|
|
5
|
+
label?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
emoji?: string | APIMessageComponentEmoji;
|
|
9
|
+
default?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** Builder for Discord string select menu option components. */
|
|
12
|
+
export declare class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {
|
|
13
|
+
private data;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new string select menu option builder with optional seed data.
|
|
16
|
+
*/
|
|
17
|
+
constructor(data?: StringSelectMenuOptionBuilderData);
|
|
18
|
+
/**
|
|
19
|
+
* Sets the user-facing name of the option (max 100 characters).
|
|
20
|
+
*/
|
|
21
|
+
setLabel(label: string): this;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the dev-defined value of the option (max 100 characters).
|
|
24
|
+
*/
|
|
25
|
+
setValue(value: string): this;
|
|
26
|
+
/**
|
|
27
|
+
* Sets an additional description of the option (max 100 characters).
|
|
28
|
+
*/
|
|
29
|
+
setDescription(description: string | null | undefined): this;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the emoji to display to the left of the option.
|
|
32
|
+
* Accepts:
|
|
33
|
+
* - Unicode emoji: "😀"
|
|
34
|
+
* - Custom emoji string: "<:name:id>" or "<a:name:id>"
|
|
35
|
+
* - Emoji object: { name: "😀" } or { name: "name", id: "id", animated: true }
|
|
36
|
+
*/
|
|
37
|
+
setEmoji(emoji: string | APIMessageComponentEmoji | null | undefined): this;
|
|
38
|
+
/**
|
|
39
|
+
* Sets whether this option should be already-selected by default.
|
|
40
|
+
*/
|
|
41
|
+
setDefault(isDefault: boolean): this;
|
|
42
|
+
/**
|
|
43
|
+
* Serialises the builder into an API compatible select menu option payload.
|
|
44
|
+
*/
|
|
45
|
+
toJSON(): APISelectMenuOption;
|
|
46
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses an emoji string into an APIMessageComponentEmoji object.
|
|
3
|
+
* Supports:
|
|
4
|
+
* - Unicode emojis: "😀"
|
|
5
|
+
* - Custom emojis: "<:name:id>" or "<a:name:id>"
|
|
6
|
+
* - Emoji objects: { name: "😀" } or { name: "name", id: "id" }
|
|
7
|
+
*/
|
|
8
|
+
function parseEmoji(emoji) {
|
|
9
|
+
if (typeof emoji === "object") {
|
|
10
|
+
return emoji;
|
|
11
|
+
}
|
|
12
|
+
// Check for custom emoji format: <:name:id> or <a:name:id>
|
|
13
|
+
const customEmojiMatch = emoji.match(/^<(a)?:([^:]+):(\d+)>$/);
|
|
14
|
+
if (customEmojiMatch) {
|
|
15
|
+
return {
|
|
16
|
+
name: customEmojiMatch[2],
|
|
17
|
+
id: customEmojiMatch[3],
|
|
18
|
+
animated: customEmojiMatch[1] === "a",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// Treat as unicode emoji
|
|
22
|
+
return { name: emoji };
|
|
23
|
+
}
|
|
24
|
+
/** Builder for Discord string select menu option components. */
|
|
25
|
+
export class StringSelectMenuOptionBuilder {
|
|
26
|
+
data;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new string select menu option builder with optional seed data.
|
|
29
|
+
*/
|
|
30
|
+
constructor(data = {}) {
|
|
31
|
+
this.data = {
|
|
32
|
+
label: data.label,
|
|
33
|
+
value: data.value,
|
|
34
|
+
description: data.description,
|
|
35
|
+
emoji: data.emoji ? parseEmoji(data.emoji) : undefined,
|
|
36
|
+
default: data.default,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the user-facing name of the option (max 100 characters).
|
|
41
|
+
*/
|
|
42
|
+
setLabel(label) {
|
|
43
|
+
this.data.label = label;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the dev-defined value of the option (max 100 characters).
|
|
48
|
+
*/
|
|
49
|
+
setValue(value) {
|
|
50
|
+
this.data.value = value;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sets an additional description of the option (max 100 characters).
|
|
55
|
+
*/
|
|
56
|
+
setDescription(description) {
|
|
57
|
+
this.data.description = description ?? undefined;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets the emoji to display to the left of the option.
|
|
62
|
+
* Accepts:
|
|
63
|
+
* - Unicode emoji: "😀"
|
|
64
|
+
* - Custom emoji string: "<:name:id>" or "<a:name:id>"
|
|
65
|
+
* - Emoji object: { name: "😀" } or { name: "name", id: "id", animated: true }
|
|
66
|
+
*/
|
|
67
|
+
setEmoji(emoji) {
|
|
68
|
+
this.data.emoji = emoji ? parseEmoji(emoji) : undefined;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sets whether this option should be already-selected by default.
|
|
73
|
+
*/
|
|
74
|
+
setDefault(isDefault) {
|
|
75
|
+
this.data.default = isDefault;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Serialises the builder into an API compatible select menu option payload.
|
|
80
|
+
*/
|
|
81
|
+
toJSON() {
|
|
82
|
+
const { label, value } = this.data;
|
|
83
|
+
if (!label) {
|
|
84
|
+
throw new Error("[StringSelectMenuOptionBuilder] label is required.");
|
|
85
|
+
}
|
|
86
|
+
if (!value) {
|
|
87
|
+
throw new Error("[StringSelectMenuOptionBuilder] value is required.");
|
|
88
|
+
}
|
|
89
|
+
if (label.length > 100) {
|
|
90
|
+
throw new Error("[StringSelectMenuOptionBuilder] label must be 100 characters or less.");
|
|
91
|
+
}
|
|
92
|
+
if (value.length > 100) {
|
|
93
|
+
throw new Error("[StringSelectMenuOptionBuilder] value must be 100 characters or less.");
|
|
94
|
+
}
|
|
95
|
+
if (this.data.description && this.data.description.length > 100) {
|
|
96
|
+
throw new Error("[StringSelectMenuOptionBuilder] description must be 100 characters or less.");
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
label,
|
|
100
|
+
value,
|
|
101
|
+
description: this.data.description,
|
|
102
|
+
emoji: this.data.emoji ? { ...this.data.emoji } : undefined,
|
|
103
|
+
default: this.data.default,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TextInputStyle, type APITextInputComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { type JSONEncodable } from './shared.js';
|
|
3
|
+
export type TextInputBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
style?: TextInputStyle;
|
|
6
|
+
minLength?: number;
|
|
7
|
+
maxLength?: number;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
value?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare class TextInputBuilder implements JSONEncodable<APITextInputComponent> {
|
|
13
|
+
private readonly data;
|
|
14
|
+
constructor(data?: TextInputBuilderData);
|
|
15
|
+
setCustomId(customId: string): this;
|
|
16
|
+
setStyle(style: TextInputStyle): this;
|
|
17
|
+
setMinLength(minLength: number): this;
|
|
18
|
+
setMaxLength(maxLength: number): this;
|
|
19
|
+
setRequired(required: boolean): this;
|
|
20
|
+
setValue(value: string): this;
|
|
21
|
+
setPlaceholder(placeholder: string): this;
|
|
22
|
+
toJSON(): APITextInputComponent;
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ComponentType, TextInputStyle } from 'discord-api-types/v10';
|
|
2
|
+
import { assertDefined, assertRange, assertStringLength } from '../types/validation.js';
|
|
3
|
+
export class TextInputBuilder {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data = {}) { this.data = { style: TextInputStyle.Short, ...data }; }
|
|
6
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
7
|
+
setStyle(style) { this.data.style = style; return this; }
|
|
8
|
+
setMinLength(minLength) { this.data.minLength = minLength; return this; }
|
|
9
|
+
setMaxLength(maxLength) { this.data.maxLength = maxLength; return this; }
|
|
10
|
+
setRequired(required) { this.data.required = required; return this; }
|
|
11
|
+
setValue(value) { this.data.value = value; return this; }
|
|
12
|
+
setPlaceholder(placeholder) { this.data.placeholder = placeholder; return this; }
|
|
13
|
+
toJSON() {
|
|
14
|
+
const customId = assertDefined('TextInputBuilder', 'custom_id', this.data.customId);
|
|
15
|
+
assertStringLength('TextInputBuilder', 'custom_id', customId, 1, 100);
|
|
16
|
+
if (this.data.minLength !== undefined)
|
|
17
|
+
assertRange('TextInputBuilder', 'min_length', this.data.minLength, 0, 4000);
|
|
18
|
+
if (this.data.maxLength !== undefined)
|
|
19
|
+
assertRange('TextInputBuilder', 'max_length', this.data.maxLength, 1, 4000);
|
|
20
|
+
if (this.data.placeholder)
|
|
21
|
+
assertStringLength('TextInputBuilder', 'placeholder', this.data.placeholder, 1, 100);
|
|
22
|
+
if (this.data.value)
|
|
23
|
+
assertStringLength('TextInputBuilder', 'value', this.data.value, 0, 4000);
|
|
24
|
+
return { type: ComponentType.TextInput, custom_id: customId, style: this.data.style ?? TextInputStyle.Short, min_length: this.data.minLength, max_length: this.data.maxLength, required: this.data.required, value: this.data.value, placeholder: this.data.placeholder };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Re-exports component builders and shared types for convenience. */
|
|
2
|
+
export { ActionRowBuilder } from "./ActionRowBuilder.js";
|
|
3
|
+
export type { ActionRowComponentLike } from "./ActionRowBuilder.js";
|
|
4
|
+
export { ButtonBuilder } from "./ButtonBuilder.js";
|
|
5
|
+
export type { ButtonBuilderData } from "./ButtonBuilder.js";
|
|
6
|
+
export { StringSelectMenuBuilder } from "./StringSelectMenuBuilder.js";
|
|
7
|
+
export type { StringSelectMenuBuilderData } from "./StringSelectMenuBuilder.js";
|
|
8
|
+
export { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
9
|
+
export type { StringSelectMenuOptionBuilderData } from "./StringSelectMenuOptionBuilder.js";
|
|
10
|
+
export { RoleSelectMenuBuilder } from "./RoleSelectMenuBuilder.js";
|
|
11
|
+
export type { RoleSelectMenuBuilderData } from "./RoleSelectMenuBuilder.js";
|
|
12
|
+
export { ChannelSelectMenuBuilder } from "./ChannelSelectMenuBuilder.js";
|
|
13
|
+
export type { ChannelSelectMenuBuilderData } from "./ChannelSelectMenuBuilder.js";
|
|
14
|
+
export { ModalStringSelectMenuBuilder } from "./ModalStringSelectMenuBuilder.js";
|
|
15
|
+
export type { ModalStringSelectMenuBuilderData } from "./ModalStringSelectMenuBuilder.js";
|
|
16
|
+
export { ModalRoleSelectMenuBuilder } from "./ModalRoleSelectMenuBuilder.js";
|
|
17
|
+
export type { ModalRoleSelectMenuBuilderData } from "./ModalRoleSelectMenuBuilder.js";
|
|
18
|
+
export { ModalUserSelectMenuBuilder } from "./ModalUserSelectMenuBuilder.js";
|
|
19
|
+
export type { ModalUserSelectMenuBuilderData } from "./ModalUserSelectMenuBuilder.js";
|
|
20
|
+
export { ModalChannelSelectMenuBuilder } from "./ModalChannelSelectMenuBuilder.js";
|
|
21
|
+
export type { ModalChannelSelectMenuBuilderData } from "./ModalChannelSelectMenuBuilder.js";
|
|
22
|
+
export { ModalMentionableSelectMenuBuilder } from "./ModalMentionableSelectMenuBuilder.js";
|
|
23
|
+
export type { ModalMentionableSelectMenuBuilderData } from "./ModalMentionableSelectMenuBuilder.js";
|
|
24
|
+
export { ModalBuilder } from "./ModalBuilder.js";
|
|
25
|
+
export type { ModalBuilderData, ModalComponentLike } from "./ModalBuilder.js";
|
|
26
|
+
export { TextInputBuilder } from "./TextInputBuilder.js";
|
|
27
|
+
export type { TextInputBuilderData } from "./TextInputBuilder.js";
|
|
28
|
+
export { LabelBuilder } from "./LabelBuilder.js";
|
|
29
|
+
export type { LabelBuilderData, LabelComponentLike } from "./LabelBuilder.js";
|
|
30
|
+
export { FileUploadBuilder } from "./FileUploadBuilder.js";
|
|
31
|
+
export type { FileUploadBuilderData } from "./FileUploadBuilder.js";
|
|
32
|
+
export { AutomodRuleBuilder } from "./AutomodRuleBuilder.js";
|
|
33
|
+
export type { AutomodRuleBuilderData } from "./AutomodRuleBuilder.js";
|
|
34
|
+
export { EmbedBuilder } from "./EmbedBuilder.js";
|
|
35
|
+
export type { EmbedBuilderData } from "./EmbedBuilder.js";
|
|
36
|
+
export { ContainerBuilder, SectionBuilder, TextDisplayBuilder, SeparatorBuilder, GalleryBuilder, GalleryItemBuilder, ThumbnailBuilder, } from "./MiniContainerBuilder.js";
|
|
37
|
+
export type { ContainerBuilderData, SectionBuilderData, TextDisplayBuilderData, SeparatorBuilderData, GalleryBuilderData, GalleryItemBuilderData, ThumbnailBuilderData, MiniContainerComponent, MiniSectionComponent, MiniTextDisplayComponent, MiniSeparatorComponent, MiniGalleryComponent, MiniGalleryItemComponent, MiniThumbnailComponent, MiniContentComponent, MiniSectionAccessoryComponent, } from "./MiniContainerBuilder.js";
|
|
38
|
+
export type { JSONEncodable } from "./shared.js";
|
|
39
|
+
export { RadioBuilder } from "./RadioBuilder.js";
|
|
40
|
+
export type { RadioBuilderData } from "./RadioBuilder.js";
|
|
41
|
+
export { CheckboxBuilder } from "./CheckboxBuilder.js";
|
|
42
|
+
export type { CheckboxBuilderData } from "./CheckboxBuilder.js";
|
|
43
|
+
export { CheckboxGroupBuilder } from "./CheckboxGroupBuilder.js";
|
|
44
|
+
export type { CheckboxGroupBuilderData } from "./CheckboxGroupBuilder.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Re-exports component builders and shared types for convenience. */
|
|
2
|
+
export { ActionRowBuilder } from "./ActionRowBuilder.js";
|
|
3
|
+
export { ButtonBuilder } from "./ButtonBuilder.js";
|
|
4
|
+
export { StringSelectMenuBuilder } from "./StringSelectMenuBuilder.js";
|
|
5
|
+
export { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
6
|
+
export { RoleSelectMenuBuilder } from "./RoleSelectMenuBuilder.js";
|
|
7
|
+
export { ChannelSelectMenuBuilder } from "./ChannelSelectMenuBuilder.js";
|
|
8
|
+
export { ModalStringSelectMenuBuilder } from "./ModalStringSelectMenuBuilder.js";
|
|
9
|
+
export { ModalRoleSelectMenuBuilder } from "./ModalRoleSelectMenuBuilder.js";
|
|
10
|
+
export { ModalUserSelectMenuBuilder } from "./ModalUserSelectMenuBuilder.js";
|
|
11
|
+
export { ModalChannelSelectMenuBuilder } from "./ModalChannelSelectMenuBuilder.js";
|
|
12
|
+
export { ModalMentionableSelectMenuBuilder } from "./ModalMentionableSelectMenuBuilder.js";
|
|
13
|
+
export { ModalBuilder } from "./ModalBuilder.js";
|
|
14
|
+
export { TextInputBuilder } from "./TextInputBuilder.js";
|
|
15
|
+
export { LabelBuilder } from "./LabelBuilder.js";
|
|
16
|
+
export { FileUploadBuilder } from "./FileUploadBuilder.js";
|
|
17
|
+
export { AutomodRuleBuilder } from "./AutomodRuleBuilder.js";
|
|
18
|
+
export { EmbedBuilder } from "./EmbedBuilder.js";
|
|
19
|
+
export { ContainerBuilder, SectionBuilder, TextDisplayBuilder, SeparatorBuilder, GalleryBuilder, GalleryItemBuilder, ThumbnailBuilder, } from "./MiniContainerBuilder.js";
|
|
20
|
+
export { RadioBuilder } from "./RadioBuilder.js";
|
|
21
|
+
export { CheckboxBuilder } from "./CheckboxBuilder.js";
|
|
22
|
+
export { CheckboxGroupBuilder } from "./CheckboxGroupBuilder.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Interface describing objects capable of encoding themselves as JSON payloads. */
|
|
2
|
+
export interface JSONEncodable<T> {
|
|
3
|
+
toJSON(): T;
|
|
4
|
+
}
|
|
5
|
+
/** Type guard that checks whether a value provides a `toJSON` method. */
|
|
6
|
+
export declare function isJSONEncodable<T>(value: JSONEncodable<T> | unknown): value is JSONEncodable<T>;
|
|
7
|
+
/** Normalises a value that might either be a JSON encodable object or plain payload. */
|
|
8
|
+
export declare function resolveJSONEncodable<T>(value: JSONEncodable<T> | T): T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Type guard that checks whether a value provides a `toJSON` method. */
|
|
2
|
+
export function isJSONEncodable(value) {
|
|
3
|
+
return (typeof value === "object" &&
|
|
4
|
+
value !== null &&
|
|
5
|
+
"toJSON" in value &&
|
|
6
|
+
typeof value.toJSON === "function");
|
|
7
|
+
}
|
|
8
|
+
/** Normalises a value that might either be a JSON encodable object or plain payload. */
|
|
9
|
+
export function resolveJSONEncodable(value) {
|
|
10
|
+
return isJSONEncodable(value) ? value.toJSON() : value;
|
|
11
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, readdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
function parseArgs(argv) {
|
|
5
|
+
const options = {
|
|
6
|
+
commands: "src/commands",
|
|
7
|
+
components: "src/components",
|
|
8
|
+
modals: "src/modals",
|
|
9
|
+
out: "src/mini-interactions.generated.ts",
|
|
10
|
+
};
|
|
11
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
12
|
+
const arg = argv[index];
|
|
13
|
+
if (arg === "generate")
|
|
14
|
+
continue;
|
|
15
|
+
if (!arg.startsWith("--"))
|
|
16
|
+
continue;
|
|
17
|
+
const key = arg.slice(2);
|
|
18
|
+
const value = argv[index + 1];
|
|
19
|
+
if (!value || !(key in options))
|
|
20
|
+
throw new Error(`Unknown or incomplete option: ${arg}`);
|
|
21
|
+
options[key] = value;
|
|
22
|
+
index += 1;
|
|
23
|
+
}
|
|
24
|
+
return options;
|
|
25
|
+
}
|
|
26
|
+
async function walk(directory) {
|
|
27
|
+
let entries;
|
|
28
|
+
try {
|
|
29
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const files = await Promise.all(entries.map(async (entry) => {
|
|
35
|
+
const resolved = path.join(directory, entry.name);
|
|
36
|
+
return entry.isDirectory() ? walk(resolved) : [resolved];
|
|
37
|
+
}));
|
|
38
|
+
return files.flat().filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts") && !file.includes(".test."));
|
|
39
|
+
}
|
|
40
|
+
function importPath(outFile, sourceFile) {
|
|
41
|
+
let relative = path.relative(path.dirname(outFile), sourceFile).split(path.sep).join("/");
|
|
42
|
+
if (!relative.startsWith("."))
|
|
43
|
+
relative = `./${relative}`;
|
|
44
|
+
return relative.replace(/\.ts$/, ".js");
|
|
45
|
+
}
|
|
46
|
+
async function generate(options) {
|
|
47
|
+
const cwd = process.cwd();
|
|
48
|
+
const outFile = path.resolve(cwd, options.out);
|
|
49
|
+
const groups = await Promise.all([
|
|
50
|
+
["commands", options.commands],
|
|
51
|
+
["components", options.components],
|
|
52
|
+
["modals", options.modals],
|
|
53
|
+
].map(async ([name, directory]) => [
|
|
54
|
+
name,
|
|
55
|
+
(await walk(path.resolve(cwd, directory))).filter((file) => path.resolve(file) !== outFile).sort(),
|
|
56
|
+
]));
|
|
57
|
+
const imports = [];
|
|
58
|
+
const arrays = [];
|
|
59
|
+
for (const [name, files] of groups) {
|
|
60
|
+
imports.push(...files.map((file, index) => `import * as ${name}${index} from "${importPath(outFile, file)}";`));
|
|
61
|
+
arrays.push(`export const ${name} = [\n${files.map((_, index) => `\t...Object.values(${name}${index}),`).join("\n")}\n];`);
|
|
62
|
+
}
|
|
63
|
+
const output = `// Generated by mini-interactions. Run \`mini-interactions generate\` after adding modules.\nimport type { MiniBot } from "mini-interactions";\n${imports.join("\n")}\n\n${arrays.join("\n\n")}\n\nexport function registerMiniInteractions(bot: MiniBot): void {\n\tbot.modules({ commands, components, modals });\n}\n`;
|
|
64
|
+
await mkdir(path.dirname(outFile), { recursive: true });
|
|
65
|
+
await writeFile(outFile, output);
|
|
66
|
+
console.log(`[mini-interactions] generated ${path.relative(cwd, outFile)} (${groups.map(([n, f]) => `${n}=${f.length}`).join(" ")})`);
|
|
67
|
+
}
|
|
68
|
+
generate(parseArgs(process.argv.slice(2))).catch((error) => {
|
|
69
|
+
console.error(error instanceof Error ? error.message : error);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
});
|