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0B,CAAA,SAAS,CAAI,CAAA,EAAA,OAAA,CAAQ,IAAI,CAAA,CAAA,CAAA;AAAA,KACrI;AAEA,IAAA,KAAA,CAAM,SAAS,EAAE,GAAG,OAAS,EAAA,IAAA,EAAM,aAAwB,CAAA,CAAA;AAE3D,IAAI,IAAA,IAAA,CAAK,QAAQ,kBAAoB,EAAA;AACpC,MAAA,MAAM,EAAE,iBAAA,EAAmB,eAAgB,EAAA,GAAI,KAAK,OAAQ,CAAA,kBAAA,CAAA;AAC5D,MAAwB,uBAAA,CAAA,IAAA,EAAM,mBAAmB,eAAe,CAAA,CAAA;AAAA,KACjE;AAEA,IAAI,IAAA,IAAA,CAAK,QAAQ,yBAA2B,EAAA;AAC3C,MAAA,MAAM,EAAE,iBAAmB,EAAA,SAAA,EAAW,eAAgB,EAAA,GAAI,KAAK,OAAQ,CAAA,yBAAA,CAAA;AACvE,MAA6B,4BAAA,CAAA,IAAA,EAAM,iBAAmB,EAAA,SAAA,EAAW,eAAe,CAAA,CAAA;AAAA,KACjF;AAAA,GACD;AACD,CAAA,CAAA;AA/BmD,MAAA,CAAA,QAAA,EAAA,SAAA,CAAA,CAAA;AAH5C,IAAM,OAAN,GAAA,SAAA;AA0IA,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBC,YAAyB,CAAA;AAAA,EAAlD,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AACN,IAAA,aAAA,CAAA,IAAA,EAAO,OAAQ,EAAA,wBAAA,CAAA,CAAA;AAAA,GAAA;AAChB,CAAA,CAAA;AAFyD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAlD,IAAM,UAAN,GAAA","file":"command.mjs","sourcesContent":["import {\n\tAliasPiece,\n\tApplicationCommandRegistry,\n\tArgs,\n\tCommand as SapphireCommand,\n\tcontainer,\n\ttype CommandJSON,\n\ttype CommandOptionsRunType,\n\ttype CommandRunInUnion,\n\ttype CommandSpecificRunIn\n} from '@sapphire/framework';\nimport { Subcommand as SapphirePluginSubcommand, type SubcommandOptions } from '@sapphire/plugin-subcommands';\n\nimport { RegisterSubcommandsHooks } from '../utils/const';\nimport { analizeSubcommandGroupParsed, analizeSubCommandParsed, parseSlashSubcommand } from '../utils/functions';\n\nimport type { CommandOptions } from '../utils/types';\nimport type { CacheType } from 'discord.js';\n\n/**\n * **Command**\n *\n * Command class extended from the original `@sapphire/framework` class that includes the methods to register subcommands based on command class.\n *\n * It is necessary to have a parent command that manages the subcommands configured with the plugin. The name of the parent command must be the same as the one set in the `prentCommandName` option of the command options.\n *\n * When creating the chatInputRun and messageRun methods (both are optional but one of them must always exist) the method will be automatically linked in the subcommand of the parent command.\n *\n * **Register the command as a subcommand in a parent command**\n *\n * To register commands as subcommands of the parent command it is necessary to use the `registerSubCommand` option of the command options.\n *\n * *Parent command*\n *\n * ```typescript\n * import { SubCommand } from '@kaname-png/plugin-subcommands-advanced';\n * import { ApplicationCommandRegistry } from '@sapphire/framework';\n *\n * export class ParentCommand extends SubCommand {\n * \t\tpublic constructor(context: Command.Context, options: Command.Options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tname: 'utils'\n * \t\t\t});\n * \t\t}\n *\n * \t\tpublic override registerApplicationCommands(interaction: ApplicationCommandRegistry) {\n * \t\t\tregistry.registerChatInputCommand(\n *\t\t\t\t(ctx) => {\n *\t\t\t\t\t// It is necessary to call this hook and pass the builder context to register the subcommands stored in the subcommand register in the parent command.\n *\t\t\t\t\tthis.hooks.subcommands(this, ctx);\n *\n *\t\t\t\t\treturn ctx\n *\t\t\t\t\t\t.setName(this.name)\n *\t\t\t\t\t\t.setDescription('Parent command of utils subcommands)\n *\t\t\t\t}\n *\t\t\t);\n * \t\t}\n * }\n * ```\n *\n * *With Typescript*\n * ```typescript\n * import { SubCommand } from '@kaname-png/plugin-subcommands-advanced'\n *\n * export class UtilsCommand extends SubCommand {\n * \t\tpublic constructor(context: Command.Context, options: Command.Options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tregisterSubCommand: {\n * \t\t\t\t\tparentCommandName: 'utils', // Name of the parent command (parent.js).\n * \t\t\t\t\tsubcommand: (builder) => builder.setName('ping').setDescription('Hi!') // Builder that will be embedded in the registry of the parent command.\n * \t\t\t\t}\n * \t\t\t});\n * \t\t}\n *\n * \t\tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\t\treturn interaction.reply('uwu');\n * \t\t}\n * }\n * ```\n *\n * *With JavaScript*\n *\n * ```javascript\n * import { Command } from '@kaname-png/plugin-subcommands-advanced'\n *\n * export class UtilsCommand extends Command {\n * \t\tconstructor(context, options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tregisterSubCommand: {\n * \t\t\t\t\tparentCommandName: 'utils', // Name of the parent command (parent.js).\n * \t\t\t\t\tsubcommand: (builder) => builder.setName('ping').setDescription('Hi!') // Builder that will be embedded in the registry of the parent command.\n * \t\t\t\t}\n * \t\t\t});\n * \t\t}\n *\n * \t\tchatInputRun(interaction) {\n * \t\t\treturn interaction.reply('uwu');\n * \t\t}\n * }\n * ```\n *\n * **Register a command as a subcommand of a group of subcommands of the parent command**\n *\n * To register commands as group subcommands it is important to first register the groups to be used in the main command.\n *\n * *Parent command*\n *\n * ```typescript\n * import { SubCommand } from '@kaname-png/plugin-subcommands-advanced';\n * import { ApplicationCommandRegistry } from '@sapphire/framework';\n *\n * export class ParentCommand extends SubCommand {\n * \t\tpublic constructor(context: Command.Context, options: Command.Options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tname: 'utils'\n * \t\t\t});\n * \t\t}\n *\n * \t\tpublic override registerApplicationCommands(interaction: ApplicationCommandRegistry) {\n * \t\t\tregistry.registerChatInputCommand(\n *\t\t\t\t(ctx) => {\n *\t\t\t\t\t// First it is necessary to register the subcommand groups in the context of the constructor.\n *\t\t\t\t\tctx.addSubcommandGroup((sc) =>\n *\t\t\t\t\t\tsc\n *\t\t\t\t\t\t\t.setName('poll')\n *\t\t\t\t\t\t\t.setDescription('Make awesome polls!')\n *\t\t\t\t\t);\n *\n *\t\t\t\t\t// It is necessary to call this hook and pass the constructor context to register the subcommands stored in the subcommand registry in the subcommand groups of the parent command.\n *\t\t\t\t\tthis.hooks.groups(this, ctx);\n *\n *\t\t\t\t\treturn ctx\n *\t\t\t\t\t\t.setName(this.name)\n *\t\t\t\t\t\t.setDescription('Parent command of utils subcommands)\n *\t\t\t\t}\n *\t\t\t);\n * \t\t}\n * }\n * ```\n *\n * *With Typescript*\n *\n * ```typescript\n * import { Command } from '@kaname-png/plugin-subcommands-advanced'\n *\n * export class PollCreateCommand extends Command {\n * \t\tpublic constructor(context: Command.Context, options: Command.Options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tregisterSubCommand: {\n * \t\t\t\t\tparentCommandName: 'utils', // Name of the parent command (parent.js).\n * \t\t\t\t\tgroupName: 'poll', // Name of the group that was registered in the builder context of the parent command.\n * \t\t\t\t\tsubcommand: (builder) => builder.setName('create').setDescription('Create a poll') // Builder that will be embedded in the registry of the parent command.\n * \t\t\t\t}\n * \t\t\t});\n * \t\t}\n *\n * \t\tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\t\treturn interaction.reply('uwu');\n * \t\t}\n * }\n * ```\n *\n * *With JavaScript*\n *\n * ```javascript\n * import { Command } from '@kaname-png/plugin-subcommands-advanced'\n *\n * export class PollCreateCommand extends Command {\n * \t\tconstructor(context, options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tregisterSubCommand: {\n * \t\t\t\t\tparentCommandName: 'utils', // Name of the parent command (parent.js).\n * \t\t\t\t\tgroupName: 'poll', // Name of the group that was registered in the builder context of the parent command.\n * \t\t\t\t\tsubcommand: (builder) => builder.setName('create').setDescription('Create a poll') // Builder that will be embedded in the registry of the parent command.\n * \t\t\t\t}\n * \t\t\t});\n * \t\t}\n *\n * \t\tchatInputRun(interaction) {\n * \t\t\treturn interaction.reply('uwu');\n * \t\t}\n * }\n * ```\n *\n * That's it, the plugin will take care of configuring everything so that when the subcommand of the parent command is called, the linked command is executed.\n *\n * @since 1.0.0\n */\nexport class Command<\n\tPreParseReturn extends Args = Args,\n\tOptions extends CommandOptions & SapphireCommand.Options = CommandOptions & SapphireCommand.Options\n> extends SapphireCommand<PreParseReturn, Options> {\n\tpublic constructor(context: Command.LoaderContext, options: Command.Options) {\n\t\tlet nameCommand = options.name;\n\n\t\tif (options.registerSubCommand && container.client.options.subcommandsAdvanced?.nameCommandsAutogenerated === true) {\n\t\t\tconst slashSubcommandParsed = parseSlashSubcommand(options.registerSubCommand.slashSubcommand);\n\t\t\tif (slashSubcommandParsed) {\n\t\t\t\tnameCommand = `${options.registerSubCommand.parentCommandName}/${slashSubcommandParsed.name}`;\n\t\t\t} else nameCommand = `${options.registerSubCommand.parentCommandName}/${options.name}`;\n\t\t}\n\n\t\tif (options.registerSubcommandInGroup && container.client.options.subcommandsAdvanced?.nameCommandsAutogenerated === true) {\n\t\t\tconst slashSubcommandParsed = parseSlashSubcommand(options.registerSubcommandInGroup.slashSubcommand);\n\t\t\tif (slashSubcommandParsed) {\n\t\t\t\tnameCommand = `${options.registerSubcommandInGroup.parentCommandName}/${options.registerSubcommandInGroup.groupName}/${slashSubcommandParsed.name}`;\n\t\t\t} else\n\t\t\t\tnameCommand = `${options.registerSubcommandInGroup.parentCommandName}/${options.registerSubcommandInGroup.groupName}/${options.name}`;\n\t\t}\n\n\t\tsuper(context, { ...options, name: nameCommand } as Options);\n\n\t\tif (this.options.registerSubCommand) {\n\t\t\tconst { parentCommandName, slashSubcommand } = this.options.registerSubCommand;\n\t\t\tanalizeSubCommandParsed(this, parentCommandName, slashSubcommand);\n\t\t}\n\n\t\tif (this.options.registerSubcommandInGroup) {\n\t\t\tconst { parentCommandName, groupName, slashSubcommand } = this.options.registerSubcommandInGroup;\n\t\t\tanalizeSubcommandGroupParsed(this, parentCommandName, groupName, slashSubcommand);\n\t\t}\n\t}\n}\n\nexport namespace Command {\n\texport type Options = CommandOptions & SapphireCommand.Options;\n\texport type JSON = CommandJSON;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = AliasPiece.LoaderContext<'commands'>;\n\texport type RunInTypes = CommandOptionsRunType;\n\texport type RunInUnion = CommandRunInUnion;\n\texport type SpecificRunIn = CommandSpecificRunIn;\n\texport type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = SapphireCommand.ChatInputCommandInteraction<Cached>;\n\texport type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = SapphireCommand.ContextMenuCommandInteraction<Cached>;\n\texport type AutocompleteInteraction<Cached extends CacheType = CacheType> = SapphireCommand.AutocompleteInteraction<Cached>;\n\texport type Registry = ApplicationCommandRegistry;\n}\n/**\n * **Parent command**\n *\n * Subcommand class that extends the original subcommand plugin class and incorporates the hooks into the class for ease of use.\n *\n * The parent command is important because it is where the subcommands and subcommand group will be registered and is necessary for `@sapphire/framework` to know what to do with the subcommands.\n *\n * *TypeScript*\n *\n * ```typescript\n * import { Subcommand } from '@kaname-png/plugin-subcommands-advanced';\n * import { ApplicationCommandRegistry } from '@sapphire/framework';\n *\n * export class ParentCommand extends Subcommand {\n * \t\tpublic constructor(context: Subcommand.Context, options: Subcommand.Options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tname: 'utils'\n * \t\t\t});\n * \t\t}\n *\n * \t\tpublic override registerApplicationCommands(interaction: ApplicationCommandRegistry) {\n * \t\t\tregistry.registerChatInputCommand(\n *\t\t\t\t(ctx) => {\n *\t\t\t\t\t// If you want to link commands in groups of subcommands you first need to register them in the builder context of the parent command.\n *\t\t\t\t\tctx.addSubcommandGroup((sc) =>\n *\t\t\t\t\t\tsc\n *\t\t\t\t\t\t\t.setName('poll')\n *\t\t\t\t\t\t\t.setDescription('Make awesome polls!')\n *\t\t\t\t\t);\n *\n *\t\t\t\t\t// It is necessary to call this hook and pass the constructor context to register the subcommands stored in the subcommand registry in the subcommand groups of the parent command.\n *\t\t\t\t\tthis.hooks.groups(this, ctx);\n *\n *\t\t\t\t\t// It is necessary to call this hook and pass the builder context to register the subcommands stored in the subcommand register in the parent command.\n *\t\t\t\t\tthis.hooks.subcommands(this, ctx);\n *\n * \t\t\t\t\t// Calling both hooks is only necessary if required, it is not mandatory.\n *\t\t\t\t\treturn ctx\n *\t\t\t\t\t\t.setName(this.name)\n *\t\t\t\t\t\t.setDescription('Parent command of utils subcommands')\n *\t\t\t\t}\n *\t\t\t);\n * \t\t}\n * }\n * ```\n *\n * *JavaScript*\n *\n * ```javascript\n * import { Subcommand } from '@kaname-png/plugin-subcommands-advanced';\n *\n * export class ParentCommand extends Subcommand {\n * \t\tpublic constructor(context, options) {\n * \t\t\tsuper(context, {\n * \t\t\t\t...options,\n * \t\t\t\tname: 'utils'\n * \t\t\t});\n * \t\t}\n *\n * \t\tpublic override registerApplicationCommands(interaction) {\n * \t\t\tregistry.registerChatInputCommand(\n *\t\t\t\t(ctx) => {\n *\t\t\t\t\t// If you want to link commands in groups of subcommands you first need to register them in the builder context of the parent command.\n *\t\t\t\t\tctx.addSubcommandGroup((sc) =>\n *\t\t\t\t\t\tsc\n *\t\t\t\t\t\t\t.setName('poll')\n *\t\t\t\t\t\t\t.setDescription('Make awesome polls!')\n *\t\t\t\t\t);\n *\n *\t\t\t\t\t// It is necessary to call this hook and pass the constructor context to register the subcommands stored in the subcommand registry in the subcommand groups of the parent command.\n *\t\t\t\t\tthis.hooks.groups(this, ctx);\n *\n *\t\t\t\t\t// It is necessary to call this hook and pass the builder context to register the subcommands stored in the subcommand register in the parent command.\n *\t\t\t\t\tthis.hooks.subcommands(this, ctx);\n *\n * \t\t\t\t\t// Calling both hooks is only necessary if required, it is not mandatory.\n *\t\t\t\t\treturn ctx\n *\t\t\t\t\t\t.setName(this.name)\n *\t\t\t\t\t\t.setDescription('Parent command of utils subcommands');\n *\t\t\t\t}\n *\t\t\t);\n * \t\t}\n * }\n * ```\n *\n * @since 1.0.0\n */\nexport class Subcommand extends SapphirePluginSubcommand {\n\tpublic hooks = RegisterSubcommandsHooks;\n}\n\nexport namespace Subcommand {\n\texport type Options = SubcommandOptions;\n\texport type JSON = SapphireCommand.JSON;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = SapphireCommand.LoaderContext;\n\texport type RunInTypes = SapphireCommand.RunInTypes;\n\texport type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = SapphireCommand.ChatInputCommandInteraction<Cached>;\n\texport type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = SapphireCommand.ContextMenuCommandInteraction<Cached>;\n\texport type AutocompleteInteraction<Cached extends CacheType = CacheType> = SapphireCommand.AutocompleteInteraction<Cached>;\n\texport type Registry = SapphireCommand.Registry;\n}\n"]}