MCPcopy Create free account
hub / github.com/Botloader/botloader / genCommandsBinding

Method genCommandsBinding

components/runtime/src/ts/script.ts:409–498  ·  view source on GitHub ↗

* @internal

()

Source from the content-addressed store, hash-verified

407 * @internal
408 */
409 genCommandsBinding(): [Internal.Command[], Internal.CommandGroup[]] {
410
411 const commands: Internal.Command[] = this.commands.map(cmd => {
412 const options: Internal.CommandOption[] = [];
413 for (let prop in cmd.options) {
414 if (Object.prototype.hasOwnProperty.call(cmd.options, prop)) {
415 let entry = cmd.options[prop];
416 options.push({
417 name: prop,
418 description: entry.description,
419 kind: entry.kind,
420 required: entry.required || false,
421 extraOptions: entry.extraOptions,
422 autocompleteEnabled: "autocomplete" in entry.extraOptions ? Boolean(entry.extraOptions.autocomplete) : false
423 })
424 }
425 }
426
427 let group = undefined;
428 let subGroup = undefined;
429 if (cmd.group) {
430 if (cmd.group.parent) {
431 group = cmd.group.parent.name;
432 subGroup = cmd.group.name;
433 } else {
434 group = cmd.group.name;
435 }
436 }
437
438 return {
439 name: cmd.name,
440 description: cmd.description,
441 options: options,
442 kind: cmd.kind,
443 group,
444 subGroup,
445 defaultMemberPermissions: cmd.defaultMemberPermissions,
446 }
447 });
448
449 // collect all the groups
450 const groups: Internal.CommandGroup[] = [];
451
452 OUTER:
453 for (let cmd of this.commands) {
454 if (cmd.group) {
455 if (cmd.group.parent) {
456 // this is a subgroup
457 let parent = groups.find(g => g.name === cmd.group?.parent?.name);
458 if (!parent) {
459 // parent did not exist
460 parent = {
461 name: cmd.group.parent.name,
462 description: cmd.group.description,
463 subGroups: [],
464 defaultMemberPermissions: cmd.group.parent.defaultMemberPermissions,
465 }
466 groups.push(parent);

Callers 1

runMethod · 0.95

Calls 1

callMethod · 0.45

Tested by

no test coverage detected