@discordjs/builders 0.15.0-dev.1654430642-7a1095b → 0.15.0-dev.1654517016-e1176fa
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/index.d.ts +15 -12
- package/dist/index.js +33 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,9 @@ declare namespace Assertions$5 {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
declare function normalizeArray<T>(arr: RestOrArray<T>): T[];
|
|
82
|
+
declare type RestOrArray<T> = T[] | [T[]];
|
|
83
|
+
|
|
81
84
|
declare type RGBTuple = [red: number, green: number, blue: number];
|
|
82
85
|
interface IconData {
|
|
83
86
|
/**
|
|
@@ -110,7 +113,7 @@ declare class UnsafeEmbedBuilder {
|
|
|
110
113
|
*
|
|
111
114
|
* @param fields The fields to add
|
|
112
115
|
*/
|
|
113
|
-
addFields(fields: APIEmbedField
|
|
116
|
+
addFields(...fields: RestOrArray<APIEmbedField>): this;
|
|
114
117
|
/**
|
|
115
118
|
* Removes, replaces, or inserts fields in the embed (max 25)
|
|
116
119
|
*
|
|
@@ -123,7 +126,7 @@ declare class UnsafeEmbedBuilder {
|
|
|
123
126
|
* Sets the embed's fields (max 25).
|
|
124
127
|
* @param fields The fields to set
|
|
125
128
|
*/
|
|
126
|
-
setFields(fields: APIEmbedField
|
|
129
|
+
setFields(...fields: RestOrArray<APIEmbedField>): this;
|
|
127
130
|
/**
|
|
128
131
|
* Sets the author of this embed
|
|
129
132
|
*
|
|
@@ -188,7 +191,7 @@ declare class UnsafeEmbedBuilder {
|
|
|
188
191
|
* Represents a validated embed in a message (image/video preview, rich embed, etc.)
|
|
189
192
|
*/
|
|
190
193
|
declare class EmbedBuilder extends UnsafeEmbedBuilder {
|
|
191
|
-
addFields(fields: APIEmbedField
|
|
194
|
+
addFields(...fields: RestOrArray<APIEmbedField>): this;
|
|
192
195
|
spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this;
|
|
193
196
|
setAuthor(options: EmbedAuthorOptions | null): this;
|
|
194
197
|
setColor(color: number | RGBTuple | null): this;
|
|
@@ -584,12 +587,12 @@ declare class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentB
|
|
|
584
587
|
* @param components The components to add to this action row.
|
|
585
588
|
* @returns
|
|
586
589
|
*/
|
|
587
|
-
addComponents(components: T
|
|
590
|
+
addComponents(...components: RestOrArray<T>): this;
|
|
588
591
|
/**
|
|
589
592
|
* Sets the components in this action row
|
|
590
593
|
* @param components The components to set this row to
|
|
591
594
|
*/
|
|
592
|
-
setComponents(components: T
|
|
595
|
+
setComponents(...components: RestOrArray<T>): this;
|
|
593
596
|
toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>>;
|
|
594
597
|
}
|
|
595
598
|
|
|
@@ -763,12 +766,12 @@ declare class UnsafeModalBuilder implements JSONEncodable<APIModalInteractionRes
|
|
|
763
766
|
* Adds components to this modal
|
|
764
767
|
* @param components The components to add to this modal
|
|
765
768
|
*/
|
|
766
|
-
addComponents(components:
|
|
769
|
+
addComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder> | APIActionRowComponent<APIModalActionRowComponent>>): this;
|
|
767
770
|
/**
|
|
768
771
|
* Sets the components in this modal
|
|
769
772
|
* @param components The components to set this modal to
|
|
770
773
|
*/
|
|
771
|
-
setComponents(components: ActionRowBuilder<ModalActionRowComponentBuilder
|
|
774
|
+
setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>): this;
|
|
772
775
|
toJSON(): APIModalInteractionResponseCallbackData;
|
|
773
776
|
}
|
|
774
777
|
|
|
@@ -831,12 +834,12 @@ declare class UnsafeSelectMenuBuilder extends ComponentBuilder<APISelectMenuComp
|
|
|
831
834
|
* @param options The options to add to this select menu
|
|
832
835
|
* @returns
|
|
833
836
|
*/
|
|
834
|
-
addOptions(options:
|
|
837
|
+
addOptions(...options: RestOrArray<UnsafeSelectMenuOptionBuilder | APISelectMenuOption>): this;
|
|
835
838
|
/**
|
|
836
839
|
* Sets the options on this select menu
|
|
837
840
|
* @param options The options to set on this select menu
|
|
838
841
|
*/
|
|
839
|
-
setOptions(options:
|
|
842
|
+
setOptions(...options: RestOrArray<UnsafeSelectMenuOptionBuilder | APISelectMenuOption>): this;
|
|
840
843
|
toJSON(): APISelectMenuComponent;
|
|
841
844
|
}
|
|
842
845
|
|
|
@@ -849,8 +852,8 @@ declare class SelectMenuBuilder extends UnsafeSelectMenuBuilder {
|
|
|
849
852
|
setMaxValues(maxValues: number): this;
|
|
850
853
|
setCustomId(customId: string): this;
|
|
851
854
|
setDisabled(disabled?: boolean): this;
|
|
852
|
-
addOptions(options:
|
|
853
|
-
setOptions(options:
|
|
855
|
+
addOptions(...options: RestOrArray<UnsafeSelectMenuOptionBuilder | APISelectMenuOption>): this;
|
|
856
|
+
setOptions(...options: RestOrArray<UnsafeSelectMenuOptionBuilder | APISelectMenuOption>): this;
|
|
854
857
|
toJSON(): APISelectMenuComponent;
|
|
855
858
|
}
|
|
856
859
|
|
|
@@ -1422,4 +1425,4 @@ declare function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatab
|
|
|
1422
1425
|
|
|
1423
1426
|
declare function embedLength(data: APIEmbed): number;
|
|
1424
1427
|
|
|
1425
|
-
export { ActionRowBuilder, AnyAPIActionRowComponent, AnyComponentBuilder, ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionAllowedChannelTypes, ApplicationCommandOptionBase, ApplicationCommandOptionChannelTypesMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin, ButtonBuilder, Assertions$4 as ComponentAssertions, ComponentBuilder, Assertions as ContextMenuCommandAssertions, ContextMenuCommandBuilder, ContextMenuCommandType, Assertions$5 as EmbedAssertions, EmbedAuthorData, EmbedAuthorOptions, EmbedBuilder, EmbedFooterData, EmbedFooterOptions, EmbedImageData, Equatable, Faces, IconData, JSONEncodable, MappedComponentTypes, MessageActionRowComponentBuilder, MessageComponentBuilder, ModalActionRowComponentBuilder, Assertions$2 as ModalAssertions, ModalBuilder, ModalComponentBuilder, RGBTuple, SelectMenuBuilder, SelectMenuOptionBuilder, SharedNameAndDescription, SharedSlashCommandOptions, Assertions$1 as SlashCommandAssertions, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandOptionsOnlyBuilder, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandUserOption, Assertions$3 as TextInputAssertions, TextInputBuilder, TimestampStyles, TimestampStylesString, ToAPIApplicationCommandOptions, UnsafeButtonBuilder, UnsafeEmbedBuilder, UnsafeModalBuilder, UnsafeSelectMenuBuilder, UnsafeSelectMenuOptionBuilder, UnsafeTextInputBuilder, blockQuote, bold, channelMention, codeBlock, createComponentBuilder, embedLength, formatEmoji, hideLinkEmbed, hyperlink, inlineCode, isEquatable, isJSONEncodable, italic, quote, roleMention, spoiler, strikethrough, time, underscore, userMention };
|
|
1428
|
+
export { ActionRowBuilder, AnyAPIActionRowComponent, AnyComponentBuilder, ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionAllowedChannelTypes, ApplicationCommandOptionBase, ApplicationCommandOptionChannelTypesMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin, ButtonBuilder, Assertions$4 as ComponentAssertions, ComponentBuilder, Assertions as ContextMenuCommandAssertions, ContextMenuCommandBuilder, ContextMenuCommandType, Assertions$5 as EmbedAssertions, EmbedAuthorData, EmbedAuthorOptions, EmbedBuilder, EmbedFooterData, EmbedFooterOptions, EmbedImageData, Equatable, Faces, IconData, JSONEncodable, MappedComponentTypes, MessageActionRowComponentBuilder, MessageComponentBuilder, ModalActionRowComponentBuilder, Assertions$2 as ModalAssertions, ModalBuilder, ModalComponentBuilder, RGBTuple, RestOrArray, SelectMenuBuilder, SelectMenuOptionBuilder, SharedNameAndDescription, SharedSlashCommandOptions, Assertions$1 as SlashCommandAssertions, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandOptionsOnlyBuilder, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandUserOption, Assertions$3 as TextInputAssertions, TextInputBuilder, TimestampStyles, TimestampStylesString, ToAPIApplicationCommandOptions, UnsafeButtonBuilder, UnsafeEmbedBuilder, UnsafeModalBuilder, UnsafeSelectMenuBuilder, UnsafeSelectMenuOptionBuilder, UnsafeTextInputBuilder, blockQuote, bold, channelMention, codeBlock, createComponentBuilder, embedLength, formatEmoji, hideLinkEmbed, hyperlink, inlineCode, isEquatable, isJSONEncodable, italic, normalizeArray, quote, roleMention, spoiler, strikethrough, time, underscore, userMention };
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ __export(src_exports, {
|
|
|
92
92
|
isEquatable: () => isEquatable,
|
|
93
93
|
isJSONEncodable: () => isJSONEncodable,
|
|
94
94
|
italic: () => italic,
|
|
95
|
+
normalizeArray: () => normalizeArray,
|
|
95
96
|
quote: () => quote,
|
|
96
97
|
roleMention: () => roleMention,
|
|
97
98
|
spoiler: () => spoiler,
|
|
@@ -162,6 +163,14 @@ var embedFooterPredicate = import_shapeshift.s.object({
|
|
|
162
163
|
var timestampPredicate = import_shapeshift.s.union(import_shapeshift.s.number, import_shapeshift.s.date).nullable;
|
|
163
164
|
var titlePredicate = fieldNamePredicate.nullable;
|
|
164
165
|
|
|
166
|
+
// src/util/normalizeArray.ts
|
|
167
|
+
function normalizeArray(arr) {
|
|
168
|
+
if (Array.isArray(arr[0]))
|
|
169
|
+
return arr[0];
|
|
170
|
+
return arr;
|
|
171
|
+
}
|
|
172
|
+
__name(normalizeArray, "normalizeArray");
|
|
173
|
+
|
|
165
174
|
// src/messages/embed/UnsafeEmbed.ts
|
|
166
175
|
var UnsafeEmbedBuilder = class {
|
|
167
176
|
constructor(data = {}) {
|
|
@@ -170,7 +179,8 @@ var UnsafeEmbedBuilder = class {
|
|
|
170
179
|
if (data.timestamp)
|
|
171
180
|
this.data.timestamp = new Date(data.timestamp).toISOString();
|
|
172
181
|
}
|
|
173
|
-
addFields(fields) {
|
|
182
|
+
addFields(...fields) {
|
|
183
|
+
fields = normalizeArray(fields);
|
|
174
184
|
if (this.data.fields)
|
|
175
185
|
this.data.fields.push(...fields);
|
|
176
186
|
else
|
|
@@ -184,8 +194,8 @@ var UnsafeEmbedBuilder = class {
|
|
|
184
194
|
this.data.fields = fields;
|
|
185
195
|
return this;
|
|
186
196
|
}
|
|
187
|
-
setFields(fields) {
|
|
188
|
-
this.spliceFields(0, this.data.fields?.length ?? 0, ...fields);
|
|
197
|
+
setFields(...fields) {
|
|
198
|
+
this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));
|
|
189
199
|
return this;
|
|
190
200
|
}
|
|
191
201
|
setAuthor(options) {
|
|
@@ -245,9 +255,10 @@ __name(UnsafeEmbedBuilder, "UnsafeEmbedBuilder");
|
|
|
245
255
|
|
|
246
256
|
// src/messages/embed/Embed.ts
|
|
247
257
|
var EmbedBuilder = class extends UnsafeEmbedBuilder {
|
|
248
|
-
addFields(fields) {
|
|
258
|
+
addFields(...fields) {
|
|
259
|
+
fields = normalizeArray(fields);
|
|
249
260
|
validateFieldLength(fields.length, this.data.fields);
|
|
250
|
-
return super.addFields(embedFieldsArrayPredicate.parse(fields));
|
|
261
|
+
return super.addFields(...embedFieldsArrayPredicate.parse(fields));
|
|
251
262
|
}
|
|
252
263
|
spliceFields(index, deleteCount, ...fields) {
|
|
253
264
|
validateFieldLength(fields.length - deleteCount, this.data.fields);
|
|
@@ -528,12 +539,12 @@ var ActionRowBuilder = class extends ComponentBuilder {
|
|
|
528
539
|
__publicField(this, "components");
|
|
529
540
|
this.components = components?.map((c) => createComponentBuilder(c)) ?? [];
|
|
530
541
|
}
|
|
531
|
-
addComponents(components) {
|
|
532
|
-
this.components.push(...components);
|
|
542
|
+
addComponents(...components) {
|
|
543
|
+
this.components.push(...normalizeArray(components));
|
|
533
544
|
return this;
|
|
534
545
|
}
|
|
535
|
-
setComponents(components) {
|
|
536
|
-
this.components.splice(0, this.components.length, ...components);
|
|
546
|
+
setComponents(...components) {
|
|
547
|
+
this.components.splice(0, this.components.length, ...normalizeArray(components));
|
|
537
548
|
return this;
|
|
538
549
|
}
|
|
539
550
|
toJSON() {
|
|
@@ -731,12 +742,12 @@ var UnsafeModalBuilder = class {
|
|
|
731
742
|
this.data.custom_id = customId;
|
|
732
743
|
return this;
|
|
733
744
|
}
|
|
734
|
-
addComponents(components) {
|
|
735
|
-
this.components.push(...components.map((component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component)));
|
|
745
|
+
addComponents(...components) {
|
|
746
|
+
this.components.push(...normalizeArray(components).map((component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component)));
|
|
736
747
|
return this;
|
|
737
748
|
}
|
|
738
|
-
setComponents(components) {
|
|
739
|
-
this.components.splice(0, this.components.length, ...components);
|
|
749
|
+
setComponents(...components) {
|
|
750
|
+
this.components.splice(0, this.components.length, ...normalizeArray(components));
|
|
740
751
|
return this;
|
|
741
752
|
}
|
|
742
753
|
toJSON() {
|
|
@@ -809,12 +820,12 @@ var UnsafeSelectMenuBuilder = class extends ComponentBuilder {
|
|
|
809
820
|
this.data.disabled = disabled;
|
|
810
821
|
return this;
|
|
811
822
|
}
|
|
812
|
-
addOptions(options) {
|
|
813
|
-
this.options.push(...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
823
|
+
addOptions(...options) {
|
|
824
|
+
this.options.push(...normalizeArray(options).map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
814
825
|
return this;
|
|
815
826
|
}
|
|
816
|
-
setOptions(options) {
|
|
817
|
-
this.options.splice(0, this.options.length, ...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
827
|
+
setOptions(...options) {
|
|
828
|
+
this.options.splice(0, this.options.length, ...normalizeArray(options).map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
818
829
|
return this;
|
|
819
830
|
}
|
|
820
831
|
toJSON() {
|
|
@@ -843,12 +854,14 @@ var SelectMenuBuilder = class extends UnsafeSelectMenuBuilder {
|
|
|
843
854
|
setDisabled(disabled = true) {
|
|
844
855
|
return super.setDisabled(disabledValidator.parse(disabled));
|
|
845
856
|
}
|
|
846
|
-
addOptions(options) {
|
|
857
|
+
addOptions(...options) {
|
|
858
|
+
options = normalizeArray(options);
|
|
847
859
|
optionsLengthValidator.parse(this.options.length + options.length);
|
|
848
860
|
this.options.push(...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(optionValidator.parse(option))));
|
|
849
861
|
return this;
|
|
850
862
|
}
|
|
851
|
-
setOptions(options) {
|
|
863
|
+
setOptions(...options) {
|
|
864
|
+
options = normalizeArray(options);
|
|
852
865
|
optionsLengthValidator.parse(options.length);
|
|
853
866
|
this.options.splice(0, this.options.length, ...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(optionValidator.parse(option))));
|
|
854
867
|
return this;
|
|
@@ -1673,6 +1686,7 @@ __name(embedLength, "embedLength");
|
|
|
1673
1686
|
isEquatable,
|
|
1674
1687
|
isJSONEncodable,
|
|
1675
1688
|
italic,
|
|
1689
|
+
normalizeArray,
|
|
1676
1690
|
quote,
|
|
1677
1691
|
roleMention,
|
|
1678
1692
|
spoiler,
|