@ovencord/builders 1.11.1
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 +191 -0
- package/README.md +92 -0
- package/package.json +70 -0
- package/src/Assertions.ts +15 -0
- package/src/components/ActionRow.ts +346 -0
- package/src/components/Assertions.ts +190 -0
- package/src/components/Component.ts +47 -0
- package/src/components/Components.ts +275 -0
- package/src/components/button/Button.ts +34 -0
- package/src/components/button/CustomIdButton.ts +74 -0
- package/src/components/button/LinkButton.ts +39 -0
- package/src/components/button/PremiumButton.ts +26 -0
- package/src/components/button/mixins/EmojiOrLabelButtonMixin.ts +52 -0
- package/src/components/fileUpload/Assertions.ts +12 -0
- package/src/components/fileUpload/FileUpload.ts +109 -0
- package/src/components/label/Assertions.ts +28 -0
- package/src/components/label/Label.ts +215 -0
- package/src/components/selectMenu/BaseSelectMenu.ts +89 -0
- package/src/components/selectMenu/ChannelSelectMenu.ts +115 -0
- package/src/components/selectMenu/MentionableSelectMenu.ts +126 -0
- package/src/components/selectMenu/RoleSelectMenu.ts +89 -0
- package/src/components/selectMenu/StringSelectMenu.ts +165 -0
- package/src/components/selectMenu/StringSelectMenuOption.ts +113 -0
- package/src/components/selectMenu/UserSelectMenu.ts +89 -0
- package/src/components/textInput/Assertions.ts +15 -0
- package/src/components/textInput/TextInput.ts +154 -0
- package/src/components/v2/Assertions.ts +82 -0
- package/src/components/v2/Container.ts +254 -0
- package/src/components/v2/File.ts +81 -0
- package/src/components/v2/MediaGallery.ts +128 -0
- package/src/components/v2/MediaGalleryItem.ts +85 -0
- package/src/components/v2/Section.ts +266 -0
- package/src/components/v2/Separator.ts +82 -0
- package/src/components/v2/TextDisplay.ts +63 -0
- package/src/components/v2/Thumbnail.ts +100 -0
- package/src/index.ts +109 -0
- package/src/interactions/commands/Command.ts +87 -0
- package/src/interactions/commands/SharedName.ts +68 -0
- package/src/interactions/commands/SharedNameAndDescription.ts +69 -0
- package/src/interactions/commands/chatInput/Assertions.ts +180 -0
- package/src/interactions/commands/chatInput/ChatInputCommand.ts +40 -0
- package/src/interactions/commands/chatInput/ChatInputCommandSubcommands.ts +117 -0
- package/src/interactions/commands/chatInput/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.ts +52 -0
- package/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.ts +57 -0
- package/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionWithAutocompleteMixin.ts +32 -0
- package/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionWithChoicesMixin.ts +43 -0
- package/src/interactions/commands/chatInput/mixins/SharedChatInputCommandOptions.ts +204 -0
- package/src/interactions/commands/chatInput/mixins/SharedSubcommands.ts +61 -0
- package/src/interactions/commands/chatInput/options/ApplicationCommandOptionBase.ts +66 -0
- package/src/interactions/commands/chatInput/options/attachment.ts +20 -0
- package/src/interactions/commands/chatInput/options/boolean.ts +20 -0
- package/src/interactions/commands/chatInput/options/channel.ts +28 -0
- package/src/interactions/commands/chatInput/options/integer.ts +34 -0
- package/src/interactions/commands/chatInput/options/mentionable.ts +20 -0
- package/src/interactions/commands/chatInput/options/number.ts +34 -0
- package/src/interactions/commands/chatInput/options/role.ts +20 -0
- package/src/interactions/commands/chatInput/options/string.ts +71 -0
- package/src/interactions/commands/chatInput/options/user.ts +20 -0
- package/src/interactions/commands/contextMenu/Assertions.ts +31 -0
- package/src/interactions/commands/contextMenu/ContextMenuCommand.ts +42 -0
- package/src/interactions/commands/contextMenu/MessageCommand.ts +19 -0
- package/src/interactions/commands/contextMenu/UserCommand.ts +19 -0
- package/src/interactions/modals/Assertions.ts +27 -0
- package/src/interactions/modals/Modal.ts +158 -0
- package/src/messages/AllowedMentions.ts +193 -0
- package/src/messages/Assertions.ts +148 -0
- package/src/messages/Attachment.ts +209 -0
- package/src/messages/Message.ts +692 -0
- package/src/messages/MessageReference.ts +111 -0
- package/src/messages/embed/Assertions.ts +53 -0
- package/src/messages/embed/Embed.ts +352 -0
- package/src/messages/embed/EmbedAuthor.ts +83 -0
- package/src/messages/embed/EmbedField.ts +67 -0
- package/src/messages/embed/EmbedFooter.ts +65 -0
- package/src/messages/poll/Assertions.ts +20 -0
- package/src/messages/poll/Poll.ts +243 -0
- package/src/messages/poll/PollAnswer.ts +77 -0
- package/src/messages/poll/PollAnswerMedia.ts +38 -0
- package/src/messages/poll/PollMedia.ts +41 -0
- package/src/messages/poll/PollQuestion.ts +20 -0
- package/src/util/ValidationError.ts +21 -0
- package/src/util/normalizeArray.ts +19 -0
- package/src/util/resolveBuilder.ts +40 -0
- package/src/util/validation.ts +58 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
APITextDisplayComponent,
|
|
3
|
+
APISectionComponent,
|
|
4
|
+
APIButtonComponentWithCustomId,
|
|
5
|
+
APIThumbnailComponent,
|
|
6
|
+
APIButtonComponentWithSKUId,
|
|
7
|
+
APIButtonComponentWithURL,
|
|
8
|
+
ButtonStyle,
|
|
9
|
+
} from 'discord-api-types/v10';
|
|
10
|
+
import { ComponentType } from 'discord-api-types/v10';
|
|
11
|
+
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
|
12
|
+
import { resolveBuilder } from '../../util/resolveBuilder.js';
|
|
13
|
+
import { validate } from '../../util/validation.js';
|
|
14
|
+
import { ComponentBuilder } from '../Component.js';
|
|
15
|
+
import { resolveAccessoryComponent, type ButtonBuilder } from '../Components.js';
|
|
16
|
+
import {
|
|
17
|
+
DangerButtonBuilder,
|
|
18
|
+
PrimaryButtonBuilder,
|
|
19
|
+
SecondaryButtonBuilder,
|
|
20
|
+
SuccessButtonBuilder,
|
|
21
|
+
} from '../button/CustomIdButton.js';
|
|
22
|
+
import { LinkButtonBuilder } from '../button/LinkButton.js';
|
|
23
|
+
import { PremiumButtonBuilder } from '../button/PremiumButton.js';
|
|
24
|
+
import { sectionPredicate } from './Assertions.js';
|
|
25
|
+
import { TextDisplayBuilder } from './TextDisplay.js';
|
|
26
|
+
import { ThumbnailBuilder } from './Thumbnail.js';
|
|
27
|
+
|
|
28
|
+
export type SectionBuilderAccessory = ButtonBuilder | ThumbnailBuilder;
|
|
29
|
+
|
|
30
|
+
export interface SectionBuilderData extends Partial<Omit<APISectionComponent, 'accessory' | 'components'>> {
|
|
31
|
+
accessory?: SectionBuilderAccessory;
|
|
32
|
+
components: TextDisplayBuilder[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A builder that creates API-compatible JSON data for sections.
|
|
37
|
+
*/
|
|
38
|
+
export class SectionBuilder extends ComponentBuilder<APISectionComponent> {
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
protected readonly data: SectionBuilderData;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The components within this section.
|
|
46
|
+
*/
|
|
47
|
+
public get components(): readonly TextDisplayBuilder[] {
|
|
48
|
+
return this.data.components;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new section.
|
|
53
|
+
*
|
|
54
|
+
* @param data - The API data to create this section with
|
|
55
|
+
* @example
|
|
56
|
+
* Creating a section from an API data object:
|
|
57
|
+
* ```ts
|
|
58
|
+
* const section = new SectionBuilder({
|
|
59
|
+
* components: [
|
|
60
|
+
* {
|
|
61
|
+
* content: "Some text here",
|
|
62
|
+
* type: ComponentType.TextDisplay,
|
|
63
|
+
* },
|
|
64
|
+
* ],
|
|
65
|
+
* accessory: {
|
|
66
|
+
* media: {
|
|
67
|
+
* url: 'https://cdn.discordapp.com/embed/avatars/3.png',
|
|
68
|
+
* },
|
|
69
|
+
* }
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
* @example
|
|
73
|
+
* Creating a section using setters and API data:
|
|
74
|
+
* ```ts
|
|
75
|
+
* const section = new SectionBuilder({
|
|
76
|
+
* components: [
|
|
77
|
+
* {
|
|
78
|
+
* content: "# Heading",
|
|
79
|
+
* type: ComponentType.TextDisplay,
|
|
80
|
+
* },
|
|
81
|
+
* ],
|
|
82
|
+
* })
|
|
83
|
+
* .setPrimaryButtonAccessory(button);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
public constructor(data: Partial<APISectionComponent> = {}) {
|
|
87
|
+
super();
|
|
88
|
+
|
|
89
|
+
const { components = [], accessory, ...rest } = data;
|
|
90
|
+
|
|
91
|
+
this.data = {
|
|
92
|
+
...structuredClone(rest),
|
|
93
|
+
accessory: accessory && resolveAccessoryComponent(accessory),
|
|
94
|
+
components: components.map((component) => new TextDisplayBuilder(component)),
|
|
95
|
+
type: ComponentType.Section,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Adds text display components to this section.
|
|
101
|
+
*
|
|
102
|
+
* @param input - The text display components to add
|
|
103
|
+
*/
|
|
104
|
+
public addTextDisplayComponents(
|
|
105
|
+
...input: RestOrArray<
|
|
106
|
+
APITextDisplayComponent | TextDisplayBuilder | ((builder: TextDisplayBuilder) => TextDisplayBuilder)
|
|
107
|
+
>
|
|
108
|
+
): this {
|
|
109
|
+
const normalized = normalizeArray(input);
|
|
110
|
+
const resolved = normalized.map((component) => resolveBuilder(component, TextDisplayBuilder));
|
|
111
|
+
|
|
112
|
+
this.data.components.push(...resolved);
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Sets a primary button component to be the accessory of this section.
|
|
118
|
+
*
|
|
119
|
+
* @param input - The button to set as the accessory
|
|
120
|
+
*/
|
|
121
|
+
public setPrimaryButtonAccessory(
|
|
122
|
+
input:
|
|
123
|
+
| PrimaryButtonBuilder
|
|
124
|
+
| ((builder: PrimaryButtonBuilder) => PrimaryButtonBuilder)
|
|
125
|
+
| (APIButtonComponentWithCustomId & { style: ButtonStyle.Primary }),
|
|
126
|
+
): this {
|
|
127
|
+
const builder = resolveBuilder(input, PrimaryButtonBuilder);
|
|
128
|
+
|
|
129
|
+
this.data.accessory = builder;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Sets a secondary button component to be the accessory of this section.
|
|
135
|
+
*
|
|
136
|
+
* @param input - The button to set as the accessory
|
|
137
|
+
*/
|
|
138
|
+
public setSecondaryButtonAccessory(
|
|
139
|
+
input:
|
|
140
|
+
| SecondaryButtonBuilder
|
|
141
|
+
| ((builder: SecondaryButtonBuilder) => SecondaryButtonBuilder)
|
|
142
|
+
| (APIButtonComponentWithCustomId & { style: ButtonStyle.Secondary }),
|
|
143
|
+
): this {
|
|
144
|
+
const builder = resolveBuilder(input, SecondaryButtonBuilder);
|
|
145
|
+
|
|
146
|
+
this.data.accessory = builder;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Sets a success button component to be the accessory of this section.
|
|
152
|
+
*
|
|
153
|
+
* @param input - The button to set as the accessory
|
|
154
|
+
*/
|
|
155
|
+
public setSuccessButtonAccessory(
|
|
156
|
+
input:
|
|
157
|
+
| SuccessButtonBuilder
|
|
158
|
+
| ((builder: SuccessButtonBuilder) => SuccessButtonBuilder)
|
|
159
|
+
| (APIButtonComponentWithCustomId & { style: ButtonStyle.Success }),
|
|
160
|
+
): this {
|
|
161
|
+
const builder = resolveBuilder(input, SuccessButtonBuilder);
|
|
162
|
+
|
|
163
|
+
this.data.accessory = builder;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Sets a danger button component to be the accessory of this section.
|
|
169
|
+
*
|
|
170
|
+
* @param input - The button to set as the accessory
|
|
171
|
+
*/
|
|
172
|
+
public setDangerButtonAccessory(
|
|
173
|
+
input:
|
|
174
|
+
| DangerButtonBuilder
|
|
175
|
+
| ((builder: DangerButtonBuilder) => DangerButtonBuilder)
|
|
176
|
+
| (APIButtonComponentWithCustomId & { style: ButtonStyle.Danger }),
|
|
177
|
+
): this {
|
|
178
|
+
const builder = resolveBuilder(input, DangerButtonBuilder);
|
|
179
|
+
|
|
180
|
+
this.data.accessory = builder;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Sets a SKU id button component to be the accessory of this section.
|
|
186
|
+
*
|
|
187
|
+
* @param input - The button to set as the accessory
|
|
188
|
+
*/
|
|
189
|
+
public setPremiumButtonAccessory(
|
|
190
|
+
input:
|
|
191
|
+
| APIButtonComponentWithSKUId
|
|
192
|
+
| PremiumButtonBuilder
|
|
193
|
+
| ((builder: PremiumButtonBuilder) => PremiumButtonBuilder),
|
|
194
|
+
): this {
|
|
195
|
+
const builder = resolveBuilder(input, PremiumButtonBuilder);
|
|
196
|
+
|
|
197
|
+
this.data.accessory = builder;
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Sets a URL button component to be the accessory of this section.
|
|
203
|
+
*
|
|
204
|
+
* @param input - The button to set as the accessory
|
|
205
|
+
*/
|
|
206
|
+
public setLinkButtonAccessory(
|
|
207
|
+
input: APIButtonComponentWithURL | LinkButtonBuilder | ((builder: LinkButtonBuilder) => LinkButtonBuilder),
|
|
208
|
+
): this {
|
|
209
|
+
const builder = resolveBuilder(input, LinkButtonBuilder);
|
|
210
|
+
|
|
211
|
+
this.data.accessory = builder;
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Sets a thumbnail component to be the accessory of this section.
|
|
217
|
+
*
|
|
218
|
+
* @param input - The thumbnail to set as the accessory
|
|
219
|
+
*/
|
|
220
|
+
public setThumbnailAccessory(
|
|
221
|
+
input: APIThumbnailComponent | ThumbnailBuilder | ((builder: ThumbnailBuilder) => ThumbnailBuilder),
|
|
222
|
+
): this {
|
|
223
|
+
const builder = resolveBuilder(input, ThumbnailBuilder);
|
|
224
|
+
|
|
225
|
+
this.data.accessory = builder;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Removes, replaces, or inserts text display components for this section.
|
|
231
|
+
*
|
|
232
|
+
* @param index - The index to start removing, replacing or inserting text display components
|
|
233
|
+
* @param deleteCount - The amount of text display components to remove
|
|
234
|
+
* @param components - The text display components to insert
|
|
235
|
+
*/
|
|
236
|
+
public spliceTextDisplayComponents(
|
|
237
|
+
index: number,
|
|
238
|
+
deleteCount: number,
|
|
239
|
+
...components: RestOrArray<
|
|
240
|
+
APITextDisplayComponent | TextDisplayBuilder | ((builder: TextDisplayBuilder) => TextDisplayBuilder)
|
|
241
|
+
>
|
|
242
|
+
): this {
|
|
243
|
+
const normalized = normalizeArray(components);
|
|
244
|
+
const resolved = normalized.map((component) => resolveBuilder(component, TextDisplayBuilder));
|
|
245
|
+
|
|
246
|
+
this.data.components.splice(index, deleteCount, ...resolved);
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* {@inheritDoc ComponentBuilder.toJSON}
|
|
252
|
+
*/
|
|
253
|
+
public override toJSON(validationOverride?: boolean): APISectionComponent {
|
|
254
|
+
const { components, accessory, ...rest } = this.data;
|
|
255
|
+
|
|
256
|
+
const data = {
|
|
257
|
+
...structuredClone(rest),
|
|
258
|
+
components: components.map((component) => component.toJSON(false)),
|
|
259
|
+
accessory: accessory?.toJSON(validationOverride),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
validate(sectionPredicate, data, validationOverride);
|
|
263
|
+
|
|
264
|
+
return data as APISectionComponent;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { SeparatorSpacingSize, APISeparatorComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { ComponentType } from 'discord-api-types/v10';
|
|
3
|
+
import { validate } from '../../util/validation.js';
|
|
4
|
+
import { ComponentBuilder } from '../Component.js';
|
|
5
|
+
import { separatorPredicate } from './Assertions.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A builder that creates API-compatible JSON data for separators.
|
|
9
|
+
*/
|
|
10
|
+
export class SeparatorBuilder extends ComponentBuilder<APISeparatorComponent> {
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
protected readonly data: Partial<APISeparatorComponent>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new separator.
|
|
18
|
+
*
|
|
19
|
+
* @param data - The API data to create this separator with
|
|
20
|
+
* @example
|
|
21
|
+
* Creating a separator from an API data object:
|
|
22
|
+
* ```ts
|
|
23
|
+
* const separator = new SeparatorBuilder({
|
|
24
|
+
* spacing: SeparatorSpacingSize.Small,
|
|
25
|
+
* divider: true,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
* @example
|
|
29
|
+
* Creating a separator using setters and API data:
|
|
30
|
+
* ```ts
|
|
31
|
+
* const separator = new SeparatorBuilder({
|
|
32
|
+
* spacing: SeparatorSpacingSize.Large,
|
|
33
|
+
* })
|
|
34
|
+
* .setDivider(false);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
public constructor(data: Partial<APISeparatorComponent> = {}) {
|
|
38
|
+
super();
|
|
39
|
+
this.data = {
|
|
40
|
+
...structuredClone(data),
|
|
41
|
+
type: ComponentType.Separator,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets whether this separator should show a divider line.
|
|
47
|
+
*
|
|
48
|
+
* @param divider - Whether to show a divider line
|
|
49
|
+
*/
|
|
50
|
+
public setDivider(divider = true) {
|
|
51
|
+
this.data.divider = divider;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Sets the spacing of this separator.
|
|
57
|
+
*
|
|
58
|
+
* @param spacing - The spacing to use
|
|
59
|
+
*/
|
|
60
|
+
public setSpacing(spacing: SeparatorSpacingSize) {
|
|
61
|
+
this.data.spacing = spacing;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Clears the spacing of this separator.
|
|
67
|
+
*/
|
|
68
|
+
public clearSpacing() {
|
|
69
|
+
this.data.spacing = undefined;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* {@inheritDoc ComponentBuilder.toJSON}
|
|
75
|
+
*/
|
|
76
|
+
public override toJSON(validationOverride?: boolean): APISeparatorComponent {
|
|
77
|
+
const clone = structuredClone(this.data);
|
|
78
|
+
validate(separatorPredicate, clone, validationOverride);
|
|
79
|
+
|
|
80
|
+
return clone as APISeparatorComponent;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { APITextDisplayComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { ComponentType } from 'discord-api-types/v10';
|
|
3
|
+
import { validate } from '../../util/validation.js';
|
|
4
|
+
import { ComponentBuilder } from '../Component.js';
|
|
5
|
+
import { textDisplayPredicate } from './Assertions.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A builder that creates API-compatible JSON data for text displays.
|
|
9
|
+
*/
|
|
10
|
+
export class TextDisplayBuilder extends ComponentBuilder<APITextDisplayComponent> {
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
protected readonly data: Partial<APITextDisplayComponent>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new text display.
|
|
18
|
+
*
|
|
19
|
+
* @param data - The API data to create this text display with
|
|
20
|
+
* @example
|
|
21
|
+
* Creating a text display from an API data object:
|
|
22
|
+
* ```ts
|
|
23
|
+
* const textDisplay = new TextDisplayBuilder({
|
|
24
|
+
* content: 'some text',
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
* @example
|
|
28
|
+
* Creating a text display using setters and API data:
|
|
29
|
+
* ```ts
|
|
30
|
+
* const textDisplay = new TextDisplayBuilder({
|
|
31
|
+
* content: 'old text',
|
|
32
|
+
* })
|
|
33
|
+
* .setContent('new text');
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
public constructor(data: Partial<APITextDisplayComponent> = {}) {
|
|
37
|
+
super();
|
|
38
|
+
this.data = {
|
|
39
|
+
...structuredClone(data),
|
|
40
|
+
type: ComponentType.TextDisplay,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Sets the text of this text display.
|
|
46
|
+
*
|
|
47
|
+
* @param content - The text to use
|
|
48
|
+
*/
|
|
49
|
+
public setContent(content: string) {
|
|
50
|
+
this.data.content = content;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* {@inheritDoc ComponentBuilder.toJSON}
|
|
56
|
+
*/
|
|
57
|
+
public override toJSON(validationOverride?: boolean): APITextDisplayComponent {
|
|
58
|
+
const clone = structuredClone(this.data);
|
|
59
|
+
validate(textDisplayPredicate, clone, validationOverride);
|
|
60
|
+
|
|
61
|
+
return clone as APITextDisplayComponent;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { APIThumbnailComponent } from 'discord-api-types/v10';
|
|
2
|
+
import { ComponentType } from 'discord-api-types/v10';
|
|
3
|
+
import { validate } from '../../util/validation.js';
|
|
4
|
+
import { ComponentBuilder } from '../Component.js';
|
|
5
|
+
import { thumbnailPredicate } from './Assertions.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A builder that creates API-compatible JSON data for thumbnails.
|
|
9
|
+
*/
|
|
10
|
+
export class ThumbnailBuilder extends ComponentBuilder<APIThumbnailComponent> {
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
protected readonly data: Partial<APIThumbnailComponent>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new thumbnail.
|
|
18
|
+
*
|
|
19
|
+
* @param data - The API data to create this thumbnail with
|
|
20
|
+
* @example
|
|
21
|
+
* Creating a thumbnail from an API data object:
|
|
22
|
+
* ```ts
|
|
23
|
+
* const thumbnail = new ThumbnailBuilder({
|
|
24
|
+
* description: 'some text',
|
|
25
|
+
* media: {
|
|
26
|
+
* url: 'https://cdn.discordapp.com/embed/avatars/4.png',
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
* @example
|
|
31
|
+
* Creating a thumbnail using setters and API data:
|
|
32
|
+
* ```ts
|
|
33
|
+
* const thumbnail = new ThumbnailBuilder({
|
|
34
|
+
* media: {
|
|
35
|
+
* url: 'attachment://image.png',
|
|
36
|
+
* },
|
|
37
|
+
* })
|
|
38
|
+
* .setDescription('alt text');
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
public constructor(data: Partial<APIThumbnailComponent> = {}) {
|
|
42
|
+
super();
|
|
43
|
+
|
|
44
|
+
const { media, ...rest } = data;
|
|
45
|
+
|
|
46
|
+
this.data = {
|
|
47
|
+
...structuredClone(rest),
|
|
48
|
+
media: media && { url: media.url },
|
|
49
|
+
type: ComponentType.Thumbnail,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Sets the description of this thumbnail.
|
|
55
|
+
*
|
|
56
|
+
* @param description - The description to use
|
|
57
|
+
*/
|
|
58
|
+
public setDescription(description: string) {
|
|
59
|
+
this.data.description = description;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Clears the description of this thumbnail.
|
|
65
|
+
*/
|
|
66
|
+
public clearDescription() {
|
|
67
|
+
this.data.description = undefined;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sets the spoiler status of this thumbnail.
|
|
73
|
+
*
|
|
74
|
+
* @param spoiler - The spoiler status to use
|
|
75
|
+
*/
|
|
76
|
+
public setSpoiler(spoiler = true) {
|
|
77
|
+
this.data.spoiler = spoiler;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Sets the media URL of this thumbnail.
|
|
83
|
+
*
|
|
84
|
+
* @param url - The URL to use
|
|
85
|
+
*/
|
|
86
|
+
public setURL(url: string) {
|
|
87
|
+
this.data.media = { url };
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* {@inheritdoc ComponentBuilder.toJSON}
|
|
93
|
+
*/
|
|
94
|
+
public override toJSON(validationOverride?: boolean): APIThumbnailComponent {
|
|
95
|
+
const clone = structuredClone(this.data);
|
|
96
|
+
validate(thumbnailPredicate, clone, validationOverride);
|
|
97
|
+
|
|
98
|
+
return clone as APIThumbnailComponent;
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export * from './components/button/mixins/EmojiOrLabelButtonMixin.js';
|
|
2
|
+
export * from './components/button/Button.js';
|
|
3
|
+
export * from './components/button/CustomIdButton.js';
|
|
4
|
+
export * from './components/button/LinkButton.js';
|
|
5
|
+
export * from './components/button/PremiumButton.js';
|
|
6
|
+
|
|
7
|
+
export * from './components/fileUpload/FileUpload.js';
|
|
8
|
+
export * from './components/fileUpload/Assertions.js';
|
|
9
|
+
|
|
10
|
+
export * from './components/label/Label.js';
|
|
11
|
+
export * from './components/label/Assertions.js';
|
|
12
|
+
|
|
13
|
+
export * from './components/selectMenu/BaseSelectMenu.js';
|
|
14
|
+
export * from './components/selectMenu/ChannelSelectMenu.js';
|
|
15
|
+
export * from './components/selectMenu/MentionableSelectMenu.js';
|
|
16
|
+
export * from './components/selectMenu/RoleSelectMenu.js';
|
|
17
|
+
export * from './components/selectMenu/StringSelectMenu.js';
|
|
18
|
+
export * from './components/selectMenu/StringSelectMenuOption.js';
|
|
19
|
+
export * from './components/selectMenu/UserSelectMenu.js';
|
|
20
|
+
|
|
21
|
+
export * from './components/textInput/TextInput.js';
|
|
22
|
+
export * from './components/textInput/Assertions.js';
|
|
23
|
+
|
|
24
|
+
export * from './components/ActionRow.js';
|
|
25
|
+
export * from './components/Assertions.js';
|
|
26
|
+
export * from './components/Component.js';
|
|
27
|
+
export * from './components/Components.js';
|
|
28
|
+
|
|
29
|
+
export * from './components/v2/Assertions.js';
|
|
30
|
+
export * from './components/v2/Container.js';
|
|
31
|
+
export * from './components/v2/File.js';
|
|
32
|
+
export * from './components/v2/MediaGallery.js';
|
|
33
|
+
export * from './components/v2/MediaGalleryItem.js';
|
|
34
|
+
export * from './components/v2/Section.js';
|
|
35
|
+
export * from './components/v2/Separator.js';
|
|
36
|
+
export * from './components/v2/TextDisplay.js';
|
|
37
|
+
export * from './components/v2/Thumbnail.js';
|
|
38
|
+
|
|
39
|
+
export * from './interactions/commands/chatInput/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';
|
|
40
|
+
export * from './interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.js';
|
|
41
|
+
export * from './interactions/commands/chatInput/mixins/ApplicationCommandOptionWithAutocompleteMixin.js';
|
|
42
|
+
export * from './interactions/commands/chatInput/mixins/ApplicationCommandOptionWithChoicesMixin.js';
|
|
43
|
+
export * from './interactions/commands/chatInput/mixins/SharedChatInputCommandOptions.js';
|
|
44
|
+
export * from './interactions/commands/chatInput/mixins/SharedSubcommands.js';
|
|
45
|
+
|
|
46
|
+
export * from './interactions/commands/chatInput/options/ApplicationCommandOptionBase.js';
|
|
47
|
+
export * from './interactions/commands/chatInput/options/boolean.js';
|
|
48
|
+
export * from './interactions/commands/chatInput/options/channel.js';
|
|
49
|
+
export * from './interactions/commands/chatInput/options/integer.js';
|
|
50
|
+
export * from './interactions/commands/chatInput/options/mentionable.js';
|
|
51
|
+
export * from './interactions/commands/chatInput/options/number.js';
|
|
52
|
+
export * from './interactions/commands/chatInput/options/role.js';
|
|
53
|
+
export * from './interactions/commands/chatInput/options/attachment.js';
|
|
54
|
+
export * from './interactions/commands/chatInput/options/string.js';
|
|
55
|
+
export * from './interactions/commands/chatInput/options/user.js';
|
|
56
|
+
|
|
57
|
+
export * from './interactions/commands/chatInput/Assertions.js';
|
|
58
|
+
export * from './interactions/commands/chatInput/ChatInputCommand.js';
|
|
59
|
+
export { ChatInputCommandBuilder as SlashCommandBuilder } from './interactions/commands/chatInput/ChatInputCommand.js';
|
|
60
|
+
export * from './interactions/commands/chatInput/ChatInputCommandSubcommands.js';
|
|
61
|
+
|
|
62
|
+
export * from './interactions/commands/contextMenu/Assertions.js';
|
|
63
|
+
export * from './interactions/commands/contextMenu/ContextMenuCommand.js';
|
|
64
|
+
export * from './interactions/commands/contextMenu/MessageCommand.js';
|
|
65
|
+
export * from './interactions/commands/contextMenu/UserCommand.js';
|
|
66
|
+
|
|
67
|
+
export * from './interactions/commands/Command.js';
|
|
68
|
+
export * from './interactions/commands/SharedName.js';
|
|
69
|
+
export * from './interactions/commands/SharedNameAndDescription.js';
|
|
70
|
+
|
|
71
|
+
export * from './interactions/modals/Assertions.js';
|
|
72
|
+
export * from './interactions/modals/Modal.js';
|
|
73
|
+
|
|
74
|
+
export * from './messages/embed/Assertions.js';
|
|
75
|
+
export * from './messages/embed/Embed.js';
|
|
76
|
+
export * from './messages/embed/EmbedAuthor.js';
|
|
77
|
+
export * from './messages/embed/EmbedField.js';
|
|
78
|
+
export * from './messages/embed/EmbedFooter.js';
|
|
79
|
+
|
|
80
|
+
export * from './messages/poll/Assertions.js';
|
|
81
|
+
export * from './messages/poll/Poll.js';
|
|
82
|
+
export * from './messages/poll/PollAnswer.js';
|
|
83
|
+
export * from './messages/poll/PollAnswerMedia.js';
|
|
84
|
+
export * from './messages/poll/PollMedia.js';
|
|
85
|
+
export * from './messages/poll/PollQuestion.js';
|
|
86
|
+
|
|
87
|
+
export * from './messages/AllowedMentions.js';
|
|
88
|
+
export * from './messages/Assertions.js';
|
|
89
|
+
export * from './messages/Attachment.js';
|
|
90
|
+
export * from './messages/Message.js';
|
|
91
|
+
export * from './messages/MessageReference.js';
|
|
92
|
+
|
|
93
|
+
export * from './util/normalizeArray.js';
|
|
94
|
+
export * from './util/resolveBuilder.js';
|
|
95
|
+
export { disableValidators, enableValidators, isValidationEnabled } from './util/validation.js';
|
|
96
|
+
export * from './util/ValidationError.js';
|
|
97
|
+
|
|
98
|
+
export * from './Assertions.js';
|
|
99
|
+
|
|
100
|
+
// We expose this type in our public API. We shouldn't assume every user of builders is also using REST
|
|
101
|
+
export type { RawFile } from '@ovencord/util';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The {@link https://github.com/ovencord/ovencord/blob/main/packages/builders#readme | @ovencord/builders} version
|
|
105
|
+
* that you are currently using.
|
|
106
|
+
*
|
|
107
|
+
* @privateRemarks This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild.
|
|
108
|
+
*/
|
|
109
|
+
export const version = '[VI]{{inject}}[/VI]' as string;
|