| 1 | /** |
| 2 | * @typedef {'enum' | 'command' | 'namedArgument' | 'variable' | 'qr' | 'macro' | 'number' | 'name'} EnumType |
| 3 | */ |
| 4 | |
| 5 | /** |
| 6 | * Collection of the enum types that can be used with `SlashCommandEnumValue` |
| 7 | * |
| 8 | * Contains documentation on which color this will result to |
| 9 | */ |
| 10 | export const enumTypes = { |
| 11 | /** 'enum' - [string] - light orange @type {EnumType} */ |
| 12 | enum: 'enum', |
| 13 | /** 'command' - [cmd] - light yellow @type {EnumType} */ |
| 14 | command: 'command', |
| 15 | /** 'namedArgument' - [argName] - sky blue @type {EnumType} */ |
| 16 | namedArgument: 'namedArgument', |
| 17 | /** 'variable' - [punctuationL1] - pink @type {EnumType} */ |
| 18 | variable: 'variable', |
| 19 | /** 'qr' - [variable] - light blue @type {EnumType} */ |
| 20 | qr: 'qr', |
| 21 | /** 'macro' - [variableLanguage] - blue @type {EnumType} */ |
| 22 | macro: 'macro', |
| 23 | /** 'number' - [number] - light green @type {EnumType} */ |
| 24 | number: 'number', |
| 25 | /** 'name' - [type] - forest green @type {EnumType} */ |
| 26 | name: 'name', |
| 27 | |
| 28 | /** |
| 29 | * Gets the value of the enum type based on the provided index |
| 30 | * |
| 31 | * Can be used to get differing colors or even random colors, by providing the index of a unique set |
| 32 | * |
| 33 | * @param {number?} index - The index used to retrieve the enum type |
| 34 | * @return {EnumType} The enum type corresponding to the index |
| 35 | */ |
| 36 | getBasedOnIndex(index) { |
| 37 | const keys = Object.keys(this); |
| 38 | return this[keys[(index ?? 0) % keys.length]]; |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | export class SlashCommandEnumValue { |
| 43 | /**@type {string}*/ value; |
| 44 | /**@type {string}*/ description; |
| 45 | /**@type {EnumType}*/ type = 'enum'; |
| 46 | /**@type {string}*/ typeIcon = '◊'; |
| 47 | /**@type {(input:string)=>boolean}*/ matchProvider; |
| 48 | /**@type {(input:string)=>string}*/ valueProvider; |
| 49 | /**@type {boolean}*/ makeSelectable = false; |
| 50 | |
| 51 | /** |
| 52 | * A constructor for creating a SlashCommandEnumValue instance. |
| 53 | * |
| 54 | * @param {string} value - The value |
| 55 | * @param {string?} description - Optional description, displayed in a second line |
| 56 | * @param {EnumType?} type - type of the enum (defining its color) |
| 57 | * @param {string?} typeIcon - The icon to display (Can be pulled from `enumIcons` for common ones) |
| 58 | * @param {(input:string)=>boolean?} matchProvider - A custom function to match autocomplete input instead of startsWith/includes/fuzzy. Should only be used for generic options like "any number" or "any string". "input" is the part of the text that is getting auto completed. |
| 59 | * @param {(input:string)=>string?} valueProvider - A function returning a value to be used in autocomplete instead of the enum value. "input" is the part of the text that is getting auto completed. By default, values with a valueProvider will not be selectable in the autocomplete (with tab/enter). |
| 60 | * @param {boolean?} makeSelectable - Set to true to make the value selectable (through tab/enter) even though a valueProvider exists. |
| 61 | */ |
| 62 | constructor(value, description = null, type = 'enum', typeIcon = '◊', matchProvider = null, valueProvider = null, makeSelectable = false) { |
| 63 | this.value = value; |
| 64 | this.description = description; |
| 65 | this.type = type ?? 'enum'; |
| 66 | this.typeIcon = typeIcon; |
| 67 | this.matchProvider = matchProvider; |
| 68 | this.valueProvider = valueProvider; |
| 69 | this.makeSelectable = makeSelectable; |
| 70 | } |
| 71 | |
| 72 | toString() { |
| 73 | return this.value; |
| 74 | } |
| 75 | } |