-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make builders types great again (#10026)
* refactor: make builders types great again * fix: subcommands only type --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fed7f34
commit a0c83a2
Showing
11 changed files
with
270 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...rs/src/interactions/slashCommands/mixins/ApplicationCommandOptionWithAutocompleteMixin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { s } from '@sapphire/shapeshift'; | ||
import type { ApplicationCommandOptionType } from 'discord-api-types/v10'; | ||
|
||
const booleanPredicate = s.boolean; | ||
|
||
/** | ||
* This mixin holds choices and autocomplete symbols used for options. | ||
*/ | ||
export class ApplicationCommandOptionWithAutocompleteMixin { | ||
/** | ||
* Whether this option utilizes autocomplete. | ||
*/ | ||
public readonly autocomplete?: boolean; | ||
|
||
/** | ||
* The type of this option. | ||
* | ||
* @privateRemarks Since this is present and this is a mixin, this is needed. | ||
*/ | ||
public readonly type!: ApplicationCommandOptionType; | ||
|
||
/** | ||
* Whether this option uses autocomplete. | ||
* | ||
* @param autocomplete - Whether this option should use autocomplete | ||
*/ | ||
public setAutocomplete(autocomplete: boolean): this { | ||
// Assert that you actually passed a boolean | ||
booleanPredicate.parse(autocomplete); | ||
|
||
if (autocomplete && 'choices' in this && Array.isArray(this.choices) && this.choices.length > 0) { | ||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.'); | ||
} | ||
|
||
Reflect.set(this, 'autocomplete', autocomplete); | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.