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,22 @@
|
|
|
1
|
+
import type { JSONEncodable } from "./shared.js";
|
|
2
|
+
import type { ActionRowComponent, MiniActionRow } from "../types/ComponentTypes.js";
|
|
3
|
+
/** Values accepted when composing component action rows. */
|
|
4
|
+
export type ActionRowComponentLike<T extends ActionRowComponent> = JSONEncodable<T> | T;
|
|
5
|
+
/** Builder for creating Action Row components. */
|
|
6
|
+
export declare class ActionRowBuilder<T extends ActionRowComponent> implements JSONEncodable<MiniActionRow<T>> {
|
|
7
|
+
private components;
|
|
8
|
+
constructor(data?: Partial<MiniActionRow<T>>);
|
|
9
|
+
/**
|
|
10
|
+
* Adds components to this action row.
|
|
11
|
+
*
|
|
12
|
+
* @param components - The components to add (can be builders or raw objects).
|
|
13
|
+
*/
|
|
14
|
+
addComponents(...components: (T | JSONEncodable<T>)[]): this;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the components for this action row, replacing any existing ones.
|
|
17
|
+
*
|
|
18
|
+
* @param components - The new components to set.
|
|
19
|
+
*/
|
|
20
|
+
setComponents(...components: (T | JSONEncodable<T>)[]): this;
|
|
21
|
+
toJSON(): MiniActionRow<T>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ComponentType } from "discord-api-types/v10";
|
|
2
|
+
import { resolveJSONEncodable } from "./shared.js";
|
|
3
|
+
/** Builder for creating Action Row components. */
|
|
4
|
+
export class ActionRowBuilder {
|
|
5
|
+
components = [];
|
|
6
|
+
constructor(data = {}) {
|
|
7
|
+
this.components = [...(data.components ?? [])];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adds components to this action row.
|
|
11
|
+
*
|
|
12
|
+
* @param components - The components to add (can be builders or raw objects).
|
|
13
|
+
*/
|
|
14
|
+
addComponents(...components) {
|
|
15
|
+
this.components.push(...components.map((c) => resolveJSONEncodable(c)));
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sets the components for this action row, replacing any existing ones.
|
|
20
|
+
*
|
|
21
|
+
* @param components - The new components to set.
|
|
22
|
+
*/
|
|
23
|
+
setComponents(...components) {
|
|
24
|
+
this.components = components.map((c) => resolveJSONEncodable(c));
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
toJSON() {
|
|
28
|
+
return {
|
|
29
|
+
type: ComponentType.ActionRow,
|
|
30
|
+
components: [...this.components],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type APIAutoModerationAction, type APIAutoModerationRuleTriggerMetadata, AutoModerationRuleEventType, AutoModerationRuleTriggerType } from "discord-api-types/v10";
|
|
2
|
+
import type { RESTPostAPIAutoModerationRuleJSONBody } from "discord-api-types/v10";
|
|
3
|
+
import type { JSONEncodable } from "./shared.js";
|
|
4
|
+
/**
|
|
5
|
+
* Shape describing initial data used to seed the auto moderation rule builder.
|
|
6
|
+
*/
|
|
7
|
+
export type AutomodRuleBuilderData = Partial<RESTPostAPIAutoModerationRuleJSONBody> & {
|
|
8
|
+
name?: string;
|
|
9
|
+
event_type?: AutoModerationRuleEventType;
|
|
10
|
+
trigger_type?: AutoModerationRuleTriggerType;
|
|
11
|
+
actions?: APIAutoModerationAction[];
|
|
12
|
+
};
|
|
13
|
+
/** Builder that produces Discord auto moderation rule payloads. */
|
|
14
|
+
export declare class AutomodRuleBuilder implements JSONEncodable<RESTPostAPIAutoModerationRuleJSONBody> {
|
|
15
|
+
private data;
|
|
16
|
+
constructor(data?: AutomodRuleBuilderData);
|
|
17
|
+
/** Sets the name of the rule. */
|
|
18
|
+
setName(name: string): this;
|
|
19
|
+
/** Sets the event type that will trigger the rule. */
|
|
20
|
+
setEventType(eventType: AutoModerationRuleEventType): this;
|
|
21
|
+
/** Sets the trigger type for the rule. */
|
|
22
|
+
setTriggerType(triggerType: AutoModerationRuleTriggerType): this;
|
|
23
|
+
/**
|
|
24
|
+
* Assigns trigger metadata describing how the rule should match content.
|
|
25
|
+
*/
|
|
26
|
+
setTriggerMetadata(metadata: APIAutoModerationRuleTriggerMetadata | null | undefined): this;
|
|
27
|
+
/**
|
|
28
|
+
* Replaces the actions executed when the rule triggers.
|
|
29
|
+
*/
|
|
30
|
+
setActions(actions: Array<APIAutoModerationAction | JSONEncodable<APIAutoModerationAction>>): this;
|
|
31
|
+
/** Adds an action to execute when the rule triggers. */
|
|
32
|
+
addAction(action: APIAutoModerationAction | JSONEncodable<APIAutoModerationAction>): this;
|
|
33
|
+
/** Enables or disables the rule. */
|
|
34
|
+
setEnabled(enabled: boolean): this;
|
|
35
|
+
/** Replaces the list of exempt role ids. */
|
|
36
|
+
setExemptRoles(roleIds: string[]): this;
|
|
37
|
+
/** Adds an exempt role id if not already present. */
|
|
38
|
+
addExemptRole(roleId: string): this;
|
|
39
|
+
/** Replaces the list of exempt channel ids. */
|
|
40
|
+
setExemptChannels(channelIds: string[]): this;
|
|
41
|
+
/** Adds an exempt channel id if not already present. */
|
|
42
|
+
addExemptChannel(channelId: string): this;
|
|
43
|
+
/** Serialises the builder into a REST auto moderation rule payload. */
|
|
44
|
+
toJSON(): RESTPostAPIAutoModerationRuleJSONBody;
|
|
45
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { resolveJSONEncodable } from "./shared.js";
|
|
2
|
+
/** Builder that produces Discord auto moderation rule payloads. */
|
|
3
|
+
export class AutomodRuleBuilder {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data = {}) {
|
|
6
|
+
this.data = {
|
|
7
|
+
...data,
|
|
8
|
+
actions: data.actions?.map(cloneAutoModerationAction) ?? [],
|
|
9
|
+
trigger_metadata: data.trigger_metadata
|
|
10
|
+
? cloneTriggerMetadata(data.trigger_metadata)
|
|
11
|
+
: undefined,
|
|
12
|
+
exempt_roles: data.exempt_roles ? [...data.exempt_roles] : undefined,
|
|
13
|
+
exempt_channels: data.exempt_channels
|
|
14
|
+
? [...data.exempt_channels]
|
|
15
|
+
: undefined,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Sets the name of the rule. */
|
|
19
|
+
setName(name) {
|
|
20
|
+
this.data.name = name;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/** Sets the event type that will trigger the rule. */
|
|
24
|
+
setEventType(eventType) {
|
|
25
|
+
this.data.event_type = eventType;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/** Sets the trigger type for the rule. */
|
|
29
|
+
setTriggerType(triggerType) {
|
|
30
|
+
this.data.trigger_type = triggerType;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Assigns trigger metadata describing how the rule should match content.
|
|
35
|
+
*/
|
|
36
|
+
setTriggerMetadata(metadata) {
|
|
37
|
+
this.data.trigger_metadata = metadata
|
|
38
|
+
? cloneTriggerMetadata(metadata)
|
|
39
|
+
: undefined;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Replaces the actions executed when the rule triggers.
|
|
44
|
+
*/
|
|
45
|
+
setActions(actions) {
|
|
46
|
+
this.data.actions = actions.map((action) => cloneAutoModerationAction(resolveJSONEncodable(action)));
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/** Adds an action to execute when the rule triggers. */
|
|
50
|
+
addAction(action) {
|
|
51
|
+
if (!this.data.actions) {
|
|
52
|
+
this.data.actions = [];
|
|
53
|
+
}
|
|
54
|
+
this.data.actions.push(cloneAutoModerationAction(resolveJSONEncodable(action)));
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/** Enables or disables the rule. */
|
|
58
|
+
setEnabled(enabled) {
|
|
59
|
+
this.data.enabled = enabled;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/** Replaces the list of exempt role ids. */
|
|
63
|
+
setExemptRoles(roleIds) {
|
|
64
|
+
this.data.exempt_roles = [...roleIds];
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/** Adds an exempt role id if not already present. */
|
|
68
|
+
addExemptRole(roleId) {
|
|
69
|
+
if (!this.data.exempt_roles) {
|
|
70
|
+
this.data.exempt_roles = [];
|
|
71
|
+
}
|
|
72
|
+
if (!this.data.exempt_roles.includes(roleId)) {
|
|
73
|
+
this.data.exempt_roles.push(roleId);
|
|
74
|
+
}
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/** Replaces the list of exempt channel ids. */
|
|
78
|
+
setExemptChannels(channelIds) {
|
|
79
|
+
this.data.exempt_channels = [...channelIds];
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/** Adds an exempt channel id if not already present. */
|
|
83
|
+
addExemptChannel(channelId) {
|
|
84
|
+
if (!this.data.exempt_channels) {
|
|
85
|
+
this.data.exempt_channels = [];
|
|
86
|
+
}
|
|
87
|
+
if (!this.data.exempt_channels.includes(channelId)) {
|
|
88
|
+
this.data.exempt_channels.push(channelId);
|
|
89
|
+
}
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/** Serialises the builder into a REST auto moderation rule payload. */
|
|
93
|
+
toJSON() {
|
|
94
|
+
const { name, event_type, trigger_type } = this.data;
|
|
95
|
+
const actions = this.data.actions ?? [];
|
|
96
|
+
if (!name) {
|
|
97
|
+
throw new Error("[AutomodRuleBuilder] name is required");
|
|
98
|
+
}
|
|
99
|
+
if (event_type === undefined) {
|
|
100
|
+
throw new Error("[AutomodRuleBuilder] event type is required");
|
|
101
|
+
}
|
|
102
|
+
if (trigger_type === undefined) {
|
|
103
|
+
throw new Error("[AutomodRuleBuilder] trigger type is required");
|
|
104
|
+
}
|
|
105
|
+
if (actions.length === 0) {
|
|
106
|
+
throw new Error("[AutomodRuleBuilder] at least one action is required");
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
name,
|
|
110
|
+
event_type,
|
|
111
|
+
trigger_type,
|
|
112
|
+
trigger_metadata: this.data.trigger_metadata
|
|
113
|
+
? cloneTriggerMetadata(this.data.trigger_metadata)
|
|
114
|
+
: undefined,
|
|
115
|
+
actions: actions.map(cloneAutoModerationAction),
|
|
116
|
+
enabled: this.data.enabled,
|
|
117
|
+
exempt_roles: this.data.exempt_roles
|
|
118
|
+
? [...this.data.exempt_roles]
|
|
119
|
+
: undefined,
|
|
120
|
+
exempt_channels: this.data.exempt_channels
|
|
121
|
+
? [...this.data.exempt_channels]
|
|
122
|
+
: undefined,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function cloneTriggerMetadata(metadata) {
|
|
127
|
+
return {
|
|
128
|
+
keyword_filter: metadata.keyword_filter
|
|
129
|
+
? [...metadata.keyword_filter]
|
|
130
|
+
: undefined,
|
|
131
|
+
presets: metadata.presets ? [...metadata.presets] : undefined,
|
|
132
|
+
allow_list: metadata.allow_list ? [...metadata.allow_list] : undefined,
|
|
133
|
+
regex_patterns: metadata.regex_patterns
|
|
134
|
+
? [...metadata.regex_patterns]
|
|
135
|
+
: undefined,
|
|
136
|
+
mention_total_limit: metadata.mention_total_limit,
|
|
137
|
+
mention_raid_protection_enabled: metadata.mention_raid_protection_enabled,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function cloneAutoModerationAction(action) {
|
|
141
|
+
return {
|
|
142
|
+
type: action.type,
|
|
143
|
+
metadata: action.metadata
|
|
144
|
+
? {
|
|
145
|
+
channel_id: action.metadata.channel_id,
|
|
146
|
+
duration_seconds: action.metadata.duration_seconds,
|
|
147
|
+
custom_message: action.metadata.custom_message,
|
|
148
|
+
}
|
|
149
|
+
: undefined,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type APIButtonComponent, type APIMessageComponentEmoji } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
import { ButtonStyle } from "../types/ButtonStyle.js";
|
|
4
|
+
/** Shape describing initial button data accepted by the builder. */
|
|
5
|
+
export type ButtonBuilderData = {
|
|
6
|
+
style?: ButtonStyle;
|
|
7
|
+
label?: string;
|
|
8
|
+
emoji?: APIMessageComponentEmoji;
|
|
9
|
+
customId?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
skuId?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Builder for Discord button components. */
|
|
15
|
+
export declare class ButtonBuilder implements JSONEncodable<APIButtonComponent> {
|
|
16
|
+
private data;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new button builder with optional seed data.
|
|
19
|
+
*/
|
|
20
|
+
constructor(data?: ButtonBuilderData);
|
|
21
|
+
/**
|
|
22
|
+
* Sets the visual style of the button.
|
|
23
|
+
*/
|
|
24
|
+
setStyle(style: ButtonStyle): this;
|
|
25
|
+
/**
|
|
26
|
+
* Sets or clears the button label text.
|
|
27
|
+
*/
|
|
28
|
+
setLabel(label: string | null | undefined): this;
|
|
29
|
+
/**
|
|
30
|
+
* Sets or clears the emoji displayed on the button.
|
|
31
|
+
*/
|
|
32
|
+
setEmoji(emoji: APIMessageComponentEmoji | null | undefined): this;
|
|
33
|
+
/**
|
|
34
|
+
* Configures the button as an interaction component with the provided custom identifier.
|
|
35
|
+
*/
|
|
36
|
+
setCustomId(customId: string): this;
|
|
37
|
+
/**
|
|
38
|
+
* Configures the button as a link button.
|
|
39
|
+
*/
|
|
40
|
+
setURL(url: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Configures the button as a premium purchase button.
|
|
43
|
+
*/
|
|
44
|
+
setSKUId(skuId: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* Toggles whether the button is disabled.
|
|
47
|
+
*/
|
|
48
|
+
setDisabled(disabled: boolean): this;
|
|
49
|
+
/**
|
|
50
|
+
* Serialises the builder into an API compatible button payload.
|
|
51
|
+
*/
|
|
52
|
+
toJSON(): APIButtonComponent;
|
|
53
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ComponentType, } from "discord-api-types/v10";
|
|
2
|
+
import { ButtonStyle } from "../types/ButtonStyle.js";
|
|
3
|
+
/** Builder for Discord button components. */
|
|
4
|
+
export class ButtonBuilder {
|
|
5
|
+
data;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new button builder with optional seed data.
|
|
8
|
+
*/
|
|
9
|
+
constructor(data = {}) {
|
|
10
|
+
this.data = {
|
|
11
|
+
style: data.style ?? ButtonStyle.Secondary,
|
|
12
|
+
label: data.label,
|
|
13
|
+
emoji: data.emoji ? { ...data.emoji } : undefined,
|
|
14
|
+
customId: data.customId,
|
|
15
|
+
url: data.url,
|
|
16
|
+
disabled: data.disabled,
|
|
17
|
+
skuId: data.skuId,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets the visual style of the button.
|
|
22
|
+
*/
|
|
23
|
+
setStyle(style) {
|
|
24
|
+
this.data.style = style;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sets or clears the button label text.
|
|
29
|
+
*/
|
|
30
|
+
setLabel(label) {
|
|
31
|
+
this.data.label = label ?? undefined;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets or clears the emoji displayed on the button.
|
|
36
|
+
*/
|
|
37
|
+
setEmoji(emoji) {
|
|
38
|
+
this.data.emoji = emoji ? { ...emoji } : undefined;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configures the button as an interaction component with the provided custom identifier.
|
|
43
|
+
*/
|
|
44
|
+
setCustomId(customId) {
|
|
45
|
+
this.data.customId = customId;
|
|
46
|
+
if (this.data.style === ButtonStyle.Link) {
|
|
47
|
+
this.data.style = ButtonStyle.Secondary;
|
|
48
|
+
}
|
|
49
|
+
this.data.url = undefined;
|
|
50
|
+
this.data.skuId = undefined;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Configures the button as a link button.
|
|
55
|
+
*/
|
|
56
|
+
setURL(url) {
|
|
57
|
+
this.data.url = url;
|
|
58
|
+
this.data.customId = undefined;
|
|
59
|
+
this.data.skuId = undefined;
|
|
60
|
+
this.data.style = ButtonStyle.Link;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Configures the button as a premium purchase button.
|
|
65
|
+
*/
|
|
66
|
+
setSKUId(skuId) {
|
|
67
|
+
this.data.skuId = skuId;
|
|
68
|
+
this.data.customId = undefined;
|
|
69
|
+
this.data.url = undefined;
|
|
70
|
+
this.data.style = ButtonStyle.Premium;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Toggles whether the button is disabled.
|
|
75
|
+
*/
|
|
76
|
+
setDisabled(disabled) {
|
|
77
|
+
this.data.disabled = disabled;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serialises the builder into an API compatible button payload.
|
|
82
|
+
*/
|
|
83
|
+
toJSON() {
|
|
84
|
+
const { style, label, emoji, disabled } = this.data;
|
|
85
|
+
if (style === ButtonStyle.Link) {
|
|
86
|
+
const url = this.data.url;
|
|
87
|
+
if (!url) {
|
|
88
|
+
throw new Error("[ButtonBuilder] Link buttons must have a URL.");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
type: ComponentType.Button,
|
|
92
|
+
style,
|
|
93
|
+
label,
|
|
94
|
+
emoji: emoji ? { ...emoji } : undefined,
|
|
95
|
+
disabled,
|
|
96
|
+
url,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (style === ButtonStyle.Premium) {
|
|
100
|
+
const skuId = this.data.skuId;
|
|
101
|
+
if (!skuId) {
|
|
102
|
+
throw new Error("[ButtonBuilder] Premium buttons must have an SKU id.");
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
type: ComponentType.Button,
|
|
106
|
+
style,
|
|
107
|
+
disabled,
|
|
108
|
+
sku_id: skuId,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const customId = this.data.customId;
|
|
112
|
+
if (!customId) {
|
|
113
|
+
throw new Error("[ButtonBuilder] Non-link buttons must have a custom id.");
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type: ComponentType.Button,
|
|
117
|
+
style,
|
|
118
|
+
label,
|
|
119
|
+
emoji: emoji ? { ...emoji } : undefined,
|
|
120
|
+
disabled,
|
|
121
|
+
custom_id: customId,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SelectMenuDefaultValueType, type APIChannelSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
|
|
2
|
+
import { ChannelType } from "../types/ChannelType.js";
|
|
3
|
+
import type { JSONEncodable } from "./shared.js";
|
|
4
|
+
/** Shape describing initial channel select menu data accepted by the builder. */
|
|
5
|
+
export type ChannelSelectMenuBuilderData = {
|
|
6
|
+
customId?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
minValues?: number;
|
|
9
|
+
maxValues?: number;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
channelTypes?: ChannelType[];
|
|
12
|
+
defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>[];
|
|
13
|
+
};
|
|
14
|
+
/** Builder for Discord channel select menu components. */
|
|
15
|
+
export declare class ChannelSelectMenuBuilder implements JSONEncodable<APIChannelSelectComponent> {
|
|
16
|
+
private data;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new channel select menu builder with optional seed data.
|
|
19
|
+
*/
|
|
20
|
+
constructor(data?: ChannelSelectMenuBuilderData);
|
|
21
|
+
/**
|
|
22
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
23
|
+
*/
|
|
24
|
+
setCustomId(customId: string): this;
|
|
25
|
+
/**
|
|
26
|
+
* Sets or clears the placeholder text displayed when no channel is selected.
|
|
27
|
+
*/
|
|
28
|
+
setPlaceholder(placeholder: string | null | undefined): this;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the minimum number of channels that must be selected.
|
|
31
|
+
*/
|
|
32
|
+
setMinValues(minValues: number | null | undefined): this;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the maximum number of channels that can be selected.
|
|
35
|
+
*/
|
|
36
|
+
setMaxValues(maxValues: number | null | undefined): this;
|
|
37
|
+
/**
|
|
38
|
+
* Toggles whether the select menu is disabled.
|
|
39
|
+
*/
|
|
40
|
+
setDisabled(disabled: boolean): this;
|
|
41
|
+
/**
|
|
42
|
+
* Filters selectable channels by the provided channel types.
|
|
43
|
+
*/
|
|
44
|
+
setChannelTypes(channelTypes: Iterable<ChannelType>): this;
|
|
45
|
+
/**
|
|
46
|
+
* Replaces the default channel selections displayed when the menu renders.
|
|
47
|
+
*/
|
|
48
|
+
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Serialises the builder into an API compatible channel select menu payload.
|
|
51
|
+
*/
|
|
52
|
+
toJSON(): APIChannelSelectComponent;
|
|
53
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ComponentType, SelectMenuDefaultValueType, } from "discord-api-types/v10";
|
|
2
|
+
/** Builder for Discord channel select menu components. */
|
|
3
|
+
export class ChannelSelectMenuBuilder {
|
|
4
|
+
data;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new channel select menu builder with optional seed data.
|
|
7
|
+
*/
|
|
8
|
+
constructor(data = {}) {
|
|
9
|
+
this.data = {
|
|
10
|
+
customId: data.customId,
|
|
11
|
+
placeholder: data.placeholder,
|
|
12
|
+
minValues: data.minValues,
|
|
13
|
+
maxValues: data.maxValues,
|
|
14
|
+
disabled: data.disabled,
|
|
15
|
+
channelTypes: data.channelTypes
|
|
16
|
+
? [...data.channelTypes]
|
|
17
|
+
: undefined,
|
|
18
|
+
defaultValues: data.defaultValues
|
|
19
|
+
? data.defaultValues.map((value) => ({
|
|
20
|
+
...value,
|
|
21
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
22
|
+
}))
|
|
23
|
+
: undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
28
|
+
*/
|
|
29
|
+
setCustomId(customId) {
|
|
30
|
+
this.data.customId = customId;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets or clears the placeholder text displayed when no channel is selected.
|
|
35
|
+
*/
|
|
36
|
+
setPlaceholder(placeholder) {
|
|
37
|
+
this.data.placeholder = placeholder ?? undefined;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the minimum number of channels that must be selected.
|
|
42
|
+
*/
|
|
43
|
+
setMinValues(minValues) {
|
|
44
|
+
this.data.minValues = minValues ?? undefined;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the maximum number of channels that can be selected.
|
|
49
|
+
*/
|
|
50
|
+
setMaxValues(maxValues) {
|
|
51
|
+
this.data.maxValues = maxValues ?? undefined;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Toggles whether the select menu is disabled.
|
|
56
|
+
*/
|
|
57
|
+
setDisabled(disabled) {
|
|
58
|
+
this.data.disabled = disabled;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Filters selectable channels by the provided channel types.
|
|
63
|
+
*/
|
|
64
|
+
setChannelTypes(channelTypes) {
|
|
65
|
+
this.data.channelTypes = Array.from(channelTypes);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Replaces the default channel selections displayed when the menu renders.
|
|
70
|
+
*/
|
|
71
|
+
setDefaultValues(defaultValues) {
|
|
72
|
+
this.data.defaultValues = Array.from(defaultValues, (value) => ({
|
|
73
|
+
...value,
|
|
74
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
75
|
+
}));
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Serialises the builder into an API compatible channel select menu payload.
|
|
80
|
+
*/
|
|
81
|
+
toJSON() {
|
|
82
|
+
const { customId } = this.data;
|
|
83
|
+
if (!customId) {
|
|
84
|
+
throw new Error("[ChannelSelectMenuBuilder] custom id is required.");
|
|
85
|
+
}
|
|
86
|
+
if (this.data.placeholder && this.data.placeholder.length > 150) {
|
|
87
|
+
throw new Error("[ChannelSelectMenuBuilder] placeholder must be 150 characters or less.");
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: ComponentType.ChannelSelect,
|
|
91
|
+
custom_id: customId,
|
|
92
|
+
placeholder: this.data.placeholder,
|
|
93
|
+
min_values: this.data.minValues,
|
|
94
|
+
max_values: this.data.maxValues,
|
|
95
|
+
disabled: this.data.disabled,
|
|
96
|
+
channel_types: this.data.channelTypes
|
|
97
|
+
? [...this.data.channelTypes]
|
|
98
|
+
: undefined,
|
|
99
|
+
default_values: this.data.defaultValues?.map((value) => ({
|
|
100
|
+
...value,
|
|
101
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
102
|
+
})),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JSONEncodable } from './shared.js';
|
|
2
|
+
import { APICheckboxComponent } from '../types/checkbox.js';
|
|
3
|
+
export type CheckboxBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
default?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Builder for Discord's modal-only single Checkbox component (type 23).
|
|
9
|
+
* A single checkbox holds no options; use {@link CheckboxGroupBuilder} for
|
|
10
|
+
* multi-option checkbox groups.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox}
|
|
13
|
+
*/
|
|
14
|
+
export declare class CheckboxBuilder implements JSONEncodable<APICheckboxComponent> {
|
|
15
|
+
private readonly data;
|
|
16
|
+
constructor(data?: CheckboxBuilderData);
|
|
17
|
+
setCustomId(customId: string): this;
|
|
18
|
+
setDefault(isDefault: boolean): this;
|
|
19
|
+
toJSON(): APICheckboxComponent;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CHECKBOX_COMPONENT_TYPE } from '../types/checkbox.js';
|
|
2
|
+
import { assertDefined, assertStringLength } from '../types/validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builder for Discord's modal-only single Checkbox component (type 23).
|
|
5
|
+
* A single checkbox holds no options; use {@link CheckboxGroupBuilder} for
|
|
6
|
+
* multi-option checkbox groups.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox}
|
|
9
|
+
*/
|
|
10
|
+
export class CheckboxBuilder {
|
|
11
|
+
data;
|
|
12
|
+
constructor(data = {}) { this.data = { ...data }; }
|
|
13
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
14
|
+
setDefault(isDefault) { this.data.default = isDefault; return this; }
|
|
15
|
+
toJSON() {
|
|
16
|
+
const customId = assertDefined('CheckboxBuilder', 'custom_id', this.data.customId);
|
|
17
|
+
assertStringLength('CheckboxBuilder', 'custom_id', customId, 1, 100);
|
|
18
|
+
return { type: CHECKBOX_COMPONENT_TYPE, custom_id: customId, default: this.data.default };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JSONEncodable } from './shared.js';
|
|
2
|
+
import type { APICheckboxGroupComponent, APICheckboxGroupOption } from '../types/checkbox.js';
|
|
3
|
+
export type CheckboxGroupBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
minValues?: number;
|
|
6
|
+
maxValues?: number;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
options?: APICheckboxGroupOption[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builder for Discord's modal-only CheckboxGroup component (type 22).
|
|
12
|
+
* Groups hold up to 10 options and support multiple pre-selected defaults.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://discord.com/developers/docs/components/reference#checkbox-group}
|
|
15
|
+
*/
|
|
16
|
+
export declare class CheckboxGroupBuilder implements JSONEncodable<APICheckboxGroupComponent> {
|
|
17
|
+
private readonly data;
|
|
18
|
+
constructor(data?: CheckboxGroupBuilderData);
|
|
19
|
+
setCustomId(customId: string): this;
|
|
20
|
+
setRequired(required: boolean): this;
|
|
21
|
+
setMinValues(minValues: number): this;
|
|
22
|
+
setMaxValues(maxValues: number): this;
|
|
23
|
+
addOptions(...options: APICheckboxGroupOption[]): this;
|
|
24
|
+
toJSON(): APICheckboxGroupComponent;
|
|
25
|
+
}
|