2024-05-12 21:15:05 +02:00
|
|
|
import { SlashCommandClosure } from './SlashCommandClosure.js';
|
|
|
|
import { SlashCommandEnumValue } from './SlashCommandEnumValue.js';
|
2024-06-14 23:48:41 +02:00
|
|
|
import { SlashCommandExecutor } from './SlashCommandExecutor.js';
|
2024-05-12 21:15:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**@readonly*/
|
|
|
|
/**@enum {string}*/
|
|
|
|
export const ARGUMENT_TYPE = {
|
|
|
|
'STRING': 'string',
|
|
|
|
'NUMBER': 'number',
|
|
|
|
'RANGE': 'range',
|
|
|
|
'BOOLEAN': 'bool',
|
|
|
|
'VARIABLE_NAME': 'varname',
|
|
|
|
'CLOSURE': 'closure',
|
|
|
|
'SUBCOMMAND': 'subcommand',
|
|
|
|
'LIST': 'list',
|
|
|
|
'DICTIONARY': 'dictionary',
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class SlashCommandArgument {
|
|
|
|
/**
|
2024-05-30 13:49:57 +02:00
|
|
|
* Creates an unnamed argument from a properties object.
|
2024-05-12 21:15:05 +02:00
|
|
|
* @param {Object} props
|
|
|
|
* @param {string} props.description description of the argument
|
|
|
|
* @param {ARGUMENT_TYPE|ARGUMENT_TYPE[]} props.typeList default: ARGUMENT_TYPE.STRING - list of accepted types (from ARGUMENT_TYPE)
|
|
|
|
* @param {boolean} [props.isRequired] default: false - whether the argument is required (false = optional argument)
|
|
|
|
* @param {boolean} [props.acceptsMultiple] default: false - whether argument accepts multiple values
|
|
|
|
* @param {string|SlashCommandClosure} [props.defaultValue] default value if no value is provided
|
|
|
|
* @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} [props.enumList] list of accepted values
|
2024-06-14 23:48:41 +02:00
|
|
|
* @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} [props.enumProvider] function that returns auto complete options
|
|
|
|
* @param {boolean} [props.forceEnum] default: true - whether the input must match one of the enum values
|
2024-05-12 21:15:05 +02:00
|
|
|
*/
|
|
|
|
static fromProps(props) {
|
|
|
|
return new SlashCommandArgument(
|
|
|
|
props.description,
|
|
|
|
props.typeList ?? [ARGUMENT_TYPE.STRING],
|
|
|
|
props.isRequired ?? false,
|
|
|
|
props.acceptsMultiple ?? false,
|
|
|
|
props.defaultValue ?? null,
|
|
|
|
props.enumList ?? [],
|
2024-06-14 23:48:41 +02:00
|
|
|
props.enumProvider ?? null,
|
|
|
|
props.forceEnum ?? true,
|
2024-05-12 21:15:05 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**@type {string}*/ description;
|
|
|
|
/**@type {ARGUMENT_TYPE[]}*/ typeList = [];
|
|
|
|
/**@type {boolean}*/ isRequired = false;
|
|
|
|
/**@type {boolean}*/ acceptsMultiple = false;
|
|
|
|
/**@type {string|SlashCommandClosure}*/ defaultValue;
|
|
|
|
/**@type {SlashCommandEnumValue[]}*/ enumList = [];
|
2024-06-14 23:48:41 +02:00
|
|
|
/**@type {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]}*/ enumProvider = null;
|
|
|
|
/**@type {boolean}*/ forceEnum = true;
|
2024-05-12 21:15:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} description
|
|
|
|
* @param {ARGUMENT_TYPE|ARGUMENT_TYPE[]} types
|
|
|
|
* @param {string|SlashCommandClosure} defaultValue
|
|
|
|
* @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} enums
|
2024-06-14 23:48:41 +02:00
|
|
|
* @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} enumProvider function that returns auto complete options
|
2024-05-12 21:15:05 +02:00
|
|
|
*/
|
2024-06-14 23:48:41 +02:00
|
|
|
constructor(description, types, isRequired = false, acceptsMultiple = false, defaultValue = null, enums = [], enumProvider = null, forceEnum = true) {
|
2024-05-12 21:15:05 +02:00
|
|
|
this.description = description;
|
|
|
|
this.typeList = types ? Array.isArray(types) ? types : [types] : [];
|
|
|
|
this.isRequired = isRequired ?? false;
|
|
|
|
this.acceptsMultiple = acceptsMultiple ?? false;
|
|
|
|
this.defaultValue = defaultValue;
|
|
|
|
this.enumList = (enums ? Array.isArray(enums) ? enums : [enums] : []).map(it=>{
|
|
|
|
if (it instanceof SlashCommandEnumValue) return it;
|
|
|
|
return new SlashCommandEnumValue(it);
|
|
|
|
});
|
2024-06-14 23:48:41 +02:00
|
|
|
this.enumProvider = enumProvider;
|
|
|
|
this.forceEnum = forceEnum;
|
2024-05-12 21:15:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class SlashCommandNamedArgument extends SlashCommandArgument {
|
|
|
|
/**
|
2024-05-30 13:49:57 +02:00
|
|
|
* Creates an unnamed argument from a properties object.
|
2024-05-12 21:15:05 +02:00
|
|
|
* @param {Object} props
|
|
|
|
* @param {string} props.name the argument's name
|
|
|
|
* @param {string[]} [props.aliasList] list of aliases
|
|
|
|
* @param {string} props.description description of the argument
|
|
|
|
* @param {ARGUMENT_TYPE|ARGUMENT_TYPE[]} props.typeList default: ARGUMENT_TYPE.STRING - list of accepted types (from ARGUMENT_TYPE)
|
|
|
|
* @param {boolean} [props.isRequired] default: false - whether the argument is required (false = optional argument)
|
|
|
|
* @param {boolean} [props.acceptsMultiple] default: false - whether argument accepts multiple values
|
|
|
|
* @param {string|SlashCommandClosure} [props.defaultValue] default value if no value is provided
|
|
|
|
* @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} [props.enumList] list of accepted values
|
2024-06-14 23:48:41 +02:00
|
|
|
* @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} [props.enumProvider] function that returns auto complete options
|
|
|
|
* @param {boolean} [props.forceEnum] default: true - whether the input must match one of the enum values
|
2024-05-12 21:15:05 +02:00
|
|
|
*/
|
|
|
|
static fromProps(props) {
|
|
|
|
return new SlashCommandNamedArgument(
|
|
|
|
props.name,
|
|
|
|
props.description,
|
|
|
|
props.typeList ?? [ARGUMENT_TYPE.STRING],
|
|
|
|
props.isRequired ?? false,
|
|
|
|
props.acceptsMultiple ?? false,
|
|
|
|
props.defaultValue ?? null,
|
|
|
|
props.enumList ?? [],
|
|
|
|
props.aliasList ?? [],
|
2024-06-14 23:48:41 +02:00
|
|
|
props.enumProvider ?? null,
|
|
|
|
props.forceEnum ?? true,
|
2024-05-12 21:15:05 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**@type {string}*/ name;
|
|
|
|
/**@type {string[]}*/ aliasList = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {string} description
|
|
|
|
* @param {ARGUMENT_TYPE|ARGUMENT_TYPE[]} types
|
|
|
|
* @param {string|SlashCommandClosure} defaultValue
|
|
|
|
* @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} enums
|
2024-06-14 23:48:41 +02:00
|
|
|
* @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} enumProvider function that returns auto complete options
|
|
|
|
* @param {boolean} forceEnum
|
2024-05-12 21:15:05 +02:00
|
|
|
*/
|
2024-06-14 23:48:41 +02:00
|
|
|
constructor(name, description, types, isRequired = false, acceptsMultiple = false, defaultValue = null, enums = [], aliases = [], enumProvider = null, forceEnum = true) {
|
|
|
|
super(description, types, isRequired, acceptsMultiple, defaultValue, enums, enumProvider, forceEnum);
|
2024-05-12 21:15:05 +02:00
|
|
|
this.name = name;
|
|
|
|
this.aliasList = aliases ? Array.isArray(aliases) ? aliases : [aliases] : [];
|
|
|
|
}
|
|
|
|
}
|