@sapphire/plugin-subcommands 7.0.2-next.ea411df → 7.0.2-next.ebf804c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/Subcommand.cjs +3 -3
- package/dist/cjs/lib/Subcommand.cjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/Subcommand.mjs +3 -3
- package/dist/esm/lib/Subcommand.mjs.map +1 -1
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ var subcommandCooldown_cjs__namespace = /*#__PURE__*/_interopNamespace(subcomman
|
|
|
33
33
|
var SubcommandPreconditions = {
|
|
34
34
|
PluginSubcommandCooldown: PluginSubcommandCooldown_cjs.PluginPrecondition
|
|
35
35
|
};
|
|
36
|
-
var version = "7.0.2-next.
|
|
36
|
+
var version = "7.0.2-next.ebf804c";
|
|
37
37
|
|
|
38
38
|
Object.defineProperty(exports, "PluginSubcommandCooldownPrecondition", {
|
|
39
39
|
enumerable: true,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["PluginSubcommandCooldown"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDO,IAAM,uBAA0B,GAAA;AAAA,4BACtCA;AACD;AAoBO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { CooldownOptions } from '@sapphire/framework';\nimport {\n\tPluginPrecondition as PluginSubcommandCooldown,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport * from './lib/Subcommand';\nexport * as SubcommandPreconditionResolvers from './lib/precondition-resolvers/subcommandCooldown';\nexport * from './lib/types/Enums';\nexport * from './lib/types/Events';\nexport * from './lib/types/SubcommandMappings';\nexport {\n\tPluginPrecondition as PluginSubcommandCooldownPrecondition,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadPreconditions } from './preconditions/_load';\n\ndeclare module 'discord.js' {\n\tinterface ClientOptions {\n\t\t/**\n\t\t * If Plugin-subcommand to load pre-included subcommand error event listeners that log any encountered errors to the {@link SapphireClient.logger} instance\n\t\t * @since 3.1.2\n\t\t * @default true\n\t\t */\n\t\tloadSubcommandErrorListeners?: boolean;\n\t\t/**\n\t\t * Sets the default cooldown time for all subcommands.\n\t\t * @remark This is separate from {@link ClientOptions.defaultCooldown} as it is only used for subcommands\n\t\t * @remark Note that for the `filteredCommands` option you have to provide it as\n\t\t * - For a subcommand without a group: `commandName.subcommandName` (e.g. `config.show`).\n\t\t * - For a subcommand with a group: `commandName.groupName.subcommandName` (e.g. `config.set.prefix`).\n\t\t * @since 5.1.0\n\t\t * @default \"No cooldown options\"\n\t\t */\n\t\tsubcommandDefaultCooldown?: CooldownOptions;\n\t}\n}\n\ndeclare module '@sapphire/framework' {\n\tinterface Preconditions {\n\t\tPluginSubcommandCooldown: SubcommandPreconditions.PluginSubcommandCooldownContext;\n\t}\n}\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldown}\n * in the next major version as opposed to a namespaced export.\n */\nexport const SubcommandPreconditions = {\n\tPluginSubcommandCooldown\n};\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldownPreconditionContext}\n * in the next major version as opposed to a namespaced export.\n */\nexport namespace SubcommandPreconditions {\n\t/** The context for the subcommand cooldown precondition */\n\texport type PluginSubcommandCooldownContext = PluginSubcommandCooldownPreconditionContext;\n}\n\n/**\n * The [@sapphire/plugin-subcommands](https://github.com/sapphiredev/plugins/blob/main/packages/subcommands) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.2-next.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["PluginSubcommandCooldown"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDO,IAAM,uBAA0B,GAAA;AAAA,4BACtCA;AACD;AAoBO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { CooldownOptions } from '@sapphire/framework';\nimport {\n\tPluginPrecondition as PluginSubcommandCooldown,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport * from './lib/Subcommand';\nexport * as SubcommandPreconditionResolvers from './lib/precondition-resolvers/subcommandCooldown';\nexport * from './lib/types/Enums';\nexport * from './lib/types/Events';\nexport * from './lib/types/SubcommandMappings';\nexport {\n\tPluginPrecondition as PluginSubcommandCooldownPrecondition,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadPreconditions } from './preconditions/_load';\n\ndeclare module 'discord.js' {\n\tinterface ClientOptions {\n\t\t/**\n\t\t * If Plugin-subcommand to load pre-included subcommand error event listeners that log any encountered errors to the {@link SapphireClient.logger} instance\n\t\t * @since 3.1.2\n\t\t * @default true\n\t\t */\n\t\tloadSubcommandErrorListeners?: boolean;\n\t\t/**\n\t\t * Sets the default cooldown time for all subcommands.\n\t\t * @remark This is separate from {@link ClientOptions.defaultCooldown} as it is only used for subcommands\n\t\t * @remark Note that for the `filteredCommands` option you have to provide it as\n\t\t * - For a subcommand without a group: `commandName.subcommandName` (e.g. `config.show`).\n\t\t * - For a subcommand with a group: `commandName.groupName.subcommandName` (e.g. `config.set.prefix`).\n\t\t * @since 5.1.0\n\t\t * @default \"No cooldown options\"\n\t\t */\n\t\tsubcommandDefaultCooldown?: CooldownOptions;\n\t}\n}\n\ndeclare module '@sapphire/framework' {\n\tinterface Preconditions {\n\t\tPluginSubcommandCooldown: SubcommandPreconditions.PluginSubcommandCooldownContext;\n\t}\n}\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldown}\n * in the next major version as opposed to a namespaced export.\n */\nexport const SubcommandPreconditions = {\n\tPluginSubcommandCooldown\n};\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldownPreconditionContext}\n * in the next major version as opposed to a namespaced export.\n */\nexport namespace SubcommandPreconditions {\n\t/** The context for the subcommand cooldown precondition */\n\texport type PluginSubcommandCooldownContext = PluginSubcommandCooldownPreconditionContext;\n}\n\n/**\n * The [@sapphire/plugin-subcommands](https://github.com/sapphiredev/plugins/blob/main/packages/subcommands) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.2-next.ebf804c';\n"]}
|
|
@@ -215,7 +215,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
|
|
|
215
215
|
args.restore();
|
|
216
216
|
if (actualSubcommandToRun) {
|
|
217
217
|
args.next();
|
|
218
|
-
let subcommandGroupName =
|
|
218
|
+
let subcommandGroupName = undefined;
|
|
219
219
|
if (matchedWithGroupedSubcommand) {
|
|
220
220
|
subcommandGroupName = subcommandOrGroup.unwrap();
|
|
221
221
|
args.next();
|
|
@@ -223,7 +223,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
|
|
|
223
223
|
return __privateMethod(this, _Subcommand_instances, handleMessageRun_fn).call(this, message, args, context, actualSubcommandToRun, subcommandGroupName);
|
|
224
224
|
}
|
|
225
225
|
if (defaultCommand) {
|
|
226
|
-
let subcommandGroupName =
|
|
226
|
+
let subcommandGroupName = undefined;
|
|
227
227
|
if (matchedWithGroupedSubcommand) {
|
|
228
228
|
subcommandGroupName = subcommandOrGroup.unwrap();
|
|
229
229
|
args.next();
|
|
@@ -261,7 +261,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
|
|
|
261
261
|
continue;
|
|
262
262
|
}
|
|
263
263
|
if (mapping.type === "method" && mapping.name === subcommandName) {
|
|
264
|
-
return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping,
|
|
264
|
+
return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping, undefined);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
this.container.client.emit(Events_cjs.SubcommandPluginEvents.ChatInputSubcommandNoMatch, interaction, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/Subcommand.ts"],"names":["Command","deepClone","PreconditionContainerArray","PreconditionResolvers","SubcommandPreconditionResolvers","SubcommandPluginEvents","SubcommandPluginIdentifiers","Result","result","UserError","cast"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAA,qBAAA,EAAA,mBAAA,EAAA,+BAAA,EAAA,mBAAA,EAAA,gCAAA,EAAA,iBAAA,EAAA,sBAAA;AAoCO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgHA,iBAG3H,CAAA;AAAA,EAmBM,WAAA,CAAY,SAAmC,OAAkB,EAAA;AAEvE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAxBjB,IAAA,YAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAQN;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,yBAAA,sBAA8B,GAAwC,EAAA,CAAA;AAMtF;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA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EAAA,YAAA,EAAc,KAAM,EAAA;AAAA;AACvC;AAGD,EAAA,OAAO,EAAE,OAAA,EAAS,YAAc,EAAA,YAAA,EAAc,IAAK,EAAA;AACpD,CAhBe,EAAA,iBAAA,CAAA;AAkBf,sBAAA,mCAAqB,WAAqD,EAAA;AACzE,EAAA,OAAO,IAAK,CAAA,wBAAA,CAAyB,IAAK,CAAA,CAAC,OAAY,KAAA;AACtD,IAAI,IAAA,OAAA,CAAQ,SAAS,OAAS,EAAA;AAC7B,MAAO,OAAA,OAAA,CAAQ,QAAQ,IAAK,CAAA,CAAC,iBAAiB,OAAQ,CAAA,GAAA,CAAI,YAAc,EAAA,WAAW,CAAC,CAAA;AAAA;AAErF,IAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,OAAA,EAAS,WAAW,CAAA;AAAA,GACvC,CAAA;AACF,CAPoB,EAAA,sBAAA,CAAA;AAngBnB,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHK,IAAM,UAAN,GAAA","file":"Subcommand.cjs","sourcesContent":["import {\n\tCommand,\n\tPreconditionContainerArray,\n\tPreconditionResolvers,\n\tResult,\n\tUserError,\n\ttype Args,\n\ttype ChatInputCommand,\n\ttype MessageCommand,\n\ttype MessageCommandDeniedPayload\n} from '@sapphire/framework';\nimport { cast, deepClone } from '@sapphire/utilities';\nimport type { CacheType, Message } from 'discord.js';\nimport { SubcommandPreconditionResolvers } from '../index';\nimport {\n\tSubcommandPluginEvents,\n\tSubcommandPluginIdentifiers,\n\ttype ChatInputSubcommandAcceptedPayload,\n\ttype MessageSubcommandAcceptedPayload\n} from './types/Events';\nimport type {\n\tChatInputCommandSubcommandMappingMethod,\n\tMessageSubcommandMappingMethod,\n\tSubcommandMappingArray,\n\tSubcommandMappingMethod\n} from './types/SubcommandMappings';\n\n/**\n * The class to extends for commands that have subcommands.\n * Specify the subcommands through the {@link Subcommand.Options.subcommands} option.\n *\n * Note that you should not make **all** your commands extend this class, _only_ the ones that have subcommands.\n * The reason for this is that this class implements {@link Command.messageRun} and {@link Command.chatInputRun}\n * which you wouldn't necessarily want to do for commands that don't have subcommands.\n * Furthermore, it also just adds general unnecessary memory overhead.\n */\nexport class Subcommand<PreParseReturn extends Args = Args, Options extends Subcommand.Options = Subcommand.Options> extends Command<\n\tPreParseReturn,\n\tOptions\n> {\n\t/**\n\t * The preconditions to be run for each specified subcommand.\n\t * @since 4.1.0\n\t */\n\tpublic readonly subcommandPreconditions = new Map<string, PreconditionContainerArray>();\n\n\t/**\n\t * The parsed subcommand mappings that were provided with the {@link SubcommandOptions.subcommands} option.\n\t * This is built at construction time and is used to determine which subcommand to run.\n\t */\n\tpublic parsedSubcommandMappings: SubcommandMappingArray;\n\n\t/**\n\t * Whether to use case insensitive subcommands. This is only relevant for message-command styled commands as\n\t * chat input commands are always lowercase. This can be enabled through `clientOptions.caseInsensitiveCommands`.\n\t */\n\tpublic caseInsensitiveSubcommands = false;\n\n\tpublic constructor(context: Subcommand.LoaderContext, options: Options) {\n\t\t// #region Base parsing\n\t\tsuper(context, options);\n\t\tthis.parsedSubcommandMappings = options.subcommands ?? [];\n\n\t\tconst clientOptions = this.container.client.options;\n\t\t// #endregion\n\n\t\t// #region Case Insensitive Commands\n\t\tif (clientOptions.caseInsensitiveCommands) {\n\t\t\tthis.caseInsensitiveSubcommands = true;\n\n\t\t\t// Because slash commands must be lowercase anyway, we can transform all to lowercase.\n\t\t\tfor (const cmd of this.parsedSubcommandMappings) {\n\t\t\t\tcmd.name = cmd.name.toLowerCase();\n\t\t\t\tif (cmd.type === 'group') {\n\t\t\t\t\tfor (const groupCommand of cmd.entries) {\n\t\t\t\t\t\tgroupCommand.name = groupCommand.name.toLowerCase();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Generate Dashless Aliases\n\t\tif (options.generateDashLessAliases) {\n\t\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\t\tif (!Reflect.has(mapping, 'messageRun')) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst dashLessMappings: SubcommandMappingArray = [];\n\n\t\t\t\tif (mapping.type === 'group') {\n\t\t\t\t\t// Keep track of whether we have changed entries or not, so we don't need to do expensive object comparison later.\n\t\t\t\t\tlet hasChangedEntries: boolean | null = null;\n\n\t\t\t\t\t// Deeply clone the entire mapping to avoid mutating the original.\n\t\t\t\t\tconst clonedMapping = deepClone(mapping);\n\n\t\t\t\t\t// Loop through the group's subcommands and add a dash-less alias for each, if applicable.\n\t\t\t\t\tfor (const groupCommand of mapping.entries) {\n\t\t\t\t\t\tif (groupCommand.name.includes('-')) {\n\t\t\t\t\t\t\t// If we are inside this if statement then we flip `hasChangedEntries` to true to be able to read it later.\n\t\t\t\t\t\t\thasChangedEntries ??= true;\n\n\t\t\t\t\t\t\tclonedMapping.entries.push({\n\t\t\t\t\t\t\t\t...groupCommand,\n\t\t\t\t\t\t\t\tname: groupCommand.name.replaceAll('-', '')\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If any of the entries in the group had a dash then `hasChangedEntries` was flipped to true\n\t\t\t\t\t * and so we want to register a mapping with the base name and all dash-less entries\n\t\t\t\t\t * in the group.\n\t\t\t\t\t */\n\t\t\t\t\tif (hasChangedEntries) {\n\t\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\t\tentries: clonedMapping.entries\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If the group name itself has a dash then register a dash-less copy of it.\n\t\t\t\t\t * If the entries in the group didn't have any dashes then `clonedMapping.entries` is still\n\t\t\t\t\t * the same original array, so it can be safely overwritten.\n\t\t\t\t\t *\n\t\t\t\t\t * If the entries in the group did have any dashes then `clonedMapping.entries` has\n\t\t\t\t\t * all entries both with and without dashes.\n\t\t\t\t\t */\n\t\t\t\t\tif (clonedMapping.name.includes('-')) {\n\t\t\t\t\t\tclonedMapping.name = clonedMapping.name.replaceAll('-', '');\n\t\t\t\t\t\tdashLessMappings.push(clonedMapping);\n\t\t\t\t\t}\n\t\t\t\t} else if (mapping.name.includes('-')) {\n\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\tname: mapping.name.replaceAll('-', '')\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// For every dash-less mapping, push a new subcommand\n\t\t\t\tfor (const dashLessMapping of dashLessMappings) {\n\t\t\t\t\tthis.parsedSubcommandMappings.push(dashLessMapping);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Subcommand Preconditions\n\t\tfor (const subcommand of this.parsedSubcommandMappings) {\n\t\t\tsubcommand.type ??= 'method';\n\n\t\t\tif (subcommand.type === 'method') {\n\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(subcommand.preconditions);\n\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\tsubcommand.runIn,\n\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(subcommand.nsfw, preconditionContainerArray);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\tsubcommand.requiredClientPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\tsubcommand.requiredUserPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\tsubcommand: this,\n\t\t\t\t\tcooldownDelay: subcommand.cooldownDelay,\n\t\t\t\t\tcooldownFilteredUsers: subcommand.cooldownFilteredUsers,\n\t\t\t\t\tcooldownLimit: subcommand.cooldownLimit,\n\t\t\t\t\tcooldownScope: subcommand.cooldownScope,\n\t\t\t\t\tsubcommandMethodName: subcommand.name,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t});\n\n\t\t\t\tthis.subcommandPreconditions.set(subcommand.name, preconditionContainerArray);\n\t\t\t}\n\n\t\t\tif (subcommand.type === 'group') {\n\t\t\t\tfor (const groupedSubcommand of subcommand.entries) {\n\t\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(groupedSubcommand.preconditions);\n\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\t\tgroupedSubcommand.runIn,\n\t\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(groupedSubcommand.nsfw, preconditionContainerArray);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredClientPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredUserPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\t\tsubcommand: this,\n\t\t\t\t\t\tcooldownDelay: groupedSubcommand.cooldownDelay,\n\t\t\t\t\t\tcooldownFilteredUsers: groupedSubcommand.cooldownFilteredUsers,\n\t\t\t\t\t\tcooldownLimit: groupedSubcommand.cooldownLimit,\n\t\t\t\t\t\tcooldownScope: groupedSubcommand.cooldownScope,\n\t\t\t\t\t\tsubcommandGroupName: subcommand.name,\n\t\t\t\t\t\tsubcommandMethodName: groupedSubcommand.name,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t});\n\n\t\t\t\t\tthis.subcommandPreconditions.set(`${subcommand.name}.${groupedSubcommand.name}`, preconditionContainerArray);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\t}\n\n\tpublic override onLoad() {\n\t\tsuper.onLoad();\n\n\t\tconst externalMapping = Reflect.get(this, 'subcommandMappings');\n\t\tif (externalMapping) {\n\t\t\tconst subcommands = Array.isArray(externalMapping) ? externalMapping : [];\n\t\t\tthis.parsedSubcommandMappings = subcommands;\n\t\t\tthis.options.subcommands = subcommands;\n\t\t}\n\t}\n\n\t/**\n\t * Whether this command has message-based subcommands or not\n\t * @returns `true` if this command has message-based subcommands, otherwise `false`\n\t */\n\tpublic override supportsMessageCommands(): this is MessageCommand {\n\t\treturn this.#supportsCommandType('messageRun');\n\t}\n\n\t/**\n\t * Whether this command has chat input subcommands or not\n\t * @returns `true` if this command has chat input subcommands, otherwise `false`\n\t */\n\tpublic override supportsChatInputCommands(): this is ChatInputCommand {\n\t\treturn this.#supportsCommandType('chatInputRun');\n\t}\n\n\t/**\n\t * The method that is ran when a message-based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async messageRun(message: Message, args: PreParseReturn, context: MessageCommand.RunContext) {\n\t\targs.save();\n\t\tconst subcommandOrGroup = args.nextMaybe();\n\t\tconst subcommandName = args.nextMaybe();\n\t\tlet defaultCommand: SubcommandMappingMethod | null = null;\n\t\tlet actualSubcommandToRun: SubcommandMappingMethod | null = null;\n\t\tlet matchedWithGroupedSubcommand = false;\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.type === 'method') {\n\t\t\t\tif (mapping.default && !defaultCommand) {\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\tdefaultCommand = mapping;\n\t\t\t\t}\n\n\t\t\t\tif (subcommandOrGroup.isSomeAnd((value) => mapping.name === (this.caseInsensitiveSubcommands ? value.toLowerCase() : value))) {\n\t\t\t\t\tactualSubcommandToRun = mapping;\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\t// Exit early\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We expect a group mapping\n\t\t\tif (mapping.type === 'group' && subcommandOrGroup.isSome() && subcommandName.isSome()) {\n\t\t\t\tconst unwrappedSubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\tconst unwrappedSubcommandName = subcommandName.unwrap();\n\n\t\t\t\t// We know a group was passed in here\n\t\t\t\tif (mapping.name === unwrappedSubcommandGroupName) {\n\t\t\t\t\t// Find the actual subcommand to run\n\t\t\t\t\tconst findResult = this.#findSubcommand(\n\t\t\t\t\t\tmapping.entries,\n\t\t\t\t\t\tthis.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName\n\t\t\t\t\t);\n\n\t\t\t\t\tif (findResult.defaultMatch) {\n\t\t\t\t\t\tdefaultCommand = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tactualSubcommandToRun = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t\t// Exit early\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Preemptively restore the args state, to provide a correct args result for users\n\t\targs.restore();\n\n\t\tif (actualSubcommandToRun) {\n\t\t\t// Skip over the subcommandOrGroup\n\t\t\targs.next();\n\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 more arg\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, actualSubcommandToRun, subcommandGroupName);\n\t\t}\n\n\t\t// No subcommand matched, let's try to run default, if any:\n\t\tif (defaultCommand) {\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 the group name\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, defaultCommand, subcommandGroupName);\n\t\t}\n\n\t\tconst commandPrefix = this.#getCommandPrefix(message.content, args.commandContext.prefix);\n\t\tconst prefixLessContent = message.content.slice(commandPrefix.length).trim();\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandNoMatch, message, args, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on message command \"${this.name}\" at path \"${this.location.full}\" with content ${prefixLessContent}`,\n\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t});\n\t}\n\n\t/**\n\t * The method that is ran when a chat input based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async chatInputRun(interaction: ChatInputCommand.Interaction, context: ChatInputCommand.RunContext) {\n\t\tconst subcommandName = interaction.options.getSubcommand(false);\n\t\tconst subcommandGroupName = interaction.options.getSubcommandGroup(false);\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\t// If we have a group, we know we also have a subcommand and we should find and run it\n\t\t\tif (subcommandGroupName && subcommandName) {\n\t\t\t\tif (mapping.type !== 'group') continue;\n\t\t\t\tif (mapping.name !== subcommandGroupName) continue;\n\n\t\t\t\tconst foundSubcommand = this.#findSubcommand(mapping.entries, subcommandName!);\n\n\t\t\t\t// Only run if its not the \"default\" found command mapping, as interactions don't have that\n\t\t\t\tif (!foundSubcommand.defaultMatch) {\n\t\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, foundSubcommand.mapping, subcommandGroupName);\n\t\t\t\t}\n\n\t\t\t\t// Skip to the next entry\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If we have a direct subcommand, and no group, then run the mapping\n\t\t\tif (mapping.type === 'method' && mapping.name === subcommandName) {\n\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, mapping, undefined);\n\t\t\t}\n\t\t}\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandNoMatch, interaction, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on chat input command \"${this.name}\" at path \"${this.location.full}\"`\n\t\t});\n\t}\n\n\t#getCommandPrefix(content: string, prefix: string | RegExp): string {\n\t\treturn typeof prefix === 'string' ? prefix : prefix.exec(content)![0];\n\t}\n\n\tasync #getMessageParametersAsString(args: Args): Promise<Partial<Pick<MessageCommandDeniedPayload, 'parameters'>>> {\n\t\targs.save();\n\t\tconst parameters = await args.restResult('string');\n\t\targs.restore();\n\n\t\tconst params: Partial<Pick<MessageCommandDeniedPayload, 'parameters'>> = {};\n\n\t\tif (parameters.isOk()) {\n\t\t\tparams.parameters = parameters.unwrap();\n\t\t}\n\n\t\treturn params;\n\t}\n\n\tasync #handleMessageRun(\n\t\tmessage: Message,\n\t\targs: Args,\n\t\tcontext: MessageCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: MessageSubcommandAcceptedPayload = {\n\t\t\tmessage,\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Attempt to get the remaining parameters as string:\n\t\t\tconst messageParametersAsString = await this.#getMessageParametersAsString(args);\n\n\t\t\t// Build the precondition payload:\n\t\t\tconst preconditionPayload = { ...messageParametersAsString, ...payload };\n\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.messageRun(message, this, preconditionPayload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandDenied, localSubcommandResult.unwrapErr(), preconditionPayload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If subcommand preconditions have passed then we run the actual subcommand:\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.messageRun) {\n\t\t\t\tconst casted = subcommand as MessageSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandRun, message, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.messageRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.messageRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"messageRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['messageRun']>(method), this, [message, args, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.messageRun(message, args, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandSuccess, message, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.SubcommandMappingIsMissingMessageCommandHandler, message, subcommand, payload);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.MessageSubcommandError, error, payload));\n\t}\n\n\tasync #handleChatInputInteractionRun(\n\t\tinteraction: ChatInputCommand.Interaction,\n\t\tcontext: ChatInputCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: ChatInputSubcommandAcceptedPayload = {\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tinteraction,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.chatInputRun(interaction, this, payload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandDenied, localSubcommandResult.unwrapErr(), payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.chatInputRun) {\n\t\t\t\tconst casted = subcommand as ChatInputCommandSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandRun, interaction, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.chatInputRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.chatInputRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"chatInputRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['chatInputRun']>(method), this, [interaction, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.chatInputRun(interaction, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandSuccess, interaction, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(\n\t\t\t\t\tSubcommandPluginEvents.SubcommandMappingIsMissingChatInputCommandHandler,\n\t\t\t\t\tinteraction,\n\t\t\t\t\tsubcommand,\n\t\t\t\t\tpayload\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandError, error, payload));\n\t}\n\n\t#findSubcommand(mappings: SubcommandMappingMethod[], expectedName: string) {\n\t\tlet foundDefault: SubcommandMappingMethod | null = null;\n\n\t\tfor (const mapping of mappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.default) {\n\t\t\t\tfoundDefault = mapping;\n\t\t\t}\n\n\t\t\tif (mapping.name === expectedName) {\n\t\t\t\treturn { mapping, defaultMatch: false } as const;\n\t\t\t}\n\t\t}\n\n\t\treturn { mapping: foundDefault, defaultMatch: true } as const;\n\t}\n\n\t#supportsCommandType(commandType: 'messageRun' | 'chatInputRun'): boolean {\n\t\treturn this.parsedSubcommandMappings.some((mapping) => {\n\t\t\tif (mapping.type === 'group') {\n\t\t\t\treturn mapping.entries.some((groupCommand) => Reflect.has(groupCommand, commandType));\n\t\t\t}\n\t\t\treturn Reflect.has(mapping, commandType);\n\t\t});\n\t}\n}\n\nexport interface SubcommandOptions extends Command.Options {\n\tsubcommands?: SubcommandMappingArray;\n\t/**\n\t * Whether to add aliases for subcommands with dashes in them\n\t *\n\t * When this option is enabled *and* the subcommand implements `messageRun`, dashless aliases will be added.\n\t *\n\t * For subcommands groups both the group itself and all subcommands within the group will have dashless aliases added.\n\t *\n\t * @since 3.0.0\n\t * @default false\n\t */\n\tgenerateDashLessAliases?: boolean;\n}\n\nexport namespace Subcommand {\n\texport type Options = SubcommandOptions;\n\texport type JSON = Command.JSON;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Command.LoaderContext;\n\texport type RunInTypes = Command.RunInTypes;\n\texport type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = Command.ChatInputCommandInteraction<Cached>;\n\texport type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = Command.ContextMenuCommandInteraction<Cached>;\n\texport type AutocompleteInteraction<Cached extends CacheType = CacheType> = Command.AutocompleteInteraction<Cached>;\n\texport type Registry = Command.Registry;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/Subcommand.ts"],"names":["Command","deepClone","PreconditionContainerArray","PreconditionResolvers","SubcommandPreconditionResolvers","SubcommandPluginEvents","SubcommandPluginIdentifiers","Result","result","UserError","cast"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAA,qBAAA,EAAA,mBAAA,EAAA,+BAAA,EAAA,mBAAA,EAAA,gCAAA,EAAA,iBAAA,EAAA,sBAAA;AAoCO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgHA,iBAG3H,CAAA;AAAA,EAmBM,WAAA,CAAY,SAAmC,OAAkB,EAAA;AAEvE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAxBjB,IAAA,YAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAQN;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,yBAAA,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,OAAS,EAAA;AACpB,MAAe,YAAA,GAAA,OAAA;AAAA;AAGhB,IAAI,IAAA,OAAA,CAAQ,SAAS,YAAc,EAAA;AAClC,MAAO,OAAA,EAAE,OAAS,EAAA,YAAA,EAAc,KAAM,EAAA;AAAA;AACvC;AAGD,EAAA,OAAO,EAAE,OAAA,EAAS,YAAc,EAAA,YAAA,EAAc,IAAK,EAAA;AACpD,CAhBe,EAAA,iBAAA,CAAA;AAkBf,sBAAA,mCAAqB,WAAqD,EAAA;AACzE,EAAA,OAAO,IAAK,CAAA,wBAAA,CAAyB,IAAK,CAAA,CAAC,OAAY,KAAA;AACtD,IAAI,IAAA,OAAA,CAAQ,SAAS,OAAS,EAAA;AAC7B,MAAO,OAAA,OAAA,CAAQ,QAAQ,IAAK,CAAA,CAAC,iBAAiB,OAAQ,CAAA,GAAA,CAAI,YAAc,EAAA,WAAW,CAAC,CAAA;AAAA;AAErF,IAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,OAAA,EAAS,WAAW,CAAA;AAAA,GACvC,CAAA;AACF,CAPoB,EAAA,sBAAA,CAAA;AAngBnB,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHK,IAAM,UAAN,GAAA","file":"Subcommand.cjs","sourcesContent":["import {\n\tCommand,\n\tPreconditionContainerArray,\n\tPreconditionResolvers,\n\tResult,\n\tUserError,\n\ttype Args,\n\ttype ChatInputCommand,\n\ttype MessageCommand,\n\ttype MessageCommandDeniedPayload\n} from '@sapphire/framework';\nimport { cast, deepClone } from '@sapphire/utilities';\nimport type { CacheType, Message } from 'discord.js';\nimport { SubcommandPreconditionResolvers } from '../index';\nimport {\n\tSubcommandPluginEvents,\n\tSubcommandPluginIdentifiers,\n\ttype ChatInputSubcommandAcceptedPayload,\n\ttype MessageSubcommandAcceptedPayload\n} from './types/Events';\nimport type {\n\tChatInputCommandSubcommandMappingMethod,\n\tMessageSubcommandMappingMethod,\n\tSubcommandMappingArray,\n\tSubcommandMappingMethod\n} from './types/SubcommandMappings';\n\n/**\n * The class to extends for commands that have subcommands.\n * Specify the subcommands through the {@link Subcommand.Options.subcommands} option.\n *\n * Note that you should not make **all** your commands extend this class, _only_ the ones that have subcommands.\n * The reason for this is that this class implements {@link Command.messageRun} and {@link Command.chatInputRun}\n * which you wouldn't necessarily want to do for commands that don't have subcommands.\n * Furthermore, it also just adds general unnecessary memory overhead.\n */\nexport class Subcommand<PreParseReturn extends Args = Args, Options extends Subcommand.Options = Subcommand.Options> extends Command<\n\tPreParseReturn,\n\tOptions\n> {\n\t/**\n\t * The preconditions to be run for each specified subcommand.\n\t * @since 4.1.0\n\t */\n\tpublic readonly subcommandPreconditions = new Map<string, PreconditionContainerArray>();\n\n\t/**\n\t * The parsed subcommand mappings that were provided with the {@link SubcommandOptions.subcommands} option.\n\t * This is built at construction time and is used to determine which subcommand to run.\n\t */\n\tpublic parsedSubcommandMappings: SubcommandMappingArray;\n\n\t/**\n\t * Whether to use case insensitive subcommands. This is only relevant for message-command styled commands as\n\t * chat input commands are always lowercase. This can be enabled through `clientOptions.caseInsensitiveCommands`.\n\t */\n\tpublic caseInsensitiveSubcommands = false;\n\n\tpublic constructor(context: Subcommand.LoaderContext, options: Options) {\n\t\t// #region Base parsing\n\t\tsuper(context, options);\n\t\tthis.parsedSubcommandMappings = options.subcommands ?? [];\n\n\t\tconst clientOptions = this.container.client.options;\n\t\t// #endregion\n\n\t\t// #region Case Insensitive Commands\n\t\tif (clientOptions.caseInsensitiveCommands) {\n\t\t\tthis.caseInsensitiveSubcommands = true;\n\n\t\t\t// Because slash commands must be lowercase anyway, we can transform all to lowercase.\n\t\t\tfor (const cmd of this.parsedSubcommandMappings) {\n\t\t\t\tcmd.name = cmd.name.toLowerCase();\n\t\t\t\tif (cmd.type === 'group') {\n\t\t\t\t\tfor (const groupCommand of cmd.entries) {\n\t\t\t\t\t\tgroupCommand.name = groupCommand.name.toLowerCase();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Generate Dashless Aliases\n\t\tif (options.generateDashLessAliases) {\n\t\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\t\tif (!Reflect.has(mapping, 'messageRun')) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst dashLessMappings: SubcommandMappingArray = [];\n\n\t\t\t\tif (mapping.type === 'group') {\n\t\t\t\t\t// Keep track of whether we have changed entries or not, so we don't need to do expensive object comparison later.\n\t\t\t\t\tlet hasChangedEntries: boolean | null = null;\n\n\t\t\t\t\t// Deeply clone the entire mapping to avoid mutating the original.\n\t\t\t\t\tconst clonedMapping = deepClone(mapping);\n\n\t\t\t\t\t// Loop through the group's subcommands and add a dash-less alias for each, if applicable.\n\t\t\t\t\tfor (const groupCommand of mapping.entries) {\n\t\t\t\t\t\tif (groupCommand.name.includes('-')) {\n\t\t\t\t\t\t\t// If we are inside this if statement then we flip `hasChangedEntries` to true to be able to read it later.\n\t\t\t\t\t\t\thasChangedEntries ??= true;\n\n\t\t\t\t\t\t\tclonedMapping.entries.push({\n\t\t\t\t\t\t\t\t...groupCommand,\n\t\t\t\t\t\t\t\tname: groupCommand.name.replaceAll('-', '')\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If any of the entries in the group had a dash then `hasChangedEntries` was flipped to true\n\t\t\t\t\t * and so we want to register a mapping with the base name and all dash-less entries\n\t\t\t\t\t * in the group.\n\t\t\t\t\t */\n\t\t\t\t\tif (hasChangedEntries) {\n\t\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\t\tentries: clonedMapping.entries\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If the group name itself has a dash then register a dash-less copy of it.\n\t\t\t\t\t * If the entries in the group didn't have any dashes then `clonedMapping.entries` is still\n\t\t\t\t\t * the same original array, so it can be safely overwritten.\n\t\t\t\t\t *\n\t\t\t\t\t * If the entries in the group did have any dashes then `clonedMapping.entries` has\n\t\t\t\t\t * all entries both with and without dashes.\n\t\t\t\t\t */\n\t\t\t\t\tif (clonedMapping.name.includes('-')) {\n\t\t\t\t\t\tclonedMapping.name = clonedMapping.name.replaceAll('-', '');\n\t\t\t\t\t\tdashLessMappings.push(clonedMapping);\n\t\t\t\t\t}\n\t\t\t\t} else if (mapping.name.includes('-')) {\n\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\tname: mapping.name.replaceAll('-', '')\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// For every dash-less mapping, push a new subcommand\n\t\t\t\tfor (const dashLessMapping of dashLessMappings) {\n\t\t\t\t\tthis.parsedSubcommandMappings.push(dashLessMapping);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Subcommand Preconditions\n\t\tfor (const subcommand of this.parsedSubcommandMappings) {\n\t\t\tsubcommand.type ??= 'method';\n\n\t\t\tif (subcommand.type === 'method') {\n\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(subcommand.preconditions);\n\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\tsubcommand.runIn,\n\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(subcommand.nsfw, preconditionContainerArray);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\tsubcommand.requiredClientPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\tsubcommand.requiredUserPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\tsubcommand: this,\n\t\t\t\t\tcooldownDelay: subcommand.cooldownDelay,\n\t\t\t\t\tcooldownFilteredUsers: subcommand.cooldownFilteredUsers,\n\t\t\t\t\tcooldownLimit: subcommand.cooldownLimit,\n\t\t\t\t\tcooldownScope: subcommand.cooldownScope,\n\t\t\t\t\tsubcommandMethodName: subcommand.name,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t});\n\n\t\t\t\tthis.subcommandPreconditions.set(subcommand.name, preconditionContainerArray);\n\t\t\t}\n\n\t\t\tif (subcommand.type === 'group') {\n\t\t\t\tfor (const groupedSubcommand of subcommand.entries) {\n\t\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(groupedSubcommand.preconditions);\n\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\t\tgroupedSubcommand.runIn,\n\t\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(groupedSubcommand.nsfw, preconditionContainerArray);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredClientPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredUserPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\t\tsubcommand: this,\n\t\t\t\t\t\tcooldownDelay: groupedSubcommand.cooldownDelay,\n\t\t\t\t\t\tcooldownFilteredUsers: groupedSubcommand.cooldownFilteredUsers,\n\t\t\t\t\t\tcooldownLimit: groupedSubcommand.cooldownLimit,\n\t\t\t\t\t\tcooldownScope: groupedSubcommand.cooldownScope,\n\t\t\t\t\t\tsubcommandGroupName: subcommand.name,\n\t\t\t\t\t\tsubcommandMethodName: groupedSubcommand.name,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t});\n\n\t\t\t\t\tthis.subcommandPreconditions.set(`${subcommand.name}.${groupedSubcommand.name}`, preconditionContainerArray);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\t}\n\n\tpublic override onLoad() {\n\t\tsuper.onLoad();\n\n\t\tconst externalMapping = Reflect.get(this, 'subcommandMappings');\n\t\tif (externalMapping) {\n\t\t\tconst subcommands = Array.isArray(externalMapping) ? externalMapping : [];\n\t\t\tthis.parsedSubcommandMappings = subcommands;\n\t\t\tthis.options.subcommands = subcommands;\n\t\t}\n\t}\n\n\t/**\n\t * Whether this command has message-based subcommands or not\n\t * @returns `true` if this command has message-based subcommands, otherwise `false`\n\t */\n\tpublic override supportsMessageCommands(): this is MessageCommand {\n\t\treturn this.#supportsCommandType('messageRun');\n\t}\n\n\t/**\n\t * Whether this command has chat input subcommands or not\n\t * @returns `true` if this command has chat input subcommands, otherwise `false`\n\t */\n\tpublic override supportsChatInputCommands(): this is ChatInputCommand {\n\t\treturn this.#supportsCommandType('chatInputRun');\n\t}\n\n\t/**\n\t * The method that is ran when a message-based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async messageRun(message: Message, args: PreParseReturn, context: MessageCommand.RunContext) {\n\t\targs.save();\n\t\tconst subcommandOrGroup = args.nextMaybe();\n\t\tconst subcommandName = args.nextMaybe();\n\t\tlet defaultCommand: SubcommandMappingMethod | null = null;\n\t\tlet actualSubcommandToRun: SubcommandMappingMethod | null = null;\n\t\tlet matchedWithGroupedSubcommand = false;\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.type === 'method') {\n\t\t\t\tif (mapping.default && !defaultCommand) {\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\tdefaultCommand = mapping;\n\t\t\t\t}\n\n\t\t\t\tif (subcommandOrGroup.isSomeAnd((value) => mapping.name === (this.caseInsensitiveSubcommands ? value.toLowerCase() : value))) {\n\t\t\t\t\tactualSubcommandToRun = mapping;\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\t// Exit early\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We expect a group mapping\n\t\t\tif (mapping.type === 'group' && subcommandOrGroup.isSome() && subcommandName.isSome()) {\n\t\t\t\tconst unwrappedSubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\tconst unwrappedSubcommandName = subcommandName.unwrap();\n\n\t\t\t\t// We know a group was passed in here\n\t\t\t\tif (mapping.name === unwrappedSubcommandGroupName) {\n\t\t\t\t\t// Find the actual subcommand to run\n\t\t\t\t\tconst findResult = this.#findSubcommand(\n\t\t\t\t\t\tmapping.entries,\n\t\t\t\t\t\tthis.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName\n\t\t\t\t\t);\n\n\t\t\t\t\tif (findResult.defaultMatch) {\n\t\t\t\t\t\tdefaultCommand = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tactualSubcommandToRun = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t\t// Exit early\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Preemptively restore the args state, to provide a correct args result for users\n\t\targs.restore();\n\n\t\tif (actualSubcommandToRun) {\n\t\t\t// Skip over the subcommandOrGroup\n\t\t\targs.next();\n\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 more arg\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, actualSubcommandToRun, subcommandGroupName);\n\t\t}\n\n\t\t// No subcommand matched, let's try to run default, if any:\n\t\tif (defaultCommand) {\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 the group name\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, defaultCommand, subcommandGroupName);\n\t\t}\n\n\t\tconst commandPrefix = this.#getCommandPrefix(message.content, args.commandContext.prefix);\n\t\tconst prefixLessContent = message.content.slice(commandPrefix.length).trim();\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandNoMatch, message, args, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on message command \"${this.name}\" at path \"${this.location.full}\" with content ${prefixLessContent}`,\n\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t});\n\t}\n\n\t/**\n\t * The method that is ran when a chat input based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async chatInputRun(interaction: ChatInputCommand.Interaction, context: ChatInputCommand.RunContext) {\n\t\tconst subcommandName = interaction.options.getSubcommand(false);\n\t\tconst subcommandGroupName = interaction.options.getSubcommandGroup(false);\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\t// If we have a group, we know we also have a subcommand and we should find and run it\n\t\t\tif (subcommandGroupName && subcommandName) {\n\t\t\t\tif (mapping.type !== 'group') continue;\n\t\t\t\tif (mapping.name !== subcommandGroupName) continue;\n\n\t\t\t\tconst foundSubcommand = this.#findSubcommand(mapping.entries, subcommandName!);\n\n\t\t\t\t// Only run if its not the \"default\" found command mapping, as interactions don't have that\n\t\t\t\tif (!foundSubcommand.defaultMatch) {\n\t\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, foundSubcommand.mapping, subcommandGroupName);\n\t\t\t\t}\n\n\t\t\t\t// Skip to the next entry\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If we have a direct subcommand, and no group, then run the mapping\n\t\t\tif (mapping.type === 'method' && mapping.name === subcommandName) {\n\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, mapping, undefined);\n\t\t\t}\n\t\t}\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandNoMatch, interaction, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on chat input command \"${this.name}\" at path \"${this.location.full}\"`\n\t\t});\n\t}\n\n\t#getCommandPrefix(content: string, prefix: string | RegExp): string {\n\t\treturn typeof prefix === 'string' ? prefix : prefix.exec(content)![0];\n\t}\n\n\tasync #getMessageParametersAsString(args: Args): Promise<Partial<Pick<MessageCommandDeniedPayload, 'parameters'>>> {\n\t\targs.save();\n\t\tconst parameters = await args.restResult('string');\n\t\targs.restore();\n\n\t\tconst params: Partial<Pick<MessageCommandDeniedPayload, 'parameters'>> = {};\n\n\t\tif (parameters.isOk()) {\n\t\t\tparams.parameters = parameters.unwrap();\n\t\t}\n\n\t\treturn params;\n\t}\n\n\tasync #handleMessageRun(\n\t\tmessage: Message,\n\t\targs: Args,\n\t\tcontext: MessageCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: MessageSubcommandAcceptedPayload = {\n\t\t\tmessage,\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Attempt to get the remaining parameters as string:\n\t\t\tconst messageParametersAsString = await this.#getMessageParametersAsString(args);\n\n\t\t\t// Build the precondition payload:\n\t\t\tconst preconditionPayload = { ...messageParametersAsString, ...payload };\n\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.messageRun(message, this, preconditionPayload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandDenied, localSubcommandResult.unwrapErr(), preconditionPayload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If subcommand preconditions have passed then we run the actual subcommand:\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.messageRun) {\n\t\t\t\tconst casted = subcommand as MessageSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandRun, message, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.messageRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.messageRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"messageRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['messageRun']>(method), this, [message, args, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.messageRun(message, args, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandSuccess, message, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.SubcommandMappingIsMissingMessageCommandHandler, message, subcommand, payload);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.MessageSubcommandError, error, payload));\n\t}\n\n\tasync #handleChatInputInteractionRun(\n\t\tinteraction: ChatInputCommand.Interaction,\n\t\tcontext: ChatInputCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: ChatInputSubcommandAcceptedPayload = {\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tinteraction,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.chatInputRun(interaction, this, payload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandDenied, localSubcommandResult.unwrapErr(), payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.chatInputRun) {\n\t\t\t\tconst casted = subcommand as ChatInputCommandSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandRun, interaction, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.chatInputRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.chatInputRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"chatInputRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['chatInputRun']>(method), this, [interaction, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.chatInputRun(interaction, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandSuccess, interaction, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(\n\t\t\t\t\tSubcommandPluginEvents.SubcommandMappingIsMissingChatInputCommandHandler,\n\t\t\t\t\tinteraction,\n\t\t\t\t\tsubcommand,\n\t\t\t\t\tpayload\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandError, error, payload));\n\t}\n\n\t#findSubcommand(mappings: SubcommandMappingMethod[], expectedName: string) {\n\t\tlet foundDefault: SubcommandMappingMethod | null = null;\n\n\t\tfor (const mapping of mappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.default) {\n\t\t\t\tfoundDefault = mapping;\n\t\t\t}\n\n\t\t\tif (mapping.name === expectedName) {\n\t\t\t\treturn { mapping, defaultMatch: false } as const;\n\t\t\t}\n\t\t}\n\n\t\treturn { mapping: foundDefault, defaultMatch: true } as const;\n\t}\n\n\t#supportsCommandType(commandType: 'messageRun' | 'chatInputRun'): boolean {\n\t\treturn this.parsedSubcommandMappings.some((mapping) => {\n\t\t\tif (mapping.type === 'group') {\n\t\t\t\treturn mapping.entries.some((groupCommand) => Reflect.has(groupCommand, commandType));\n\t\t\t}\n\t\t\treturn Reflect.has(mapping, commandType);\n\t\t});\n\t}\n}\n\nexport interface SubcommandOptions extends Command.Options {\n\tsubcommands?: SubcommandMappingArray;\n\t/**\n\t * Whether to add aliases for subcommands with dashes in them\n\t *\n\t * When this option is enabled *and* the subcommand implements `messageRun`, dashless aliases will be added.\n\t *\n\t * For subcommands groups both the group itself and all subcommands within the group will have dashless aliases added.\n\t *\n\t * @since 3.0.0\n\t * @default false\n\t */\n\tgenerateDashLessAliases?: boolean;\n}\n\nexport namespace Subcommand {\n\texport type Options = SubcommandOptions;\n\texport type JSON = Command.JSON;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Command.LoaderContext;\n\texport type RunInTypes = Command.RunInTypes;\n\texport type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = Command.ChatInputCommandInteraction<Cached>;\n\texport type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = Command.ContextMenuCommandInteraction<Cached>;\n\texport type AutocompleteInteraction<Cached extends CacheType = CacheType> = Command.AutocompleteInteraction<Cached>;\n\texport type Registry = Command.Registry;\n}\n"]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ export { loadPreconditions } from './preconditions/_load.mjs';
|
|
|
13
13
|
var SubcommandPreconditions = {
|
|
14
14
|
PluginSubcommandCooldown: PluginPrecondition
|
|
15
15
|
};
|
|
16
|
-
var version = "7.0.2-next.
|
|
16
|
+
var version = "7.0.2-next.ebf804c";
|
|
17
17
|
|
|
18
18
|
export { SubcommandPreconditions, version };
|
|
19
19
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["PluginSubcommandCooldown"],"mappings":";;;;;;;;;;;;AAoDO,IAAM,uBAA0B,GAAA;AAAA,4BACtCA;AACD;AAoBO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CooldownOptions } from '@sapphire/framework';\nimport {\n\tPluginPrecondition as PluginSubcommandCooldown,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport * from './lib/Subcommand';\nexport * as SubcommandPreconditionResolvers from './lib/precondition-resolvers/subcommandCooldown';\nexport * from './lib/types/Enums';\nexport * from './lib/types/Events';\nexport * from './lib/types/SubcommandMappings';\nexport {\n\tPluginPrecondition as PluginSubcommandCooldownPrecondition,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadPreconditions } from './preconditions/_load';\n\ndeclare module 'discord.js' {\n\tinterface ClientOptions {\n\t\t/**\n\t\t * If Plugin-subcommand to load pre-included subcommand error event listeners that log any encountered errors to the {@link SapphireClient.logger} instance\n\t\t * @since 3.1.2\n\t\t * @default true\n\t\t */\n\t\tloadSubcommandErrorListeners?: boolean;\n\t\t/**\n\t\t * Sets the default cooldown time for all subcommands.\n\t\t * @remark This is separate from {@link ClientOptions.defaultCooldown} as it is only used for subcommands\n\t\t * @remark Note that for the `filteredCommands` option you have to provide it as\n\t\t * - For a subcommand without a group: `commandName.subcommandName` (e.g. `config.show`).\n\t\t * - For a subcommand with a group: `commandName.groupName.subcommandName` (e.g. `config.set.prefix`).\n\t\t * @since 5.1.0\n\t\t * @default \"No cooldown options\"\n\t\t */\n\t\tsubcommandDefaultCooldown?: CooldownOptions;\n\t}\n}\n\ndeclare module '@sapphire/framework' {\n\tinterface Preconditions {\n\t\tPluginSubcommandCooldown: SubcommandPreconditions.PluginSubcommandCooldownContext;\n\t}\n}\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldown}\n * in the next major version as opposed to a namespaced export.\n */\nexport const SubcommandPreconditions = {\n\tPluginSubcommandCooldown\n};\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldownPreconditionContext}\n * in the next major version as opposed to a namespaced export.\n */\nexport namespace SubcommandPreconditions {\n\t/** The context for the subcommand cooldown precondition */\n\texport type PluginSubcommandCooldownContext = PluginSubcommandCooldownPreconditionContext;\n}\n\n/**\n * The [@sapphire/plugin-subcommands](https://github.com/sapphiredev/plugins/blob/main/packages/subcommands) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.2-next.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["PluginSubcommandCooldown"],"mappings":";;;;;;;;;;;;AAoDO,IAAM,uBAA0B,GAAA;AAAA,4BACtCA;AACD;AAoBO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CooldownOptions } from '@sapphire/framework';\nimport {\n\tPluginPrecondition as PluginSubcommandCooldown,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport * from './lib/Subcommand';\nexport * as SubcommandPreconditionResolvers from './lib/precondition-resolvers/subcommandCooldown';\nexport * from './lib/types/Enums';\nexport * from './lib/types/Events';\nexport * from './lib/types/SubcommandMappings';\nexport {\n\tPluginPrecondition as PluginSubcommandCooldownPrecondition,\n\ttype PluginSubcommandCooldownPreconditionContext\n} from './preconditions/PluginSubcommandCooldown';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadPreconditions } from './preconditions/_load';\n\ndeclare module 'discord.js' {\n\tinterface ClientOptions {\n\t\t/**\n\t\t * If Plugin-subcommand to load pre-included subcommand error event listeners that log any encountered errors to the {@link SapphireClient.logger} instance\n\t\t * @since 3.1.2\n\t\t * @default true\n\t\t */\n\t\tloadSubcommandErrorListeners?: boolean;\n\t\t/**\n\t\t * Sets the default cooldown time for all subcommands.\n\t\t * @remark This is separate from {@link ClientOptions.defaultCooldown} as it is only used for subcommands\n\t\t * @remark Note that for the `filteredCommands` option you have to provide it as\n\t\t * - For a subcommand without a group: `commandName.subcommandName` (e.g. `config.show`).\n\t\t * - For a subcommand with a group: `commandName.groupName.subcommandName` (e.g. `config.set.prefix`).\n\t\t * @since 5.1.0\n\t\t * @default \"No cooldown options\"\n\t\t */\n\t\tsubcommandDefaultCooldown?: CooldownOptions;\n\t}\n}\n\ndeclare module '@sapphire/framework' {\n\tinterface Preconditions {\n\t\tPluginSubcommandCooldown: SubcommandPreconditions.PluginSubcommandCooldownContext;\n\t}\n}\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldown}\n * in the next major version as opposed to a namespaced export.\n */\nexport const SubcommandPreconditions = {\n\tPluginSubcommandCooldown\n};\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\n * @deprecated - This will be replaced with a regular top level export of {@link PluginSubcommandCooldownPreconditionContext}\n * in the next major version as opposed to a namespaced export.\n */\nexport namespace SubcommandPreconditions {\n\t/** The context for the subcommand cooldown precondition */\n\texport type PluginSubcommandCooldownContext = PluginSubcommandCooldownPreconditionContext;\n}\n\n/**\n * The [@sapphire/plugin-subcommands](https://github.com/sapphiredev/plugins/blob/main/packages/subcommands) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.2-next.ebf804c';\n"]}
|
|
@@ -204,7 +204,7 @@ var _Subcommand = class _Subcommand extends Command {
|
|
|
204
204
|
args.restore();
|
|
205
205
|
if (actualSubcommandToRun) {
|
|
206
206
|
args.next();
|
|
207
|
-
let subcommandGroupName =
|
|
207
|
+
let subcommandGroupName = undefined;
|
|
208
208
|
if (matchedWithGroupedSubcommand) {
|
|
209
209
|
subcommandGroupName = subcommandOrGroup.unwrap();
|
|
210
210
|
args.next();
|
|
@@ -212,7 +212,7 @@ var _Subcommand = class _Subcommand extends Command {
|
|
|
212
212
|
return __privateMethod(this, _Subcommand_instances, handleMessageRun_fn).call(this, message, args, context, actualSubcommandToRun, subcommandGroupName);
|
|
213
213
|
}
|
|
214
214
|
if (defaultCommand) {
|
|
215
|
-
let subcommandGroupName =
|
|
215
|
+
let subcommandGroupName = undefined;
|
|
216
216
|
if (matchedWithGroupedSubcommand) {
|
|
217
217
|
subcommandGroupName = subcommandOrGroup.unwrap();
|
|
218
218
|
args.next();
|
|
@@ -250,7 +250,7 @@ var _Subcommand = class _Subcommand extends Command {
|
|
|
250
250
|
continue;
|
|
251
251
|
}
|
|
252
252
|
if (mapping.type === "method" && mapping.name === subcommandName) {
|
|
253
|
-
return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping,
|
|
253
|
+
return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping, undefined);
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
this.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandNoMatch, interaction, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/Subcommand.ts"],"names":["result"],"mappings":";;;;;;AAAA,IAAA,qBAAA,EAAA,mBAAA,EAAA,+BAAA,EAAA,mBAAA,EAAA,gCAAA,EAAA,iBAAA,EAAA,sBAAA;AAoCO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgH,OAG3H,CAAA;AAAA,EAmBM,WAAA,CAAY,SAAmC,OAAkB,EAAA;AAEvE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAxBjB,IAAA,YAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAQN;AAAA;AAAA;A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AEjB,IAAA,IAAI,QAAQ,OAAS,EAAA;AACpB,MAAe,YAAA,GAAA,OAAA;AAAA;AAGhB,IAAI,IAAA,OAAA,CAAQ,SAAS,YAAc,EAAA;AAClC,MAAO,OAAA,EAAE,OAAS,EAAA,YAAA,EAAc,KAAM,EAAA;AAAA;AACvC;AAGD,EAAA,OAAO,EAAE,OAAA,EAAS,YAAc,EAAA,YAAA,EAAc,IAAK,EAAA;AACpD,CAhBe,EAAA,iBAAA,CAAA;AAkBf,sBAAA,mCAAqB,WAAqD,EAAA;AACzE,EAAA,OAAO,IAAK,CAAA,wBAAA,CAAyB,IAAK,CAAA,CAAC,OAAY,KAAA;AACtD,IAAI,IAAA,OAAA,CAAQ,SAAS,OAAS,EAAA;AAC7B,MAAO,OAAA,OAAA,CAAQ,QAAQ,IAAK,CAAA,CAAC,iBAAiB,OAAQ,CAAA,GAAA,CAAI,YAAc,EAAA,WAAW,CAAC,CAAA;AAAA;AAErF,IAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,OAAA,EAAS,WAAW,CAAA;AAAA,GACvC,CAAA;AACF,CAPoB,EAAA,sBAAA,CAAA;AAngBnB,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHK,IAAM,UAAN,GAAA","file":"Subcommand.mjs","sourcesContent":["import {\n\tCommand,\n\tPreconditionContainerArray,\n\tPreconditionResolvers,\n\tResult,\n\tUserError,\n\ttype Args,\n\ttype ChatInputCommand,\n\ttype MessageCommand,\n\ttype MessageCommandDeniedPayload\n} from '@sapphire/framework';\nimport { cast, deepClone } from '@sapphire/utilities';\nimport type { CacheType, Message } from 'discord.js';\nimport { SubcommandPreconditionResolvers } from '../index';\nimport {\n\tSubcommandPluginEvents,\n\tSubcommandPluginIdentifiers,\n\ttype ChatInputSubcommandAcceptedPayload,\n\ttype MessageSubcommandAcceptedPayload\n} from './types/Events';\nimport type {\n\tChatInputCommandSubcommandMappingMethod,\n\tMessageSubcommandMappingMethod,\n\tSubcommandMappingArray,\n\tSubcommandMappingMethod\n} from './types/SubcommandMappings';\n\n/**\n * The class to extends for commands that have subcommands.\n * Specify the subcommands through the {@link Subcommand.Options.subcommands} option.\n *\n * Note that you should not make **all** your commands extend this class, _only_ the ones that have subcommands.\n * The reason for this is that this class implements {@link Command.messageRun} and {@link Command.chatInputRun}\n * which you wouldn't necessarily want to do for commands that don't have subcommands.\n * Furthermore, it also just adds general unnecessary memory overhead.\n */\nexport class Subcommand<PreParseReturn extends Args = Args, Options extends Subcommand.Options = Subcommand.Options> extends Command<\n\tPreParseReturn,\n\tOptions\n> {\n\t/**\n\t * The preconditions to be run for each specified subcommand.\n\t * @since 4.1.0\n\t */\n\tpublic readonly subcommandPreconditions = new Map<string, PreconditionContainerArray>();\n\n\t/**\n\t * The parsed subcommand mappings that were provided with the {@link SubcommandOptions.subcommands} option.\n\t * This is built at construction time and is used to determine which subcommand to run.\n\t */\n\tpublic parsedSubcommandMappings: SubcommandMappingArray;\n\n\t/**\n\t * Whether to use case insensitive subcommands. This is only relevant for message-command styled commands as\n\t * chat input commands are always lowercase. This can be enabled through `clientOptions.caseInsensitiveCommands`.\n\t */\n\tpublic caseInsensitiveSubcommands = false;\n\n\tpublic constructor(context: Subcommand.LoaderContext, options: Options) {\n\t\t// #region Base parsing\n\t\tsuper(context, options);\n\t\tthis.parsedSubcommandMappings = options.subcommands ?? [];\n\n\t\tconst clientOptions = this.container.client.options;\n\t\t// #endregion\n\n\t\t// #region Case Insensitive Commands\n\t\tif (clientOptions.caseInsensitiveCommands) {\n\t\t\tthis.caseInsensitiveSubcommands = true;\n\n\t\t\t// Because slash commands must be lowercase anyway, we can transform all to lowercase.\n\t\t\tfor (const cmd of this.parsedSubcommandMappings) {\n\t\t\t\tcmd.name = cmd.name.toLowerCase();\n\t\t\t\tif (cmd.type === 'group') {\n\t\t\t\t\tfor (const groupCommand of cmd.entries) {\n\t\t\t\t\t\tgroupCommand.name = groupCommand.name.toLowerCase();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Generate Dashless Aliases\n\t\tif (options.generateDashLessAliases) {\n\t\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\t\tif (!Reflect.has(mapping, 'messageRun')) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst dashLessMappings: SubcommandMappingArray = [];\n\n\t\t\t\tif (mapping.type === 'group') {\n\t\t\t\t\t// Keep track of whether we have changed entries or not, so we don't need to do expensive object comparison later.\n\t\t\t\t\tlet hasChangedEntries: boolean | null = null;\n\n\t\t\t\t\t// Deeply clone the entire mapping to avoid mutating the original.\n\t\t\t\t\tconst clonedMapping = deepClone(mapping);\n\n\t\t\t\t\t// Loop through the group's subcommands and add a dash-less alias for each, if applicable.\n\t\t\t\t\tfor (const groupCommand of mapping.entries) {\n\t\t\t\t\t\tif (groupCommand.name.includes('-')) {\n\t\t\t\t\t\t\t// If we are inside this if statement then we flip `hasChangedEntries` to true to be able to read it later.\n\t\t\t\t\t\t\thasChangedEntries ??= true;\n\n\t\t\t\t\t\t\tclonedMapping.entries.push({\n\t\t\t\t\t\t\t\t...groupCommand,\n\t\t\t\t\t\t\t\tname: groupCommand.name.replaceAll('-', '')\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If any of the entries in the group had a dash then `hasChangedEntries` was flipped to true\n\t\t\t\t\t * and so we want to register a mapping with the base name and all dash-less entries\n\t\t\t\t\t * in the group.\n\t\t\t\t\t */\n\t\t\t\t\tif (hasChangedEntries) {\n\t\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\t\tentries: clonedMapping.entries\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If the group name itself has a dash then register a dash-less copy of it.\n\t\t\t\t\t * If the entries in the group didn't have any dashes then `clonedMapping.entries` is still\n\t\t\t\t\t * the same original array, so it can be safely overwritten.\n\t\t\t\t\t *\n\t\t\t\t\t * If the entries in the group did have any dashes then `clonedMapping.entries` has\n\t\t\t\t\t * all entries both with and without dashes.\n\t\t\t\t\t */\n\t\t\t\t\tif (clonedMapping.name.includes('-')) {\n\t\t\t\t\t\tclonedMapping.name = clonedMapping.name.replaceAll('-', '');\n\t\t\t\t\t\tdashLessMappings.push(clonedMapping);\n\t\t\t\t\t}\n\t\t\t\t} else if (mapping.name.includes('-')) {\n\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\tname: mapping.name.replaceAll('-', '')\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// For every dash-less mapping, push a new subcommand\n\t\t\t\tfor (const dashLessMapping of dashLessMappings) {\n\t\t\t\t\tthis.parsedSubcommandMappings.push(dashLessMapping);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Subcommand Preconditions\n\t\tfor (const subcommand of this.parsedSubcommandMappings) {\n\t\t\tsubcommand.type ??= 'method';\n\n\t\t\tif (subcommand.type === 'method') {\n\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(subcommand.preconditions);\n\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\tsubcommand.runIn,\n\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(subcommand.nsfw, preconditionContainerArray);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\tsubcommand.requiredClientPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\tsubcommand.requiredUserPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\tsubcommand: this,\n\t\t\t\t\tcooldownDelay: subcommand.cooldownDelay,\n\t\t\t\t\tcooldownFilteredUsers: subcommand.cooldownFilteredUsers,\n\t\t\t\t\tcooldownLimit: subcommand.cooldownLimit,\n\t\t\t\t\tcooldownScope: subcommand.cooldownScope,\n\t\t\t\t\tsubcommandMethodName: subcommand.name,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t});\n\n\t\t\t\tthis.subcommandPreconditions.set(subcommand.name, preconditionContainerArray);\n\t\t\t}\n\n\t\t\tif (subcommand.type === 'group') {\n\t\t\t\tfor (const groupedSubcommand of subcommand.entries) {\n\t\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(groupedSubcommand.preconditions);\n\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\t\tgroupedSubcommand.runIn,\n\t\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(groupedSubcommand.nsfw, preconditionContainerArray);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredClientPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredUserPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\t\tsubcommand: this,\n\t\t\t\t\t\tcooldownDelay: groupedSubcommand.cooldownDelay,\n\t\t\t\t\t\tcooldownFilteredUsers: groupedSubcommand.cooldownFilteredUsers,\n\t\t\t\t\t\tcooldownLimit: groupedSubcommand.cooldownLimit,\n\t\t\t\t\t\tcooldownScope: groupedSubcommand.cooldownScope,\n\t\t\t\t\t\tsubcommandGroupName: subcommand.name,\n\t\t\t\t\t\tsubcommandMethodName: groupedSubcommand.name,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t});\n\n\t\t\t\t\tthis.subcommandPreconditions.set(`${subcommand.name}.${groupedSubcommand.name}`, preconditionContainerArray);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\t}\n\n\tpublic override onLoad() {\n\t\tsuper.onLoad();\n\n\t\tconst externalMapping = Reflect.get(this, 'subcommandMappings');\n\t\tif (externalMapping) {\n\t\t\tconst subcommands = Array.isArray(externalMapping) ? externalMapping : [];\n\t\t\tthis.parsedSubcommandMappings = subcommands;\n\t\t\tthis.options.subcommands = subcommands;\n\t\t}\n\t}\n\n\t/**\n\t * Whether this command has message-based subcommands or not\n\t * @returns `true` if this command has message-based subcommands, otherwise `false`\n\t */\n\tpublic override supportsMessageCommands(): this is MessageCommand {\n\t\treturn this.#supportsCommandType('messageRun');\n\t}\n\n\t/**\n\t * Whether this command has chat input subcommands or not\n\t * @returns `true` if this command has chat input subcommands, otherwise `false`\n\t */\n\tpublic override supportsChatInputCommands(): this is ChatInputCommand {\n\t\treturn this.#supportsCommandType('chatInputRun');\n\t}\n\n\t/**\n\t * The method that is ran when a message-based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async messageRun(message: Message, args: PreParseReturn, context: MessageCommand.RunContext) {\n\t\targs.save();\n\t\tconst subcommandOrGroup = args.nextMaybe();\n\t\tconst subcommandName = args.nextMaybe();\n\t\tlet defaultCommand: SubcommandMappingMethod | null = null;\n\t\tlet actualSubcommandToRun: SubcommandMappingMethod | null = null;\n\t\tlet matchedWithGroupedSubcommand = false;\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.type === 'method') {\n\t\t\t\tif (mapping.default && !defaultCommand) {\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\tdefaultCommand = mapping;\n\t\t\t\t}\n\n\t\t\t\tif (subcommandOrGroup.isSomeAnd((value) => mapping.name === (this.caseInsensitiveSubcommands ? value.toLowerCase() : value))) {\n\t\t\t\t\tactualSubcommandToRun = mapping;\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\t// Exit early\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We expect a group mapping\n\t\t\tif (mapping.type === 'group' && subcommandOrGroup.isSome() && subcommandName.isSome()) {\n\t\t\t\tconst unwrappedSubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\tconst unwrappedSubcommandName = subcommandName.unwrap();\n\n\t\t\t\t// We know a group was passed in here\n\t\t\t\tif (mapping.name === unwrappedSubcommandGroupName) {\n\t\t\t\t\t// Find the actual subcommand to run\n\t\t\t\t\tconst findResult = this.#findSubcommand(\n\t\t\t\t\t\tmapping.entries,\n\t\t\t\t\t\tthis.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName\n\t\t\t\t\t);\n\n\t\t\t\t\tif (findResult.defaultMatch) {\n\t\t\t\t\t\tdefaultCommand = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tactualSubcommandToRun = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t\t// Exit early\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Preemptively restore the args state, to provide a correct args result for users\n\t\targs.restore();\n\n\t\tif (actualSubcommandToRun) {\n\t\t\t// Skip over the subcommandOrGroup\n\t\t\targs.next();\n\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 more arg\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, actualSubcommandToRun, subcommandGroupName);\n\t\t}\n\n\t\t// No subcommand matched, let's try to run default, if any:\n\t\tif (defaultCommand) {\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 the group name\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, defaultCommand, subcommandGroupName);\n\t\t}\n\n\t\tconst commandPrefix = this.#getCommandPrefix(message.content, args.commandContext.prefix);\n\t\tconst prefixLessContent = message.content.slice(commandPrefix.length).trim();\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandNoMatch, message, args, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on message command \"${this.name}\" at path \"${this.location.full}\" with content ${prefixLessContent}`,\n\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t});\n\t}\n\n\t/**\n\t * The method that is ran when a chat input based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async chatInputRun(interaction: ChatInputCommand.Interaction, context: ChatInputCommand.RunContext) {\n\t\tconst subcommandName = interaction.options.getSubcommand(false);\n\t\tconst subcommandGroupName = interaction.options.getSubcommandGroup(false);\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\t// If we have a group, we know we also have a subcommand and we should find and run it\n\t\t\tif (subcommandGroupName && subcommandName) {\n\t\t\t\tif (mapping.type !== 'group') continue;\n\t\t\t\tif (mapping.name !== subcommandGroupName) continue;\n\n\t\t\t\tconst foundSubcommand = this.#findSubcommand(mapping.entries, subcommandName!);\n\n\t\t\t\t// Only run if its not the \"default\" found command mapping, as interactions don't have that\n\t\t\t\tif (!foundSubcommand.defaultMatch) {\n\t\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, foundSubcommand.mapping, subcommandGroupName);\n\t\t\t\t}\n\n\t\t\t\t// Skip to the next entry\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If we have a direct subcommand, and no group, then run the mapping\n\t\t\tif (mapping.type === 'method' && mapping.name === subcommandName) {\n\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, mapping, undefined);\n\t\t\t}\n\t\t}\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandNoMatch, interaction, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on chat input command \"${this.name}\" at path \"${this.location.full}\"`\n\t\t});\n\t}\n\n\t#getCommandPrefix(content: string, prefix: string | RegExp): string {\n\t\treturn typeof prefix === 'string' ? prefix : prefix.exec(content)![0];\n\t}\n\n\tasync #getMessageParametersAsString(args: Args): Promise<Partial<Pick<MessageCommandDeniedPayload, 'parameters'>>> {\n\t\targs.save();\n\t\tconst parameters = await args.restResult('string');\n\t\targs.restore();\n\n\t\tconst params: Partial<Pick<MessageCommandDeniedPayload, 'parameters'>> = {};\n\n\t\tif (parameters.isOk()) {\n\t\t\tparams.parameters = parameters.unwrap();\n\t\t}\n\n\t\treturn params;\n\t}\n\n\tasync #handleMessageRun(\n\t\tmessage: Message,\n\t\targs: Args,\n\t\tcontext: MessageCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: MessageSubcommandAcceptedPayload = {\n\t\t\tmessage,\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Attempt to get the remaining parameters as string:\n\t\t\tconst messageParametersAsString = await this.#getMessageParametersAsString(args);\n\n\t\t\t// Build the precondition payload:\n\t\t\tconst preconditionPayload = { ...messageParametersAsString, ...payload };\n\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.messageRun(message, this, preconditionPayload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandDenied, localSubcommandResult.unwrapErr(), preconditionPayload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If subcommand preconditions have passed then we run the actual subcommand:\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.messageRun) {\n\t\t\t\tconst casted = subcommand as MessageSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandRun, message, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.messageRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.messageRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"messageRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['messageRun']>(method), this, [message, args, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.messageRun(message, args, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandSuccess, message, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.SubcommandMappingIsMissingMessageCommandHandler, message, subcommand, payload);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.MessageSubcommandError, error, payload));\n\t}\n\n\tasync #handleChatInputInteractionRun(\n\t\tinteraction: ChatInputCommand.Interaction,\n\t\tcontext: ChatInputCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: ChatInputSubcommandAcceptedPayload = {\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tinteraction,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.chatInputRun(interaction, this, payload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandDenied, localSubcommandResult.unwrapErr(), payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.chatInputRun) {\n\t\t\t\tconst casted = subcommand as ChatInputCommandSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandRun, interaction, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.chatInputRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.chatInputRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"chatInputRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['chatInputRun']>(method), this, [interaction, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.chatInputRun(interaction, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandSuccess, interaction, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(\n\t\t\t\t\tSubcommandPluginEvents.SubcommandMappingIsMissingChatInputCommandHandler,\n\t\t\t\t\tinteraction,\n\t\t\t\t\tsubcommand,\n\t\t\t\t\tpayload\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandError, error, payload));\n\t}\n\n\t#findSubcommand(mappings: SubcommandMappingMethod[], expectedName: string) {\n\t\tlet foundDefault: SubcommandMappingMethod | null = null;\n\n\t\tfor (const mapping of mappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.default) {\n\t\t\t\tfoundDefault = mapping;\n\t\t\t}\n\n\t\t\tif (mapping.name === expectedName) {\n\t\t\t\treturn { mapping, defaultMatch: false } as const;\n\t\t\t}\n\t\t}\n\n\t\treturn { mapping: foundDefault, defaultMatch: true } as const;\n\t}\n\n\t#supportsCommandType(commandType: 'messageRun' | 'chatInputRun'): boolean {\n\t\treturn this.parsedSubcommandMappings.some((mapping) => {\n\t\t\tif (mapping.type === 'group') {\n\t\t\t\treturn mapping.entries.some((groupCommand) => Reflect.has(groupCommand, commandType));\n\t\t\t}\n\t\t\treturn Reflect.has(mapping, commandType);\n\t\t});\n\t}\n}\n\nexport interface SubcommandOptions extends Command.Options {\n\tsubcommands?: SubcommandMappingArray;\n\t/**\n\t * Whether to add aliases for subcommands with dashes in them\n\t *\n\t * When this option is enabled *and* the subcommand implements `messageRun`, dashless aliases will be added.\n\t *\n\t * For subcommands groups both the group itself and all subcommands within the group will have dashless aliases added.\n\t *\n\t * @since 3.0.0\n\t * @default false\n\t */\n\tgenerateDashLessAliases?: boolean;\n}\n\nexport namespace Subcommand {\n\texport type Options = SubcommandOptions;\n\texport type JSON = Command.JSON;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Command.LoaderContext;\n\texport type RunInTypes = Command.RunInTypes;\n\texport type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = Command.ChatInputCommandInteraction<Cached>;\n\texport type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = Command.ContextMenuCommandInteraction<Cached>;\n\texport type AutocompleteInteraction<Cached extends CacheType = CacheType> = Command.AutocompleteInteraction<Cached>;\n\texport type Registry = Command.Registry;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/Subcommand.ts"],"names":["result"],"mappings":";;;;;;AAAA,IAAA,qBAAA,EAAA,mBAAA,EAAA,+BAAA,EAAA,mBAAA,EAAA,gCAAA,EAAA,iBAAA,EAAA,sBAAA;AAoCO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAgH,OAG3H,CAAA;AAAA,EAmBM,WAAA,CAAY,SAAmC,OAAkB,EAAA;AAEvE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAxBjB,IAAA,YAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAQN;AAAA;AAAA;AAAA;AAA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AAS,EAAA;AACpB,MAAe,YAAA,GAAA,OAAA;AAAA;AAGhB,IAAI,IAAA,OAAA,CAAQ,SAAS,YAAc,EAAA;AAClC,MAAO,OAAA,EAAE,OAAS,EAAA,YAAA,EAAc,KAAM,EAAA;AAAA;AACvC;AAGD,EAAA,OAAO,EAAE,OAAA,EAAS,YAAc,EAAA,YAAA,EAAc,IAAK,EAAA;AACpD,CAhBe,EAAA,iBAAA,CAAA;AAkBf,sBAAA,mCAAqB,WAAqD,EAAA;AACzE,EAAA,OAAO,IAAK,CAAA,wBAAA,CAAyB,IAAK,CAAA,CAAC,OAAY,KAAA;AACtD,IAAI,IAAA,OAAA,CAAQ,SAAS,OAAS,EAAA;AAC7B,MAAO,OAAA,OAAA,CAAQ,QAAQ,IAAK,CAAA,CAAC,iBAAiB,OAAQ,CAAA,GAAA,CAAI,YAAc,EAAA,WAAW,CAAC,CAAA;AAAA;AAErF,IAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,OAAA,EAAS,WAAW,CAAA;AAAA,GACvC,CAAA;AACF,CAPoB,EAAA,sBAAA,CAAA;AAngBnB,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAHK,IAAM,UAAN,GAAA","file":"Subcommand.mjs","sourcesContent":["import {\n\tCommand,\n\tPreconditionContainerArray,\n\tPreconditionResolvers,\n\tResult,\n\tUserError,\n\ttype Args,\n\ttype ChatInputCommand,\n\ttype MessageCommand,\n\ttype MessageCommandDeniedPayload\n} from '@sapphire/framework';\nimport { cast, deepClone } from '@sapphire/utilities';\nimport type { CacheType, Message } from 'discord.js';\nimport { SubcommandPreconditionResolvers } from '../index';\nimport {\n\tSubcommandPluginEvents,\n\tSubcommandPluginIdentifiers,\n\ttype ChatInputSubcommandAcceptedPayload,\n\ttype MessageSubcommandAcceptedPayload\n} from './types/Events';\nimport type {\n\tChatInputCommandSubcommandMappingMethod,\n\tMessageSubcommandMappingMethod,\n\tSubcommandMappingArray,\n\tSubcommandMappingMethod\n} from './types/SubcommandMappings';\n\n/**\n * The class to extends for commands that have subcommands.\n * Specify the subcommands through the {@link Subcommand.Options.subcommands} option.\n *\n * Note that you should not make **all** your commands extend this class, _only_ the ones that have subcommands.\n * The reason for this is that this class implements {@link Command.messageRun} and {@link Command.chatInputRun}\n * which you wouldn't necessarily want to do for commands that don't have subcommands.\n * Furthermore, it also just adds general unnecessary memory overhead.\n */\nexport class Subcommand<PreParseReturn extends Args = Args, Options extends Subcommand.Options = Subcommand.Options> extends Command<\n\tPreParseReturn,\n\tOptions\n> {\n\t/**\n\t * The preconditions to be run for each specified subcommand.\n\t * @since 4.1.0\n\t */\n\tpublic readonly subcommandPreconditions = new Map<string, PreconditionContainerArray>();\n\n\t/**\n\t * The parsed subcommand mappings that were provided with the {@link SubcommandOptions.subcommands} option.\n\t * This is built at construction time and is used to determine which subcommand to run.\n\t */\n\tpublic parsedSubcommandMappings: SubcommandMappingArray;\n\n\t/**\n\t * Whether to use case insensitive subcommands. This is only relevant for message-command styled commands as\n\t * chat input commands are always lowercase. This can be enabled through `clientOptions.caseInsensitiveCommands`.\n\t */\n\tpublic caseInsensitiveSubcommands = false;\n\n\tpublic constructor(context: Subcommand.LoaderContext, options: Options) {\n\t\t// #region Base parsing\n\t\tsuper(context, options);\n\t\tthis.parsedSubcommandMappings = options.subcommands ?? [];\n\n\t\tconst clientOptions = this.container.client.options;\n\t\t// #endregion\n\n\t\t// #region Case Insensitive Commands\n\t\tif (clientOptions.caseInsensitiveCommands) {\n\t\t\tthis.caseInsensitiveSubcommands = true;\n\n\t\t\t// Because slash commands must be lowercase anyway, we can transform all to lowercase.\n\t\t\tfor (const cmd of this.parsedSubcommandMappings) {\n\t\t\t\tcmd.name = cmd.name.toLowerCase();\n\t\t\t\tif (cmd.type === 'group') {\n\t\t\t\t\tfor (const groupCommand of cmd.entries) {\n\t\t\t\t\t\tgroupCommand.name = groupCommand.name.toLowerCase();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Generate Dashless Aliases\n\t\tif (options.generateDashLessAliases) {\n\t\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\t\tif (!Reflect.has(mapping, 'messageRun')) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst dashLessMappings: SubcommandMappingArray = [];\n\n\t\t\t\tif (mapping.type === 'group') {\n\t\t\t\t\t// Keep track of whether we have changed entries or not, so we don't need to do expensive object comparison later.\n\t\t\t\t\tlet hasChangedEntries: boolean | null = null;\n\n\t\t\t\t\t// Deeply clone the entire mapping to avoid mutating the original.\n\t\t\t\t\tconst clonedMapping = deepClone(mapping);\n\n\t\t\t\t\t// Loop through the group's subcommands and add a dash-less alias for each, if applicable.\n\t\t\t\t\tfor (const groupCommand of mapping.entries) {\n\t\t\t\t\t\tif (groupCommand.name.includes('-')) {\n\t\t\t\t\t\t\t// If we are inside this if statement then we flip `hasChangedEntries` to true to be able to read it later.\n\t\t\t\t\t\t\thasChangedEntries ??= true;\n\n\t\t\t\t\t\t\tclonedMapping.entries.push({\n\t\t\t\t\t\t\t\t...groupCommand,\n\t\t\t\t\t\t\t\tname: groupCommand.name.replaceAll('-', '')\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If any of the entries in the group had a dash then `hasChangedEntries` was flipped to true\n\t\t\t\t\t * and so we want to register a mapping with the base name and all dash-less entries\n\t\t\t\t\t * in the group.\n\t\t\t\t\t */\n\t\t\t\t\tif (hasChangedEntries) {\n\t\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\t\tentries: clonedMapping.entries\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * If the group name itself has a dash then register a dash-less copy of it.\n\t\t\t\t\t * If the entries in the group didn't have any dashes then `clonedMapping.entries` is still\n\t\t\t\t\t * the same original array, so it can be safely overwritten.\n\t\t\t\t\t *\n\t\t\t\t\t * If the entries in the group did have any dashes then `clonedMapping.entries` has\n\t\t\t\t\t * all entries both with and without dashes.\n\t\t\t\t\t */\n\t\t\t\t\tif (clonedMapping.name.includes('-')) {\n\t\t\t\t\t\tclonedMapping.name = clonedMapping.name.replaceAll('-', '');\n\t\t\t\t\t\tdashLessMappings.push(clonedMapping);\n\t\t\t\t\t}\n\t\t\t\t} else if (mapping.name.includes('-')) {\n\t\t\t\t\tdashLessMappings.push({\n\t\t\t\t\t\t...mapping,\n\t\t\t\t\t\tname: mapping.name.replaceAll('-', '')\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// For every dash-less mapping, push a new subcommand\n\t\t\t\tfor (const dashLessMapping of dashLessMappings) {\n\t\t\t\t\tthis.parsedSubcommandMappings.push(dashLessMapping);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\n\t\t// #region Subcommand Preconditions\n\t\tfor (const subcommand of this.parsedSubcommandMappings) {\n\t\t\tsubcommand.type ??= 'method';\n\n\t\t\tif (subcommand.type === 'method') {\n\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(subcommand.preconditions);\n\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\tsubcommand.runIn,\n\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(subcommand.nsfw, preconditionContainerArray);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\tsubcommand.requiredClientPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\tsubcommand.requiredUserPermissions,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t);\n\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\tsubcommand: this,\n\t\t\t\t\tcooldownDelay: subcommand.cooldownDelay,\n\t\t\t\t\tcooldownFilteredUsers: subcommand.cooldownFilteredUsers,\n\t\t\t\t\tcooldownLimit: subcommand.cooldownLimit,\n\t\t\t\t\tcooldownScope: subcommand.cooldownScope,\n\t\t\t\t\tsubcommandMethodName: subcommand.name,\n\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t});\n\n\t\t\t\tthis.subcommandPreconditions.set(subcommand.name, preconditionContainerArray);\n\t\t\t}\n\n\t\t\tif (subcommand.type === 'group') {\n\t\t\t\tfor (const groupedSubcommand of subcommand.entries) {\n\t\t\t\t\tconst preconditionContainerArray = new PreconditionContainerArray(groupedSubcommand.preconditions);\n\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRunIn(\n\t\t\t\t\t\tgroupedSubcommand.runIn,\n\t\t\t\t\t\tthis.resolveConstructorPreConditionsRunType.bind(this),\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsNsfw(groupedSubcommand.nsfw, preconditionContainerArray);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredClientPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredClientPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tPreconditionResolvers.parseConstructorPreConditionsRequiredUserPermissions(\n\t\t\t\t\t\tgroupedSubcommand.requiredUserPermissions,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t);\n\t\t\t\t\tSubcommandPreconditionResolvers.parseSubcommandConstructorPreConditionsCooldown({\n\t\t\t\t\t\tsubcommand: this,\n\t\t\t\t\t\tcooldownDelay: groupedSubcommand.cooldownDelay,\n\t\t\t\t\t\tcooldownFilteredUsers: groupedSubcommand.cooldownFilteredUsers,\n\t\t\t\t\t\tcooldownLimit: groupedSubcommand.cooldownLimit,\n\t\t\t\t\t\tcooldownScope: groupedSubcommand.cooldownScope,\n\t\t\t\t\t\tsubcommandGroupName: subcommand.name,\n\t\t\t\t\t\tsubcommandMethodName: groupedSubcommand.name,\n\t\t\t\t\t\tpreconditionContainerArray\n\t\t\t\t\t});\n\n\t\t\t\t\tthis.subcommandPreconditions.set(`${subcommand.name}.${groupedSubcommand.name}`, preconditionContainerArray);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// #endregion\n\t}\n\n\tpublic override onLoad() {\n\t\tsuper.onLoad();\n\n\t\tconst externalMapping = Reflect.get(this, 'subcommandMappings');\n\t\tif (externalMapping) {\n\t\t\tconst subcommands = Array.isArray(externalMapping) ? externalMapping : [];\n\t\t\tthis.parsedSubcommandMappings = subcommands;\n\t\t\tthis.options.subcommands = subcommands;\n\t\t}\n\t}\n\n\t/**\n\t * Whether this command has message-based subcommands or not\n\t * @returns `true` if this command has message-based subcommands, otherwise `false`\n\t */\n\tpublic override supportsMessageCommands(): this is MessageCommand {\n\t\treturn this.#supportsCommandType('messageRun');\n\t}\n\n\t/**\n\t * Whether this command has chat input subcommands or not\n\t * @returns `true` if this command has chat input subcommands, otherwise `false`\n\t */\n\tpublic override supportsChatInputCommands(): this is ChatInputCommand {\n\t\treturn this.#supportsCommandType('chatInputRun');\n\t}\n\n\t/**\n\t * The method that is ran when a message-based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async messageRun(message: Message, args: PreParseReturn, context: MessageCommand.RunContext) {\n\t\targs.save();\n\t\tconst subcommandOrGroup = args.nextMaybe();\n\t\tconst subcommandName = args.nextMaybe();\n\t\tlet defaultCommand: SubcommandMappingMethod | null = null;\n\t\tlet actualSubcommandToRun: SubcommandMappingMethod | null = null;\n\t\tlet matchedWithGroupedSubcommand = false;\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.type === 'method') {\n\t\t\t\tif (mapping.default && !defaultCommand) {\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\tdefaultCommand = mapping;\n\t\t\t\t}\n\n\t\t\t\tif (subcommandOrGroup.isSomeAnd((value) => mapping.name === (this.caseInsensitiveSubcommands ? value.toLowerCase() : value))) {\n\t\t\t\t\tactualSubcommandToRun = mapping;\n\t\t\t\t\tmatchedWithGroupedSubcommand = false;\n\t\t\t\t\t// Exit early\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We expect a group mapping\n\t\t\tif (mapping.type === 'group' && subcommandOrGroup.isSome() && subcommandName.isSome()) {\n\t\t\t\tconst unwrappedSubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\tconst unwrappedSubcommandName = subcommandName.unwrap();\n\n\t\t\t\t// We know a group was passed in here\n\t\t\t\tif (mapping.name === unwrappedSubcommandGroupName) {\n\t\t\t\t\t// Find the actual subcommand to run\n\t\t\t\t\tconst findResult = this.#findSubcommand(\n\t\t\t\t\t\tmapping.entries,\n\t\t\t\t\t\tthis.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName\n\t\t\t\t\t);\n\n\t\t\t\t\tif (findResult.defaultMatch) {\n\t\t\t\t\t\tdefaultCommand = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tactualSubcommandToRun = findResult.mapping;\n\t\t\t\t\t\tmatchedWithGroupedSubcommand = true;\n\t\t\t\t\t\t// Exit early\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Preemptively restore the args state, to provide a correct args result for users\n\t\targs.restore();\n\n\t\tif (actualSubcommandToRun) {\n\t\t\t// Skip over the subcommandOrGroup\n\t\t\targs.next();\n\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 more arg\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, actualSubcommandToRun, subcommandGroupName);\n\t\t}\n\n\t\t// No subcommand matched, let's try to run default, if any:\n\t\tif (defaultCommand) {\n\t\t\t// If we matched with a subcommand in a group we need to skip 1 the group name\n\t\t\tlet subcommandGroupName: string | undefined = undefined;\n\t\t\tif (matchedWithGroupedSubcommand) {\n\t\t\t\tsubcommandGroupName = subcommandOrGroup.unwrap();\n\t\t\t\targs.next();\n\t\t\t}\n\n\t\t\treturn this.#handleMessageRun(message, args, context, defaultCommand, subcommandGroupName);\n\t\t}\n\n\t\tconst commandPrefix = this.#getCommandPrefix(message.content, args.commandContext.prefix);\n\t\tconst prefixLessContent = message.content.slice(commandPrefix.length).trim();\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandNoMatch, message, args, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on message command \"${this.name}\" at path \"${this.location.full}\" with content ${prefixLessContent}`,\n\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t});\n\t}\n\n\t/**\n\t * The method that is ran when a chat input based subcommand is ran.\n\t *\n\t * **DO NOT** override this in your implementation of a subcommand!\n\t */\n\tpublic override async chatInputRun(interaction: ChatInputCommand.Interaction, context: ChatInputCommand.RunContext) {\n\t\tconst subcommandName = interaction.options.getSubcommand(false);\n\t\tconst subcommandGroupName = interaction.options.getSubcommandGroup(false);\n\n\t\tfor (const mapping of this.parsedSubcommandMappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\t// If we have a group, we know we also have a subcommand and we should find and run it\n\t\t\tif (subcommandGroupName && subcommandName) {\n\t\t\t\tif (mapping.type !== 'group') continue;\n\t\t\t\tif (mapping.name !== subcommandGroupName) continue;\n\n\t\t\t\tconst foundSubcommand = this.#findSubcommand(mapping.entries, subcommandName!);\n\n\t\t\t\t// Only run if its not the \"default\" found command mapping, as interactions don't have that\n\t\t\t\tif (!foundSubcommand.defaultMatch) {\n\t\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, foundSubcommand.mapping, subcommandGroupName);\n\t\t\t\t}\n\n\t\t\t\t// Skip to the next entry\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If we have a direct subcommand, and no group, then run the mapping\n\t\t\tif (mapping.type === 'method' && mapping.name === subcommandName) {\n\t\t\t\treturn this.#handleChatInputInteractionRun(interaction, context, mapping, undefined);\n\t\t\t}\n\t\t}\n\n\t\t// No match and no subcommand, emit an error:\n\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandNoMatch, interaction, {\n\t\t\t...context,\n\t\t\tcommand: this,\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: `Unable to match a subcommand on chat input command \"${this.name}\" at path \"${this.location.full}\"`\n\t\t});\n\t}\n\n\t#getCommandPrefix(content: string, prefix: string | RegExp): string {\n\t\treturn typeof prefix === 'string' ? prefix : prefix.exec(content)![0];\n\t}\n\n\tasync #getMessageParametersAsString(args: Args): Promise<Partial<Pick<MessageCommandDeniedPayload, 'parameters'>>> {\n\t\targs.save();\n\t\tconst parameters = await args.restResult('string');\n\t\targs.restore();\n\n\t\tconst params: Partial<Pick<MessageCommandDeniedPayload, 'parameters'>> = {};\n\n\t\tif (parameters.isOk()) {\n\t\t\tparams.parameters = parameters.unwrap();\n\t\t}\n\n\t\treturn params;\n\t}\n\n\tasync #handleMessageRun(\n\t\tmessage: Message,\n\t\targs: Args,\n\t\tcontext: MessageCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: MessageSubcommandAcceptedPayload = {\n\t\t\tmessage,\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Attempt to get the remaining parameters as string:\n\t\t\tconst messageParametersAsString = await this.#getMessageParametersAsString(args);\n\n\t\t\t// Build the precondition payload:\n\t\t\tconst preconditionPayload = { ...messageParametersAsString, ...payload };\n\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.messageRun(message, this, preconditionPayload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandDenied, localSubcommandResult.unwrapErr(), preconditionPayload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If subcommand preconditions have passed then we run the actual subcommand:\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.messageRun) {\n\t\t\t\tconst casted = subcommand as MessageSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandRun, message, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.messageRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.messageRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"messageRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['messageRun']>(method), this, [message, args, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.messageRun(message, args, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.MessageSubcommandSuccess, message, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.SubcommandMappingIsMissingMessageCommandHandler, message, subcommand, payload);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.MessageSubcommandError, error, payload));\n\t}\n\n\tasync #handleChatInputInteractionRun(\n\t\tinteraction: ChatInputCommand.Interaction,\n\t\tcontext: ChatInputCommand.RunContext,\n\t\tsubcommand: SubcommandMappingMethod,\n\t\tsubcommandGroupName: string | undefined\n\t) {\n\t\tconst payload: ChatInputSubcommandAcceptedPayload = {\n\t\t\tcommand: this,\n\t\t\tcontext,\n\t\t\tinteraction,\n\t\t\tmatchedSubcommandMapping: subcommand\n\t\t};\n\n\t\t// Check if any subcommand preconditions were defined for thus subcommand:\n\t\tconst preconditionsForSubcommand = this.subcommandPreconditions.get(\n\t\t\tsubcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name\n\t\t);\n\n\t\tif (preconditionsForSubcommand) {\n\t\t\t// Run the subcommand specific preconditions:\n\t\t\tconst localSubcommandResult = await preconditionsForSubcommand.chatInputRun(interaction, this, payload as any);\n\t\t\tif (localSubcommandResult.isErr()) {\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandDenied, localSubcommandResult.unwrapErr(), payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst result = await Result.fromAsync(async () => {\n\t\t\tif (subcommand.chatInputRun) {\n\t\t\t\tconst casted = subcommand as ChatInputCommandSubcommandMappingMethod;\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandRun, interaction, casted, payload);\n\t\t\t\tlet result: unknown;\n\n\t\t\t\tif (typeof subcommand.chatInputRun === 'string') {\n\t\t\t\t\tconst method = Reflect.get(this, subcommand.chatInputRun);\n\t\t\t\t\tif (!method) {\n\t\t\t\t\t\tthrow new UserError({\n\t\t\t\t\t\t\tidentifier: SubcommandPluginIdentifiers.SubcommandNotFound,\n\t\t\t\t\t\t\tmessage: `The method configured at \"chatInputRun\" for the subcommand ${subcommand.name} was not implemented in the class.`,\n\t\t\t\t\t\t\tcontext: { ...payload }\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresult = await Reflect.apply(cast<this['chatInputRun']>(method), this, [interaction, context]);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await subcommand.chatInputRun(interaction, context);\n\t\t\t\t}\n\n\t\t\t\tthis.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandSuccess, interaction, casted, { ...payload, result });\n\t\t\t} else {\n\t\t\t\tthis.container.client.emit(\n\t\t\t\t\tSubcommandPluginEvents.SubcommandMappingIsMissingChatInputCommandHandler,\n\t\t\t\t\tinteraction,\n\t\t\t\t\tsubcommand,\n\t\t\t\t\tpayload\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tresult.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandError, error, payload));\n\t}\n\n\t#findSubcommand(mappings: SubcommandMappingMethod[], expectedName: string) {\n\t\tlet foundDefault: SubcommandMappingMethod | null = null;\n\n\t\tfor (const mapping of mappings) {\n\t\t\tmapping.type ??= 'method';\n\n\t\t\tif (mapping.default) {\n\t\t\t\tfoundDefault = mapping;\n\t\t\t}\n\n\t\t\tif (mapping.name === expectedName) {\n\t\t\t\treturn { mapping, defaultMatch: false } as const;\n\t\t\t}\n\t\t}\n\n\t\treturn { mapping: foundDefault, defaultMatch: true } as const;\n\t}\n\n\t#supportsCommandType(commandType: 'messageRun' | 'chatInputRun'): boolean {\n\t\treturn this.parsedSubcommandMappings.some((mapping) => {\n\t\t\tif (mapping.type === 'group') {\n\t\t\t\treturn mapping.entries.some((groupCommand) => Reflect.has(groupCommand, commandType));\n\t\t\t}\n\t\t\treturn Reflect.has(mapping, commandType);\n\t\t});\n\t}\n}\n\nexport interface SubcommandOptions extends Command.Options {\n\tsubcommands?: SubcommandMappingArray;\n\t/**\n\t * Whether to add aliases for subcommands with dashes in them\n\t *\n\t * When this option is enabled *and* the subcommand implements `messageRun`, dashless aliases will be added.\n\t *\n\t * For subcommands groups both the group itself and all subcommands within the group will have dashless aliases added.\n\t *\n\t * @since 3.0.0\n\t * @default false\n\t */\n\tgenerateDashLessAliases?: boolean;\n}\n\nexport namespace Subcommand {\n\texport type Options = SubcommandOptions;\n\texport type JSON = Command.JSON;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Command.LoaderContext;\n\texport type RunInTypes = Command.RunInTypes;\n\texport type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = Command.ChatInputCommandInteraction<Cached>;\n\texport type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = Command.ContextMenuCommandInteraction<Cached>;\n\texport type AutocompleteInteraction<Cached extends CacheType = CacheType> = Command.AutocompleteInteraction<Cached>;\n\texport type Registry = Command.Registry;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-subcommands",
|
|
3
|
-
"version": "7.0.2-next.
|
|
3
|
+
"version": "7.0.2-next.ebf804c",
|
|
4
4
|
"description": "Plugin for @sapphire/framework that adds support for subcommands.",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"lint": "eslint src --ext ts --fix",
|
|
39
39
|
"build": "tsup && yarn build:types && yarn build:rename-cjs-register",
|
|
40
40
|
"build:types": "concurrently \"yarn:build:types:*\"",
|
|
41
|
-
"build:types:cjs": "rollup-type-bundler -d dist/cjs -
|
|
41
|
+
"build:types:cjs": "rollup-type-bundler -d dist/cjs --output-typings-file-extension .cts",
|
|
42
42
|
"build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
|
|
43
43
|
"build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
|
|
44
44
|
"build:rename-cjs-register": "tsx ../../scripts/rename-cjs-register.mts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"check-update": "cliff-jumper --dry-run"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@sapphire/utilities": "^3.18.
|
|
52
|
+
"@sapphire/utilities": "^3.18.1"
|
|
53
53
|
},
|
|
54
54
|
"repository": {
|
|
55
55
|
"type": "git",
|
|
@@ -81,9 +81,9 @@
|
|
|
81
81
|
"access": "public"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@favware/cliff-jumper": "^
|
|
85
|
-
"@favware/rollup-type-bundler": "^
|
|
86
|
-
"concurrently": "^9.
|
|
84
|
+
"@favware/cliff-jumper": "^6.0.0",
|
|
85
|
+
"@favware/rollup-type-bundler": "^4.0.0",
|
|
86
|
+
"concurrently": "^9.1.2",
|
|
87
87
|
"tsup": "^8.3.5",
|
|
88
88
|
"tsx": "^4.19.2",
|
|
89
89
|
"typedoc": "^0.26.11",
|