@sapphire/plugin-subcommands 6.0.2-next.f2a5969.0 → 6.0.2-next.f6cd4b6.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.
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +9 -9
- package/dist/cjs/lib/precondition-resolvers/subcommandCooldown.cjs +1 -1
- package/dist/cjs/lib/precondition-resolvers/subcommandCooldown.cjs.map +1 -1
- package/dist/cjs/lib/types/Enums.cjs +1 -1
- package/dist/cjs/lib/types/Enums.cjs.map +1 -1
- package/dist/cjs/preconditions/PluginSubcommandCooldown.cjs.map +1 -1
- package/dist/esm/index.d.mts +9 -9
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/precondition-resolvers/subcommandCooldown.mjs +1 -1
- package/dist/esm/lib/precondition-resolvers/subcommandCooldown.mjs.map +1 -1
- package/dist/esm/lib/types/Enums.mjs +1 -1
- package/dist/esm/lib/types/Enums.mjs.map +1 -1
- package/dist/esm/preconditions/PluginSubcommandCooldown.mjs.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -31,9 +31,9 @@ var subcommandCooldown_cjs__namespace = /*#__PURE__*/_interopNamespace(subcomman
|
|
|
31
31
|
|
|
32
32
|
// src/index.ts
|
|
33
33
|
var SubcommandPreconditions = {
|
|
34
|
-
|
|
34
|
+
PluginSubcommandCooldown: PluginSubcommandCooldown_cjs.PluginPrecondition
|
|
35
35
|
};
|
|
36
|
-
var version = "6.0.2-next.
|
|
36
|
+
var version = "6.0.2-next.f6cd4b6.0";
|
|
37
37
|
|
|
38
38
|
exports.SubcommandPreconditionResolvers = subcommandCooldown_cjs__namespace;
|
|
39
39
|
Object.defineProperty(exports, 'loadListeners', {
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AACA,
|
|
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;AAEd,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAiC3B,IAAM,0BAA0B;AAAA,EACtC;AACD;AAkBO,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';\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 */\nexport const SubcommandPreconditions = {\n\tPluginSubcommandCooldown\n};\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\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.2-next.f6cd4b6.0';\n"]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -173,7 +173,7 @@ declare namespace Subcommand {
|
|
|
173
173
|
* The context for the subcommand cooldown precondition
|
|
174
174
|
* @since 5.1.0
|
|
175
175
|
*/
|
|
176
|
-
interface
|
|
176
|
+
interface PluginSubcommandCooldownPreconditionContext extends CorePreconditions.CooldownContext {
|
|
177
177
|
/** The name of the subcommand */
|
|
178
178
|
subcommandMethodName: string;
|
|
179
179
|
/** The name of the subcommand group, if any */
|
|
@@ -186,9 +186,9 @@ interface SubcommandCooldownPreconditionContext extends CorePreconditions.Cooldo
|
|
|
186
186
|
*/
|
|
187
187
|
declare class PluginPrecondition extends AllFlowsPrecondition {
|
|
188
188
|
subcommandBuckets: WeakMap<Subcommand<_sapphire_framework.Args, SubcommandOptions>, RateLimitManager<string>>;
|
|
189
|
-
messageRun(message: Message, subcommand: Subcommand, context:
|
|
190
|
-
chatInputRun(interaction: ChatInputCommandInteraction, subcommand: Subcommand, context:
|
|
191
|
-
contextMenuRun(interaction: ContextMenuCommandInteraction, subcommand: Command, context:
|
|
189
|
+
messageRun(message: Message, subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext): AllFlowsPrecondition.Result;
|
|
190
|
+
chatInputRun(interaction: ChatInputCommandInteraction, subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext): AllFlowsPrecondition.Result;
|
|
191
|
+
contextMenuRun(interaction: ContextMenuCommandInteraction, subcommand: Command, context: PluginSubcommandCooldownPreconditionContext): AllFlowsPrecondition.Result;
|
|
192
192
|
private sharedRun;
|
|
193
193
|
private getIdFromMessage;
|
|
194
194
|
private getIdFromInteraction;
|
|
@@ -216,7 +216,7 @@ interface ParseSubcommandConstructorPreConditionsCooldownParameters<PreParseRetu
|
|
|
216
216
|
preconditionContainerArray: PreconditionContainerArray;
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
|
-
* Appends the `
|
|
219
|
+
* Appends the `PluginSubcommandCooldown` precondition when {@link Subcommand.Options.cooldownLimit} and
|
|
220
220
|
* {@link Subcommand.Options.cooldownDelay} are both non-zero.
|
|
221
221
|
*
|
|
222
222
|
* @param options The {@link ParseSubcommandConstructorPreConditionsCooldownParameters} for adding this subcommand cooldown precondition
|
|
@@ -234,7 +234,7 @@ declare namespace subcommandCooldown {
|
|
|
234
234
|
* @since 2.0.0
|
|
235
235
|
*/
|
|
236
236
|
declare enum SubcommandCommandPreConditions {
|
|
237
|
-
|
|
237
|
+
PluginSubcommandCooldown = "PluginSubcommandCooldown"
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* The available subcommand pre-conditions.
|
|
@@ -366,7 +366,7 @@ declare module 'discord.js' {
|
|
|
366
366
|
}
|
|
367
367
|
declare module '@sapphire/framework' {
|
|
368
368
|
interface Preconditions {
|
|
369
|
-
|
|
369
|
+
PluginSubcommandCooldown: SubcommandPreconditions.PluginSubcommandCooldownContext;
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
/**
|
|
@@ -374,7 +374,7 @@ declare module '@sapphire/framework' {
|
|
|
374
374
|
* @since 5.1.0
|
|
375
375
|
*/
|
|
376
376
|
declare const SubcommandPreconditions: {
|
|
377
|
-
|
|
377
|
+
PluginSubcommandCooldown: typeof PluginPrecondition;
|
|
378
378
|
};
|
|
379
379
|
/**
|
|
380
380
|
* The preconditions specific to subcommands
|
|
@@ -382,7 +382,7 @@ declare const SubcommandPreconditions: {
|
|
|
382
382
|
*/
|
|
383
383
|
declare namespace SubcommandPreconditions {
|
|
384
384
|
/** The context for the subcommand cooldown precondition */
|
|
385
|
-
type
|
|
385
|
+
type PluginSubcommandCooldownContext = PluginSubcommandCooldownPreconditionContext;
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
388
388
|
* The [@sapphire/plugin-subcommands](https://github.com/sapphiredev/plugins/blob/main/packages/subcommands) version that you are currently using.
|
|
@@ -27,7 +27,7 @@ function parseSubcommandConstructorPreConditionsCooldown({
|
|
|
27
27
|
const scope = cooldownScope ?? subcommandDefaultCooldown?.scope ?? framework.BucketScope.User;
|
|
28
28
|
const filteredUsers = cooldownFilteredUsers ?? subcommandDefaultCooldown?.filteredUsers;
|
|
29
29
|
preconditionContainerArray.append({
|
|
30
|
-
name: Enums_cjs.SubcommandCommandPreConditions.
|
|
30
|
+
name: Enums_cjs.SubcommandCommandPreConditions.PluginSubcommandCooldown,
|
|
31
31
|
context: { scope, limit, delay, filteredUsers, subcommandGroupName, subcommandMethodName }
|
|
32
32
|
});
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/precondition-resolvers/subcommandCooldown.ts"],"names":[],"mappings":";;;;AAAA,SAAe,mBAA+C;AAC9D,SAAS,iBAAiB;AAC1B,OAA2B;AAC3B,SAAS,sCAAsC;AA+BxC,SAAS,gDAGd;AAAA,EACD,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAuF;AACtF,QAAM,EAAE,0BAA0B,IAAI,UAAU,OAAO;AAKvD,QAAM,WACL,2BAA2B,kBAAkB;AAAA,IAC5C,sBAAsB,GAAG,QAAQ,IAAI,IAAI,mBAAmB,IAAI,oBAAoB,KAAK,GAAG,QAAQ,IAAI,IAAI,oBAAoB;AAAA,EACjI,KAAK;AACN,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AACnF,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AAEnF,MAAI,SAAS,OAAO;AACnB,UAAM,QAAQ,iBAAiB,2BAA2B,SAAS,YAAY;AAC/E,UAAM,gBAAgB,yBAAyB,2BAA2B;AAE1E,+BAA2B,OAAO;AAAA,MACjC,MAAM,+BAA+B;AAAA,MACrC,SAAS,EAAE,OAAO,OAAO,OAAO,eAAe,qBAAqB,qBAAqB;AAAA,IAC1F,CAAC;AAAA,EACF;AACD;AAlCgB","sourcesContent":["import { Args, BucketScope, PreconditionContainerArray } from '@sapphire/framework';\nimport { container } from '@sapphire/pieces';\nimport { Subcommand } from '../Subcommand';\nimport { SubcommandCommandPreConditions } from '../types/Enums';\n\n/** The options for adding this subcommand cooldown precondition */\nexport interface ParseSubcommandConstructorPreConditionsCooldownParameters<\n\tPreParseReturn extends Args = Args,\n\tOptions extends Subcommand.Options = Subcommand.Options\n> {\n\t/** The command to parse cooldowns for. */\n\tsubcommand: Subcommand<PreParseReturn, Options>;\n\t/** The cooldown limit to use. */\n\tcooldownLimit: number | undefined;\n\t/** The cooldown delay to use. */\n\tcooldownDelay: number | undefined;\n\t/** The cooldown scope to use. */\n\tcooldownScope: BucketScope | undefined;\n\t/** The cooldown filtered users to use. */\n\tcooldownFilteredUsers: string[] | undefined;\n\t/** The name this precondition is for. */\n\tsubcommandMethodName: string;\n\t/** The group this precondition is for, if any. */\n\tsubcommandGroupName?: string;\n\t/** The precondition container array to append the precondition to. */\n\tpreconditionContainerArray: PreconditionContainerArray;\n}\n\n/**\n * Appends the `
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/precondition-resolvers/subcommandCooldown.ts"],"names":[],"mappings":";;;;AAAA,SAAe,mBAA+C;AAC9D,SAAS,iBAAiB;AAC1B,OAA2B;AAC3B,SAAS,sCAAsC;AA+BxC,SAAS,gDAGd;AAAA,EACD,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAuF;AACtF,QAAM,EAAE,0BAA0B,IAAI,UAAU,OAAO;AAKvD,QAAM,WACL,2BAA2B,kBAAkB;AAAA,IAC5C,sBAAsB,GAAG,QAAQ,IAAI,IAAI,mBAAmB,IAAI,oBAAoB,KAAK,GAAG,QAAQ,IAAI,IAAI,oBAAoB;AAAA,EACjI,KAAK;AACN,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AACnF,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AAEnF,MAAI,SAAS,OAAO;AACnB,UAAM,QAAQ,iBAAiB,2BAA2B,SAAS,YAAY;AAC/E,UAAM,gBAAgB,yBAAyB,2BAA2B;AAE1E,+BAA2B,OAAO;AAAA,MACjC,MAAM,+BAA+B;AAAA,MACrC,SAAS,EAAE,OAAO,OAAO,OAAO,eAAe,qBAAqB,qBAAqB;AAAA,IAC1F,CAAC;AAAA,EACF;AACD;AAlCgB","sourcesContent":["import { Args, BucketScope, PreconditionContainerArray } from '@sapphire/framework';\nimport { container } from '@sapphire/pieces';\nimport { Subcommand } from '../Subcommand';\nimport { SubcommandCommandPreConditions } from '../types/Enums';\n\n/** The options for adding this subcommand cooldown precondition */\nexport interface ParseSubcommandConstructorPreConditionsCooldownParameters<\n\tPreParseReturn extends Args = Args,\n\tOptions extends Subcommand.Options = Subcommand.Options\n> {\n\t/** The command to parse cooldowns for. */\n\tsubcommand: Subcommand<PreParseReturn, Options>;\n\t/** The cooldown limit to use. */\n\tcooldownLimit: number | undefined;\n\t/** The cooldown delay to use. */\n\tcooldownDelay: number | undefined;\n\t/** The cooldown scope to use. */\n\tcooldownScope: BucketScope | undefined;\n\t/** The cooldown filtered users to use. */\n\tcooldownFilteredUsers: string[] | undefined;\n\t/** The name this precondition is for. */\n\tsubcommandMethodName: string;\n\t/** The group this precondition is for, if any. */\n\tsubcommandGroupName?: string;\n\t/** The precondition container array to append the precondition to. */\n\tpreconditionContainerArray: PreconditionContainerArray;\n}\n\n/**\n * Appends the `PluginSubcommandCooldown` precondition when {@link Subcommand.Options.cooldownLimit} and\n * {@link Subcommand.Options.cooldownDelay} are both non-zero.\n *\n * @param options The {@link ParseSubcommandConstructorPreConditionsCooldownParameters} for adding this subcommand cooldown precondition\n */\nexport function parseSubcommandConstructorPreConditionsCooldown<\n\tPreParseReturn extends Args = Args,\n\tOptions extends Subcommand.Options = Subcommand.Options\n>({\n\tsubcommand: command,\n\tcooldownLimit,\n\tcooldownDelay,\n\tcooldownScope,\n\tcooldownFilteredUsers,\n\tsubcommandMethodName,\n\tsubcommandGroupName,\n\tpreconditionContainerArray\n}: ParseSubcommandConstructorPreConditionsCooldownParameters<PreParseReturn, Options>) {\n\tconst { subcommandDefaultCooldown } = container.client.options;\n\n\t// We will check for whether the subcommand is filtered from the defaults, but we will allow overridden values to\n\t// be set. If an overridden value is passed, it will have priority. Otherwise, it will default to 0 if filtered\n\t// (causing the precondition to not be registered) or the default value with a fallback to a single-use cooldown.\n\tconst filtered =\n\t\tsubcommandDefaultCooldown?.filteredCommands?.includes(\n\t\t\tsubcommandGroupName ? `${command.name}.${subcommandGroupName}.${subcommandMethodName}` : `${command.name}.${subcommandMethodName}`\n\t\t) ?? false;\n\tconst limit = cooldownLimit ?? (filtered ? 0 : subcommandDefaultCooldown?.limit ?? 1);\n\tconst delay = cooldownDelay ?? (filtered ? 0 : subcommandDefaultCooldown?.delay ?? 0);\n\n\tif (limit && delay) {\n\t\tconst scope = cooldownScope ?? subcommandDefaultCooldown?.scope ?? BucketScope.User;\n\t\tconst filteredUsers = cooldownFilteredUsers ?? subcommandDefaultCooldown?.filteredUsers;\n\n\t\tpreconditionContainerArray.append({\n\t\t\tname: SubcommandCommandPreConditions.PluginSubcommandCooldown,\n\t\t\tcontext: { scope, limit, delay, filteredUsers, subcommandGroupName, subcommandMethodName }\n\t\t});\n\t}\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/lib/types/Enums.ts
|
|
4
4
|
var SubcommandCommandPreConditions = /* @__PURE__ */ ((SubcommandCommandPreConditions2) => {
|
|
5
|
-
SubcommandCommandPreConditions2["
|
|
5
|
+
SubcommandCommandPreConditions2["PluginSubcommandCooldown"] = "PluginSubcommandCooldown";
|
|
6
6
|
return SubcommandCommandPreConditions2;
|
|
7
7
|
})(SubcommandCommandPreConditions || {});
|
|
8
8
|
var SubcommandIdentifiers = /* @__PURE__ */ ((SubcommandIdentifiers2) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/types/Enums.ts"],"names":["SubcommandCommandPreConditions","SubcommandIdentifiers"],"mappings":";AAIO,IAAK,iCAAL,kBAAKA,oCAAL;AACN,EAAAA,gCAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/types/Enums.ts"],"names":["SubcommandCommandPreConditions","SubcommandIdentifiers"],"mappings":";AAIO,IAAK,iCAAL,kBAAKA,oCAAL;AACN,EAAAA,gCAAA,8BAA2B;AADhB,SAAAA;AAAA,GAAA;AAQL,IAAK,wBAAL,kBAAKC,2BAAL;AAEN,EAAAA,uBAAA,oCAAiC;AAFtB,SAAAA;AAAA,GAAA","sourcesContent":["/**\n * The available command pre-conditions.\n * @since 2.0.0\n */\nexport enum SubcommandCommandPreConditions {\n\tPluginSubcommandCooldown = 'PluginSubcommandCooldown'\n}\n\n/**\n * The available subcommand pre-conditions.\n * @since 5.1.0\n */\nexport enum SubcommandIdentifiers {\n\t/** The identifier for the subcommand cooldown precondition */\n\tSubcommandPreconditionCooldown = 'subcommandPreconditionCooldown'\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/preconditions/PluginSubcommandCooldown.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,sB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A,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"]}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -173,7 +173,7 @@ declare namespace Subcommand {
|
|
|
173
173
|
* The context for the subcommand cooldown precondition
|
|
174
174
|
* @since 5.1.0
|
|
175
175
|
*/
|
|
176
|
-
interface
|
|
176
|
+
interface PluginSubcommandCooldownPreconditionContext extends CorePreconditions.CooldownContext {
|
|
177
177
|
/** The name of the subcommand */
|
|
178
178
|
subcommandMethodName: string;
|
|
179
179
|
/** The name of the subcommand group, if any */
|
|
@@ -186,9 +186,9 @@ interface SubcommandCooldownPreconditionContext extends CorePreconditions.Cooldo
|
|
|
186
186
|
*/
|
|
187
187
|
declare class PluginPrecondition extends AllFlowsPrecondition {
|
|
188
188
|
subcommandBuckets: WeakMap<Subcommand<_sapphire_framework.Args, SubcommandOptions>, RateLimitManager<string>>;
|
|
189
|
-
messageRun(message: Message, subcommand: Subcommand, context:
|
|
190
|
-
chatInputRun(interaction: ChatInputCommandInteraction, subcommand: Subcommand, context:
|
|
191
|
-
contextMenuRun(interaction: ContextMenuCommandInteraction, subcommand: Command, context:
|
|
189
|
+
messageRun(message: Message, subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext): AllFlowsPrecondition.Result;
|
|
190
|
+
chatInputRun(interaction: ChatInputCommandInteraction, subcommand: Subcommand, context: PluginSubcommandCooldownPreconditionContext): AllFlowsPrecondition.Result;
|
|
191
|
+
contextMenuRun(interaction: ContextMenuCommandInteraction, subcommand: Command, context: PluginSubcommandCooldownPreconditionContext): AllFlowsPrecondition.Result;
|
|
192
192
|
private sharedRun;
|
|
193
193
|
private getIdFromMessage;
|
|
194
194
|
private getIdFromInteraction;
|
|
@@ -216,7 +216,7 @@ interface ParseSubcommandConstructorPreConditionsCooldownParameters<PreParseRetu
|
|
|
216
216
|
preconditionContainerArray: PreconditionContainerArray;
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
|
-
* Appends the `
|
|
219
|
+
* Appends the `PluginSubcommandCooldown` precondition when {@link Subcommand.Options.cooldownLimit} and
|
|
220
220
|
* {@link Subcommand.Options.cooldownDelay} are both non-zero.
|
|
221
221
|
*
|
|
222
222
|
* @param options The {@link ParseSubcommandConstructorPreConditionsCooldownParameters} for adding this subcommand cooldown precondition
|
|
@@ -234,7 +234,7 @@ declare namespace subcommandCooldown {
|
|
|
234
234
|
* @since 2.0.0
|
|
235
235
|
*/
|
|
236
236
|
declare enum SubcommandCommandPreConditions {
|
|
237
|
-
|
|
237
|
+
PluginSubcommandCooldown = "PluginSubcommandCooldown"
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* The available subcommand pre-conditions.
|
|
@@ -366,7 +366,7 @@ declare module 'discord.js' {
|
|
|
366
366
|
}
|
|
367
367
|
declare module '@sapphire/framework' {
|
|
368
368
|
interface Preconditions {
|
|
369
|
-
|
|
369
|
+
PluginSubcommandCooldown: SubcommandPreconditions.PluginSubcommandCooldownContext;
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
/**
|
|
@@ -374,7 +374,7 @@ declare module '@sapphire/framework' {
|
|
|
374
374
|
* @since 5.1.0
|
|
375
375
|
*/
|
|
376
376
|
declare const SubcommandPreconditions: {
|
|
377
|
-
|
|
377
|
+
PluginSubcommandCooldown: typeof PluginPrecondition;
|
|
378
378
|
};
|
|
379
379
|
/**
|
|
380
380
|
* The preconditions specific to subcommands
|
|
@@ -382,7 +382,7 @@ declare const SubcommandPreconditions: {
|
|
|
382
382
|
*/
|
|
383
383
|
declare namespace SubcommandPreconditions {
|
|
384
384
|
/** The context for the subcommand cooldown precondition */
|
|
385
|
-
type
|
|
385
|
+
type PluginSubcommandCooldownContext = PluginSubcommandCooldownPreconditionContext;
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
388
388
|
* The [@sapphire/plugin-subcommands](https://github.com/sapphiredev/plugins/blob/main/packages/subcommands) version that you are currently using.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -10,9 +10,9 @@ export { loadListeners } from './listeners/_load.mjs';
|
|
|
10
10
|
export { loadPreconditions } from './preconditions/_load.mjs';
|
|
11
11
|
|
|
12
12
|
var SubcommandPreconditions = {
|
|
13
|
-
|
|
13
|
+
PluginSubcommandCooldown: PluginPrecondition
|
|
14
14
|
};
|
|
15
|
-
var version = "6.0.2-next.
|
|
15
|
+
var version = "6.0.2-next.f6cd4b6.0";
|
|
16
16
|
|
|
17
17
|
export { SubcommandPreconditions, version };
|
|
18
18
|
//# sourceMappingURL=out.js.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,
|
|
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;AAEd,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAiC3B,IAAM,0BAA0B;AAAA,EACtC;AACD;AAkBO,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';\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 */\nexport const SubcommandPreconditions = {\n\tPluginSubcommandCooldown\n};\n\n/**\n * The preconditions specific to subcommands\n * @since 5.1.0\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.2-next.f6cd4b6.0';\n"]}
|
|
@@ -24,7 +24,7 @@ function parseSubcommandConstructorPreConditionsCooldown({
|
|
|
24
24
|
const scope = cooldownScope ?? subcommandDefaultCooldown?.scope ?? BucketScope.User;
|
|
25
25
|
const filteredUsers = cooldownFilteredUsers ?? subcommandDefaultCooldown?.filteredUsers;
|
|
26
26
|
preconditionContainerArray.append({
|
|
27
|
-
name: SubcommandCommandPreConditions.
|
|
27
|
+
name: SubcommandCommandPreConditions.PluginSubcommandCooldown,
|
|
28
28
|
context: { scope, limit, delay, filteredUsers, subcommandGroupName, subcommandMethodName }
|
|
29
29
|
});
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/precondition-resolvers/subcommandCooldown.ts"],"names":[],"mappings":";;;;;AAAA,SAAe,mBAA+C;AAC9D,SAAS,iBAAiB;AAC1B,OAA2B;AAC3B,SAAS,sCAAsC;AA+BxC,SAAS,gDAGd;AAAA,EACD,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAuF;AACtF,QAAM,EAAE,0BAA0B,IAAI,UAAU,OAAO;AAKvD,QAAM,WACL,2BAA2B,kBAAkB;AAAA,IAC5C,sBAAsB,GAAG,QAAQ,IAAI,IAAI,mBAAmB,IAAI,oBAAoB,KAAK,GAAG,QAAQ,IAAI,IAAI,oBAAoB;AAAA,EACjI,KAAK;AACN,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AACnF,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AAEnF,MAAI,SAAS,OAAO;AACnB,UAAM,QAAQ,iBAAiB,2BAA2B,SAAS,YAAY;AAC/E,UAAM,gBAAgB,yBAAyB,2BAA2B;AAE1E,+BAA2B,OAAO;AAAA,MACjC,MAAM,+BAA+B;AAAA,MACrC,SAAS,EAAE,OAAO,OAAO,OAAO,eAAe,qBAAqB,qBAAqB;AAAA,IAC1F,CAAC;AAAA,EACF;AACD;AAlCgB","sourcesContent":["import { Args, BucketScope, PreconditionContainerArray } from '@sapphire/framework';\nimport { container } from '@sapphire/pieces';\nimport { Subcommand } from '../Subcommand';\nimport { SubcommandCommandPreConditions } from '../types/Enums';\n\n/** The options for adding this subcommand cooldown precondition */\nexport interface ParseSubcommandConstructorPreConditionsCooldownParameters<\n\tPreParseReturn extends Args = Args,\n\tOptions extends Subcommand.Options = Subcommand.Options\n> {\n\t/** The command to parse cooldowns for. */\n\tsubcommand: Subcommand<PreParseReturn, Options>;\n\t/** The cooldown limit to use. */\n\tcooldownLimit: number | undefined;\n\t/** The cooldown delay to use. */\n\tcooldownDelay: number | undefined;\n\t/** The cooldown scope to use. */\n\tcooldownScope: BucketScope | undefined;\n\t/** The cooldown filtered users to use. */\n\tcooldownFilteredUsers: string[] | undefined;\n\t/** The name this precondition is for. */\n\tsubcommandMethodName: string;\n\t/** The group this precondition is for, if any. */\n\tsubcommandGroupName?: string;\n\t/** The precondition container array to append the precondition to. */\n\tpreconditionContainerArray: PreconditionContainerArray;\n}\n\n/**\n * Appends the `
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/precondition-resolvers/subcommandCooldown.ts"],"names":[],"mappings":";;;;;AAAA,SAAe,mBAA+C;AAC9D,SAAS,iBAAiB;AAC1B,OAA2B;AAC3B,SAAS,sCAAsC;AA+BxC,SAAS,gDAGd;AAAA,EACD,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAuF;AACtF,QAAM,EAAE,0BAA0B,IAAI,UAAU,OAAO;AAKvD,QAAM,WACL,2BAA2B,kBAAkB;AAAA,IAC5C,sBAAsB,GAAG,QAAQ,IAAI,IAAI,mBAAmB,IAAI,oBAAoB,KAAK,GAAG,QAAQ,IAAI,IAAI,oBAAoB;AAAA,EACjI,KAAK;AACN,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AACnF,QAAM,QAAQ,kBAAkB,WAAW,IAAI,2BAA2B,SAAS;AAEnF,MAAI,SAAS,OAAO;AACnB,UAAM,QAAQ,iBAAiB,2BAA2B,SAAS,YAAY;AAC/E,UAAM,gBAAgB,yBAAyB,2BAA2B;AAE1E,+BAA2B,OAAO;AAAA,MACjC,MAAM,+BAA+B;AAAA,MACrC,SAAS,EAAE,OAAO,OAAO,OAAO,eAAe,qBAAqB,qBAAqB;AAAA,IAC1F,CAAC;AAAA,EACF;AACD;AAlCgB","sourcesContent":["import { Args, BucketScope, PreconditionContainerArray } from '@sapphire/framework';\nimport { container } from '@sapphire/pieces';\nimport { Subcommand } from '../Subcommand';\nimport { SubcommandCommandPreConditions } from '../types/Enums';\n\n/** The options for adding this subcommand cooldown precondition */\nexport interface ParseSubcommandConstructorPreConditionsCooldownParameters<\n\tPreParseReturn extends Args = Args,\n\tOptions extends Subcommand.Options = Subcommand.Options\n> {\n\t/** The command to parse cooldowns for. */\n\tsubcommand: Subcommand<PreParseReturn, Options>;\n\t/** The cooldown limit to use. */\n\tcooldownLimit: number | undefined;\n\t/** The cooldown delay to use. */\n\tcooldownDelay: number | undefined;\n\t/** The cooldown scope to use. */\n\tcooldownScope: BucketScope | undefined;\n\t/** The cooldown filtered users to use. */\n\tcooldownFilteredUsers: string[] | undefined;\n\t/** The name this precondition is for. */\n\tsubcommandMethodName: string;\n\t/** The group this precondition is for, if any. */\n\tsubcommandGroupName?: string;\n\t/** The precondition container array to append the precondition to. */\n\tpreconditionContainerArray: PreconditionContainerArray;\n}\n\n/**\n * Appends the `PluginSubcommandCooldown` precondition when {@link Subcommand.Options.cooldownLimit} and\n * {@link Subcommand.Options.cooldownDelay} are both non-zero.\n *\n * @param options The {@link ParseSubcommandConstructorPreConditionsCooldownParameters} for adding this subcommand cooldown precondition\n */\nexport function parseSubcommandConstructorPreConditionsCooldown<\n\tPreParseReturn extends Args = Args,\n\tOptions extends Subcommand.Options = Subcommand.Options\n>({\n\tsubcommand: command,\n\tcooldownLimit,\n\tcooldownDelay,\n\tcooldownScope,\n\tcooldownFilteredUsers,\n\tsubcommandMethodName,\n\tsubcommandGroupName,\n\tpreconditionContainerArray\n}: ParseSubcommandConstructorPreConditionsCooldownParameters<PreParseReturn, Options>) {\n\tconst { subcommandDefaultCooldown } = container.client.options;\n\n\t// We will check for whether the subcommand is filtered from the defaults, but we will allow overridden values to\n\t// be set. If an overridden value is passed, it will have priority. Otherwise, it will default to 0 if filtered\n\t// (causing the precondition to not be registered) or the default value with a fallback to a single-use cooldown.\n\tconst filtered =\n\t\tsubcommandDefaultCooldown?.filteredCommands?.includes(\n\t\t\tsubcommandGroupName ? `${command.name}.${subcommandGroupName}.${subcommandMethodName}` : `${command.name}.${subcommandMethodName}`\n\t\t) ?? false;\n\tconst limit = cooldownLimit ?? (filtered ? 0 : subcommandDefaultCooldown?.limit ?? 1);\n\tconst delay = cooldownDelay ?? (filtered ? 0 : subcommandDefaultCooldown?.delay ?? 0);\n\n\tif (limit && delay) {\n\t\tconst scope = cooldownScope ?? subcommandDefaultCooldown?.scope ?? BucketScope.User;\n\t\tconst filteredUsers = cooldownFilteredUsers ?? subcommandDefaultCooldown?.filteredUsers;\n\n\t\tpreconditionContainerArray.append({\n\t\t\tname: SubcommandCommandPreConditions.PluginSubcommandCooldown,\n\t\t\tcontext: { scope, limit, delay, filteredUsers, subcommandGroupName, subcommandMethodName }\n\t\t});\n\t}\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import '../../chunk-K3DKV2RO.mjs';
|
|
|
2
2
|
|
|
3
3
|
// src/lib/types/Enums.ts
|
|
4
4
|
var SubcommandCommandPreConditions = /* @__PURE__ */ ((SubcommandCommandPreConditions2) => {
|
|
5
|
-
SubcommandCommandPreConditions2["
|
|
5
|
+
SubcommandCommandPreConditions2["PluginSubcommandCooldown"] = "PluginSubcommandCooldown";
|
|
6
6
|
return SubcommandCommandPreConditions2;
|
|
7
7
|
})(SubcommandCommandPreConditions || {});
|
|
8
8
|
var SubcommandIdentifiers = /* @__PURE__ */ ((SubcommandIdentifiers2) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/types/Enums.ts"],"names":["SubcommandCommandPreConditions","SubcommandIdentifiers"],"mappings":";;;AAIO,IAAK,iCAAL,kBAAKA,oCAAL;AACN,EAAAA,gCAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/types/Enums.ts"],"names":["SubcommandCommandPreConditions","SubcommandIdentifiers"],"mappings":";;;AAIO,IAAK,iCAAL,kBAAKA,oCAAL;AACN,EAAAA,gCAAA,8BAA2B;AADhB,SAAAA;AAAA,GAAA;AAQL,IAAK,wBAAL,kBAAKC,2BAAL;AAEN,EAAAA,uBAAA,oCAAiC;AAFtB,SAAAA;AAAA,GAAA","sourcesContent":["/**\n * The available command pre-conditions.\n * @since 2.0.0\n */\nexport enum SubcommandCommandPreConditions {\n\tPluginSubcommandCooldown = 'PluginSubcommandCooldown'\n}\n\n/**\n * The available subcommand pre-conditions.\n * @since 5.1.0\n */\nexport enum SubcommandIdentifiers {\n\t/** The identifier for the subcommand cooldown precondition */\n\tSubcommandPreconditionCooldown = 'subcommandPreconditionCooldown'\n}\n"]}
|
|
@@ -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,EACzG;AAAA,EAEQ,UACP,UACA,YACA,SACA,YACA,aAC8B;AAE9B,QAAI,QAAQ;AAAU,aAAO,KAAK,GAAG;AAGrC,QAAI,CAAC,QAAQ;AAAO,aAAO,KAAK,GAAG;AAGnC,QAAI,QAAQ,eAAe,SAAS,QAAQ;AAAG,aAAO,KAAK,GAAG;AAE9D,UAAM,YAAY,KAAK,WAAW,YAAY,OAAO,EAAE,QAAQ,UAAU;AAEzE,QAAI,UAAU,SAAS;AACtB,YAAM,YAAY,UAAU;AAE5B,YA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AC5G;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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-subcommands",
|
|
3
|
-
"version": "6.0.2-next.
|
|
3
|
+
"version": "6.0.2-next.f6cd4b6.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework that adds support for subcommands.",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@favware/rollup-type-bundler": "^3.2.1",
|
|
86
86
|
"concurrently": "^8.2.2",
|
|
87
87
|
"tsup": "^8.0.1",
|
|
88
|
-
"tsx": "^4.
|
|
88
|
+
"tsx": "^4.7.0",
|
|
89
89
|
"typedoc": "^0.25.4",
|
|
90
90
|
"typedoc-json-parser": "^9.0.1",
|
|
91
91
|
"typescript": "^5.3.3"
|