@sapphire/plugin-subcommands 6.0.4-next.43df709.0 → 6.0.4-next.4ab5259.0

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.
@@ -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 = "6.0.4-next.43df709.0";
36
+ var version = "6.0.4-next.4ab5259.0";
37
37
 
38
38
  Object.defineProperty(exports, "PluginSubcommandCooldownPrecondition", {
39
39
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AACA;AAAA,EACC,sBAAsB;AAAA,OAEhB;AAEP,cAAc;AACd,YAAY,qCAAqC;AACjD,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACuB;AAAA,OAEhB;AAEP,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAmC3B,IAAM,0BAA0B;AAAA,EACtC;AACD;AAoBO,IAAM,UAAkB","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 = '6.0.4-next.43df709.0';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AACA;AAAA,EACC,sBAAsB;AAAA,OAEhB;AAEP,cAAc;AACd,YAAY,qCAAqC;AACjD,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACuB;AAAA,OAEhB;AAEP,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAmC3B,IAAM,0BAA0B;AAAA,EACtC;AACD;AAoBO,IAAM,UAAkB","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 = '6.0.4-next.4ab5259.0';\n"]}
@@ -6,34 +6,20 @@ var index_cjs = require('../index.cjs');
6
6
  var Events_cjs = require('./types/Events.cjs');
7
7
 
8
8
  var __defProp = Object.defineProperty;
9
+ var __typeError = (msg) => {
10
+ throw TypeError(msg);
11
+ };
9
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
13
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- var __publicField = (obj, key, value) => {
12
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
- return value;
14
- };
15
- var __accessCheck = (obj, member, msg) => {
16
- if (!member.has(obj))
17
- throw TypeError("Cannot " + msg);
18
- };
19
- var __privateAdd = (obj, member, value) => {
20
- if (member.has(obj))
21
- throw TypeError("Cannot add the same private member more than once");
22
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
23
- };
24
- var __privateMethod = (obj, member, method) => {
25
- __accessCheck(obj, member, "access private method");
26
- return method;
27
- };
28
- var _getMessageParametersAsString, getMessageParametersAsString_fn, _handleMessageRun, handleMessageRun_fn, _handleChatInputInteractionRun, handleChatInputInteractionRun_fn, _findSubcommand, findSubcommand_fn, _supportsCommandType, supportsCommandType_fn;
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
17
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
18
+ var _Subcommand_instances, getMessageParametersAsString_fn, handleMessageRun_fn, handleChatInputInteractionRun_fn, findSubcommand_fn, supportsCommandType_fn;
29
19
  var _Subcommand = class _Subcommand extends framework.Command {
30
20
  constructor(context, options) {
31
21
  super(context, options);
32
- __privateAdd(this, _getMessageParametersAsString);
33
- __privateAdd(this, _handleMessageRun);
34
- __privateAdd(this, _handleChatInputInteractionRun);
35
- __privateAdd(this, _findSubcommand);
36
- __privateAdd(this, _supportsCommandType);
22
+ __privateAdd(this, _Subcommand_instances);
37
23
  /**
38
24
  * The preconditions to be run for each specified subcommand.
39
25
  * @since 4.1.0
@@ -176,14 +162,14 @@ var _Subcommand = class _Subcommand extends framework.Command {
176
162
  * @returns `true` if this command has message-based subcommands, otherwise `false`
177
163
  */
178
164
  supportsMessageCommands() {
179
- return __privateMethod(this, _supportsCommandType, supportsCommandType_fn).call(this, "messageRun");
165
+ return __privateMethod(this, _Subcommand_instances, supportsCommandType_fn).call(this, "messageRun");
180
166
  }
181
167
  /**
182
168
  * Whether this command has chat input subcommands or not
183
169
  * @returns `true` if this command has chat input subcommands, otherwise `false`
184
170
  */
185
171
  supportsChatInputCommands() {
186
- return __privateMethod(this, _supportsCommandType, supportsCommandType_fn).call(this, "chatInputRun");
172
+ return __privateMethod(this, _Subcommand_instances, supportsCommandType_fn).call(this, "chatInputRun");
187
173
  }
188
174
  /**
189
175
  * The method that is ran when a message-based subcommand is ran.
@@ -214,7 +200,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
214
200
  const unwrappedSubcommandGroupName = subcommandOrGroup.unwrap();
215
201
  const unwrappedSubcommandName = subcommandName.unwrap();
216
202
  if (mapping.name === unwrappedSubcommandGroupName) {
217
- const findResult = __privateMethod(this, _findSubcommand, findSubcommand_fn).call(this, mapping.entries, this.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName);
203
+ const findResult = __privateMethod(this, _Subcommand_instances, findSubcommand_fn).call(this, mapping.entries, this.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName);
218
204
  if (findResult.defaultMatch) {
219
205
  defaultCommand = findResult.mapping;
220
206
  matchedWithGroupedSubcommand = true;
@@ -234,7 +220,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
234
220
  subcommandGroupName = subcommandOrGroup.unwrap();
235
221
  args.next();
236
222
  }
237
- return __privateMethod(this, _handleMessageRun, handleMessageRun_fn).call(this, message, args, context, actualSubcommandToRun, subcommandGroupName);
223
+ return __privateMethod(this, _Subcommand_instances, handleMessageRun_fn).call(this, message, args, context, actualSubcommandToRun, subcommandGroupName);
238
224
  }
239
225
  if (defaultCommand) {
240
226
  let subcommandGroupName = void 0;
@@ -242,7 +228,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
242
228
  subcommandGroupName = subcommandOrGroup.unwrap();
243
229
  args.next();
244
230
  }
245
- return __privateMethod(this, _handleMessageRun, handleMessageRun_fn).call(this, message, args, context, defaultCommand, subcommandGroupName);
231
+ return __privateMethod(this, _Subcommand_instances, handleMessageRun_fn).call(this, message, args, context, defaultCommand, subcommandGroupName);
246
232
  }
247
233
  throw new framework.UserError({
248
234
  identifier: Events_cjs.SubcommandPluginIdentifiers.MessageSubcommandNoMatch,
@@ -265,18 +251,16 @@ var _Subcommand = class _Subcommand extends framework.Command {
265
251
  for (const mapping of this.parsedSubcommandMappings) {
266
252
  mapping.type ??= "method";
267
253
  if (subcommandGroupName && subcommandName) {
268
- if (mapping.type !== "group")
269
- continue;
270
- if (mapping.name !== subcommandGroupName)
271
- continue;
272
- const foundSubcommand = __privateMethod(this, _findSubcommand, findSubcommand_fn).call(this, mapping.entries, subcommandName);
254
+ if (mapping.type !== "group") continue;
255
+ if (mapping.name !== subcommandGroupName) continue;
256
+ const foundSubcommand = __privateMethod(this, _Subcommand_instances, findSubcommand_fn).call(this, mapping.entries, subcommandName);
273
257
  if (!foundSubcommand.defaultMatch) {
274
- return __privateMethod(this, _handleChatInputInteractionRun, handleChatInputInteractionRun_fn).call(this, interaction, context, foundSubcommand.mapping, subcommandGroupName);
258
+ return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, foundSubcommand.mapping, subcommandGroupName);
275
259
  }
276
260
  continue;
277
261
  }
278
262
  if (mapping.type === "method" && mapping.name === subcommandName) {
279
- return __privateMethod(this, _handleChatInputInteractionRun, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping, void 0);
263
+ return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping, void 0);
280
264
  }
281
265
  }
282
266
  throw new framework.UserError({
@@ -286,7 +270,7 @@ var _Subcommand = class _Subcommand extends framework.Command {
286
270
  });
287
271
  }
288
272
  };
289
- _getMessageParametersAsString = new WeakSet();
273
+ _Subcommand_instances = new WeakSet();
290
274
  getMessageParametersAsString_fn = /* @__PURE__ */ __name(async function(args) {
291
275
  args.save();
292
276
  const parameters = await args.restResult("string");
@@ -297,7 +281,6 @@ getMessageParametersAsString_fn = /* @__PURE__ */ __name(async function(args) {
297
281
  }
298
282
  return params;
299
283
  }, "#getMessageParametersAsString");
300
- _handleMessageRun = new WeakSet();
301
284
  handleMessageRun_fn = /* @__PURE__ */ __name(async function(message, args, context, subcommand, subcommandGroupName) {
302
285
  const payload = {
303
286
  message,
@@ -309,7 +292,7 @@ handleMessageRun_fn = /* @__PURE__ */ __name(async function(message, args, conte
309
292
  subcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name
310
293
  );
311
294
  if (preconditionsForSubcommand) {
312
- const messageParametersAsString = await __privateMethod(this, _getMessageParametersAsString, getMessageParametersAsString_fn).call(this, args);
295
+ const messageParametersAsString = await __privateMethod(this, _Subcommand_instances, getMessageParametersAsString_fn).call(this, args);
313
296
  const preconditionPayload = { ...messageParametersAsString, ...payload };
314
297
  const localSubcommandResult = await preconditionsForSubcommand.messageRun(message, this, preconditionPayload);
315
298
  if (localSubcommandResult.isErr()) {
@@ -342,7 +325,6 @@ handleMessageRun_fn = /* @__PURE__ */ __name(async function(message, args, conte
342
325
  });
343
326
  result.inspectErr((error) => this.container.client.emit(Events_cjs.SubcommandPluginEvents.MessageSubcommandError, error, payload));
344
327
  }, "#handleMessageRun");
345
- _handleChatInputInteractionRun = new WeakSet();
346
328
  handleChatInputInteractionRun_fn = /* @__PURE__ */ __name(async function(interaction, context, subcommand, subcommandGroupName) {
347
329
  const payload = {
348
330
  command: this,
@@ -390,7 +372,6 @@ handleChatInputInteractionRun_fn = /* @__PURE__ */ __name(async function(interac
390
372
  });
391
373
  result.inspectErr((error) => this.container.client.emit(Events_cjs.SubcommandPluginEvents.ChatInputSubcommandError, error, payload));
392
374
  }, "#handleChatInputInteractionRun");
393
- _findSubcommand = new WeakSet();
394
375
  findSubcommand_fn = /* @__PURE__ */ __name(function(mappings, expectedName) {
395
376
  let foundDefault = null;
396
377
  for (const mapping of mappings) {
@@ -404,7 +385,6 @@ findSubcommand_fn = /* @__PURE__ */ __name(function(mappings, expectedName) {
404
385
  }
405
386
  return { mapping: foundDefault, defaultMatch: true };
406
387
  }, "#findSubcommand");
407
- _supportsCommandType = new WeakSet();
408
388
  supportsCommandType_fn = /* @__PURE__ */ __name(function(commandType) {
409
389
  return this.parsedSubcommandMappings.some((mapping) => {
410
390
  if (mapping.type === "group") {
@@ -1 +1 @@
1
- {"version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ommand,\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(): boolean {\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\t// No match and no subcommand, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided arguments.',\n\t\t\tcontext: {\n\t\t\t\t...context,\n\t\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t\t}\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, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided command.',\n\t\t\tcontext\n\t\t});\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;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,MAAM,iBAAiB;AAEhC,SAAS,uCAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AAnBP;AAoCO,IAAM,cAAN,MAAM,oBAAgH,QAG3H;AAAA,EAmBM,YAAY,SAAmC,SAAkB;AAEvE,UAAM,SAAS,OAAO;AAxBjB;AAQN;AAAA;AAAA;AAAA;AAAA,wBAAgB,2BAA0B,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AU,KAAK,UAAU,OAAO,KAAK,uBAAuB,0BAA0B,OAAO,OAAO,CAAC;AACzH,GA7DoC;AA+DpC,oBAAe,gCAAC,UAAqC,cAAsB;AAC1E,MAAI,eAA+C;AAEnD,aAAW,WAAW,UAAU;AAC/B,YAAQ,SAAS;AAEjB,QAAI,QAAQ,SAAS;AACpB,qBAAe;AAAA,IAChB;AAEA,QAAI,QAAQ,SAAS,cAAc;AAClC,aAAO,EAAE,SAAS,cAAc,MAAM;AAAA,IACvC;AAAA,EACD;AAEA,SAAO,EAAE,SAAS,cAAc,cAAc,KAAK;AACpD,GAhBe;AAkBf,yBAAoB,gCAAC,aAAqD;AACzE,SAAO,KAAK,yBAAyB,KAAK,CAAC,YAAY;AACtD,QAAI,QAAQ,SAAS,SAAS;AAC7B,aAAO,QAAQ,QAAQ,KAAK,CAAC,iBAAiB,QAAQ,IAAI,cAAc,WAAW,CAAC;AAAA,IACrF;AACA,WAAO,QAAQ,IAAI,SAAS,WAAW;AAAA,EACxC,CAAC;AACF,GAPoB;AA5fnB;AAHK,IAAM,aAAN","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(): boolean {\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\t// No match and no subcommand, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided arguments.',\n\t\t\tcontext: {\n\t\t\t\t...context,\n\t\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t\t}\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, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided command.',\n\t\t\tcontext\n\t\t});\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"]}
@@ -9,10 +9,7 @@ var Enums_cjs = require('../lib/types/Enums.cjs');
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- var __publicField = (obj, key, value) => {
13
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
- return value;
15
- };
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
13
  var _PluginPrecondition = class _PluginPrecondition extends framework.AllFlowsPrecondition {
17
14
  constructor() {
18
15
  super(...arguments);
@@ -31,12 +28,9 @@ var _PluginPrecondition = class _PluginPrecondition extends framework.AllFlowsPr
31
28
  return this.sharedRun(interaction.user.id, subcommand, context, cooldownId, "context menu");
32
29
  }
33
30
  sharedRun(authorId, subcommand, context, cooldownId, commandType) {
34
- if (context.external)
35
- return this.ok();
36
- if (!context.delay)
37
- return this.ok();
38
- if (context.filteredUsers?.includes(authorId))
39
- return this.ok();
31
+ if (context.external) return this.ok();
32
+ if (!context.delay) return this.ok();
33
+ if (context.filteredUsers?.includes(authorId)) return this.ok();
40
34
  const rateLimit = this.getManager(subcommand, context).acquire(cooldownId);
41
35
  if (rateLimit.limited) {
42
36
  const remaining = rateLimit.remainingTime;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AS;AACb,gBAAU,IAAI,iBAAiB,QAAQ,OAAO,QAAQ,KAAK;AAC3D,WAAK,kBAAkB,IAAI,YAAY,OAAO;AAAA,IAC/C;AACA,WAAO;AAAA,EACR;AACD;AA1G6D;AAAtD,IAAM,qBAAN","sourcesContent":["import { AllFlowsPrecondition, BucketScope, Command, CorePreconditions } from '@sapphire/framework';\nimport { RateLimitManager } from '@sapphire/ratelimits';\nimport {\n\tTimestampStyles,\n\ttime,\n\ttype ChatInputCommandInteraction,\n\ttype CommandInteraction,\n\ttype ContextMenuCommandInteraction,\n\ttype Message\n} from 'discord.js';\nimport { Subcommand } from '../lib/Subcommand';\nimport { SubcommandIdentifiers } from '../lib/types/Enums';\n\n/**\n * The context for the subcommand cooldown precondition\n * @since 5.1.0\n */\nexport interface PluginSubcommandCooldownPreconditionContext extends CorePreconditions.CooldownContext {\n\t/** The name of the subcommand */\n\tsubcommandMethodName: string;\n\t/** The name of the subcommand group, if any */\n\tsubcommandGroupName?: string;\n}\n\n/**\n * The subcommand cooldown precondition. This differs from the cooldown precondition in framework by using a separate\n * bucket as well as resolving the id differently to ensure it is specific to a subcommand.\n * @since 5.1.0\n */\nexport class PluginPrecondition extends AllFlowsPrecondition {\n\tpublic subcommandBuckets = new WeakMap<Subcommand, RateLimitManager<string>>();\n\n\tpublic override messageRun(\n\t\tmessage: Message,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromMessage(message, context);\n\n\t\treturn this.sharedRun(message.author.id, subcommand, context, cooldownId, 'message');\n\t}\n\n\tpublic override chatInputRun(\n\t\tinteraction: ChatInputCommandInteraction,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand, context, cooldownId, 'chat input');\n\t}\n\n\tpublic override contextMenuRun(\n\t\tinteraction: ContextMenuCommandInteraction,\n\t\tsubcommand: Command,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand as Subcommand, context, cooldownId, 'context menu');\n\t}\n\n\tprivate sharedRun(\n\t\tauthorId: string,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext,\n\t\tcooldownId: string,\n\t\tcommandType: string\n\t): AllFlowsPrecondition.Result {\n\t\t// If the subcommand it is testing for is not this one, return ok:\n\t\tif (context.external) return this.ok();\n\n\t\t// If there is no delay (undefined, null, 0), return ok:\n\t\tif (!context.delay) return this.ok();\n\n\t\t// If the user has provided any filtered users and the authorId is in that array, return ok:\n\t\tif (context.filteredUsers?.includes(authorId)) return this.ok();\n\n\t\tconst rateLimit = this.getManager(subcommand, context).acquire(cooldownId);\n\n\t\tif (rateLimit.limited) {\n\t\t\tconst remaining = rateLimit.remainingTime;\n\n\t\t\tconst nextAvailable = time(Math.floor(rateLimit.expires / 1000), TimestampStyles.RelativeTime);\n\t\t\treturn this.error({\n\t\t\t\tidentifier: SubcommandIdentifiers.SubcommandPreconditionCooldown,\n\t\t\t\tmessage: `There is a cooldown in effect for this ${commandType} subcommand. It'll be available ${nextAvailable}.`,\n\t\t\t\tcontext: { remaining }\n\t\t\t});\n\t\t}\n\n\t\trateLimit.consume();\n\t\treturn this.ok();\n\t}\n\n\tprivate getIdFromMessage(message: Message, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${message.guildId}.${subcommandIdentifier}` ?? `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${message.author.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getIdFromInteraction(interaction: CommandInteraction, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${interaction.guildId}.${subcommandIdentifier}` ?? `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${interaction.user.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getSubcommandMappingName(context: PluginSubcommandCooldownPreconditionContext) {\n\t\treturn context.subcommandGroupName ? `${context.subcommandGroupName}.${context.subcommandMethodName}` : context.subcommandMethodName;\n\t}\n\n\tprivate getManager(subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tlet manager = this.subcommandBuckets.get(subcommand);\n\t\tif (!manager) {\n\t\t\tmanager = new RateLimitManager(context.delay, context.limit);\n\t\t\tthis.subcommandBuckets.set(subcommand, manager);\n\t\t}\n\t\treturn manager;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/preconditions/PluginSubcommandCooldown.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,sBAAsB,mBAA+C;AAC9E,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA;AAAA,OAKM;AACP,OAA2B;AAC3B,SAAS,6BAA6B;AAkB/B,IAAM,sBAAN,MAAM,4BAA2B,qBAAqB;AAAA,EAAtD;AAAA;AACN,wBAAO,qBAAoB,oBAAI,QAA8C;AAAA;AAAA,EAE7D,WACf,SACA,YACA,SAC8B;AA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AChB,eAAO,GAAG,QAAQ,SAAS,IAAI,oBAAoB;AAAA,MACpD,KAAK,YAAY;AAChB,eAAO,GAAG,QAAQ,OAAO,IAAI,oBAAoB,MAAM,GAAG,QAAQ,SAAS,IAAI,oBAAoB;AAAA,MACpG;AACC,eAAO,GAAG,QAAQ,OAAO,EAAE,IAAI,oBAAoB;AAAA,IACrD;AAAA,EACD;AAAA,EAEQ,qBAAqB,aAAiC,SAAsD;AACnH,UAAM,uBAAuB,KAAK,yBAAyB,OAAO;AAClE,YAAQ,QAAQ,OAAO;AAAA,MACtB,KAAK,YAAY;AAChB,eAAO,UAAU,oBAAoB;AAAA,MACtC,KAAK,YAAY;AAChB,eAAO,GAAG,YAAY,SAAS,IAAI,oBAAoB;AAAA,MACxD,KAAK,YAAY;AAChB,eAAO,GAAG,YAAY,OAAO,IAAI,oBAAoB,MAAM,GAAG,YAAY,SAAS,IAAI,oBAAoB;AAAA,MAC5G;AACC,eAAO,GAAG,YAAY,KAAK,EAAE,IAAI,oBAAoB;AAAA,IACvD;AAAA,EACD;AAAA,EAEQ,yBAAyB,SAAsD;AACtF,WAAO,QAAQ,sBAAsB,GAAG,QAAQ,mBAAmB,IAAI,QAAQ,oBAAoB,KAAK,QAAQ;AAAA,EACjH;AAAA,EAEQ,WAAW,YAAwB,SAAsD;AAChG,QAAI,UAAU,KAAK,kBAAkB,IAAI,UAAU;AACnD,QAAI,CAAC,SAAS;AACb,gBAAU,IAAI,iBAAiB,QAAQ,OAAO,QAAQ,KAAK;AAC3D,WAAK,kBAAkB,IAAI,YAAY,OAAO;AAAA,IAC/C;AACA,WAAO;AAAA,EACR;AACD;AA1G6D;AAAtD,IAAM,qBAAN","sourcesContent":["import { AllFlowsPrecondition, BucketScope, Command, CorePreconditions } from '@sapphire/framework';\nimport { RateLimitManager } from '@sapphire/ratelimits';\nimport {\n\tTimestampStyles,\n\ttime,\n\ttype ChatInputCommandInteraction,\n\ttype CommandInteraction,\n\ttype ContextMenuCommandInteraction,\n\ttype Message\n} from 'discord.js';\nimport { Subcommand } from '../lib/Subcommand';\nimport { SubcommandIdentifiers } from '../lib/types/Enums';\n\n/**\n * The context for the subcommand cooldown precondition\n * @since 5.1.0\n */\nexport interface PluginSubcommandCooldownPreconditionContext extends CorePreconditions.CooldownContext {\n\t/** The name of the subcommand */\n\tsubcommandMethodName: string;\n\t/** The name of the subcommand group, if any */\n\tsubcommandGroupName?: string;\n}\n\n/**\n * The subcommand cooldown precondition. This differs from the cooldown precondition in framework by using a separate\n * bucket as well as resolving the id differently to ensure it is specific to a subcommand.\n * @since 5.1.0\n */\nexport class PluginPrecondition extends AllFlowsPrecondition {\n\tpublic subcommandBuckets = new WeakMap<Subcommand, RateLimitManager<string>>();\n\n\tpublic override messageRun(\n\t\tmessage: Message,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromMessage(message, context);\n\n\t\treturn this.sharedRun(message.author.id, subcommand, context, cooldownId, 'message');\n\t}\n\n\tpublic override chatInputRun(\n\t\tinteraction: ChatInputCommandInteraction,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand, context, cooldownId, 'chat input');\n\t}\n\n\tpublic override contextMenuRun(\n\t\tinteraction: ContextMenuCommandInteraction,\n\t\tsubcommand: Command,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand as Subcommand, context, cooldownId, 'context menu');\n\t}\n\n\tprivate sharedRun(\n\t\tauthorId: string,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext,\n\t\tcooldownId: string,\n\t\tcommandType: string\n\t): AllFlowsPrecondition.Result {\n\t\t// If the subcommand it is testing for is not this one, return ok:\n\t\tif (context.external) return this.ok();\n\n\t\t// If there is no delay (undefined, null, 0), return ok:\n\t\tif (!context.delay) return this.ok();\n\n\t\t// If the user has provided any filtered users and the authorId is in that array, return ok:\n\t\tif (context.filteredUsers?.includes(authorId)) return this.ok();\n\n\t\tconst rateLimit = this.getManager(subcommand, context).acquire(cooldownId);\n\n\t\tif (rateLimit.limited) {\n\t\t\tconst remaining = rateLimit.remainingTime;\n\n\t\t\tconst nextAvailable = time(Math.floor(rateLimit.expires / 1000), TimestampStyles.RelativeTime);\n\t\t\treturn this.error({\n\t\t\t\tidentifier: SubcommandIdentifiers.SubcommandPreconditionCooldown,\n\t\t\t\tmessage: `There is a cooldown in effect for this ${commandType} subcommand. It'll be available ${nextAvailable}.`,\n\t\t\t\tcontext: { remaining }\n\t\t\t});\n\t\t}\n\n\t\trateLimit.consume();\n\t\treturn this.ok();\n\t}\n\n\tprivate getIdFromMessage(message: Message, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${message.guildId}.${subcommandIdentifier}` ?? `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${message.author.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getIdFromInteraction(interaction: CommandInteraction, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${interaction.guildId}.${subcommandIdentifier}` ?? `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${interaction.user.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getSubcommandMappingName(context: PluginSubcommandCooldownPreconditionContext) {\n\t\treturn context.subcommandGroupName ? `${context.subcommandGroupName}.${context.subcommandMethodName}` : context.subcommandMethodName;\n\t}\n\n\tprivate getManager(subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tlet manager = this.subcommandBuckets.get(subcommand);\n\t\tif (!manager) {\n\t\t\tmanager = new RateLimitManager(context.delay, context.limit);\n\t\t\tthis.subcommandBuckets.set(subcommand, manager);\n\t\t}\n\t\treturn manager;\n\t}\n}\n"]}
@@ -0,0 +1,14 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
11
+
12
+ export { __name, __privateAdd, __privateMethod, __publicField };
13
+ //# sourceMappingURL=out.js.map
14
+ //# sourceMappingURL=chunk-3IXKS7M5.mjs.map
@@ -1,4 +1,4 @@
1
- import './chunk-K3DKV2RO.mjs';
1
+ import './chunk-3IXKS7M5.mjs';
2
2
  import { PluginPrecondition } from './preconditions/PluginSubcommandCooldown.mjs';
3
3
  export { PluginPrecondition as PluginSubcommandCooldownPrecondition } from './preconditions/PluginSubcommandCooldown.mjs';
4
4
  export * from './lib/Subcommand.mjs';
@@ -13,7 +13,7 @@ export { loadPreconditions } from './preconditions/_load.mjs';
13
13
  var SubcommandPreconditions = {
14
14
  PluginSubcommandCooldown: PluginPrecondition
15
15
  };
16
- var version = "6.0.4-next.43df709.0";
16
+ var version = "6.0.4-next.4ab5259.0";
17
17
 
18
18
  export { SubcommandPreconditions, version };
19
19
  //# sourceMappingURL=out.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA;AAAA,EACC,sBAAsB;AAAA,OAEhB;AAEP,cAAc;AACd,YAAY,qCAAqC;AACjD,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACuB;AAAA,OAEhB;AAEP,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAmC3B,IAAM,0BAA0B;AAAA,EACtC;AACD;AAoBO,IAAM,UAAkB","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 = '6.0.4-next.43df709.0';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA;AAAA,EACC,sBAAsB;AAAA,OAEhB;AAEP,cAAc;AACd,YAAY,qCAAqC;AACjD,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACuB;AAAA,OAEhB;AAEP,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAmC3B,IAAM,0BAA0B;AAAA,EACtC;AACD;AAoBO,IAAM,UAAkB","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 = '6.0.4-next.4ab5259.0';\n"]}
@@ -1,18 +1,14 @@
1
- import { __name, __privateAdd, __publicField, __privateMethod } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name, __privateAdd, __publicField, __privateMethod } from '../chunk-3IXKS7M5.mjs';
2
2
  import { Command, PreconditionContainerArray, PreconditionResolvers, UserError, Result } from '@sapphire/framework';
3
3
  import { deepClone, cast } from '@sapphire/utilities';
4
4
  import { SubcommandPreconditionResolvers } from '../index.mjs';
5
5
  import { SubcommandPluginIdentifiers, SubcommandPluginEvents } from './types/Events.mjs';
6
6
 
7
- var _getMessageParametersAsString, getMessageParametersAsString_fn, _handleMessageRun, handleMessageRun_fn, _handleChatInputInteractionRun, handleChatInputInteractionRun_fn, _findSubcommand, findSubcommand_fn, _supportsCommandType, supportsCommandType_fn;
7
+ var _Subcommand_instances, getMessageParametersAsString_fn, handleMessageRun_fn, handleChatInputInteractionRun_fn, findSubcommand_fn, supportsCommandType_fn;
8
8
  var _Subcommand = class _Subcommand extends Command {
9
9
  constructor(context, options) {
10
10
  super(context, options);
11
- __privateAdd(this, _getMessageParametersAsString);
12
- __privateAdd(this, _handleMessageRun);
13
- __privateAdd(this, _handleChatInputInteractionRun);
14
- __privateAdd(this, _findSubcommand);
15
- __privateAdd(this, _supportsCommandType);
11
+ __privateAdd(this, _Subcommand_instances);
16
12
  /**
17
13
  * The preconditions to be run for each specified subcommand.
18
14
  * @since 4.1.0
@@ -155,14 +151,14 @@ var _Subcommand = class _Subcommand extends Command {
155
151
  * @returns `true` if this command has message-based subcommands, otherwise `false`
156
152
  */
157
153
  supportsMessageCommands() {
158
- return __privateMethod(this, _supportsCommandType, supportsCommandType_fn).call(this, "messageRun");
154
+ return __privateMethod(this, _Subcommand_instances, supportsCommandType_fn).call(this, "messageRun");
159
155
  }
160
156
  /**
161
157
  * Whether this command has chat input subcommands or not
162
158
  * @returns `true` if this command has chat input subcommands, otherwise `false`
163
159
  */
164
160
  supportsChatInputCommands() {
165
- return __privateMethod(this, _supportsCommandType, supportsCommandType_fn).call(this, "chatInputRun");
161
+ return __privateMethod(this, _Subcommand_instances, supportsCommandType_fn).call(this, "chatInputRun");
166
162
  }
167
163
  /**
168
164
  * The method that is ran when a message-based subcommand is ran.
@@ -193,7 +189,7 @@ var _Subcommand = class _Subcommand extends Command {
193
189
  const unwrappedSubcommandGroupName = subcommandOrGroup.unwrap();
194
190
  const unwrappedSubcommandName = subcommandName.unwrap();
195
191
  if (mapping.name === unwrappedSubcommandGroupName) {
196
- const findResult = __privateMethod(this, _findSubcommand, findSubcommand_fn).call(this, mapping.entries, this.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName);
192
+ const findResult = __privateMethod(this, _Subcommand_instances, findSubcommand_fn).call(this, mapping.entries, this.caseInsensitiveSubcommands ? unwrappedSubcommandName.toLowerCase() : unwrappedSubcommandName);
197
193
  if (findResult.defaultMatch) {
198
194
  defaultCommand = findResult.mapping;
199
195
  matchedWithGroupedSubcommand = true;
@@ -213,7 +209,7 @@ var _Subcommand = class _Subcommand extends Command {
213
209
  subcommandGroupName = subcommandOrGroup.unwrap();
214
210
  args.next();
215
211
  }
216
- return __privateMethod(this, _handleMessageRun, handleMessageRun_fn).call(this, message, args, context, actualSubcommandToRun, subcommandGroupName);
212
+ return __privateMethod(this, _Subcommand_instances, handleMessageRun_fn).call(this, message, args, context, actualSubcommandToRun, subcommandGroupName);
217
213
  }
218
214
  if (defaultCommand) {
219
215
  let subcommandGroupName = void 0;
@@ -221,7 +217,7 @@ var _Subcommand = class _Subcommand extends Command {
221
217
  subcommandGroupName = subcommandOrGroup.unwrap();
222
218
  args.next();
223
219
  }
224
- return __privateMethod(this, _handleMessageRun, handleMessageRun_fn).call(this, message, args, context, defaultCommand, subcommandGroupName);
220
+ return __privateMethod(this, _Subcommand_instances, handleMessageRun_fn).call(this, message, args, context, defaultCommand, subcommandGroupName);
225
221
  }
226
222
  throw new UserError({
227
223
  identifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,
@@ -244,18 +240,16 @@ var _Subcommand = class _Subcommand extends Command {
244
240
  for (const mapping of this.parsedSubcommandMappings) {
245
241
  mapping.type ??= "method";
246
242
  if (subcommandGroupName && subcommandName) {
247
- if (mapping.type !== "group")
248
- continue;
249
- if (mapping.name !== subcommandGroupName)
250
- continue;
251
- const foundSubcommand = __privateMethod(this, _findSubcommand, findSubcommand_fn).call(this, mapping.entries, subcommandName);
243
+ if (mapping.type !== "group") continue;
244
+ if (mapping.name !== subcommandGroupName) continue;
245
+ const foundSubcommand = __privateMethod(this, _Subcommand_instances, findSubcommand_fn).call(this, mapping.entries, subcommandName);
252
246
  if (!foundSubcommand.defaultMatch) {
253
- return __privateMethod(this, _handleChatInputInteractionRun, handleChatInputInteractionRun_fn).call(this, interaction, context, foundSubcommand.mapping, subcommandGroupName);
247
+ return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, foundSubcommand.mapping, subcommandGroupName);
254
248
  }
255
249
  continue;
256
250
  }
257
251
  if (mapping.type === "method" && mapping.name === subcommandName) {
258
- return __privateMethod(this, _handleChatInputInteractionRun, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping, void 0);
252
+ return __privateMethod(this, _Subcommand_instances, handleChatInputInteractionRun_fn).call(this, interaction, context, mapping, void 0);
259
253
  }
260
254
  }
261
255
  throw new UserError({
@@ -265,7 +259,7 @@ var _Subcommand = class _Subcommand extends Command {
265
259
  });
266
260
  }
267
261
  };
268
- _getMessageParametersAsString = new WeakSet();
262
+ _Subcommand_instances = new WeakSet();
269
263
  getMessageParametersAsString_fn = /* @__PURE__ */ __name(async function(args) {
270
264
  args.save();
271
265
  const parameters = await args.restResult("string");
@@ -276,7 +270,6 @@ getMessageParametersAsString_fn = /* @__PURE__ */ __name(async function(args) {
276
270
  }
277
271
  return params;
278
272
  }, "#getMessageParametersAsString");
279
- _handleMessageRun = new WeakSet();
280
273
  handleMessageRun_fn = /* @__PURE__ */ __name(async function(message, args, context, subcommand, subcommandGroupName) {
281
274
  const payload = {
282
275
  message,
@@ -288,7 +281,7 @@ handleMessageRun_fn = /* @__PURE__ */ __name(async function(message, args, conte
288
281
  subcommandGroupName ? `${subcommandGroupName}.${subcommand.name}` : subcommand.name
289
282
  );
290
283
  if (preconditionsForSubcommand) {
291
- const messageParametersAsString = await __privateMethod(this, _getMessageParametersAsString, getMessageParametersAsString_fn).call(this, args);
284
+ const messageParametersAsString = await __privateMethod(this, _Subcommand_instances, getMessageParametersAsString_fn).call(this, args);
292
285
  const preconditionPayload = { ...messageParametersAsString, ...payload };
293
286
  const localSubcommandResult = await preconditionsForSubcommand.messageRun(message, this, preconditionPayload);
294
287
  if (localSubcommandResult.isErr()) {
@@ -321,7 +314,6 @@ handleMessageRun_fn = /* @__PURE__ */ __name(async function(message, args, conte
321
314
  });
322
315
  result.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.MessageSubcommandError, error, payload));
323
316
  }, "#handleMessageRun");
324
- _handleChatInputInteractionRun = new WeakSet();
325
317
  handleChatInputInteractionRun_fn = /* @__PURE__ */ __name(async function(interaction, context, subcommand, subcommandGroupName) {
326
318
  const payload = {
327
319
  command: this,
@@ -369,7 +361,6 @@ handleChatInputInteractionRun_fn = /* @__PURE__ */ __name(async function(interac
369
361
  });
370
362
  result.inspectErr((error) => this.container.client.emit(SubcommandPluginEvents.ChatInputSubcommandError, error, payload));
371
363
  }, "#handleChatInputInteractionRun");
372
- _findSubcommand = new WeakSet();
373
364
  findSubcommand_fn = /* @__PURE__ */ __name(function(mappings, expectedName) {
374
365
  let foundDefault = null;
375
366
  for (const mapping of mappings) {
@@ -383,7 +374,6 @@ findSubcommand_fn = /* @__PURE__ */ __name(function(mappings, expectedName) {
383
374
  }
384
375
  return { mapping: foundDefault, defaultMatch: true };
385
376
  }, "#findSubcommand");
386
- _supportsCommandType = new WeakSet();
387
377
  supportsCommandType_fn = /* @__PURE__ */ __name(function(commandType) {
388
378
  return this.parsedSubcommandMappings.some((mapping) => {
389
379
  if (mapping.type === "group") {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/Subcommand.ts"],"names":["result"],"mappings":";;;;;;;;AAAA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,MAAM,iBAAiB;AAEhC,SAAS,uCAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AAnBP;AAoCO,IAAM,cAAN,MAAM,oBAAgH,QAG3H;AAAA,EAmBM,YAAY,SAAmC,SAAkB;AAEvE,UAAM,SAAS,OAAO;AAsUvB,uBAAM;AAcN,uBAAM;AAkEN,uBAAM;AA+DN;AAkBA;AAvfA;AAAA;AAAA;AAAA;AAAA,wBAAgB,2BAA0B,oBAAI,IAAwC;AAMtF;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO,8BAA6B;AAKnC,SAAK,2BAA2B,QAAQ,eAAe,CAAC;AAExD,UAAM,gBAAgB,KAAK,UAAU,OAAO;AAI5C,QAAI,cAAc,yBAAyB;AAC1C,WAAK,6BAA6B;AAGlC,iBAAW,OAAO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AAEA,QAAI,QAAQ,SAAS,cAAc;AAClC,aAAO,EAAE,SAAS,cAAc,MAAM;AAAA,IACvC;AAAA,EACD;AAEA,SAAO,EAAE,SAAS,cAAc,cAAc,KAAK;AACpD,GAhBe;AAkBf;AAAA,yBAAoB,gCAAC,aAAqD;AACzE,SAAO,KAAK,yBAAyB,KAAK,CAAC,YAAY;AACtD,QAAI,QAAQ,SAAS,SAAS;AAC7B,aAAO,QAAQ,QAAQ,KAAK,CAAC,iBAAiB,QAAQ,IAAI,cAAc,WAAW,CAAC;AAAA,IACrF;AACA,WAAO,QAAQ,IAAI,SAAS,WAAW;AAAA,EACxC,CAAC;AACF,GAPoB;AA5fnB;AAHK,IAAM,aAAN","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(): boolean {\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\t// No match and no subcommand, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided arguments.',\n\t\t\tcontext: {\n\t\t\t\t...context,\n\t\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t\t}\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, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided command.',\n\t\t\tcontext\n\t\t});\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;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,MAAM,iBAAiB;AAEhC,SAAS,uCAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AAnBP;AAoCO,IAAM,cAAN,MAAM,oBAAgH,QAG3H;AAAA,EAmBM,YAAY,SAAmC,SAAkB;AAEvE,UAAM,SAAS,OAAO;AAxBjB;AAQN;AAAA;AAAA;AAAA;AAAA,wBAAgB,2BAA0B,oBAAI,IAAwC;AAMtF;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO,8BAA6B;AAKnC,SAAK,2BAA2B,QAAQ,eAAe,CAAC;AAExD,UAAM,gBAAgB,KAAK,UAAU,OAAO;AAI5C,QAAI,cAAc,yBAAyB;AAC1C,WAAK,6BAA6B;AAGlC,iBAAW,OAAO,KAAK,0BAA0B;AAChD,YAAI,OAAO,IAAI,KAAK,YAAY;AAChC,YAAI,IAAI,SAAS,SAAS;AACzB,qBAAW,gBAAgB,IAAI,SAAS;AACvC,yBAAa,OAAO,aAAa,KAAK,YAAY;AAAA,UACnD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAIA,QAAI,QAAQ,yBAAyB;AACpC,iBAAW,WAAW,KAAK,0BAA0B;AACpD,YAAI,CAAC,QAAQ,IAAI,SAAS,YAAY,GAAG;AACxC;AAAA,QACD;AAEA,cAAM,mBAA2C,CAAC;AAElD,YAAI,QAAQ,SAAS,SAAS;AAE7B,cAAI,oBAAoC;AAGxC,gBAAM,gBAAgB,UAAU,OAAO;AAGvC,qB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reconditionContainerArray,\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(): boolean {\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\t// No match and no subcommand, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.MessageSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided arguments.',\n\t\t\tcontext: {\n\t\t\t\t...context,\n\t\t\t\tpossibleSubcommandName: subcommandName.unwrapOr(null),\n\t\t\t\tpossibleSubcommandGroupOrName: subcommandOrGroup.unwrapOr(null)\n\t\t\t}\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, return an err:\n\t\tthrow new UserError({\n\t\t\tidentifier: SubcommandPluginIdentifiers.ChatInputSubcommandNoMatch,\n\t\t\tmessage: 'No subcommand was matched with the provided command.',\n\t\t\tcontext\n\t\t});\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,4 +1,4 @@
1
- import { __name } from '../../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../../chunk-3IXKS7M5.mjs';
2
2
  import { BucketScope } from '@sapphire/framework';
3
3
  import { container } from '@sapphire/pieces';
4
4
  import '../Subcommand.mjs';
@@ -1,4 +1,4 @@
1
- import '../../chunk-K3DKV2RO.mjs';
1
+ import '../../chunk-3IXKS7M5.mjs';
2
2
 
3
3
  // src/lib/types/Enums.ts
4
4
  var SubcommandCommandPreConditions = /* @__PURE__ */ ((SubcommandCommandPreConditions2) => {
@@ -1,4 +1,4 @@
1
- import '../../chunk-K3DKV2RO.mjs';
1
+ import '../../chunk-3IXKS7M5.mjs';
2
2
 
3
3
  // src/lib/types/Events.ts
4
4
  var SubcommandPluginEvents = {
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../chunk-3IXKS7M5.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { SubcommandPluginEvents } from '../lib/types/Events.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../chunk-3IXKS7M5.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { SubcommandPluginEvents } from '../lib/types/Events.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../chunk-3IXKS7M5.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { SubcommandPluginEvents } from '../lib/types/Events.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../chunk-3IXKS7M5.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { SubcommandPluginEvents } from '../lib/types/Events.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../chunk-3IXKS7M5.mjs';
2
2
  import { container } from '@sapphire/pieces';
3
3
  import { PluginListener } from './PluginChatInputSubcommandError.mjs';
4
4
  import { PluginListener as PluginListener$1 } from './PluginMessageSubcommandError.mjs';
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name, __publicField } from '../chunk-3IXKS7M5.mjs';
2
2
  import { AllFlowsPrecondition, BucketScope } from '@sapphire/framework';
3
3
  import { RateLimitManager } from '@sapphire/ratelimits';
4
4
  import { time, TimestampStyles } from 'discord.js';
@@ -23,12 +23,9 @@ var _PluginPrecondition = class _PluginPrecondition extends AllFlowsPrecondition
23
23
  return this.sharedRun(interaction.user.id, subcommand, context, cooldownId, "context menu");
24
24
  }
25
25
  sharedRun(authorId, subcommand, context, cooldownId, commandType) {
26
- if (context.external)
27
- return this.ok();
28
- if (!context.delay)
29
- return this.ok();
30
- if (context.filteredUsers?.includes(authorId))
31
- return this.ok();
26
+ if (context.external) return this.ok();
27
+ if (!context.delay) return this.ok();
28
+ if (context.filteredUsers?.includes(authorId)) return this.ok();
32
29
  const rateLimit = this.getManager(subcommand, context).acquire(cooldownId);
33
30
  if (rateLimit.limited) {
34
31
  const remaining = rateLimit.remainingTime;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preconditions/PluginSubcommandCooldown.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,sBAAsB,mBAA+C;AAC9E,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA;AAAA,OAKM;AACP,OAA2B;AAC3B,SAAS,6BAA6B;AAkB/B,IAAM,sBAAN,MAAM,4BAA2B,qBAAqB;AAAA,EAAtD;AAAA;AACN,wBAAO,qBAAoB,oBAAI,QAA8C;AAAA;AAAA,EAE7D,WACf,SACA,YACA,SAC8B;AAC9B,UAAM,aAAa,KAAK,iBAAiB,SAAS,OAAO;AAEzD,WAAO,KAAK,UAAU,QAAQ,OAAO,IAAI,YAAY,SAAS,YAAY,SAAS;AAAA,EACpF;AAAA,EAEgB,aACf,aACA,YACA,SAC8B;AAC9B,UAAM,aAAa,KAAK,qBAAqB,aAAa,OAAO;AAEjE,WAAO,KAAK,UAAU,YAAY,KAAK,IAAI,YAAY,SAAS,YAAY,YAAY;AAAA,EACzF;AAAA,EAEgB,eACf,aACA,YACA,SAC8B;AAC9B,UAAM,aAAa,KAAK,qBAAqB,aAAa,OAAO;AAEjE,WAAO,KAAK,UAAU,YAAY,KAAK,IAAI,YAA0B,SAAS,YAAY,cAAc;AAAA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AY,SAAS,IAAI,oBAAoB;AAAA,MACxD,KAAK,YAAY;AAChB,eAAO,GAAG,YAAY,OAAO,IAAI,oBAAoB,MAAM,GAAG,YAAY,SAAS,IAAI,oBAAoB;AAAA,MAC5G;AACC,eAAO,GAAG,YAAY,KAAK,EAAE,IAAI,oBAAoB;AAAA,IACvD;AAAA,EACD;AAAA,EAEQ,yBAAyB,SAAsD;AACtF,WAAO,QAAQ,sBAAsB,GAAG,QAAQ,mBAAmB,IAAI,QAAQ,oBAAoB,KAAK,QAAQ;AAAA,EACjH;AAAA,EAEQ,WAAW,YAAwB,SAAsD;AAChG,QAAI,UAAU,KAAK,kBAAkB,IAAI,UAAU;AACnD,QAAI,CAAC,SAAS;AACb,gBAAU,IAAI,iBAAiB,QAAQ,OAAO,QAAQ,KAAK;AAC3D,WAAK,kBAAkB,IAAI,YAAY,OAAO;AAAA,IAC/C;AACA,WAAO;AAAA,EACR;AACD;AA1G6D;AAAtD,IAAM,qBAAN","sourcesContent":["import { AllFlowsPrecondition, BucketScope, Command, CorePreconditions } from '@sapphire/framework';\nimport { RateLimitManager } from '@sapphire/ratelimits';\nimport {\n\tTimestampStyles,\n\ttime,\n\ttype ChatInputCommandInteraction,\n\ttype CommandInteraction,\n\ttype ContextMenuCommandInteraction,\n\ttype Message\n} from 'discord.js';\nimport { Subcommand } from '../lib/Subcommand';\nimport { SubcommandIdentifiers } from '../lib/types/Enums';\n\n/**\n * The context for the subcommand cooldown precondition\n * @since 5.1.0\n */\nexport interface PluginSubcommandCooldownPreconditionContext extends CorePreconditions.CooldownContext {\n\t/** The name of the subcommand */\n\tsubcommandMethodName: string;\n\t/** The name of the subcommand group, if any */\n\tsubcommandGroupName?: string;\n}\n\n/**\n * The subcommand cooldown precondition. This differs from the cooldown precondition in framework by using a separate\n * bucket as well as resolving the id differently to ensure it is specific to a subcommand.\n * @since 5.1.0\n */\nexport class PluginPrecondition extends AllFlowsPrecondition {\n\tpublic subcommandBuckets = new WeakMap<Subcommand, RateLimitManager<string>>();\n\n\tpublic override messageRun(\n\t\tmessage: Message,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromMessage(message, context);\n\n\t\treturn this.sharedRun(message.author.id, subcommand, context, cooldownId, 'message');\n\t}\n\n\tpublic override chatInputRun(\n\t\tinteraction: ChatInputCommandInteraction,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand, context, cooldownId, 'chat input');\n\t}\n\n\tpublic override contextMenuRun(\n\t\tinteraction: ContextMenuCommandInteraction,\n\t\tsubcommand: Command,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand as Subcommand, context, cooldownId, 'context menu');\n\t}\n\n\tprivate sharedRun(\n\t\tauthorId: string,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext,\n\t\tcooldownId: string,\n\t\tcommandType: string\n\t): AllFlowsPrecondition.Result {\n\t\t// If the subcommand it is testing for is not this one, return ok:\n\t\tif (context.external) return this.ok();\n\n\t\t// If there is no delay (undefined, null, 0), return ok:\n\t\tif (!context.delay) return this.ok();\n\n\t\t// If the user has provided any filtered users and the authorId is in that array, return ok:\n\t\tif (context.filteredUsers?.includes(authorId)) return this.ok();\n\n\t\tconst rateLimit = this.getManager(subcommand, context).acquire(cooldownId);\n\n\t\tif (rateLimit.limited) {\n\t\t\tconst remaining = rateLimit.remainingTime;\n\n\t\t\tconst nextAvailable = time(Math.floor(rateLimit.expires / 1000), TimestampStyles.RelativeTime);\n\t\t\treturn this.error({\n\t\t\t\tidentifier: SubcommandIdentifiers.SubcommandPreconditionCooldown,\n\t\t\t\tmessage: `There is a cooldown in effect for this ${commandType} subcommand. It'll be available ${nextAvailable}.`,\n\t\t\t\tcontext: { remaining }\n\t\t\t});\n\t\t}\n\n\t\trateLimit.consume();\n\t\treturn this.ok();\n\t}\n\n\tprivate getIdFromMessage(message: Message, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${message.guildId}.${subcommandIdentifier}` ?? `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${message.author.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getIdFromInteraction(interaction: CommandInteraction, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${interaction.guildId}.${subcommandIdentifier}` ?? `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${interaction.user.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getSubcommandMappingName(context: PluginSubcommandCooldownPreconditionContext) {\n\t\treturn context.subcommandGroupName ? `${context.subcommandGroupName}.${context.subcommandMethodName}` : context.subcommandMethodName;\n\t}\n\n\tprivate getManager(subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tlet manager = this.subcommandBuckets.get(subcommand);\n\t\tif (!manager) {\n\t\t\tmanager = new RateLimitManager(context.delay, context.limit);\n\t\t\tthis.subcommandBuckets.set(subcommand, manager);\n\t\t}\n\t\treturn manager;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/preconditions/PluginSubcommandCooldown.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,sBAAsB,mBAA+C;AAC9E,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA;AAAA,OAKM;AACP,OAA2B;AAC3B,SAAS,6BAA6B;AAkB/B,IAAM,sBAAN,MAAM,4BAA2B,qBAAqB;AAAA,EAAtD;AAAA;AACN,wBAAO,qBAAoB,oBAAI,QAA8C;AAAA;AAAA,EAE7D,WACf,SACA,YACA,SAC8B;AAC9B,UAAM,aAAa,KAAK,iBAAiB,SAAS,OAAO;AAEzD,WAAO,KAAK,UAAU,QAAQ,OAAO,IAAI,YAAY,SAAS,YAAY,SAAS;AAAA,EACpF;AAAA,EAEgB,aACf,aACA,YACA,SAC8B;AAC9B,UAAM,aAAa,KAAK,qBAAqB,aAAa,OAAO;AAEjE,WAAO,KAAK,UAAU,YAAY,KAAK,IAAI,YAAY,SAAS,YAAY,YAAY;AAAA,EACzF;AAAA,EAEgB,eACf,aACA,YACA,SAC8B;AAC9B,UAAM,aAAa,KAAK,qBAAqB,aAAa,OAAO;AAEjE,WAAO,KAAK,UAAU,YAAY,KAAK,IAAI,YAA0B,SAAS,YAAY,cAAc;AAAA,EACzG;AAAA,EAEQ,UACP,UACA,YACA,SACA,YACA,aAC8B;AAE9B,QAAI,QAAQ,SAAU,QAAO,KAAK,GAAG;AAGrC,QAAI,CAAC,QAAQ,MAAO,QAAO,KAAK,GAAG;AAGnC,QAAI,QAAQ,eAAe,SAAS,QAAQ,EAAG,QAAO,KAAK,GAAG;AAE9D,UAAM,YAAY,KAAK,WAAW,YAAY,OAAO,EAAE,QAAQ,UAAU;AAEzE,QAAI,UAAU,SAAS;AACtB,YAAM,YAAY,UAAU;AAE5B,YAAM,gBAAgB,KAAK,KAA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,WAAW,YAAwB,SAAsD;AAChG,QAAI,UAAU,KAAK,kBAAkB,IAAI,UAAU;AACnD,QAAI,CAAC,SAAS;AACb,gBAAU,IAAI,iBAAiB,QAAQ,OAAO,QAAQ,KAAK;AAC3D,WAAK,kBAAkB,IAAI,YAAY,OAAO;AAAA,IAC/C;AACA,WAAO;AAAA,EACR;AACD;AA1G6D;AAAtD,IAAM,qBAAN","sourcesContent":["import { AllFlowsPrecondition, BucketScope, Command, CorePreconditions } from '@sapphire/framework';\nimport { RateLimitManager } from '@sapphire/ratelimits';\nimport {\n\tTimestampStyles,\n\ttime,\n\ttype ChatInputCommandInteraction,\n\ttype CommandInteraction,\n\ttype ContextMenuCommandInteraction,\n\ttype Message\n} from 'discord.js';\nimport { Subcommand } from '../lib/Subcommand';\nimport { SubcommandIdentifiers } from '../lib/types/Enums';\n\n/**\n * The context for the subcommand cooldown precondition\n * @since 5.1.0\n */\nexport interface PluginSubcommandCooldownPreconditionContext extends CorePreconditions.CooldownContext {\n\t/** The name of the subcommand */\n\tsubcommandMethodName: string;\n\t/** The name of the subcommand group, if any */\n\tsubcommandGroupName?: string;\n}\n\n/**\n * The subcommand cooldown precondition. This differs from the cooldown precondition in framework by using a separate\n * bucket as well as resolving the id differently to ensure it is specific to a subcommand.\n * @since 5.1.0\n */\nexport class PluginPrecondition extends AllFlowsPrecondition {\n\tpublic subcommandBuckets = new WeakMap<Subcommand, RateLimitManager<string>>();\n\n\tpublic override messageRun(\n\t\tmessage: Message,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromMessage(message, context);\n\n\t\treturn this.sharedRun(message.author.id, subcommand, context, cooldownId, 'message');\n\t}\n\n\tpublic override chatInputRun(\n\t\tinteraction: ChatInputCommandInteraction,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand, context, cooldownId, 'chat input');\n\t}\n\n\tpublic override contextMenuRun(\n\t\tinteraction: ContextMenuCommandInteraction,\n\t\tsubcommand: Command,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext\n\t): AllFlowsPrecondition.Result {\n\t\tconst cooldownId = this.getIdFromInteraction(interaction, context);\n\n\t\treturn this.sharedRun(interaction.user.id, subcommand as Subcommand, context, cooldownId, 'context menu');\n\t}\n\n\tprivate sharedRun(\n\t\tauthorId: string,\n\t\tsubcommand: Subcommand,\n\t\tcontext: PluginSubcommandCooldownPreconditionContext,\n\t\tcooldownId: string,\n\t\tcommandType: string\n\t): AllFlowsPrecondition.Result {\n\t\t// If the subcommand it is testing for is not this one, return ok:\n\t\tif (context.external) return this.ok();\n\n\t\t// If there is no delay (undefined, null, 0), return ok:\n\t\tif (!context.delay) return this.ok();\n\n\t\t// If the user has provided any filtered users and the authorId is in that array, return ok:\n\t\tif (context.filteredUsers?.includes(authorId)) return this.ok();\n\n\t\tconst rateLimit = this.getManager(subcommand, context).acquire(cooldownId);\n\n\t\tif (rateLimit.limited) {\n\t\t\tconst remaining = rateLimit.remainingTime;\n\n\t\t\tconst nextAvailable = time(Math.floor(rateLimit.expires / 1000), TimestampStyles.RelativeTime);\n\t\t\treturn this.error({\n\t\t\t\tidentifier: SubcommandIdentifiers.SubcommandPreconditionCooldown,\n\t\t\t\tmessage: `There is a cooldown in effect for this ${commandType} subcommand. It'll be available ${nextAvailable}.`,\n\t\t\t\tcontext: { remaining }\n\t\t\t});\n\t\t}\n\n\t\trateLimit.consume();\n\t\treturn this.ok();\n\t}\n\n\tprivate getIdFromMessage(message: Message, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${message.guildId}.${subcommandIdentifier}` ?? `${message.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${message.author.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getIdFromInteraction(interaction: CommandInteraction, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tconst subcommandIdentifier = this.getSubcommandMappingName(context);\n\t\tswitch (context.scope) {\n\t\t\tcase BucketScope.Global:\n\t\t\t\treturn `global.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Channel:\n\t\t\t\treturn `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tcase BucketScope.Guild:\n\t\t\t\treturn `${interaction.guildId}.${subcommandIdentifier}` ?? `${interaction.channelId}.${subcommandIdentifier}`;\n\t\t\tdefault:\n\t\t\t\treturn `${interaction.user.id}.${subcommandIdentifier}`;\n\t\t}\n\t}\n\n\tprivate getSubcommandMappingName(context: PluginSubcommandCooldownPreconditionContext) {\n\t\treturn context.subcommandGroupName ? `${context.subcommandGroupName}.${context.subcommandMethodName}` : context.subcommandMethodName;\n\t}\n\n\tprivate getManager(subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext) {\n\t\tlet manager = this.subcommandBuckets.get(subcommand);\n\t\tif (!manager) {\n\t\t\tmanager = new RateLimitManager(context.delay, context.limit);\n\t\t\tthis.subcommandBuckets.set(subcommand, manager);\n\t\t}\n\t\treturn manager;\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-K3DKV2RO.mjs';
1
+ import { __name } from '../chunk-3IXKS7M5.mjs';
2
2
  import { container } from '@sapphire/pieces';
3
3
  import { PluginPrecondition } from './PluginSubcommandCooldown.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from './chunk-K3DKV2RO.mjs';
1
+ import { __name } from './chunk-3IXKS7M5.mjs';
2
2
  import { loadPreconditions, loadListeners } from './index.mjs';
3
3
  import { SapphireClient, postInitialization, Plugin } from '@sapphire/framework';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/plugin-subcommands",
3
- "version": "6.0.4-next.43df709.0",
3
+ "version": "6.0.4-next.4ab5259.0",
4
4
  "description": "Plugin for @sapphire/framework that adds support for subcommands.",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -84,8 +84,8 @@
84
84
  "@favware/cliff-jumper": "^3.0.3",
85
85
  "@favware/rollup-type-bundler": "^3.3.0",
86
86
  "concurrently": "^8.2.2",
87
- "tsup": "^8.0.2",
88
- "tsx": "^4.11.0",
87
+ "tsup": "^8.1.0",
88
+ "tsx": "^4.15.5",
89
89
  "typedoc": "^0.25.13",
90
90
  "typedoc-json-parser": "^10.0.0",
91
91
  "typescript": "^5.4.5"
@@ -1,24 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __publicField = (obj, key, value) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
8
- var __accessCheck = (obj, member, msg) => {
9
- if (!member.has(obj))
10
- throw TypeError("Cannot " + msg);
11
- };
12
- var __privateAdd = (obj, member, value) => {
13
- if (member.has(obj))
14
- throw TypeError("Cannot add the same private member more than once");
15
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
16
- };
17
- var __privateMethod = (obj, member, method) => {
18
- __accessCheck(obj, member, "access private method");
19
- return method;
20
- };
21
-
22
- export { __name, __privateAdd, __privateMethod, __publicField };
23
- //# sourceMappingURL=out.js.map
24
- //# sourceMappingURL=chunk-K3DKV2RO.mjs.map