@minesa-org/mini-interaction 0.1.1 → 0.1.2
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/dist/builders/ModalStringSelectMenuBuilder.d.ts +7 -2
- package/dist/builders/ModalStringSelectMenuBuilder.js +24 -2
- package/dist/builders/StringSelectMenuBuilder.d.ts +3 -2
- package/dist/builders/StringSelectMenuBuilder.js +12 -2
- package/dist/builders/StringSelectMenuOptionBuilder.d.ts +46 -0
- package/dist/builders/StringSelectMenuOptionBuilder.js +106 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type APISelectMenuOption, type APIStringSelectComponent } from "discord-api-types/v10";
|
|
2
2
|
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
import type { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
3
4
|
/** Shape describing initial modal string select menu data accepted by the builder. */
|
|
4
5
|
export type ModalStringSelectMenuBuilderData = {
|
|
5
6
|
customId?: string;
|
|
@@ -44,11 +45,15 @@ export declare class ModalStringSelectMenuBuilder implements JSONEncodable<APISt
|
|
|
44
45
|
/**
|
|
45
46
|
* Adds an option to the select menu.
|
|
46
47
|
*/
|
|
47
|
-
addOption(option: APISelectMenuOption): this;
|
|
48
|
+
addOption(option: APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Appends new option entries to the select menu.
|
|
51
|
+
*/
|
|
52
|
+
addOptions(...options: (APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>)[]): this;
|
|
48
53
|
/**
|
|
49
54
|
* Replaces all options in the select menu.
|
|
50
55
|
*/
|
|
51
|
-
setOptions(options: Iterable<APISelectMenuOption
|
|
56
|
+
setOptions(options: Iterable<APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>>): this;
|
|
52
57
|
/**
|
|
53
58
|
* Serialises the builder into an API compatible string select menu payload.
|
|
54
59
|
*/
|
|
@@ -62,14 +62,36 @@ export class ModalStringSelectMenuBuilder {
|
|
|
62
62
|
* Adds an option to the select menu.
|
|
63
63
|
*/
|
|
64
64
|
addOption(option) {
|
|
65
|
-
|
|
65
|
+
if ("toJSON" in option && typeof option.toJSON === "function") {
|
|
66
|
+
this.data.options.push({ ...option.toJSON() });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.data.options.push({ ...option });
|
|
70
|
+
}
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Appends new option entries to the select menu.
|
|
75
|
+
*/
|
|
76
|
+
addOptions(...options) {
|
|
77
|
+
this.data.options.push(...options.map((option) => {
|
|
78
|
+
if ("toJSON" in option && typeof option.toJSON === "function") {
|
|
79
|
+
return { ...option.toJSON() };
|
|
80
|
+
}
|
|
81
|
+
return { ...option };
|
|
82
|
+
}));
|
|
66
83
|
return this;
|
|
67
84
|
}
|
|
68
85
|
/**
|
|
69
86
|
* Replaces all options in the select menu.
|
|
70
87
|
*/
|
|
71
88
|
setOptions(options) {
|
|
72
|
-
this.data.options = Array.from(options)
|
|
89
|
+
this.data.options = Array.from(options, (option) => {
|
|
90
|
+
if ("toJSON" in option && typeof option.toJSON === "function") {
|
|
91
|
+
return { ...option.toJSON() };
|
|
92
|
+
}
|
|
93
|
+
return { ...option };
|
|
94
|
+
});
|
|
73
95
|
return this;
|
|
74
96
|
}
|
|
75
97
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type APISelectMenuOption, type APIStringSelectComponent } from "discord-api-types/v10";
|
|
2
2
|
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
import type { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
3
4
|
/** Shape describing initial string select menu data accepted by the builder. */
|
|
4
5
|
export type StringSelectMenuBuilderData = {
|
|
5
6
|
customId?: string;
|
|
@@ -39,11 +40,11 @@ export declare class StringSelectMenuBuilder implements JSONEncodable<APIStringS
|
|
|
39
40
|
/**
|
|
40
41
|
* Appends new option entries to the select menu.
|
|
41
42
|
*/
|
|
42
|
-
addOptions(...options: APISelectMenuOption[]): this;
|
|
43
|
+
addOptions(...options: (APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>)[]): this;
|
|
43
44
|
/**
|
|
44
45
|
* Replaces the current option set with the provided iterable.
|
|
45
46
|
*/
|
|
46
|
-
setOptions(options: Iterable<APISelectMenuOption
|
|
47
|
+
setOptions(options: Iterable<APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>>): this;
|
|
47
48
|
/**
|
|
48
49
|
* Serialises the builder into an API compatible string select menu payload.
|
|
49
50
|
*/
|
|
@@ -54,14 +54,24 @@ export class StringSelectMenuBuilder {
|
|
|
54
54
|
* Appends new option entries to the select menu.
|
|
55
55
|
*/
|
|
56
56
|
addOptions(...options) {
|
|
57
|
-
this.data.options.push(...options.map((option) =>
|
|
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
|
+
}));
|
|
58
63
|
return this;
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
66
|
* Replaces the current option set with the provided iterable.
|
|
62
67
|
*/
|
|
63
68
|
setOptions(options) {
|
|
64
|
-
this.data.options = Array.from(options, (option) =>
|
|
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
|
+
});
|
|
65
75
|
return this;
|
|
66
76
|
}
|
|
67
77
|
/**
|
|
@@ -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
|
+
}
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { ButtonBuilder } from "./ButtonBuilder.js";
|
|
|
5
5
|
export type { ButtonBuilderData } from "./ButtonBuilder.js";
|
|
6
6
|
export { StringSelectMenuBuilder } from "./StringSelectMenuBuilder.js";
|
|
7
7
|
export type { StringSelectMenuBuilderData } from "./StringSelectMenuBuilder.js";
|
|
8
|
+
export { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
9
|
+
export type { StringSelectMenuOptionBuilderData } from "./StringSelectMenuOptionBuilder.js";
|
|
8
10
|
export { RoleSelectMenuBuilder } from "./RoleSelectMenuBuilder.js";
|
|
9
11
|
export type { RoleSelectMenuBuilderData } from "./RoleSelectMenuBuilder.js";
|
|
10
12
|
export { ChannelSelectMenuBuilder } from "./ChannelSelectMenuBuilder.js";
|
package/dist/builders/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export { ActionRowBuilder } from "./ActionRowBuilder.js";
|
|
3
3
|
export { ButtonBuilder } from "./ButtonBuilder.js";
|
|
4
4
|
export { StringSelectMenuBuilder } from "./StringSelectMenuBuilder.js";
|
|
5
|
+
export { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
|
|
5
6
|
export { RoleSelectMenuBuilder } from "./RoleSelectMenuBuilder.js";
|
|
6
7
|
export { ChannelSelectMenuBuilder } from "./ChannelSelectMenuBuilder.js";
|
|
7
8
|
export { ModalStringSelectMenuBuilder } from "./ModalStringSelectMenuBuilder.js";
|
package/package.json
CHANGED