@lunibee/builders 0.2.0 → 0.2.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/README.md +28 -21
- package/package.json +1 -1
- package/src/attachment.ts +10 -1
- package/src/commands.ts +189 -82
- package/src/components.ts +237 -81
- package/src/embed.ts +35 -14
- package/src/index.ts +103 -34
package/src/embed.ts
CHANGED
|
@@ -30,24 +30,28 @@ export interface APIEmbed {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/** Builds compile-time-safe rich embed payloads for Discord API requests. */
|
|
33
|
-
export class
|
|
33
|
+
export class CreateEmbed {
|
|
34
34
|
readonly #data: APIEmbed = {};
|
|
35
|
-
/** Sets the embed title. @param value Title text. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */ public setTitle(
|
|
36
|
-
value: string,
|
|
35
|
+
/** Sets the embed title. @param value Title text, or null to clear. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */ public setTitle(
|
|
36
|
+
value: string | null,
|
|
37
37
|
): this {
|
|
38
|
-
|
|
38
|
+
if (value === null) delete this.#data.title;
|
|
39
|
+
else this.#data.title = validate(value, 256, "Embed title");
|
|
39
40
|
return this;
|
|
40
41
|
}
|
|
41
|
-
/** Sets the embed description. @param value Description text. @returns This builder. @throws {RangeError} If description exceeds Discord's limit. */ public setDescription(
|
|
42
|
-
value: string,
|
|
42
|
+
/** Sets the embed description. @param value Description text, or null to clear. @returns This builder. @throws {RangeError} If description exceeds Discord's limit. */ public setDescription(
|
|
43
|
+
value: string | null,
|
|
43
44
|
): this {
|
|
44
|
-
|
|
45
|
+
if (value === null) delete this.#data.description;
|
|
46
|
+
else
|
|
47
|
+
this.#data.description = validate(value, 4096, "Embed description");
|
|
45
48
|
return this;
|
|
46
49
|
}
|
|
47
|
-
/** Sets the embed URL. @param value Absolute URL. @returns This builder. @throws {TypeError} If URL is invalid. */ public setURL(
|
|
48
|
-
value: string,
|
|
50
|
+
/** Sets the embed URL. @param value Absolute URL, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */ public setURL(
|
|
51
|
+
value: string | null,
|
|
49
52
|
): this {
|
|
50
|
-
|
|
53
|
+
if (value === null) delete this.#data.url;
|
|
54
|
+
else this.#data.url = url(value, "Embed URL");
|
|
51
55
|
return this;
|
|
52
56
|
}
|
|
53
57
|
/** Sets the embed color. @param value RGB integer. @returns This builder. @throws {RangeError} If color is outside 24-bit RGB range. */ public setColor(
|
|
@@ -92,16 +96,24 @@ export class EmbedBuilder {
|
|
|
92
96
|
};
|
|
93
97
|
return this;
|
|
94
98
|
}
|
|
95
|
-
/** Sets the thumbnail URL. @param value Thumbnail URL or payload. @returns This builder. @throws {TypeError} If URL is invalid. */ public setThumbnail(
|
|
96
|
-
value: { url: string } | string,
|
|
99
|
+
/** Sets the thumbnail URL. @param value Thumbnail URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */ public setThumbnail(
|
|
100
|
+
value: { url: string } | string | null,
|
|
97
101
|
): this {
|
|
102
|
+
if (value === null) {
|
|
103
|
+
delete this.#data.thumbnail;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
98
106
|
const valueURL = typeof value === "string" ? value : value.url;
|
|
99
107
|
this.#data.thumbnail = { url: url(valueURL, "Thumbnail URL") };
|
|
100
108
|
return this;
|
|
101
109
|
}
|
|
102
|
-
/** Sets the image URL. @param value Image URL or payload. @returns This builder. @throws {TypeError} If URL is invalid. */ public setImage(
|
|
103
|
-
value: { url: string } | string,
|
|
110
|
+
/** Sets the image URL. @param value Image URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */ public setImage(
|
|
111
|
+
value: { url: string } | string | null,
|
|
104
112
|
): this {
|
|
113
|
+
if (value === null) {
|
|
114
|
+
delete this.#data.image;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
105
117
|
const valueURL = typeof value === "string" ? value : value.url;
|
|
106
118
|
this.#data.image = { url: url(valueURL, "Image URL") };
|
|
107
119
|
return this;
|
|
@@ -191,3 +203,12 @@ function url(value: string, field: string): string {
|
|
|
191
203
|
throw new TypeError(`${field} must be a valid URL.`, { cause: error });
|
|
192
204
|
}
|
|
193
205
|
}
|
|
206
|
+
|
|
207
|
+
// ─── Deprecated names (0.2.2), removed in 2.0 ────────────────────────────────
|
|
208
|
+
// Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
|
|
209
|
+
// `…Type` and `…Type` became `…Enum`.
|
|
210
|
+
|
|
211
|
+
/** @deprecated Use {@link CreateEmbed}. Removed in 2.0. */
|
|
212
|
+
export const EmbedBuilder = CreateEmbed;
|
|
213
|
+
/** @deprecated Use {@link CreateEmbed}. Removed in 2.0. */
|
|
214
|
+
export type EmbedBuilder = CreateEmbed;
|
package/src/index.ts
CHANGED
|
@@ -1,45 +1,114 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CreateEmbed } from "./embed.js";
|
|
2
2
|
export type { EmbedField } from "./embed.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
CreateButton,
|
|
5
|
+
ButtonType,
|
|
6
|
+
ComponentEnum,
|
|
7
|
+
CreateActionRow,
|
|
8
|
+
CreateStringSelect,
|
|
9
|
+
CreateStringSelectMenu,
|
|
10
|
+
CreateEntitySelect,
|
|
11
|
+
CreateUserSelectMenu,
|
|
12
|
+
CreateRoleSelectMenu,
|
|
13
|
+
CreateMentionableSelectMenu,
|
|
14
|
+
CreateChannelSelectMenu,
|
|
15
|
+
CreateModal,
|
|
16
|
+
CreateTextInput,
|
|
17
|
+
TextInputType,
|
|
18
|
+
CreateContainer,
|
|
19
|
+
CreateSection,
|
|
20
|
+
CreateTextDisplay,
|
|
21
|
+
CreateMediaGallery,
|
|
22
|
+
CreateFileComponent,
|
|
23
|
+
CreateSeparator,
|
|
24
|
+
CreateThumbnail,
|
|
25
|
+
CreateContentInventoryEntry,
|
|
26
|
+
componentsV2Message,
|
|
26
27
|
} from "./components.js";
|
|
27
28
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
CreateSlashCommand,
|
|
30
|
+
CreateStringOption,
|
|
31
|
+
CreateIntegerOption,
|
|
32
|
+
CreateNumberOption,
|
|
33
|
+
CreateBooleanOption,
|
|
34
|
+
CreateUserOption,
|
|
35
|
+
CreateChannelOption,
|
|
36
|
+
CreateRoleOption,
|
|
37
|
+
CreateMentionableOption,
|
|
38
|
+
CreateAttachmentOption,
|
|
39
|
+
CreateSubcommand,
|
|
40
|
+
CreateSubcommandGroup,
|
|
41
|
+
ApplicationCommandOptionEnum,
|
|
42
|
+
CreateUserCommand,
|
|
43
|
+
CreateMessageCommand,
|
|
44
|
+
CreateContextMenuCommand,
|
|
45
|
+
} from "./commands.js";
|
|
46
|
+
export { CreateAttachment, type AttachmentData } from "./attachment.js";
|
|
47
|
+
|
|
48
|
+
// Deprecated names (0.2.2), removed in 2.0.
|
|
49
|
+
export { AttachmentBuilder } from "./attachment.js";
|
|
50
|
+
export { EmbedBuilder } from "./embed.js";
|
|
51
|
+
export {
|
|
52
|
+
AttachmentOptionBuilder,
|
|
32
53
|
BooleanOptionBuilder,
|
|
33
|
-
UserOptionBuilder,
|
|
34
54
|
ChannelOptionBuilder,
|
|
35
|
-
|
|
55
|
+
CommandOptionBuilder,
|
|
56
|
+
ContextMenuCommandBuilder,
|
|
57
|
+
IntegerOptionBuilder,
|
|
36
58
|
MentionableOptionBuilder,
|
|
37
|
-
|
|
59
|
+
MessageCommandBuilder,
|
|
60
|
+
NumberOptionBuilder,
|
|
61
|
+
RoleOptionBuilder,
|
|
62
|
+
SlashCommandBuilder,
|
|
63
|
+
StringOptionBuilder,
|
|
38
64
|
SubcommandBuilder,
|
|
39
65
|
SubcommandGroupBuilder,
|
|
40
|
-
ApplicationCommandOptionType,
|
|
41
66
|
UserCommandBuilder,
|
|
42
|
-
|
|
43
|
-
|
|
67
|
+
UserOptionBuilder,
|
|
68
|
+
ApplicationCommandOptionType,
|
|
44
69
|
} from "./commands.js";
|
|
45
|
-
export {
|
|
70
|
+
export {
|
|
71
|
+
ButtonBuilder,
|
|
72
|
+
ChannelSelectMenuBuilder,
|
|
73
|
+
ContainerBuilder,
|
|
74
|
+
ContentInventoryEntryBuilder,
|
|
75
|
+
EntitySelectBuilder,
|
|
76
|
+
FileComponentBuilder,
|
|
77
|
+
MediaGalleryBuilder,
|
|
78
|
+
MentionableSelectMenuBuilder,
|
|
79
|
+
ModalBuilder,
|
|
80
|
+
RoleSelectMenuBuilder,
|
|
81
|
+
SectionBuilder,
|
|
82
|
+
SeparatorBuilder,
|
|
83
|
+
StringSelectBuilder,
|
|
84
|
+
StringSelectMenuBuilder,
|
|
85
|
+
TextDisplayBuilder,
|
|
86
|
+
TextInputBuilder,
|
|
87
|
+
ThumbnailBuilder,
|
|
88
|
+
UserSelectMenuBuilder,
|
|
89
|
+
ActionRowBuilder,
|
|
90
|
+
ButtonStyle,
|
|
91
|
+
TextInputStyle,
|
|
92
|
+
ComponentType,
|
|
93
|
+
} from "./components.js";
|
|
94
|
+
export type {
|
|
95
|
+
APIComponent,
|
|
96
|
+
APIComponentEmoji,
|
|
97
|
+
APIActionRowChild,
|
|
98
|
+
APIActionRowComponent,
|
|
99
|
+
APIButtonComponent,
|
|
100
|
+
APISelectOption,
|
|
101
|
+
APISelectDefaultValue,
|
|
102
|
+
APIStringSelectComponent,
|
|
103
|
+
APIEntitySelectComponent,
|
|
104
|
+
APITextInputComponent,
|
|
105
|
+
APIModalComponent,
|
|
106
|
+
APIContainerComponent,
|
|
107
|
+
APISectionComponent,
|
|
108
|
+
APITextDisplayComponent,
|
|
109
|
+
APIMediaGalleryComponent,
|
|
110
|
+
APIFileComponent,
|
|
111
|
+
APISeparatorComponent,
|
|
112
|
+
APIThumbnailComponent,
|
|
113
|
+
APIContentInventoryEntryComponent,
|
|
114
|
+
} from "./components.js";
|