more flexibililty for enums
custom mapping from enum value class to enum option class
This commit is contained in:
parent
b51bf8e38e
commit
4b5704896d
|
@ -115,7 +115,7 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult {
|
|||
const result = new AutoCompleteSecondaryNameResult(
|
||||
value,
|
||||
start + name.length,
|
||||
enumList.map(it=>new SlashCommandEnumAutoCompleteOption(this.executor.command, it)),
|
||||
enumList.map(it=>SlashCommandEnumAutoCompleteOption.from(this.executor.command, it)),
|
||||
true,
|
||||
);
|
||||
result.isRequired = true;
|
||||
|
@ -182,7 +182,7 @@ export class SlashCommandAutoCompleteNameResult extends AutoCompleteNameResult {
|
|||
const result = new AutoCompleteSecondaryNameResult(
|
||||
value,
|
||||
start,
|
||||
enumList.map(it=>new SlashCommandEnumAutoCompleteOption(this.executor.command, it)),
|
||||
enumList.map(it=>SlashCommandEnumAutoCompleteOption.from(this.executor.command, it)),
|
||||
false,
|
||||
);
|
||||
const isCompleteValue = enumList.find(it=>it.value == value);
|
||||
|
|
|
@ -3,6 +3,17 @@ import { SlashCommand } from './SlashCommand.js';
|
|||
import { SlashCommandEnumValue } from './SlashCommandEnumValue.js';
|
||||
|
||||
export class SlashCommandEnumAutoCompleteOption extends AutoCompleteOption {
|
||||
/**
|
||||
* @param {SlashCommand} cmd
|
||||
* @param {SlashCommandEnumValue} enumValue
|
||||
* @returns {SlashCommandEnumAutoCompleteOption}
|
||||
*/
|
||||
static from(cmd, enumValue) {
|
||||
const mapped = this.valueToOptionMap.find(it=>enumValue instanceof it.value)?.option ?? this;
|
||||
return new mapped(cmd, enumValue);
|
||||
}
|
||||
/**@type {{value:(typeof SlashCommandEnumValue), option:(typeof SlashCommandEnumAutoCompleteOption)}[]} */
|
||||
static valueToOptionMap = [];
|
||||
/**@type {SlashCommand}*/ cmd;
|
||||
/**@type {SlashCommandEnumValue}*/ enumValue;
|
||||
|
||||
|
|
Loading…
Reference in New Issue