@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
package/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionWithAutocompleteMixin.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
APIApplicationCommandIntegerOption,
|
|
3
|
+
APIApplicationCommandNumberOption,
|
|
4
|
+
APIApplicationCommandStringOption,
|
|
5
|
+
} from 'discord-api-types/v10';
|
|
6
|
+
|
|
7
|
+
export type AutocompletableOptions =
|
|
8
|
+
| APIApplicationCommandIntegerOption
|
|
9
|
+
| APIApplicationCommandNumberOption
|
|
10
|
+
| APIApplicationCommandStringOption;
|
|
11
|
+
|
|
12
|
+
export interface ApplicationCommandOptionWithAutocompleteData extends Pick<AutocompletableOptions, 'autocomplete'> {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This mixin holds choices and autocomplete symbols used for options.
|
|
16
|
+
*/
|
|
17
|
+
export class ApplicationCommandOptionWithAutocompleteMixin {
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
declare protected readonly data: ApplicationCommandOptionWithAutocompleteData;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether this option uses autocomplete.
|
|
25
|
+
*
|
|
26
|
+
* @param autocomplete - Whether this option should use autocomplete
|
|
27
|
+
*/
|
|
28
|
+
public setAutocomplete(autocomplete = true): this {
|
|
29
|
+
this.data.autocomplete = autocomplete;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionWithChoicesMixin.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
|
|
2
|
+
import { normalizeArray, type RestOrArray } from '../../../../util/normalizeArray.js';
|
|
3
|
+
|
|
4
|
+
// Unlike other places, we're not `Pick`ing from discord-api-types. The union includes `[]` and it breaks everything.
|
|
5
|
+
export interface ApplicationCommandOptionWithChoicesData {
|
|
6
|
+
choices?: APIApplicationCommandOptionChoice<number | string>[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This mixin holds choices and autocomplete symbols used for options.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam ChoiceType - The type of the choices within this option
|
|
13
|
+
*/
|
|
14
|
+
export class ApplicationCommandOptionWithChoicesMixin<ChoiceType extends number | string> {
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
declare protected readonly data: ApplicationCommandOptionWithChoicesData;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Adds multiple choices to this option.
|
|
22
|
+
*
|
|
23
|
+
* @param choices - The choices to add
|
|
24
|
+
*/
|
|
25
|
+
public addChoices(...choices: RestOrArray<APIApplicationCommandOptionChoice<ChoiceType>>): this {
|
|
26
|
+
const normalizedChoices = normalizeArray(choices);
|
|
27
|
+
|
|
28
|
+
this.data.choices ??= [];
|
|
29
|
+
this.data.choices.push(...normalizedChoices);
|
|
30
|
+
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sets multiple choices for this option.
|
|
36
|
+
*
|
|
37
|
+
* @param choices - The choices to set
|
|
38
|
+
*/
|
|
39
|
+
public setChoices(...choices: RestOrArray<APIApplicationCommandOptionChoice<ChoiceType>>): this {
|
|
40
|
+
this.data.choices = normalizeArray(choices);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { normalizeArray, type RestOrArray } from '../../../../util/normalizeArray.js';
|
|
2
|
+
import { resolveBuilder } from '../../../../util/resolveBuilder.js';
|
|
3
|
+
import type { ApplicationCommandOptionBase } from '../options/ApplicationCommandOptionBase.js';
|
|
4
|
+
import { ChatInputCommandAttachmentOption } from '../options/attachment.js';
|
|
5
|
+
import { ChatInputCommandBooleanOption } from '../options/boolean.js';
|
|
6
|
+
import { ChatInputCommandChannelOption } from '../options/channel.js';
|
|
7
|
+
import { ChatInputCommandIntegerOption } from '../options/integer.js';
|
|
8
|
+
import { ChatInputCommandMentionableOption } from '../options/mentionable.js';
|
|
9
|
+
import { ChatInputCommandNumberOption } from '../options/number.js';
|
|
10
|
+
import { ChatInputCommandRoleOption } from '../options/role.js';
|
|
11
|
+
import { ChatInputCommandStringOption } from '../options/string.js';
|
|
12
|
+
import { ChatInputCommandUserOption } from '../options/user.js';
|
|
13
|
+
|
|
14
|
+
export interface SharedChatInputCommandOptionsData {
|
|
15
|
+
options?: ApplicationCommandOptionBase[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This mixin holds symbols that can be shared in chat input command options.
|
|
20
|
+
*/
|
|
21
|
+
export class SharedChatInputCommandOptions {
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
declare protected readonly data: SharedChatInputCommandOptionsData;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The options within this command.
|
|
29
|
+
*/
|
|
30
|
+
public get options(): readonly ApplicationCommandOptionBase[] {
|
|
31
|
+
return (this.data.options ??= []);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Adds boolean options.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Options to add
|
|
38
|
+
*/
|
|
39
|
+
public addBooleanOptions(
|
|
40
|
+
...options: RestOrArray<
|
|
41
|
+
ChatInputCommandBooleanOption | ((builder: ChatInputCommandBooleanOption) => ChatInputCommandBooleanOption)
|
|
42
|
+
>
|
|
43
|
+
) {
|
|
44
|
+
return this.sharedAddOptions(ChatInputCommandBooleanOption, ...options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Adds user options.
|
|
49
|
+
*
|
|
50
|
+
* @param options - Options to add
|
|
51
|
+
*/
|
|
52
|
+
public addUserOptions(
|
|
53
|
+
...options: RestOrArray<
|
|
54
|
+
ChatInputCommandUserOption | ((builder: ChatInputCommandUserOption) => ChatInputCommandUserOption)
|
|
55
|
+
>
|
|
56
|
+
) {
|
|
57
|
+
return this.sharedAddOptions(ChatInputCommandUserOption, ...options);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Adds channel options.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Options to add
|
|
64
|
+
*/
|
|
65
|
+
public addChannelOptions(
|
|
66
|
+
...options: RestOrArray<
|
|
67
|
+
ChatInputCommandChannelOption | ((builder: ChatInputCommandChannelOption) => ChatInputCommandChannelOption)
|
|
68
|
+
>
|
|
69
|
+
) {
|
|
70
|
+
return this.sharedAddOptions(ChatInputCommandChannelOption, ...options);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds role options.
|
|
75
|
+
*
|
|
76
|
+
* @param options - Options to add
|
|
77
|
+
*/
|
|
78
|
+
public addRoleOptions(
|
|
79
|
+
...options: RestOrArray<
|
|
80
|
+
ChatInputCommandRoleOption | ((builder: ChatInputCommandRoleOption) => ChatInputCommandRoleOption)
|
|
81
|
+
>
|
|
82
|
+
) {
|
|
83
|
+
return this.sharedAddOptions(ChatInputCommandRoleOption, ...options);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Adds attachment options.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Options to add
|
|
90
|
+
*/
|
|
91
|
+
public addAttachmentOptions(
|
|
92
|
+
...options: RestOrArray<
|
|
93
|
+
| ChatInputCommandAttachmentOption
|
|
94
|
+
| ((builder: ChatInputCommandAttachmentOption) => ChatInputCommandAttachmentOption)
|
|
95
|
+
>
|
|
96
|
+
) {
|
|
97
|
+
return this.sharedAddOptions(ChatInputCommandAttachmentOption, ...options);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Adds mentionable options.
|
|
102
|
+
*
|
|
103
|
+
* @param options - Options to add
|
|
104
|
+
*/
|
|
105
|
+
public addMentionableOptions(
|
|
106
|
+
...options: RestOrArray<
|
|
107
|
+
| ChatInputCommandMentionableOption
|
|
108
|
+
| ((builder: ChatInputCommandMentionableOption) => ChatInputCommandMentionableOption)
|
|
109
|
+
>
|
|
110
|
+
) {
|
|
111
|
+
return this.sharedAddOptions(ChatInputCommandMentionableOption, ...options);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Adds string options.
|
|
116
|
+
*
|
|
117
|
+
* @param options - Options to add
|
|
118
|
+
*/
|
|
119
|
+
public addStringOptions(
|
|
120
|
+
...options: RestOrArray<
|
|
121
|
+
ChatInputCommandStringOption | ((builder: ChatInputCommandStringOption) => ChatInputCommandStringOption)
|
|
122
|
+
>
|
|
123
|
+
) {
|
|
124
|
+
return this.sharedAddOptions(ChatInputCommandStringOption, ...options);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Adds integer options.
|
|
129
|
+
*
|
|
130
|
+
* @param options - Options to add
|
|
131
|
+
*/
|
|
132
|
+
public addIntegerOptions(
|
|
133
|
+
...options: RestOrArray<
|
|
134
|
+
ChatInputCommandIntegerOption | ((builder: ChatInputCommandIntegerOption) => ChatInputCommandIntegerOption)
|
|
135
|
+
>
|
|
136
|
+
) {
|
|
137
|
+
return this.sharedAddOptions(ChatInputCommandIntegerOption, ...options);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Adds number options.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Options to add
|
|
144
|
+
*/
|
|
145
|
+
public addNumberOptions(
|
|
146
|
+
...options: RestOrArray<
|
|
147
|
+
ChatInputCommandNumberOption | ((builder: ChatInputCommandNumberOption) => ChatInputCommandNumberOption)
|
|
148
|
+
>
|
|
149
|
+
) {
|
|
150
|
+
return this.sharedAddOptions(ChatInputCommandNumberOption, ...options);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Removes, replaces, or inserts options for this command.
|
|
155
|
+
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* This method behaves similarly
|
|
158
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
159
|
+
*
|
|
160
|
+
* It's useful for modifying and adjusting order of the already-existing options for this command.
|
|
161
|
+
* @example
|
|
162
|
+
* Remove the first option:
|
|
163
|
+
* ```ts
|
|
164
|
+
* actionRow.spliceOptions(0, 1);
|
|
165
|
+
* ```
|
|
166
|
+
* @example
|
|
167
|
+
* Remove the first n options:
|
|
168
|
+
* ```ts
|
|
169
|
+
* const n = 4;
|
|
170
|
+
* actionRow.spliceOptions(0, n);
|
|
171
|
+
* ```
|
|
172
|
+
* @example
|
|
173
|
+
* Remove the last option:
|
|
174
|
+
* ```ts
|
|
175
|
+
* actionRow.spliceOptions(-1, 1);
|
|
176
|
+
* ```
|
|
177
|
+
* @param index - The index to start at
|
|
178
|
+
* @param deleteCount - The number of options to remove
|
|
179
|
+
* @param options - The replacing option objects
|
|
180
|
+
*/
|
|
181
|
+
public spliceOptions(index: number, deleteCount: number, ...options: ApplicationCommandOptionBase[]): this {
|
|
182
|
+
this.data.options ??= [];
|
|
183
|
+
this.data.options.splice(index, deleteCount, ...options);
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Where the actual adding magic happens. ✨
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
private sharedAddOptions<OptionBuilder extends ApplicationCommandOptionBase>(
|
|
193
|
+
Instance: new () => OptionBuilder,
|
|
194
|
+
...options: RestOrArray<OptionBuilder | ((builder: OptionBuilder) => OptionBuilder)>
|
|
195
|
+
): this {
|
|
196
|
+
const normalized = normalizeArray(options);
|
|
197
|
+
const resolved = normalized.map((option) => resolveBuilder(option, Instance));
|
|
198
|
+
|
|
199
|
+
this.data.options ??= [];
|
|
200
|
+
this.data.options.push(...resolved);
|
|
201
|
+
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { RestOrArray } from '../../../../util/normalizeArray.js';
|
|
2
|
+
import { normalizeArray } from '../../../../util/normalizeArray.js';
|
|
3
|
+
import { resolveBuilder } from '../../../../util/resolveBuilder.js';
|
|
4
|
+
import {
|
|
5
|
+
ChatInputCommandSubcommandGroupBuilder,
|
|
6
|
+
ChatInputCommandSubcommandBuilder,
|
|
7
|
+
} from '../ChatInputCommandSubcommands.js';
|
|
8
|
+
|
|
9
|
+
export interface SharedChatInputCommandSubcommandsData {
|
|
10
|
+
options?: (ChatInputCommandSubcommandBuilder | ChatInputCommandSubcommandGroupBuilder)[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This mixin holds symbols that can be shared in chat input subcommands.
|
|
15
|
+
*/
|
|
16
|
+
export class SharedChatInputCommandSubcommands {
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
declare protected readonly data: SharedChatInputCommandSubcommandsData;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Adds subcommand groups to this command.
|
|
24
|
+
*
|
|
25
|
+
* @param input - Subcommand groups to add
|
|
26
|
+
*/
|
|
27
|
+
public addSubcommandGroups(
|
|
28
|
+
...input: RestOrArray<
|
|
29
|
+
| ChatInputCommandSubcommandGroupBuilder
|
|
30
|
+
| ((subcommandGroup: ChatInputCommandSubcommandGroupBuilder) => ChatInputCommandSubcommandGroupBuilder)
|
|
31
|
+
>
|
|
32
|
+
): this {
|
|
33
|
+
const normalized = normalizeArray(input);
|
|
34
|
+
const resolved = normalized.map((value) => resolveBuilder(value, ChatInputCommandSubcommandGroupBuilder));
|
|
35
|
+
|
|
36
|
+
this.data.options ??= [];
|
|
37
|
+
this.data.options.push(...resolved);
|
|
38
|
+
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Adds subcommands to this command.
|
|
44
|
+
*
|
|
45
|
+
* @param input - Subcommands to add
|
|
46
|
+
*/
|
|
47
|
+
public addSubcommands(
|
|
48
|
+
...input: RestOrArray<
|
|
49
|
+
| ChatInputCommandSubcommandBuilder
|
|
50
|
+
| ((subcommandGroup: ChatInputCommandSubcommandBuilder) => ChatInputCommandSubcommandBuilder)
|
|
51
|
+
>
|
|
52
|
+
): this {
|
|
53
|
+
const normalized = normalizeArray(input);
|
|
54
|
+
const resolved = normalized.map((value) => resolveBuilder(value, ChatInputCommandSubcommandBuilder));
|
|
55
|
+
|
|
56
|
+
this.data.options ??= [];
|
|
57
|
+
this.data.options.push(...resolved);
|
|
58
|
+
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { JSONEncodable } from '@ovencord/util';
|
|
2
|
+
import type {
|
|
3
|
+
APIApplicationCommandBasicOption,
|
|
4
|
+
APIApplicationCommandOption,
|
|
5
|
+
ApplicationCommandOptionType,
|
|
6
|
+
} from 'discord-api-types/v10';
|
|
7
|
+
import type { z } from 'zod';
|
|
8
|
+
import { validate } from '../../../../util/validation.js';
|
|
9
|
+
import type { SharedNameAndDescriptionData } from '../../SharedNameAndDescription.js';
|
|
10
|
+
import { SharedNameAndDescription } from '../../SharedNameAndDescription.js';
|
|
11
|
+
|
|
12
|
+
export interface ApplicationCommandOptionBaseData extends Partial<Pick<APIApplicationCommandOption, 'required'>> {
|
|
13
|
+
type: ApplicationCommandOptionType;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The base application command option builder that contains common symbols for application command builders.
|
|
18
|
+
*/
|
|
19
|
+
export abstract class ApplicationCommandOptionBase
|
|
20
|
+
extends SharedNameAndDescription
|
|
21
|
+
implements JSONEncodable<APIApplicationCommandBasicOption>
|
|
22
|
+
{
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
protected static readonly predicate: z.ZodType;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
declare protected readonly data: ApplicationCommandOptionBaseData & SharedNameAndDescriptionData;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new application command option builder.
|
|
35
|
+
*
|
|
36
|
+
* @param type - The type of the option
|
|
37
|
+
*/
|
|
38
|
+
public constructor(type: ApplicationCommandOptionType) {
|
|
39
|
+
super();
|
|
40
|
+
this.data.type = type;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Sets whether this option is required.
|
|
45
|
+
*
|
|
46
|
+
* @param required - Whether this option should be required
|
|
47
|
+
*/
|
|
48
|
+
public setRequired(required = true) {
|
|
49
|
+
this.data.required = required;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Serializes this builder to API-compatible JSON data.
|
|
55
|
+
*
|
|
56
|
+
* Note that by disabling validation, there is no guarantee that the resulting object will be valid.
|
|
57
|
+
*
|
|
58
|
+
* @param validationOverride - Force validation to run/not run regardless of your global preference
|
|
59
|
+
*/
|
|
60
|
+
public toJSON(validationOverride?: boolean): APIApplicationCommandBasicOption {
|
|
61
|
+
const clone = structuredClone(this.data);
|
|
62
|
+
validate((this.constructor as typeof ApplicationCommandOptionBase).predicate, clone, validationOverride);
|
|
63
|
+
|
|
64
|
+
return clone as APIApplicationCommandBasicOption;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { attachmentOptionPredicate } from '../Assertions.js';
|
|
3
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A chat input command attachment option.
|
|
7
|
+
*/
|
|
8
|
+
export class ChatInputCommandAttachmentOption extends ApplicationCommandOptionBase {
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
protected static override readonly predicate = attachmentOptionPredicate;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new attachment option.
|
|
16
|
+
*/
|
|
17
|
+
public constructor() {
|
|
18
|
+
super(ApplicationCommandOptionType.Attachment);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { booleanOptionPredicate } from '../Assertions.js';
|
|
3
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A chat input command boolean option.
|
|
7
|
+
*/
|
|
8
|
+
export class ChatInputCommandBooleanOption extends ApplicationCommandOptionBase {
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
protected static override readonly predicate = booleanOptionPredicate;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new boolean option.
|
|
16
|
+
*/
|
|
17
|
+
public constructor() {
|
|
18
|
+
super(ApplicationCommandOptionType.Boolean);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { Mixin } from 'ts-mixer';
|
|
3
|
+
import { channelOptionPredicate } from '../Assertions.js';
|
|
4
|
+
import { ApplicationCommandOptionChannelTypesMixin } from '../mixins/ApplicationCommandOptionChannelTypesMixin.js';
|
|
5
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A chat input command channel option.
|
|
9
|
+
*
|
|
10
|
+
* @mixes {@link ApplicationCommandOptionBase}
|
|
11
|
+
* @mixes {@link ApplicationCommandOptionChannelTypesMixin}
|
|
12
|
+
*/
|
|
13
|
+
export class ChatInputCommandChannelOption extends Mixin(
|
|
14
|
+
ApplicationCommandOptionBase,
|
|
15
|
+
ApplicationCommandOptionChannelTypesMixin,
|
|
16
|
+
) {
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
protected static override readonly predicate = channelOptionPredicate;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new channel option.
|
|
24
|
+
*/
|
|
25
|
+
public constructor() {
|
|
26
|
+
super(ApplicationCommandOptionType.Channel);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { Mixin } from 'ts-mixer';
|
|
3
|
+
import { integerOptionPredicate } from '../Assertions.js';
|
|
4
|
+
import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';
|
|
5
|
+
import { ApplicationCommandOptionWithAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithAutocompleteMixin.js';
|
|
6
|
+
import { ApplicationCommandOptionWithChoicesMixin } from '../mixins/ApplicationCommandOptionWithChoicesMixin.js';
|
|
7
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A chat input command integer option.
|
|
11
|
+
*
|
|
12
|
+
* @mixes {@link ApplicationCommandOptionBase}
|
|
13
|
+
* @mixes {@link ApplicationCommandNumericOptionMinMaxValueMixin}
|
|
14
|
+
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
|
|
15
|
+
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<number\>
|
|
16
|
+
*/
|
|
17
|
+
export class ChatInputCommandIntegerOption extends Mixin(
|
|
18
|
+
ApplicationCommandOptionBase,
|
|
19
|
+
ApplicationCommandNumericOptionMinMaxValueMixin,
|
|
20
|
+
ApplicationCommandOptionWithAutocompleteMixin,
|
|
21
|
+
ApplicationCommandOptionWithChoicesMixin<number>,
|
|
22
|
+
) {
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
protected static override readonly predicate = integerOptionPredicate;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new integer option.
|
|
30
|
+
*/
|
|
31
|
+
public constructor() {
|
|
32
|
+
super(ApplicationCommandOptionType.Integer);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { mentionableOptionPredicate } from '../Assertions.js';
|
|
3
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A chat input command mentionable option.
|
|
7
|
+
*/
|
|
8
|
+
export class ChatInputCommandMentionableOption extends ApplicationCommandOptionBase {
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
protected static override readonly predicate = mentionableOptionPredicate;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new mentionable option.
|
|
16
|
+
*/
|
|
17
|
+
public constructor() {
|
|
18
|
+
super(ApplicationCommandOptionType.Mentionable);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { Mixin } from 'ts-mixer';
|
|
3
|
+
import { numberOptionPredicate } from '../Assertions.js';
|
|
4
|
+
import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';
|
|
5
|
+
import { ApplicationCommandOptionWithAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithAutocompleteMixin.js';
|
|
6
|
+
import { ApplicationCommandOptionWithChoicesMixin } from '../mixins/ApplicationCommandOptionWithChoicesMixin.js';
|
|
7
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A chat input command number option.
|
|
11
|
+
*
|
|
12
|
+
* @mixes {@link ApplicationCommandOptionBase}
|
|
13
|
+
* @mixes {@link ApplicationCommandNumericOptionMinMaxValueMixin}
|
|
14
|
+
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
|
|
15
|
+
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<number\>
|
|
16
|
+
*/
|
|
17
|
+
export class ChatInputCommandNumberOption extends Mixin(
|
|
18
|
+
ApplicationCommandOptionBase,
|
|
19
|
+
ApplicationCommandNumericOptionMinMaxValueMixin,
|
|
20
|
+
ApplicationCommandOptionWithAutocompleteMixin,
|
|
21
|
+
ApplicationCommandOptionWithChoicesMixin<number>,
|
|
22
|
+
) {
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
protected static override readonly predicate = numberOptionPredicate;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new number option.
|
|
30
|
+
*/
|
|
31
|
+
public constructor() {
|
|
32
|
+
super(ApplicationCommandOptionType.Number);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { roleOptionPredicate } from '../Assertions.js';
|
|
3
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A chat input command role option.
|
|
7
|
+
*/
|
|
8
|
+
export class ChatInputCommandRoleOption extends ApplicationCommandOptionBase {
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
protected static override readonly predicate = roleOptionPredicate;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new role option.
|
|
16
|
+
*/
|
|
17
|
+
public constructor() {
|
|
18
|
+
super(ApplicationCommandOptionType.Role);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType, type APIApplicationCommandStringOption } from 'discord-api-types/v10';
|
|
2
|
+
import { Mixin } from 'ts-mixer';
|
|
3
|
+
import { stringOptionPredicate } from '../Assertions.js';
|
|
4
|
+
import type { ApplicationCommandOptionWithAutocompleteData } from '../mixins/ApplicationCommandOptionWithAutocompleteMixin.js';
|
|
5
|
+
import { ApplicationCommandOptionWithAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithAutocompleteMixin.js';
|
|
6
|
+
import type { ApplicationCommandOptionWithChoicesData } from '../mixins/ApplicationCommandOptionWithChoicesMixin.js';
|
|
7
|
+
import { ApplicationCommandOptionWithChoicesMixin } from '../mixins/ApplicationCommandOptionWithChoicesMixin.js';
|
|
8
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
9
|
+
import type { ApplicationCommandOptionBaseData } from './ApplicationCommandOptionBase.js';
|
|
10
|
+
|
|
11
|
+
export class ChatInputCommandStringOption extends Mixin(
|
|
12
|
+
ApplicationCommandOptionBase,
|
|
13
|
+
ApplicationCommandOptionWithAutocompleteMixin,
|
|
14
|
+
ApplicationCommandOptionWithChoicesMixin<string>,
|
|
15
|
+
) {
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
protected static override readonly predicate = stringOptionPredicate;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
declare protected readonly data: ApplicationCommandOptionBaseData &
|
|
25
|
+
ApplicationCommandOptionWithAutocompleteData &
|
|
26
|
+
ApplicationCommandOptionWithChoicesData &
|
|
27
|
+
Partial<Pick<APIApplicationCommandStringOption, 'max_length' | 'min_length'>>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new string option builder.
|
|
31
|
+
*/
|
|
32
|
+
public constructor() {
|
|
33
|
+
super(ApplicationCommandOptionType.String);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Sets the maximum length of this string option.
|
|
38
|
+
*
|
|
39
|
+
* @param max - The maximum length this option can be
|
|
40
|
+
*/
|
|
41
|
+
public setMaxLength(max: number): this {
|
|
42
|
+
this.data.max_length = max;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Clears the maximum length of this string option.
|
|
48
|
+
*/
|
|
49
|
+
public clearMaxLength(): this {
|
|
50
|
+
this.data.max_length = undefined;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Sets the minimum length of this string option.
|
|
56
|
+
*
|
|
57
|
+
* @param min - The minimum length this option can be
|
|
58
|
+
*/
|
|
59
|
+
public setMinLength(min: number): this {
|
|
60
|
+
this.data.min_length = min;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clears the minimum length of this string option.
|
|
66
|
+
*/
|
|
67
|
+
public clearMinLength(): this {
|
|
68
|
+
this.data.min_length = undefined;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApplicationCommandOptionType } from 'discord-api-types/v10';
|
|
2
|
+
import { userOptionPredicate } from '../Assertions.js';
|
|
3
|
+
import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A chat input command user option.
|
|
7
|
+
*/
|
|
8
|
+
export class ChatInputCommandUserOption extends ApplicationCommandOptionBase {
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
protected static override readonly predicate = userOptionPredicate;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new user option.
|
|
16
|
+
*/
|
|
17
|
+
public constructor() {
|
|
18
|
+
super(ApplicationCommandOptionType.User);
|
|
19
|
+
}
|
|
20
|
+
}
|