| 1 | import { uuidv4 } from '../utils.js'; |
| 2 | import { SlashCommand } from './SlashCommand.js'; |
| 3 | import { SlashCommandClosure } from './SlashCommandClosure.js'; |
| 4 | import { SlashCommandNamedArgumentAssignment } from './SlashCommandNamedArgumentAssignment.js'; |
| 5 | import { SlashCommandUnnamedArgumentAssignment } from './SlashCommandUnnamedArgumentAssignment.js'; |
| 6 | |
| 7 | export class SlashCommandExecutor { |
| 8 | /**@type {Boolean}*/ injectPipe = true; |
| 9 | /**@type {Number}*/ start; |
| 10 | /**@type {Number}*/ end; |
| 11 | /**@type {Number}*/ startNamedArgs; |
| 12 | /**@type {Number}*/ endNamedArgs; |
| 13 | /**@type {Number}*/ startUnnamedArgs; |
| 14 | /**@type {Number}*/ endUnnamedArgs; |
| 15 | /**@type {String}*/ name = ''; |
| 16 | /**@type {String}*/ #source = uuidv4(); |
| 17 | get source() { return this.#source; } |
| 18 | set source(value) { |
| 19 | this.#source = value; |
| 20 | for (const arg of this.namedArgumentList.filter(it => it.value instanceof SlashCommandClosure)) { |
| 21 | arg.value.source = value; |
| 22 | } |
| 23 | for (const arg of this.unnamedArgumentList.filter(it => it.value instanceof SlashCommandClosure)) { |
| 24 | arg.value.source = value; |
| 25 | } |
| 26 | } |
| 27 | /** @type {SlashCommand} */ command; |
| 28 | /** @type {SlashCommandNamedArgumentAssignment[]} */ namedArgumentList = []; |
| 29 | /** @type {SlashCommandUnnamedArgumentAssignment[]} */ unnamedArgumentList = []; |
| 30 | /** @type {import('./SlashCommandParser.js').ParserFlags} */ parserFlags; |
| 31 | |
| 32 | get commandCount() { |
| 33 | return 1 |
| 34 | + this.namedArgumentList.filter(it => it.value instanceof SlashCommandClosure).map(it =>/**@type {SlashCommandClosure}*/(it.value).commandCount).reduce((cur, sum) => cur + sum, 0) |
| 35 | + this.unnamedArgumentList.filter(it => it.value instanceof SlashCommandClosure).map(it =>/**@type {SlashCommandClosure}*/(it.value).commandCount).reduce((cur, sum) => cur + sum, 0) |
| 36 | ; |
| 37 | } |
| 38 | |
| 39 | set onProgress(value) { |
| 40 | const closures = /**@type {SlashCommandClosure[]}*/([ |
| 41 | ...this.namedArgumentList.filter(it => it.value instanceof SlashCommandClosure).map(it => it.value), |
| 42 | ...this.unnamedArgumentList.filter(it => it.value instanceof SlashCommandClosure).map(it => it.value), |
| 43 | ]); |
| 44 | for (const closure of closures) { |
| 45 | closure.onProgress = value; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | constructor(start) { |
| 50 | this.start = start; |
| 51 | } |
| 52 | } |