@ovencord/builders 1.11.1 → 1.11.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@ovencord/builders",
4
- "version": "1.11.1",
4
+ "version": "1.11.3",
5
5
  "description": "A set of builders that you can use when creating your bot",
6
6
  "scripts": {
7
7
  "test": "bun test",
@@ -14,6 +14,8 @@ import {
14
14
  SecondaryButtonBuilder,
15
15
  SuccessButtonBuilder,
16
16
  } from './button/CustomIdButton.js';
17
+ import { ButtonBuilder } from './button/ButtonBuilder.js';
18
+ export { ButtonBuilder };
17
19
  import { LinkButtonBuilder } from './button/LinkButton.js';
18
20
  import { PremiumButtonBuilder } from './button/PremiumButton.js';
19
21
  import { FileUploadBuilder } from './fileUpload/FileUpload.js';
@@ -61,16 +63,7 @@ export type ModalComponentBuilder =
61
63
  | LabelBuilder
62
64
  | ModalActionRowComponentBuilder;
63
65
 
64
- /**
65
- * Any button builder
66
- */
67
- export type ButtonBuilder =
68
- | DangerButtonBuilder
69
- | LinkButtonBuilder
70
- | PremiumButtonBuilder
71
- | PrimaryButtonBuilder
72
- | SecondaryButtonBuilder
73
- | SuccessButtonBuilder;
66
+ // Any button builder is already covered by the ButtonBuilder class
74
67
 
75
68
  /**
76
69
  * The builders that may be used within an action row for messages.
@@ -0,0 +1,59 @@
1
+ import { ButtonStyle, ComponentType, type APIButtonComponent } from 'discord-api-types/v10';
2
+ import { Mixin } from 'ts-mixer';
3
+ import { BaseButtonBuilder } from './Button.js';
4
+ import { EmojiOrLabelButtonMixin } from './mixins/EmojiOrLabelButtonMixin.js';
5
+
6
+ /**
7
+ * A builder that creates API-compatible JSON data for buttons.
8
+ *
9
+ * @mixes {@link BaseButtonBuilder}\<{@link discord-api-types/v10#(APIButtonComponent:interface)}\>
10
+ * @mixes {@link EmojiOrLabelButtonMixin}
11
+ */
12
+ export interface ButtonBuilder extends BaseButtonBuilder<APIButtonComponent>, EmojiOrLabelButtonMixin {}
13
+
14
+ export class ButtonBuilder extends Mixin(BaseButtonBuilder<APIButtonComponent>, EmojiOrLabelButtonMixin) {
15
+ /**
16
+ * @internal
17
+ */
18
+ protected override readonly data: Partial<APIButtonComponent>;
19
+
20
+ /**
21
+ * Creates a new button builder.
22
+ *
23
+ * @param data - The API data to create this button with
24
+ */
25
+ public constructor(data: Partial<APIButtonComponent> = {}) {
26
+ super();
27
+ this.data = { ...structuredClone(data), type: ComponentType.Button };
28
+ }
29
+
30
+ /**
31
+ * Sets the custom id for this button.
32
+ *
33
+ * @param customId - The custom id to use
34
+ */
35
+ public setCustomId(customId: string) {
36
+ this.data.custom_id = customId;
37
+ return this;
38
+ }
39
+
40
+ /**
41
+ * Sets the style for this button.
42
+ *
43
+ * @param style - The style to use
44
+ */
45
+ public setStyle(style: ButtonStyle) {
46
+ this.data.style = style;
47
+ return this;
48
+ }
49
+
50
+ /**
51
+ * Sets the URL for this button.
52
+ *
53
+ * @param url - The URL to use
54
+ */
55
+ public setURL(url: string) {
56
+ this.data.url = url;
57
+ return this;
58
+ }
59
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './components/button/mixins/EmojiOrLabelButtonMixin.js';
2
2
  export * from './components/button/Button.js';
3
+ export * from './components/button/ButtonBuilder.js';
3
4
  export * from './components/button/CustomIdButton.js';
4
5
  export * from './components/button/LinkButton.js';
5
6
  export * from './components/button/PremiumButton.js';
@@ -44,6 +44,15 @@ export class SharedChatInputCommandOptions {
44
44
  return this.sharedAddOptions(ChatInputCommandBooleanOption, ...options);
45
45
  }
46
46
 
47
+ /**
48
+ * Adds a boolean option.
49
+ *
50
+ * @param option - Option to add
51
+ */
52
+ public addBooleanOption(option: ChatInputCommandBooleanOption | ((builder: ChatInputCommandBooleanOption) => ChatInputCommandBooleanOption)) {
53
+ return this.addBooleanOptions(option);
54
+ }
55
+
47
56
  /**
48
57
  * Adds user options.
49
58
  *
@@ -57,6 +66,15 @@ export class SharedChatInputCommandOptions {
57
66
  return this.sharedAddOptions(ChatInputCommandUserOption, ...options);
58
67
  }
59
68
 
69
+ /**
70
+ * Adds a user option.
71
+ *
72
+ * @param option - Option to add
73
+ */
74
+ public addUserOption(option: ChatInputCommandUserOption | ((builder: ChatInputCommandUserOption) => ChatInputCommandUserOption)) {
75
+ return this.addUserOptions(option);
76
+ }
77
+
60
78
  /**
61
79
  * Adds channel options.
62
80
  *
@@ -70,6 +88,15 @@ export class SharedChatInputCommandOptions {
70
88
  return this.sharedAddOptions(ChatInputCommandChannelOption, ...options);
71
89
  }
72
90
 
91
+ /**
92
+ * Adds a channel option.
93
+ *
94
+ * @param option - Option to add
95
+ */
96
+ public addChannelOption(option: ChatInputCommandChannelOption | ((builder: ChatInputCommandChannelOption) => ChatInputCommandChannelOption)) {
97
+ return this.addChannelOptions(option);
98
+ }
99
+
73
100
  /**
74
101
  * Adds role options.
75
102
  *
@@ -83,6 +110,15 @@ export class SharedChatInputCommandOptions {
83
110
  return this.sharedAddOptions(ChatInputCommandRoleOption, ...options);
84
111
  }
85
112
 
113
+ /**
114
+ * Adds a role option.
115
+ *
116
+ * @param option - Option to add
117
+ */
118
+ public addRoleOption(option: ChatInputCommandRoleOption | ((builder: ChatInputCommandRoleOption) => ChatInputCommandRoleOption)) {
119
+ return this.addRoleOptions(option);
120
+ }
121
+
86
122
  /**
87
123
  * Adds attachment options.
88
124
  *
@@ -97,6 +133,15 @@ export class SharedChatInputCommandOptions {
97
133
  return this.sharedAddOptions(ChatInputCommandAttachmentOption, ...options);
98
134
  }
99
135
 
136
+ /**
137
+ * Adds an attachment option.
138
+ *
139
+ * @param option - Option to add
140
+ */
141
+ public addAttachmentOption(option: ChatInputCommandAttachmentOption | ((builder: ChatInputCommandAttachmentOption) => ChatInputCommandAttachmentOption)) {
142
+ return this.addAttachmentOptions(option);
143
+ }
144
+
100
145
  /**
101
146
  * Adds mentionable options.
102
147
  *
@@ -111,6 +156,15 @@ export class SharedChatInputCommandOptions {
111
156
  return this.sharedAddOptions(ChatInputCommandMentionableOption, ...options);
112
157
  }
113
158
 
159
+ /**
160
+ * Adds a mentionable option.
161
+ *
162
+ * @param option - Option to add
163
+ */
164
+ public addMentionableOption(option: ChatInputCommandMentionableOption | ((builder: ChatInputCommandMentionableOption) => ChatInputCommandMentionableOption)) {
165
+ return this.addMentionableOptions(option);
166
+ }
167
+
114
168
  /**
115
169
  * Adds string options.
116
170
  *
@@ -124,6 +178,15 @@ export class SharedChatInputCommandOptions {
124
178
  return this.sharedAddOptions(ChatInputCommandStringOption, ...options);
125
179
  }
126
180
 
181
+ /**
182
+ * Adds a string option.
183
+ *
184
+ * @param option - Option to add
185
+ */
186
+ public addStringOption(option: ChatInputCommandStringOption | ((builder: ChatInputCommandStringOption) => ChatInputCommandStringOption)) {
187
+ return this.addStringOptions(option);
188
+ }
189
+
127
190
  /**
128
191
  * Adds integer options.
129
192
  *
@@ -137,6 +200,15 @@ export class SharedChatInputCommandOptions {
137
200
  return this.sharedAddOptions(ChatInputCommandIntegerOption, ...options);
138
201
  }
139
202
 
203
+ /**
204
+ * Adds an integer option.
205
+ *
206
+ * @param option - Option to add
207
+ */
208
+ public addIntegerOption(option: ChatInputCommandIntegerOption | ((builder: ChatInputCommandIntegerOption) => ChatInputCommandIntegerOption)) {
209
+ return this.addIntegerOptions(option);
210
+ }
211
+
140
212
  /**
141
213
  * Adds number options.
142
214
  *
@@ -150,6 +222,15 @@ export class SharedChatInputCommandOptions {
150
222
  return this.sharedAddOptions(ChatInputCommandNumberOption, ...options);
151
223
  }
152
224
 
225
+ /**
226
+ * Adds a number option.
227
+ *
228
+ * @param option - Option to add
229
+ */
230
+ public addNumberOption(option: ChatInputCommandNumberOption | ((builder: ChatInputCommandNumberOption) => ChatInputCommandNumberOption)) {
231
+ return this.addNumberOptions(option);
232
+ }
233
+
153
234
  /**
154
235
  * Removes, replaces, or inserts options for this command.
155
236
  *
@@ -39,6 +39,19 @@ export class SharedChatInputCommandSubcommands {
39
39
  return this;
40
40
  }
41
41
 
42
+ /**
43
+ * Adds a subcommand group to this command.
44
+ *
45
+ * @param input - Subcommand group to add
46
+ */
47
+ public addSubcommandGroup(
48
+ input:
49
+ | ChatInputCommandSubcommandGroupBuilder
50
+ | ((subcommandGroup: ChatInputCommandSubcommandGroupBuilder) => ChatInputCommandSubcommandGroupBuilder),
51
+ ): this {
52
+ return this.addSubcommandGroups(input);
53
+ }
54
+
42
55
  /**
43
56
  * Adds subcommands to this command.
44
57
  *
@@ -58,4 +71,17 @@ export class SharedChatInputCommandSubcommands {
58
71
 
59
72
  return this;
60
73
  }
74
+
75
+ /**
76
+ * Adds a subcommand to this command.
77
+ *
78
+ * @param input - Subcommand to add
79
+ */
80
+ public addSubcommand(
81
+ input:
82
+ | ChatInputCommandSubcommandBuilder
83
+ | ((subcommandGroup: ChatInputCommandSubcommandBuilder) => ChatInputCommandSubcommandBuilder),
84
+ ): this {
85
+ return this.addSubcommands(input);
86
+ }
61
87
  }