commandkit 0.1.11-dev.20250408053600 → 0.1.11-dev.20250414064855
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/index.d.ts +32 -33
- package/dist/index.js +490 -424
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2012,12 +2012,6 @@ var init_RuntimePlugin = __esm({
|
|
|
2012
2012
|
*/
|
|
2013
2013
|
async onBeforeMessageCommand(ctx, message) {
|
|
2014
2014
|
}
|
|
2015
|
-
/**
|
|
2016
|
-
* Called before message update command is processed
|
|
2017
|
-
* @param message The message
|
|
2018
|
-
*/
|
|
2019
|
-
async onBeforeMessageUpdateCommand(ctx, oldMessage, newMessage) {
|
|
2020
|
-
}
|
|
2021
2015
|
/**
|
|
2022
2016
|
* Called before command is executed. This method can execute the command itself.
|
|
2023
2017
|
* @param source The source that triggered the command
|
|
@@ -2085,6 +2079,13 @@ var init_RuntimePlugin = __esm({
|
|
|
2085
2079
|
*/
|
|
2086
2080
|
async onBeforeRegisterGuildCommands(ctx, event) {
|
|
2087
2081
|
}
|
|
2082
|
+
/**
|
|
2083
|
+
* Called after command and all of its deferred functions are executed.
|
|
2084
|
+
* @param ctx The context
|
|
2085
|
+
* @param env The environment of the command. This environment contains the command execution data such as command context and more.
|
|
2086
|
+
*/
|
|
2087
|
+
async onAfterCommand(ctx, env) {
|
|
2088
|
+
}
|
|
2088
2089
|
};
|
|
2089
2090
|
__name(_RuntimePlugin, "RuntimePlugin");
|
|
2090
2091
|
RuntimePlugin = _RuntimePlugin;
|
|
@@ -2112,7 +2113,7 @@ var init_DefaultLogger = __esm({
|
|
|
2112
2113
|
autocomplete: "Autocomplete",
|
|
2113
2114
|
messageContextMenu: "MessageContextMenu",
|
|
2114
2115
|
userContextMenu: "UserContextMenu",
|
|
2115
|
-
chatInput: "
|
|
2116
|
+
chatInput: "ChatInputCommand",
|
|
2116
2117
|
message: "Message"
|
|
2117
2118
|
};
|
|
2118
2119
|
TextColorMap = {
|
|
@@ -2265,10 +2266,10 @@ var init_Logger = __esm({
|
|
|
2265
2266
|
}
|
|
2266
2267
|
});
|
|
2267
2268
|
|
|
2268
|
-
// src/plugins/runtime/CommandKitPluginRuntime.ts
|
|
2269
|
+
// src/plugins/plugin-runtime/CommandKitPluginRuntime.ts
|
|
2269
2270
|
var import_discord12, _CommandKitPluginRuntime, CommandKitPluginRuntime;
|
|
2270
2271
|
var init_CommandKitPluginRuntime = __esm({
|
|
2271
|
-
"src/plugins/runtime/CommandKitPluginRuntime.ts"() {
|
|
2272
|
+
"src/plugins/plugin-runtime/CommandKitPluginRuntime.ts"() {
|
|
2272
2273
|
"use strict";
|
|
2273
2274
|
init_cjs_shims();
|
|
2274
2275
|
import_discord12 = require("discord.js");
|
|
@@ -2350,7 +2351,7 @@ var init_CommandKitPluginRuntime = __esm({
|
|
|
2350
2351
|
}
|
|
2351
2352
|
});
|
|
2352
2353
|
|
|
2353
|
-
// src/plugins/runtime/CompilerPluginRuntime.ts
|
|
2354
|
+
// src/plugins/plugin-runtime/CompilerPluginRuntime.ts
|
|
2354
2355
|
function fromEsbuildPlugin(plugin) {
|
|
2355
2356
|
const _EsbuildPluginCompat = class _EsbuildPluginCompat extends CompilerPlugin {
|
|
2356
2357
|
name = plugin.name;
|
|
@@ -2377,7 +2378,7 @@ function fromEsbuildPlugin(plugin) {
|
|
|
2377
2378
|
}
|
|
2378
2379
|
var import_promises, pattern, _CompilerPluginRuntime, CompilerPluginRuntime;
|
|
2379
2380
|
var init_CompilerPluginRuntime = __esm({
|
|
2380
|
-
"src/plugins/runtime/CompilerPluginRuntime.ts"() {
|
|
2381
|
+
"src/plugins/plugin-runtime/CompilerPluginRuntime.ts"() {
|
|
2381
2382
|
"use strict";
|
|
2382
2383
|
init_cjs_shims();
|
|
2383
2384
|
import_promises = require("fs/promises");
|
|
@@ -2540,17 +2541,17 @@ var init_CompilerPluginRuntime = __esm({
|
|
|
2540
2541
|
}
|
|
2541
2542
|
});
|
|
2542
2543
|
|
|
2543
|
-
// src/plugins/runtime/types.ts
|
|
2544
|
+
// src/plugins/plugin-runtime/types.ts
|
|
2544
2545
|
var init_types3 = __esm({
|
|
2545
|
-
"src/plugins/runtime/types.ts"() {
|
|
2546
|
+
"src/plugins/plugin-runtime/types.ts"() {
|
|
2546
2547
|
"use strict";
|
|
2547
2548
|
init_cjs_shims();
|
|
2548
2549
|
}
|
|
2549
2550
|
});
|
|
2550
2551
|
|
|
2551
|
-
// src/plugins/runtime/runtime.ts
|
|
2552
|
+
// src/plugins/plugin-runtime/runtime.ts
|
|
2552
2553
|
var init_runtime = __esm({
|
|
2553
|
-
"src/plugins/runtime/runtime.ts"() {
|
|
2554
|
+
"src/plugins/plugin-runtime/runtime.ts"() {
|
|
2554
2555
|
"use strict";
|
|
2555
2556
|
init_cjs_shims();
|
|
2556
2557
|
}
|
|
@@ -2571,10 +2572,139 @@ var init_plugins = __esm({
|
|
|
2571
2572
|
}
|
|
2572
2573
|
});
|
|
2573
2574
|
|
|
2574
|
-
// src/plugins/runtime/builtin/
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2575
|
+
// src/plugins/plugin-runtime/builtin/common/directive-transformer.ts
|
|
2576
|
+
function createDirectiveTransformer(options) {
|
|
2577
|
+
const IMPORT_PATH = options.importPath;
|
|
2578
|
+
const DIRECTIVE = options.directive;
|
|
2579
|
+
const CACHE_IDENTIFIER = options.importName;
|
|
2580
|
+
const ASYNC_ONLY = options.asyncOnly ?? true;
|
|
2581
|
+
const transformer = /* @__PURE__ */ __name(async (source, args) => {
|
|
2582
|
+
var _a;
|
|
2583
|
+
const ast = parser.parse(source, {
|
|
2584
|
+
sourceType: "module",
|
|
2585
|
+
plugins: ["typescript", "jsx"]
|
|
2586
|
+
});
|
|
2587
|
+
let state = {
|
|
2588
|
+
needsImport: false,
|
|
2589
|
+
hasExistingImport: false,
|
|
2590
|
+
cacheIdentifierName: CACHE_IDENTIFIER,
|
|
2591
|
+
modifications: []
|
|
2592
|
+
};
|
|
2593
|
+
traverse(ast, {
|
|
2594
|
+
Program: {
|
|
2595
|
+
enter(path3) {
|
|
2596
|
+
const binding = path3.scope.getBinding(CACHE_IDENTIFIER);
|
|
2597
|
+
if (binding) {
|
|
2598
|
+
state.cacheIdentifierName = `${CACHE_IDENTIFIER}_${generateRandomString()}`;
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
},
|
|
2602
|
+
ImportDeclaration(path3) {
|
|
2603
|
+
if (path3.node.source.value === IMPORT_PATH && path3.node.specifiers.some(
|
|
2604
|
+
(spec) => t.isImportSpecifier(spec) && // @ts-ignore
|
|
2605
|
+
spec.imported.name === CACHE_IDENTIFIER
|
|
2606
|
+
)) {
|
|
2607
|
+
state.hasExistingImport = true;
|
|
2608
|
+
if (state.cacheIdentifierName !== CACHE_IDENTIFIER) {
|
|
2609
|
+
state.modifications.push(() => {
|
|
2610
|
+
path3.node.specifiers.forEach((spec) => {
|
|
2611
|
+
if (t.isImportSpecifier(spec) && // @ts-ignore
|
|
2612
|
+
spec.imported.name === CACHE_IDENTIFIER) {
|
|
2613
|
+
spec.local.name = state.cacheIdentifierName;
|
|
2614
|
+
}
|
|
2615
|
+
});
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod"(path3) {
|
|
2621
|
+
var _a2, _b, _c;
|
|
2622
|
+
const body = t.isBlockStatement(path3.node.body) ? path3.node.body : null;
|
|
2623
|
+
const hasUseCache = (_a2 = body == null ? void 0 : body.directives) == null ? void 0 : _a2.some(
|
|
2624
|
+
(d) => d.value.value === DIRECTIVE
|
|
2625
|
+
);
|
|
2626
|
+
if (!hasUseCache && !t.isBlockStatement(path3.node.body)) {
|
|
2627
|
+
const parentFunction = path3.findParent(
|
|
2628
|
+
(p) => (p.isFunction() || p.isProgram()) && "directives" in p.node
|
|
2629
|
+
);
|
|
2630
|
+
if (!((_b = parentFunction == null ? void 0 : parentFunction.node.directives) == null ? void 0 : _b.some(
|
|
2631
|
+
(d) => d.value.value === DIRECTIVE
|
|
2632
|
+
))) {
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
if (hasUseCache || !t.isBlockStatement(path3.node.body)) {
|
|
2637
|
+
if (ASYNC_ONLY && !path3.node.async) {
|
|
2638
|
+
throw new Error(
|
|
2639
|
+
`"${DIRECTIVE}" directive may only be used in async functions at ${args.path}
|
|
2640
|
+
|
|
2641
|
+
${path3.toString()}
|
|
2642
|
+
^^^^${"-".repeat(6)} This function must be async`
|
|
2643
|
+
);
|
|
2644
|
+
}
|
|
2645
|
+
state.needsImport = true;
|
|
2646
|
+
const isDeclaration = t.isFunctionDeclaration(path3.node);
|
|
2647
|
+
const name = isDeclaration ? (_c = path3.node.id) == null ? void 0 : _c.name : void 0;
|
|
2648
|
+
const newBody = t.isBlockStatement(path3.node.body) ? t.blockStatement(
|
|
2649
|
+
path3.node.body.body,
|
|
2650
|
+
path3.node.body.directives.filter(
|
|
2651
|
+
(d) => d.value.value !== DIRECTIVE
|
|
2652
|
+
)
|
|
2653
|
+
) : path3.node.body;
|
|
2654
|
+
const wrapped = t.callExpression(
|
|
2655
|
+
t.identifier(state.cacheIdentifierName),
|
|
2656
|
+
[t.arrowFunctionExpression(path3.node.params, newBody, true)]
|
|
2657
|
+
);
|
|
2658
|
+
state.modifications.push(() => {
|
|
2659
|
+
if (t.isObjectMethod(path3.node)) {
|
|
2660
|
+
path3.replaceWith(
|
|
2661
|
+
t.objectProperty(t.identifier(path3.node.key.name), wrapped)
|
|
2662
|
+
);
|
|
2663
|
+
} else if (name) {
|
|
2664
|
+
path3.replaceWith(
|
|
2665
|
+
t.variableDeclaration(
|
|
2666
|
+
"const",
|
|
2667
|
+
[
|
|
2668
|
+
t.variableDeclarator(t.identifier(name), wrapped)
|
|
2669
|
+
]
|
|
2670
|
+
)
|
|
2671
|
+
);
|
|
2672
|
+
} else if (!t.isVariableDeclarator(path3.parent)) {
|
|
2673
|
+
path3.replaceWith(wrapped);
|
|
2674
|
+
} else {
|
|
2675
|
+
path3.parent.init = wrapped;
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2681
|
+
if (state.modifications.length > 0) {
|
|
2682
|
+
if (state.needsImport && !state.hasExistingImport) {
|
|
2683
|
+
ast.program.body.unshift(
|
|
2684
|
+
t.importDeclaration(
|
|
2685
|
+
[
|
|
2686
|
+
t.importSpecifier(
|
|
2687
|
+
t.identifier(state.cacheIdentifierName),
|
|
2688
|
+
t.identifier(CACHE_IDENTIFIER)
|
|
2689
|
+
)
|
|
2690
|
+
],
|
|
2691
|
+
t.stringLiteral(IMPORT_PATH)
|
|
2692
|
+
)
|
|
2693
|
+
);
|
|
2694
|
+
}
|
|
2695
|
+
state.modifications.forEach((modify) => modify());
|
|
2696
|
+
}
|
|
2697
|
+
const { code } = generate(ast);
|
|
2698
|
+
return {
|
|
2699
|
+
contents: code,
|
|
2700
|
+
loader: (_a = args.path) == null ? void 0 : _a.split(".").pop()
|
|
2701
|
+
};
|
|
2702
|
+
}, "transformer");
|
|
2703
|
+
return transformer;
|
|
2704
|
+
}
|
|
2705
|
+
var parser, import_traverse, import_generator, t, traverse, generate, generateRandomString;
|
|
2706
|
+
var init_directive_transformer = __esm({
|
|
2707
|
+
"src/plugins/plugin-runtime/builtin/common/directive-transformer.ts"() {
|
|
2578
2708
|
"use strict";
|
|
2579
2709
|
init_cjs_shims();
|
|
2580
2710
|
parser = __toESM(require("@babel/parser"));
|
|
@@ -2583,9 +2713,6 @@ var init_UseCacheTransformer = __esm({
|
|
|
2583
2713
|
t = __toESM(require("@babel/types"));
|
|
2584
2714
|
traverse = import_traverse.default.default || import_traverse.default;
|
|
2585
2715
|
generate = import_generator.default.default || import_generator.default;
|
|
2586
|
-
IMPORT_PATH = "commandkit";
|
|
2587
|
-
DIRECTIVE = "use cache";
|
|
2588
|
-
CACHE_IDENTIFIER = "zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired";
|
|
2589
2716
|
generateRandomString = /* @__PURE__ */ __name((length = 6) => {
|
|
2590
2717
|
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
2591
2718
|
return Array.from(
|
|
@@ -2593,135 +2720,30 @@ var init_UseCacheTransformer = __esm({
|
|
|
2593
2720
|
() => chars[Math.floor(Math.random() * chars.length)]
|
|
2594
2721
|
).join("");
|
|
2595
2722
|
}, "generateRandomString");
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
sourceType: "module",
|
|
2600
|
-
plugins: ["typescript", "jsx"]
|
|
2601
|
-
});
|
|
2602
|
-
let state = {
|
|
2603
|
-
needsImport: false,
|
|
2604
|
-
hasExistingImport: false,
|
|
2605
|
-
cacheIdentifierName: CACHE_IDENTIFIER,
|
|
2606
|
-
modifications: []
|
|
2607
|
-
};
|
|
2608
|
-
traverse(ast, {
|
|
2609
|
-
Program: {
|
|
2610
|
-
enter(path3) {
|
|
2611
|
-
const binding = path3.scope.getBinding(CACHE_IDENTIFIER);
|
|
2612
|
-
if (binding) {
|
|
2613
|
-
state.cacheIdentifierName = `${CACHE_IDENTIFIER}_${generateRandomString()}`;
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
},
|
|
2617
|
-
ImportDeclaration(path3) {
|
|
2618
|
-
if (path3.node.source.value === IMPORT_PATH && path3.node.specifiers.some(
|
|
2619
|
-
(spec) => t.isImportSpecifier(spec) && // @ts-ignore
|
|
2620
|
-
spec.imported.name === CACHE_IDENTIFIER
|
|
2621
|
-
)) {
|
|
2622
|
-
state.hasExistingImport = true;
|
|
2623
|
-
if (state.cacheIdentifierName !== CACHE_IDENTIFIER) {
|
|
2624
|
-
state.modifications.push(() => {
|
|
2625
|
-
path3.node.specifiers.forEach((spec) => {
|
|
2626
|
-
if (t.isImportSpecifier(spec) && // @ts-ignore
|
|
2627
|
-
spec.imported.name === CACHE_IDENTIFIER) {
|
|
2628
|
-
spec.local.name = state.cacheIdentifierName;
|
|
2629
|
-
}
|
|
2630
|
-
});
|
|
2631
|
-
});
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
},
|
|
2635
|
-
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod"(path3) {
|
|
2636
|
-
var _a2, _b, _c;
|
|
2637
|
-
const body = t.isBlockStatement(path3.node.body) ? path3.node.body : null;
|
|
2638
|
-
const hasUseCache = (_a2 = body == null ? void 0 : body.directives) == null ? void 0 : _a2.some(
|
|
2639
|
-
(d) => d.value.value === DIRECTIVE
|
|
2640
|
-
);
|
|
2641
|
-
if (!hasUseCache && !t.isBlockStatement(path3.node.body)) {
|
|
2642
|
-
const parentFunction = path3.findParent(
|
|
2643
|
-
(p) => (p.isFunction() || p.isProgram()) && "directives" in p.node
|
|
2644
|
-
);
|
|
2645
|
-
if (!((_b = parentFunction == null ? void 0 : parentFunction.node.directives) == null ? void 0 : _b.some(
|
|
2646
|
-
(d) => d.value.value === DIRECTIVE
|
|
2647
|
-
))) {
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
if (hasUseCache || !t.isBlockStatement(path3.node.body)) {
|
|
2652
|
-
if (!path3.node.async) {
|
|
2653
|
-
throw new Error(
|
|
2654
|
-
`"${DIRECTIVE}" directive may only be used in async functions at ${args.path}
|
|
2723
|
+
__name(createDirectiveTransformer, "createDirectiveTransformer");
|
|
2724
|
+
}
|
|
2725
|
+
});
|
|
2655
2726
|
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
const wrapped = t.callExpression(
|
|
2670
|
-
t.identifier(state.cacheIdentifierName),
|
|
2671
|
-
[t.arrowFunctionExpression(path3.node.params, newBody, true)]
|
|
2672
|
-
);
|
|
2673
|
-
state.modifications.push(() => {
|
|
2674
|
-
if (t.isObjectMethod(path3.node)) {
|
|
2675
|
-
path3.replaceWith(
|
|
2676
|
-
t.objectProperty(t.identifier(path3.node.key.name), wrapped)
|
|
2677
|
-
);
|
|
2678
|
-
} else if (name) {
|
|
2679
|
-
path3.replaceWith(
|
|
2680
|
-
t.variableDeclaration(
|
|
2681
|
-
"const",
|
|
2682
|
-
[
|
|
2683
|
-
t.variableDeclarator(t.identifier(name), wrapped)
|
|
2684
|
-
]
|
|
2685
|
-
)
|
|
2686
|
-
);
|
|
2687
|
-
} else if (!t.isVariableDeclarator(path3.parent)) {
|
|
2688
|
-
path3.replaceWith(wrapped);
|
|
2689
|
-
} else {
|
|
2690
|
-
path3.parent.init = wrapped;
|
|
2691
|
-
}
|
|
2692
|
-
});
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
});
|
|
2696
|
-
if (state.modifications.length > 0) {
|
|
2697
|
-
if (state.needsImport && !state.hasExistingImport) {
|
|
2698
|
-
ast.program.body.unshift(
|
|
2699
|
-
t.importDeclaration(
|
|
2700
|
-
[
|
|
2701
|
-
t.importSpecifier(
|
|
2702
|
-
t.identifier(state.cacheIdentifierName),
|
|
2703
|
-
t.identifier(CACHE_IDENTIFIER)
|
|
2704
|
-
)
|
|
2705
|
-
],
|
|
2706
|
-
t.stringLiteral(IMPORT_PATH)
|
|
2707
|
-
)
|
|
2708
|
-
);
|
|
2709
|
-
}
|
|
2710
|
-
state.modifications.forEach((modify) => modify());
|
|
2711
|
-
}
|
|
2712
|
-
const { code } = generate(ast);
|
|
2713
|
-
return {
|
|
2714
|
-
contents: code,
|
|
2715
|
-
loader: (_a = args.path) == null ? void 0 : _a.split(".").pop()
|
|
2716
|
-
};
|
|
2717
|
-
}, "cacheDirectivePlugin");
|
|
2727
|
+
// src/plugins/plugin-runtime/builtin/cache/UseCacheTransformer.ts
|
|
2728
|
+
var cacheDirectivePlugin;
|
|
2729
|
+
var init_UseCacheTransformer = __esm({
|
|
2730
|
+
"src/plugins/plugin-runtime/builtin/cache/UseCacheTransformer.ts"() {
|
|
2731
|
+
"use strict";
|
|
2732
|
+
init_cjs_shims();
|
|
2733
|
+
init_directive_transformer();
|
|
2734
|
+
cacheDirectivePlugin = createDirectiveTransformer({
|
|
2735
|
+
directive: "use cache",
|
|
2736
|
+
importPath: "commandkit",
|
|
2737
|
+
importName: "zxcvbnm____",
|
|
2738
|
+
asyncOnly: true
|
|
2739
|
+
});
|
|
2718
2740
|
}
|
|
2719
2741
|
});
|
|
2720
2742
|
|
|
2721
|
-
// src/plugins/runtime/builtin/cache/CachePlugin.ts
|
|
2743
|
+
// src/plugins/plugin-runtime/builtin/cache/CachePlugin.ts
|
|
2722
2744
|
var _CachePlugin, CachePlugin;
|
|
2723
2745
|
var init_CachePlugin = __esm({
|
|
2724
|
-
"src/plugins/runtime/builtin/cache/CachePlugin.ts"() {
|
|
2746
|
+
"src/plugins/plugin-runtime/builtin/cache/CachePlugin.ts"() {
|
|
2725
2747
|
"use strict";
|
|
2726
2748
|
init_cjs_shims();
|
|
2727
2749
|
init_plugins();
|
|
@@ -2745,10 +2767,10 @@ var init_CachePlugin = __esm({
|
|
|
2745
2767
|
}
|
|
2746
2768
|
});
|
|
2747
2769
|
|
|
2748
|
-
// src/plugins/runtime/builtin/MacroPlugin.ts
|
|
2770
|
+
// src/plugins/plugin-runtime/builtin/MacroPlugin.ts
|
|
2749
2771
|
var _MacroPlugin, MacroPlugin;
|
|
2750
2772
|
var init_MacroPlugin = __esm({
|
|
2751
|
-
"src/plugins/runtime/builtin/MacroPlugin.ts"() {
|
|
2773
|
+
"src/plugins/plugin-runtime/builtin/MacroPlugin.ts"() {
|
|
2752
2774
|
"use strict";
|
|
2753
2775
|
init_cjs_shims();
|
|
2754
2776
|
init_plugins();
|
|
@@ -3377,14 +3399,14 @@ var init_CommandRegistrar = __esm({
|
|
|
3377
3399
|
});
|
|
3378
3400
|
|
|
3379
3401
|
// src/context/environment.ts
|
|
3380
|
-
function
|
|
3402
|
+
function after(fn) {
|
|
3381
3403
|
const env = getContext();
|
|
3382
3404
|
if (!env) {
|
|
3383
3405
|
throw new Error("after must be called inside commandkit handler.");
|
|
3384
3406
|
}
|
|
3385
3407
|
return env.registerDeferredFunction(fn);
|
|
3386
3408
|
}
|
|
3387
|
-
function
|
|
3409
|
+
function cancelAfter(id) {
|
|
3388
3410
|
const env = getContext();
|
|
3389
3411
|
if (!env) {
|
|
3390
3412
|
throw new Error("cancelAfter must be called inside commandkit handler.");
|
|
@@ -3553,8 +3575,8 @@ var init_environment = __esm({
|
|
|
3553
3575
|
CommandKitEnvironmentType2["CommandHandler"] = "COMMAND_HANDLER";
|
|
3554
3576
|
return CommandKitEnvironmentType2;
|
|
3555
3577
|
})(CommandKitEnvironmentType || {});
|
|
3556
|
-
__name(
|
|
3557
|
-
__name(
|
|
3578
|
+
__name(after, "after");
|
|
3579
|
+
__name(cancelAfter, "cancelAfter");
|
|
3558
3580
|
}
|
|
3559
3581
|
});
|
|
3560
3582
|
|
|
@@ -3579,217 +3601,16 @@ var init_signals = __esm({
|
|
|
3579
3601
|
}
|
|
3580
3602
|
});
|
|
3581
3603
|
|
|
3582
|
-
// src/cache/utils.ts
|
|
3583
|
-
function isSerializablePrimitive(value) {
|
|
3584
|
-
return value === null || PRIMITIVE_TYPES.has(typeof value);
|
|
3585
|
-
}
|
|
3586
|
-
function createKey(val) {
|
|
3587
|
-
return `commandkit:cache:object:${val}`;
|
|
3588
|
-
}
|
|
3589
|
-
function getObjectId(obj) {
|
|
3590
|
-
const primitive = isSerializablePrimitive(obj);
|
|
3591
|
-
if (primitive) return createKey(obj);
|
|
3592
|
-
if (obj instanceof Date) return createKey(obj.getTime());
|
|
3593
|
-
if (obj instanceof RegExp) return createKey(obj);
|
|
3594
|
-
const ref = references.get(obj);
|
|
3595
|
-
if (ref) return createKey(ref);
|
|
3596
|
-
const id = tracker++;
|
|
3597
|
-
references.set(obj, id);
|
|
3598
|
-
return createKey(id);
|
|
3599
|
-
}
|
|
3600
|
-
async function createObjectHash(...args) {
|
|
3601
|
-
const serializedKey = args.map(getObjectId).join(":");
|
|
3602
|
-
try {
|
|
3603
|
-
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
3604
|
-
hash.update(serializedKey);
|
|
3605
|
-
return hash.digest("hex");
|
|
3606
|
-
} catch {
|
|
3607
|
-
return serializedKey;
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
var import_node_crypto2, tracker, references, PRIMITIVE_TYPES;
|
|
3611
|
-
var init_utils = __esm({
|
|
3612
|
-
"src/cache/utils.ts"() {
|
|
3613
|
-
"use strict";
|
|
3614
|
-
init_cjs_shims();
|
|
3615
|
-
import_node_crypto2 = require("crypto");
|
|
3616
|
-
tracker = 0n;
|
|
3617
|
-
references = /* @__PURE__ */ new WeakMap();
|
|
3618
|
-
PRIMITIVE_TYPES = /* @__PURE__ */ new Set(
|
|
3619
|
-
[
|
|
3620
|
-
"string",
|
|
3621
|
-
"number",
|
|
3622
|
-
"boolean",
|
|
3623
|
-
"bigint",
|
|
3624
|
-
"undefined"
|
|
3625
|
-
]
|
|
3626
|
-
);
|
|
3627
|
-
__name(isSerializablePrimitive, "isSerializablePrimitive");
|
|
3628
|
-
__name(createKey, "createKey");
|
|
3629
|
-
__name(getObjectId, "getObjectId");
|
|
3630
|
-
__name(createObjectHash, "createObjectHash");
|
|
3631
|
-
}
|
|
3632
|
-
});
|
|
3633
|
-
|
|
3634
|
-
// src/cache/use-cache.ts
|
|
3635
|
-
function getCacheProvider() {
|
|
3636
|
-
const commandkit2 = getCommandKit(true);
|
|
3637
|
-
const provider = commandkit2.getCacheProvider();
|
|
3638
|
-
if (!provider) {
|
|
3639
|
-
throw new Error(
|
|
3640
|
-
`Cache provider was not found, please provide a cache provider to commandkit.`
|
|
3641
|
-
);
|
|
3642
|
-
}
|
|
3643
|
-
return provider;
|
|
3644
|
-
}
|
|
3645
|
-
function useCache(fn, id, params) {
|
|
3646
|
-
const isLocal = id === CACHE_FN_ID;
|
|
3647
|
-
if (id && !isLocal) {
|
|
3648
|
-
throw new Error("Illegal use of cache function.");
|
|
3649
|
-
}
|
|
3650
|
-
const fnId = (0, import_node_crypto3.randomUUID)();
|
|
3651
|
-
const memo = /* @__PURE__ */ __name(async (...args) => {
|
|
3652
|
-
const forcedName = isLocal ? params == null ? void 0 : params.name : null;
|
|
3653
|
-
const keyHash = forcedName ?? await createObjectHash(fnId, ...args);
|
|
3654
|
-
const resolvedTTL = isLocal && (params == null ? void 0 : params.ttl) != null ? typeof params.ttl === "string" ? (0, import_ms.default)(params.ttl) : params.ttl : null;
|
|
3655
|
-
return cacheContext.run(
|
|
3656
|
-
{
|
|
3657
|
-
params: {
|
|
3658
|
-
name: keyHash,
|
|
3659
|
-
ttl: resolvedTTL ?? DEFAULT_TTL
|
|
3660
|
-
}
|
|
3661
|
-
},
|
|
3662
|
-
async () => {
|
|
3663
|
-
const provider = getCacheProvider();
|
|
3664
|
-
const context2 = cacheContext.getStore();
|
|
3665
|
-
if (!context2) {
|
|
3666
|
-
throw new Error("Cache context was not found.");
|
|
3667
|
-
}
|
|
3668
|
-
const storedFn = fnStore.get(keyHash);
|
|
3669
|
-
const effectiveKey = (storedFn == null ? void 0 : storedFn.key) ?? context2.params.name;
|
|
3670
|
-
const cached = await provider.get(effectiveKey);
|
|
3671
|
-
if (cached && cached.value != null) return cached.value;
|
|
3672
|
-
const result = await fn(...args);
|
|
3673
|
-
if (result != null) {
|
|
3674
|
-
const finalKey = context2.params.name;
|
|
3675
|
-
const ttl = context2.params.ttl ?? DEFAULT_TTL;
|
|
3676
|
-
await provider.set(finalKey, result, ttl);
|
|
3677
|
-
fnStore.set(keyHash, {
|
|
3678
|
-
key: finalKey,
|
|
3679
|
-
hash: keyHash,
|
|
3680
|
-
ttl,
|
|
3681
|
-
original: fn,
|
|
3682
|
-
memo
|
|
3683
|
-
});
|
|
3684
|
-
}
|
|
3685
|
-
return result;
|
|
3686
|
-
}
|
|
3687
|
-
);
|
|
3688
|
-
}, "memo");
|
|
3689
|
-
if (!Object.prototype.hasOwnProperty.call(fn, CACHED_FN_SYMBOL)) {
|
|
3690
|
-
Object.defineProperty(memo, CACHED_FN_SYMBOL, {
|
|
3691
|
-
get() {
|
|
3692
|
-
return true;
|
|
3693
|
-
},
|
|
3694
|
-
configurable: false,
|
|
3695
|
-
enumerable: false
|
|
3696
|
-
});
|
|
3697
|
-
}
|
|
3698
|
-
return memo;
|
|
3699
|
-
}
|
|
3700
|
-
function cache(fn, params) {
|
|
3701
|
-
return useCache(fn, CACHE_FN_ID, params);
|
|
3702
|
-
}
|
|
3703
|
-
function cacheTag(tag) {
|
|
3704
|
-
const context2 = cacheContext.getStore();
|
|
3705
|
-
if (!context2) {
|
|
3706
|
-
throw new Error("cacheTag() must be called inside a cached function.");
|
|
3707
|
-
}
|
|
3708
|
-
if (!tag) {
|
|
3709
|
-
throw new Error("cacheTag() must be called with a tag name.");
|
|
3710
|
-
}
|
|
3711
|
-
context2.params.name = tag;
|
|
3712
|
-
}
|
|
3713
|
-
function cacheLife(ttl) {
|
|
3714
|
-
const context2 = cacheContext.getStore();
|
|
3715
|
-
if (!context2) {
|
|
3716
|
-
throw new Error("cacheLife() must be called inside a cached function.");
|
|
3717
|
-
}
|
|
3718
|
-
if (ttl == null || !["string", "number"].includes(typeof ttl)) {
|
|
3719
|
-
throw new Error("cacheLife() must be called with a ttl.");
|
|
3720
|
-
}
|
|
3721
|
-
context2.params.ttl = typeof ttl === "string" ? (0, import_ms.default)(ttl) : ttl;
|
|
3722
|
-
}
|
|
3723
|
-
async function invalidate(tag) {
|
|
3724
|
-
const provider = getCacheProvider();
|
|
3725
|
-
const entry = Array.from(fnStore.values()).find(
|
|
3726
|
-
(v) => v.key === tag || v.hash === tag
|
|
3727
|
-
);
|
|
3728
|
-
if (!entry) return;
|
|
3729
|
-
await provider.delete(entry.key);
|
|
3730
|
-
}
|
|
3731
|
-
async function revalidate(tag, ...args) {
|
|
3732
|
-
const provider = getCacheProvider();
|
|
3733
|
-
const entry = Array.from(fnStore.values()).find(
|
|
3734
|
-
(v) => v.key === tag || v.hash === tag
|
|
3735
|
-
);
|
|
3736
|
-
if (!entry) return void 0;
|
|
3737
|
-
await provider.delete(entry.key);
|
|
3738
|
-
return entry.memo(...args);
|
|
3739
|
-
}
|
|
3740
|
-
function isCachedFunction(fn) {
|
|
3741
|
-
return Object.prototype.hasOwnProperty.call(fn, CACHED_FN_SYMBOL);
|
|
3742
|
-
}
|
|
3743
|
-
var import_node_async_hooks2, import_node_crypto3, import_ms, cacheContext, fnStore, DEFAULT_TTL, CACHE_FN_ID, CACHED_FN_SYMBOL, zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired;
|
|
3744
|
-
var init_use_cache = __esm({
|
|
3745
|
-
"src/cache/use-cache.ts"() {
|
|
3746
|
-
"use strict";
|
|
3747
|
-
init_cjs_shims();
|
|
3748
|
-
import_node_async_hooks2 = require("async_hooks");
|
|
3749
|
-
init_async_context();
|
|
3750
|
-
import_node_crypto3 = require("crypto");
|
|
3751
|
-
import_ms = __toESM(require("ms"));
|
|
3752
|
-
init_utils();
|
|
3753
|
-
cacheContext = new import_node_async_hooks2.AsyncLocalStorage();
|
|
3754
|
-
fnStore = /* @__PURE__ */ new Map();
|
|
3755
|
-
DEFAULT_TTL = (0, import_ms.default)("15m");
|
|
3756
|
-
CACHE_FN_ID = `__cache_fn_id_${Date.now()}__${Math.random()}__`;
|
|
3757
|
-
CACHED_FN_SYMBOL = Symbol("commandkit.cache.sentinel");
|
|
3758
|
-
__name(getCacheProvider, "getCacheProvider");
|
|
3759
|
-
__name(useCache, "useCache");
|
|
3760
|
-
__name(cache, "cache");
|
|
3761
|
-
__name(cacheTag, "cacheTag");
|
|
3762
|
-
__name(cacheLife, "cacheLife");
|
|
3763
|
-
__name(invalidate, "invalidate");
|
|
3764
|
-
__name(revalidate, "revalidate");
|
|
3765
|
-
__name(isCachedFunction, "isCachedFunction");
|
|
3766
|
-
zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired = useCache;
|
|
3767
|
-
}
|
|
3768
|
-
});
|
|
3769
|
-
|
|
3770
|
-
// src/cache/index.ts
|
|
3771
|
-
var init_cache = __esm({
|
|
3772
|
-
"src/cache/index.ts"() {
|
|
3773
|
-
"use strict";
|
|
3774
|
-
init_cjs_shims();
|
|
3775
|
-
init_CacheProvider();
|
|
3776
|
-
init_MemoryCache();
|
|
3777
|
-
init_use_cache();
|
|
3778
|
-
}
|
|
3779
|
-
});
|
|
3780
|
-
|
|
3781
3604
|
// src/app/commands/Context.ts
|
|
3782
3605
|
var CommandExecutionMode, _store, _Context, Context, _cancel, _MiddlewareContext, MiddlewareContext;
|
|
3783
3606
|
var init_Context = __esm({
|
|
3784
3607
|
"src/app/commands/Context.ts"() {
|
|
3785
3608
|
"use strict";
|
|
3786
3609
|
init_cjs_shims();
|
|
3787
|
-
init_environment();
|
|
3788
3610
|
init_async_context();
|
|
3789
3611
|
init_signals();
|
|
3790
|
-
init_cache();
|
|
3791
3612
|
CommandExecutionMode = {
|
|
3792
|
-
|
|
3613
|
+
ChatInputCommand: "chatInput",
|
|
3793
3614
|
MessageContextMenu: "messageContextMenu",
|
|
3794
3615
|
UserContextMenu: "userContextMenu",
|
|
3795
3616
|
Autocomplete: "autocomplete",
|
|
@@ -3812,6 +3633,22 @@ var init_Context = __esm({
|
|
|
3812
3633
|
* The message that triggered the command.
|
|
3813
3634
|
*/
|
|
3814
3635
|
__publicField(this, "message");
|
|
3636
|
+
/**
|
|
3637
|
+
* The guild where the command was triggered.
|
|
3638
|
+
*/
|
|
3639
|
+
__publicField(this, "guild");
|
|
3640
|
+
/**
|
|
3641
|
+
* The guild ID where the command was triggered.
|
|
3642
|
+
*/
|
|
3643
|
+
__publicField(this, "guildId");
|
|
3644
|
+
/**
|
|
3645
|
+
* The channel where the command was triggered.
|
|
3646
|
+
*/
|
|
3647
|
+
__publicField(this, "channel");
|
|
3648
|
+
/**
|
|
3649
|
+
* The channel id where the command was triggered.
|
|
3650
|
+
*/
|
|
3651
|
+
__publicField(this, "channelId");
|
|
3815
3652
|
/**
|
|
3816
3653
|
* The client instance.
|
|
3817
3654
|
*/
|
|
@@ -3827,6 +3664,18 @@ var init_Context = __esm({
|
|
|
3827
3664
|
this.client = commandkit2.client;
|
|
3828
3665
|
__privateSet(this, _store, config.store ?? /* @__PURE__ */ new Map());
|
|
3829
3666
|
this.command = config.command;
|
|
3667
|
+
if (config.interaction) {
|
|
3668
|
+
this.guild = config.interaction.guild;
|
|
3669
|
+
this.guildId = config.interaction.guildId;
|
|
3670
|
+
this.channel = config.interaction.channel;
|
|
3671
|
+
this.channelId = config.interaction.channelId;
|
|
3672
|
+
}
|
|
3673
|
+
if (config.message) {
|
|
3674
|
+
this.guild = config.message.guild;
|
|
3675
|
+
this.guildId = config.message.guildId;
|
|
3676
|
+
this.channel = config.message.channel;
|
|
3677
|
+
this.channelId = config.message.channelId;
|
|
3678
|
+
}
|
|
3830
3679
|
if (this.config.environment) {
|
|
3831
3680
|
this.config.environment.setContext(this);
|
|
3832
3681
|
}
|
|
@@ -3904,17 +3753,37 @@ var init_Context = __esm({
|
|
|
3904
3753
|
get executionMode() {
|
|
3905
3754
|
return this.config.executionMode;
|
|
3906
3755
|
}
|
|
3756
|
+
// /**
|
|
3757
|
+
// * The guild where this command was triggered.
|
|
3758
|
+
// */
|
|
3759
|
+
// public get guild() {
|
|
3760
|
+
// if (this.isInteraction()) {
|
|
3761
|
+
// return this.interaction.guild;
|
|
3762
|
+
// } else {
|
|
3763
|
+
// return (<MessageCommandContext>this).message.guild;
|
|
3764
|
+
// }
|
|
3765
|
+
// }
|
|
3766
|
+
// /**
|
|
3767
|
+
// * The guild ID where this command was triggered.
|
|
3768
|
+
// */
|
|
3769
|
+
// public get guildId() {
|
|
3770
|
+
// if (this.isInteraction()) {
|
|
3771
|
+
// return this.interaction.guildId;
|
|
3772
|
+
// } else {
|
|
3773
|
+
// return (<MessageCommandContext>this).message.guildId;
|
|
3774
|
+
// }
|
|
3775
|
+
// }
|
|
3907
3776
|
/**
|
|
3908
3777
|
* Whether the command was triggered by an interaction.
|
|
3909
3778
|
*/
|
|
3910
3779
|
isInteraction() {
|
|
3911
|
-
return this.executionMode === CommandExecutionMode.
|
|
3780
|
+
return this.executionMode === CommandExecutionMode.ChatInputCommand || this.executionMode === CommandExecutionMode.Autocomplete || this.executionMode === CommandExecutionMode.MessageContextMenu || this.executionMode === CommandExecutionMode.UserContextMenu;
|
|
3912
3781
|
}
|
|
3913
3782
|
/**
|
|
3914
3783
|
* Whether the command was triggered by a slash command interaction.
|
|
3915
3784
|
*/
|
|
3916
|
-
|
|
3917
|
-
return this.executionMode === CommandExecutionMode.
|
|
3785
|
+
isChatInputCommand() {
|
|
3786
|
+
return this.executionMode === CommandExecutionMode.ChatInputCommand;
|
|
3918
3787
|
}
|
|
3919
3788
|
/**
|
|
3920
3789
|
* Whether the command was triggered by an autocomplete interaction.
|
|
@@ -4021,28 +3890,6 @@ var init_Context = __esm({
|
|
|
4021
3890
|
exit() {
|
|
4022
3891
|
exitMiddleware();
|
|
4023
3892
|
}
|
|
4024
|
-
/**
|
|
4025
|
-
* Defers the given function to be executed after this command's execution.
|
|
4026
|
-
* @param fn The function to defer.
|
|
4027
|
-
* @returns A unique identifier for the deferred function.
|
|
4028
|
-
*/
|
|
4029
|
-
defer(fn) {
|
|
4030
|
-
return afterCommand(fn);
|
|
4031
|
-
}
|
|
4032
|
-
/**
|
|
4033
|
-
* Cancels the deferred function with the given identifier.
|
|
4034
|
-
* @param id The identifier of the deferred function.
|
|
4035
|
-
*/
|
|
4036
|
-
cancelDeferred(id) {
|
|
4037
|
-
cancelAfterCommand(id);
|
|
4038
|
-
}
|
|
4039
|
-
/**
|
|
4040
|
-
* Validates if the given function is a cached function.
|
|
4041
|
-
* @param fn The function to validate.
|
|
4042
|
-
*/
|
|
4043
|
-
isCached(fn) {
|
|
4044
|
-
return isCachedFunction(fn);
|
|
4045
|
-
}
|
|
4046
3893
|
};
|
|
4047
3894
|
_store = new WeakMap();
|
|
4048
3895
|
__name(_Context, "Context");
|
|
@@ -4102,9 +3949,6 @@ var init_AppCommandRunner = __esm({
|
|
|
4102
3949
|
__privateAdd(this, _AppCommandRunner_instances);
|
|
4103
3950
|
}
|
|
4104
3951
|
async runCommand(prepared, source) {
|
|
4105
|
-
if (source instanceof import_discord15.Message && (source.editedTimestamp || source.partial)) {
|
|
4106
|
-
return;
|
|
4107
|
-
}
|
|
4108
3952
|
const { commandkit: commandkit2 } = this.handler;
|
|
4109
3953
|
const executionMode = this.getExecutionMode(source);
|
|
4110
3954
|
let runCommand = null;
|
|
@@ -4224,7 +4068,8 @@ var init_AppCommandRunner = __esm({
|
|
|
4224
4068
|
}
|
|
4225
4069
|
getExecutionMode(source) {
|
|
4226
4070
|
if (source instanceof import_discord15.Message) return CommandExecutionMode.Message;
|
|
4227
|
-
if (source.isChatInputCommand())
|
|
4071
|
+
if (source.isChatInputCommand())
|
|
4072
|
+
return CommandExecutionMode.ChatInputCommand;
|
|
4228
4073
|
if (source.isAutocomplete()) {
|
|
4229
4074
|
return CommandExecutionMode.Autocomplete;
|
|
4230
4075
|
}
|
|
@@ -4242,6 +4087,9 @@ var init_AppCommandRunner = __esm({
|
|
|
4242
4087
|
const env = useEnvironment();
|
|
4243
4088
|
await env.runDeferredFunctions();
|
|
4244
4089
|
env.clearAllDeferredFunctions();
|
|
4090
|
+
await this.handler.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
4091
|
+
await plugin.onAfterCommand(ctx, env);
|
|
4092
|
+
});
|
|
4245
4093
|
}, "#finalizer");
|
|
4246
4094
|
__name(_AppCommandRunner, "AppCommandRunner");
|
|
4247
4095
|
AppCommandRunner = _AppCommandRunner;
|
|
@@ -4349,43 +4197,95 @@ var init_AppCommandHandler = __esm({
|
|
|
4349
4197
|
registrar;
|
|
4350
4198
|
onInteraction = null;
|
|
4351
4199
|
onMessageCreate = null;
|
|
4352
|
-
onMessageUpdate = null;
|
|
4353
4200
|
commandRunner = new AppCommandRunner(this);
|
|
4354
4201
|
externalCommandData = new import_discord16.Collection();
|
|
4355
4202
|
externalMiddlewareData = new import_discord16.Collection();
|
|
4356
4203
|
printBanner() {
|
|
4204
|
+
const uncategorized = crypto.randomUUID();
|
|
4357
4205
|
const categorizedCommands = this.getCommandsArray().reduce(
|
|
4358
4206
|
(acc, cmd) => {
|
|
4359
|
-
const category = cmd.command.category ||
|
|
4207
|
+
const category = cmd.command.category || uncategorized;
|
|
4360
4208
|
acc[category] = acc[category] || [];
|
|
4361
4209
|
acc[category].push(cmd);
|
|
4362
4210
|
return acc;
|
|
4363
4211
|
},
|
|
4364
4212
|
{}
|
|
4365
4213
|
);
|
|
4366
|
-
const categories = Object.keys(categorizedCommands).sort();
|
|
4367
4214
|
console.log(
|
|
4368
4215
|
colors_default.green(
|
|
4369
4216
|
`Loaded ${colors_default.magenta(this.loadedCommands.size.toString())} commands:`
|
|
4370
4217
|
)
|
|
4371
4218
|
);
|
|
4372
|
-
categories.
|
|
4219
|
+
const categories = Object.keys(categorizedCommands).sort();
|
|
4220
|
+
const categoryTree = {};
|
|
4221
|
+
categories.forEach((category) => {
|
|
4222
|
+
if (category === uncategorized) return;
|
|
4223
|
+
if (category.includes(":")) {
|
|
4224
|
+
const parts = category.split(":");
|
|
4225
|
+
let bestParent = null;
|
|
4226
|
+
for (let i = parts.length - 1; i > 0; i--) {
|
|
4227
|
+
const potentialParent = parts.slice(0, i).join(":");
|
|
4228
|
+
if (categories.includes(potentialParent)) {
|
|
4229
|
+
bestParent = potentialParent;
|
|
4230
|
+
break;
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
if (bestParent) {
|
|
4234
|
+
categoryTree[bestParent] = categoryTree[bestParent] || [];
|
|
4235
|
+
categoryTree[bestParent].push(category);
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
});
|
|
4239
|
+
const processedCategories = /* @__PURE__ */ new Set();
|
|
4240
|
+
const printCategory = /* @__PURE__ */ __name((category, indent = "", isLast = false, parentPrefix = "") => {
|
|
4241
|
+
if (processedCategories.has(category)) return;
|
|
4242
|
+
processedCategories.add(category);
|
|
4373
4243
|
const commands = categorizedCommands[category];
|
|
4374
|
-
const
|
|
4375
|
-
const
|
|
4376
|
-
|
|
4377
|
-
|
|
4244
|
+
const hasChildren = categoryTree[category] && categoryTree[category].length > 0;
|
|
4245
|
+
const thisPrefix = isLast ? "\u2514\u2500" : "\u251C\u2500";
|
|
4246
|
+
const childIndent = parentPrefix + (isLast ? " " : "\u2502 ");
|
|
4247
|
+
if (category !== uncategorized) {
|
|
4248
|
+
const displayName = category.includes(":") ? category.split(":").pop() : category;
|
|
4249
|
+
console.log(
|
|
4250
|
+
colors_default.cyan(`${indent}${thisPrefix} ${colors_default.bold(displayName)}`)
|
|
4251
|
+
);
|
|
4378
4252
|
}
|
|
4379
4253
|
commands.forEach((cmd, cmdIndex) => {
|
|
4380
|
-
const
|
|
4381
|
-
const
|
|
4254
|
+
const cmdIsLast = cmdIndex === commands.length - 1 && !hasChildren;
|
|
4255
|
+
const cmdPrefix = cmdIsLast ? "\u2514\u2500" : "\u251C\u2500";
|
|
4256
|
+
const cmdIndent = category !== uncategorized ? childIndent : indent;
|
|
4382
4257
|
const name = cmd.data.command.name;
|
|
4383
4258
|
const hasMw = cmd.command.middlewares.length > 0;
|
|
4384
4259
|
const middlewareIcon = hasMw ? colors_default.magenta(" (\u03BB)") : "";
|
|
4385
4260
|
console.log(
|
|
4386
|
-
`${colors_default.green(
|
|
4261
|
+
`${colors_default.green(`${cmdIndent}${cmdPrefix}`)} ${colors_default.yellow(name)}${middlewareIcon}`
|
|
4387
4262
|
);
|
|
4388
4263
|
});
|
|
4264
|
+
if (hasChildren) {
|
|
4265
|
+
const children = categoryTree[category].sort();
|
|
4266
|
+
children.forEach((childCategory, idx) => {
|
|
4267
|
+
const childIsLast = idx === children.length - 1;
|
|
4268
|
+
printCategory(childCategory, childIndent, childIsLast, childIndent);
|
|
4269
|
+
});
|
|
4270
|
+
}
|
|
4271
|
+
}, "printCategory");
|
|
4272
|
+
const topLevelCategories = categories.filter((category) => {
|
|
4273
|
+
if (category === uncategorized) return true;
|
|
4274
|
+
if (category.includes(":")) {
|
|
4275
|
+
const parts = category.split(":");
|
|
4276
|
+
for (let i = 1; i < parts.length; i++) {
|
|
4277
|
+
const parentPath = parts.slice(0, i).join(":");
|
|
4278
|
+
if (categories.includes(parentPath)) {
|
|
4279
|
+
return false;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
return true;
|
|
4283
|
+
}
|
|
4284
|
+
return true;
|
|
4285
|
+
}).sort();
|
|
4286
|
+
topLevelCategories.forEach((category, index) => {
|
|
4287
|
+
const isLast = index === topLevelCategories.length - 1;
|
|
4288
|
+
printCategory(category, "", isLast);
|
|
4389
4289
|
});
|
|
4390
4290
|
}
|
|
4391
4291
|
getCommandsArray() {
|
|
@@ -4417,26 +4317,8 @@ var init_AppCommandHandler = __esm({
|
|
|
4417
4317
|
if (!prepared) return;
|
|
4418
4318
|
return this.commandRunner.runCommand(prepared, message);
|
|
4419
4319
|
};
|
|
4420
|
-
this.onMessageUpdate ??= async (oldMessage, newMessage) => {
|
|
4421
|
-
const success = await this.commandkit.plugins.execute(
|
|
4422
|
-
async (ctx, plugin) => {
|
|
4423
|
-
return plugin.onBeforeMessageUpdateCommand(
|
|
4424
|
-
ctx,
|
|
4425
|
-
oldMessage,
|
|
4426
|
-
newMessage
|
|
4427
|
-
);
|
|
4428
|
-
}
|
|
4429
|
-
);
|
|
4430
|
-
if (success) return;
|
|
4431
|
-
if (oldMessage.partial || newMessage.partial) return;
|
|
4432
|
-
if (oldMessage.author.bot) return;
|
|
4433
|
-
const prepared = await this.prepareCommandRun(newMessage);
|
|
4434
|
-
if (!prepared) return;
|
|
4435
|
-
return this.commandRunner.runCommand(prepared, newMessage);
|
|
4436
|
-
};
|
|
4437
4320
|
this.commandkit.client.on(import_discord16.Events.InteractionCreate, this.onInteraction);
|
|
4438
4321
|
this.commandkit.client.on(import_discord16.Events.MessageCreate, this.onMessageCreate);
|
|
4439
|
-
this.commandkit.client.on(import_discord16.Events.MessageUpdate, this.onMessageUpdate);
|
|
4440
4322
|
}
|
|
4441
4323
|
async prepareCommandRun(source, cmdName) {
|
|
4442
4324
|
var _a;
|
|
@@ -4731,6 +4613,9 @@ var init_CommandsRouter = __esm({
|
|
|
4731
4613
|
if (this.isCommand(entry.name) || this.isMiddleware(entry.name)) {
|
|
4732
4614
|
await this.handle(entry, category);
|
|
4733
4615
|
}
|
|
4616
|
+
} else if (entry.isDirectory() && this.isCategory(entry.name) && category) {
|
|
4617
|
+
const nestedCategory = this.isCategory(entry.name) ? `${category}:${entry.name.slice(1, -1)}` : null;
|
|
4618
|
+
await this.traverse((0, import_node_path3.join)(path3, entry.name), nestedCategory);
|
|
4734
4619
|
}
|
|
4735
4620
|
}
|
|
4736
4621
|
}
|
|
@@ -5694,7 +5579,7 @@ var init_version = __esm({
|
|
|
5694
5579
|
"use strict";
|
|
5695
5580
|
init_cjs_shims();
|
|
5696
5581
|
version = /* @__MACRO__ $version */
|
|
5697
|
-
"0.1.11-dev.
|
|
5582
|
+
"0.1.11-dev.20250414064855";
|
|
5698
5583
|
}
|
|
5699
5584
|
});
|
|
5700
5585
|
|
|
@@ -6242,7 +6127,7 @@ async function createSpinner(text) {
|
|
|
6242
6127
|
});
|
|
6243
6128
|
}
|
|
6244
6129
|
var ora;
|
|
6245
|
-
var
|
|
6130
|
+
var init_utils = __esm({
|
|
6246
6131
|
"src/cli/utils.ts"() {
|
|
6247
6132
|
"use strict";
|
|
6248
6133
|
init_cjs_shims();
|
|
@@ -6296,7 +6181,7 @@ var init_production = __esm({
|
|
|
6296
6181
|
init_common2();
|
|
6297
6182
|
init_build();
|
|
6298
6183
|
init_plugins();
|
|
6299
|
-
|
|
6184
|
+
init_utils();
|
|
6300
6185
|
__name(bootstrapProductionServer, "bootstrapProductionServer");
|
|
6301
6186
|
__name(createProductionBuild, "createProductionBuild");
|
|
6302
6187
|
}
|
|
@@ -6312,14 +6197,14 @@ function determineExtension() {
|
|
|
6312
6197
|
return (0, import_fs2.existsSync)((0, import_path4.join)(BASE_PATH, "tsconfig.json")) ? "ts" : "js";
|
|
6313
6198
|
}
|
|
6314
6199
|
function TS_COMMAND_SOURCE(name) {
|
|
6315
|
-
return `import type { CommandData,
|
|
6200
|
+
return `import type { CommandData, ChatInputCommand, MessageCommand } from 'commandkit';
|
|
6316
6201
|
|
|
6317
6202
|
export const command: CommandData = {
|
|
6318
6203
|
name: '${name}',
|
|
6319
6204
|
description: '${name} command',
|
|
6320
6205
|
};
|
|
6321
6206
|
|
|
6322
|
-
export const chatInput:
|
|
6207
|
+
export const chatInput: ChatInputCommand = async (ctx) => {
|
|
6323
6208
|
await ctx.interaction.reply('Hello from ${name}!');
|
|
6324
6209
|
};
|
|
6325
6210
|
|
|
@@ -6338,7 +6223,7 @@ export const command = {
|
|
|
6338
6223
|
};
|
|
6339
6224
|
|
|
6340
6225
|
/**
|
|
6341
|
-
* @type {import('commandkit').
|
|
6226
|
+
* @type {import('commandkit').ChatInputCommand}
|
|
6342
6227
|
*/
|
|
6343
6228
|
export const chatInput = async (ctx) => {
|
|
6344
6229
|
await ctx.interaction.reply('Hello from ${name}!');
|
|
@@ -6616,12 +6501,12 @@ __export(index_exports, {
|
|
|
6616
6501
|
TextInput: () => TextInput,
|
|
6617
6502
|
UserSelectMenu: () => UserSelectMenu,
|
|
6618
6503
|
UserSelectMenuKit: () => UserSelectMenuKit,
|
|
6619
|
-
|
|
6504
|
+
after: () => after,
|
|
6620
6505
|
bootstrapCommandkitCLI: () => bootstrapCommandkitCLI,
|
|
6621
6506
|
cache: () => cache,
|
|
6622
6507
|
cacheLife: () => cacheLife,
|
|
6623
6508
|
cacheTag: () => cacheTag,
|
|
6624
|
-
|
|
6509
|
+
cancelAfter: () => cancelAfter,
|
|
6625
6510
|
commandkit: () => commandkit,
|
|
6626
6511
|
createElement: () => createElement,
|
|
6627
6512
|
createLogger: () => createLogger,
|
|
@@ -6654,7 +6539,7 @@ __export(index_exports, {
|
|
|
6654
6539
|
revalidate: () => revalidate,
|
|
6655
6540
|
useEnvironment: () => useEnvironment,
|
|
6656
6541
|
version: () => version,
|
|
6657
|
-
|
|
6542
|
+
zxcvbnm____: () => zxcvbnm____
|
|
6658
6543
|
});
|
|
6659
6544
|
module.exports = __toCommonJS(index_exports);
|
|
6660
6545
|
init_cjs_shims();
|
|
@@ -6664,7 +6549,188 @@ init_components();
|
|
|
6664
6549
|
init_config();
|
|
6665
6550
|
init_async_context();
|
|
6666
6551
|
init_environment();
|
|
6667
|
-
|
|
6552
|
+
|
|
6553
|
+
// src/cache/index.ts
|
|
6554
|
+
init_cjs_shims();
|
|
6555
|
+
init_CacheProvider();
|
|
6556
|
+
init_MemoryCache();
|
|
6557
|
+
|
|
6558
|
+
// src/cache/use-cache.ts
|
|
6559
|
+
init_cjs_shims();
|
|
6560
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
6561
|
+
init_async_context();
|
|
6562
|
+
var import_node_crypto3 = require("crypto");
|
|
6563
|
+
var import_ms = __toESM(require("ms"));
|
|
6564
|
+
|
|
6565
|
+
// src/cache/utils.ts
|
|
6566
|
+
init_cjs_shims();
|
|
6567
|
+
var import_node_crypto2 = require("crypto");
|
|
6568
|
+
var tracker = 0n;
|
|
6569
|
+
var references = /* @__PURE__ */ new WeakMap();
|
|
6570
|
+
var PRIMITIVE_TYPES = /* @__PURE__ */ new Set(
|
|
6571
|
+
[
|
|
6572
|
+
"string",
|
|
6573
|
+
"number",
|
|
6574
|
+
"boolean",
|
|
6575
|
+
"bigint",
|
|
6576
|
+
"undefined"
|
|
6577
|
+
]
|
|
6578
|
+
);
|
|
6579
|
+
function isSerializablePrimitive(value) {
|
|
6580
|
+
return value === null || PRIMITIVE_TYPES.has(typeof value);
|
|
6581
|
+
}
|
|
6582
|
+
__name(isSerializablePrimitive, "isSerializablePrimitive");
|
|
6583
|
+
function createKey(val) {
|
|
6584
|
+
return `commandkit:cache:object:${val}`;
|
|
6585
|
+
}
|
|
6586
|
+
__name(createKey, "createKey");
|
|
6587
|
+
function getObjectId(obj) {
|
|
6588
|
+
const primitive = isSerializablePrimitive(obj);
|
|
6589
|
+
if (primitive) return createKey(obj);
|
|
6590
|
+
if (obj instanceof Date) return createKey(obj.getTime());
|
|
6591
|
+
if (obj instanceof RegExp) return createKey(obj);
|
|
6592
|
+
const ref = references.get(obj);
|
|
6593
|
+
if (ref) return createKey(ref);
|
|
6594
|
+
const id = tracker++;
|
|
6595
|
+
references.set(obj, id);
|
|
6596
|
+
return createKey(id);
|
|
6597
|
+
}
|
|
6598
|
+
__name(getObjectId, "getObjectId");
|
|
6599
|
+
async function createObjectHash(...args) {
|
|
6600
|
+
const serializedKey = args.map(getObjectId).join(":");
|
|
6601
|
+
try {
|
|
6602
|
+
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
6603
|
+
hash.update(serializedKey);
|
|
6604
|
+
return hash.digest("hex");
|
|
6605
|
+
} catch {
|
|
6606
|
+
return serializedKey;
|
|
6607
|
+
}
|
|
6608
|
+
}
|
|
6609
|
+
__name(createObjectHash, "createObjectHash");
|
|
6610
|
+
|
|
6611
|
+
// src/cache/use-cache.ts
|
|
6612
|
+
var cacheContext = new import_node_async_hooks2.AsyncLocalStorage();
|
|
6613
|
+
var fnStore = /* @__PURE__ */ new Map();
|
|
6614
|
+
var DEFAULT_TTL = (0, import_ms.default)("15m");
|
|
6615
|
+
var CACHE_FN_ID = `__cache_fn_id_${Date.now()}__${Math.random()}__`;
|
|
6616
|
+
var CACHED_FN_SYMBOL = Symbol("commandkit.cache.sentinel");
|
|
6617
|
+
function getCacheProvider() {
|
|
6618
|
+
const commandkit2 = getCommandKit(true);
|
|
6619
|
+
const provider = commandkit2.getCacheProvider();
|
|
6620
|
+
if (!provider) {
|
|
6621
|
+
throw new Error(
|
|
6622
|
+
`Cache provider was not found, please provide a cache provider to commandkit.`
|
|
6623
|
+
);
|
|
6624
|
+
}
|
|
6625
|
+
return provider;
|
|
6626
|
+
}
|
|
6627
|
+
__name(getCacheProvider, "getCacheProvider");
|
|
6628
|
+
function useCache(fn, id, params) {
|
|
6629
|
+
const isLocal = id === CACHE_FN_ID;
|
|
6630
|
+
if (id && !isLocal) {
|
|
6631
|
+
throw new Error("Illegal use of cache function.");
|
|
6632
|
+
}
|
|
6633
|
+
const fnId = (0, import_node_crypto3.randomUUID)();
|
|
6634
|
+
const memo = /* @__PURE__ */ __name(async (...args) => {
|
|
6635
|
+
const forcedName = isLocal ? params == null ? void 0 : params.name : null;
|
|
6636
|
+
const keyHash = forcedName ?? await createObjectHash(fnId, ...args);
|
|
6637
|
+
const resolvedTTL = isLocal && (params == null ? void 0 : params.ttl) != null ? typeof params.ttl === "string" ? (0, import_ms.default)(params.ttl) : params.ttl : null;
|
|
6638
|
+
return cacheContext.run(
|
|
6639
|
+
{
|
|
6640
|
+
params: {
|
|
6641
|
+
name: keyHash,
|
|
6642
|
+
ttl: resolvedTTL ?? DEFAULT_TTL
|
|
6643
|
+
}
|
|
6644
|
+
},
|
|
6645
|
+
async () => {
|
|
6646
|
+
const provider = getCacheProvider();
|
|
6647
|
+
const context2 = cacheContext.getStore();
|
|
6648
|
+
if (!context2) {
|
|
6649
|
+
throw new Error("Cache context was not found.");
|
|
6650
|
+
}
|
|
6651
|
+
const storedFn = fnStore.get(keyHash);
|
|
6652
|
+
const effectiveKey = (storedFn == null ? void 0 : storedFn.key) ?? context2.params.name;
|
|
6653
|
+
const cached = await provider.get(effectiveKey);
|
|
6654
|
+
if (cached && cached.value != null) return cached.value;
|
|
6655
|
+
const result = await fn(...args);
|
|
6656
|
+
if (result != null) {
|
|
6657
|
+
const finalKey = context2.params.name;
|
|
6658
|
+
const ttl = context2.params.ttl ?? DEFAULT_TTL;
|
|
6659
|
+
await provider.set(finalKey, result, ttl);
|
|
6660
|
+
fnStore.set(keyHash, {
|
|
6661
|
+
key: finalKey,
|
|
6662
|
+
hash: keyHash,
|
|
6663
|
+
ttl,
|
|
6664
|
+
original: fn,
|
|
6665
|
+
memo
|
|
6666
|
+
});
|
|
6667
|
+
}
|
|
6668
|
+
return result;
|
|
6669
|
+
}
|
|
6670
|
+
);
|
|
6671
|
+
}, "memo");
|
|
6672
|
+
if (!Object.prototype.hasOwnProperty.call(fn, CACHED_FN_SYMBOL)) {
|
|
6673
|
+
Object.defineProperty(memo, CACHED_FN_SYMBOL, {
|
|
6674
|
+
get() {
|
|
6675
|
+
return true;
|
|
6676
|
+
},
|
|
6677
|
+
configurable: false,
|
|
6678
|
+
enumerable: false
|
|
6679
|
+
});
|
|
6680
|
+
}
|
|
6681
|
+
return memo;
|
|
6682
|
+
}
|
|
6683
|
+
__name(useCache, "useCache");
|
|
6684
|
+
function cache(fn, params) {
|
|
6685
|
+
return useCache(fn, CACHE_FN_ID, params);
|
|
6686
|
+
}
|
|
6687
|
+
__name(cache, "cache");
|
|
6688
|
+
function cacheTag(tag) {
|
|
6689
|
+
const context2 = cacheContext.getStore();
|
|
6690
|
+
if (!context2) {
|
|
6691
|
+
throw new Error("cacheTag() must be called inside a cached function.");
|
|
6692
|
+
}
|
|
6693
|
+
if (!tag) {
|
|
6694
|
+
throw new Error("cacheTag() must be called with a tag name.");
|
|
6695
|
+
}
|
|
6696
|
+
context2.params.name = tag;
|
|
6697
|
+
}
|
|
6698
|
+
__name(cacheTag, "cacheTag");
|
|
6699
|
+
function cacheLife(ttl) {
|
|
6700
|
+
const context2 = cacheContext.getStore();
|
|
6701
|
+
if (!context2) {
|
|
6702
|
+
throw new Error("cacheLife() must be called inside a cached function.");
|
|
6703
|
+
}
|
|
6704
|
+
if (ttl == null || !["string", "number"].includes(typeof ttl)) {
|
|
6705
|
+
throw new Error("cacheLife() must be called with a ttl.");
|
|
6706
|
+
}
|
|
6707
|
+
context2.params.ttl = typeof ttl === "string" ? (0, import_ms.default)(ttl) : ttl;
|
|
6708
|
+
}
|
|
6709
|
+
__name(cacheLife, "cacheLife");
|
|
6710
|
+
async function invalidate(tag) {
|
|
6711
|
+
const provider = getCacheProvider();
|
|
6712
|
+
const entry = Array.from(fnStore.values()).find(
|
|
6713
|
+
(v) => v.key === tag || v.hash === tag
|
|
6714
|
+
);
|
|
6715
|
+
if (!entry) return;
|
|
6716
|
+
await provider.delete(entry.key);
|
|
6717
|
+
}
|
|
6718
|
+
__name(invalidate, "invalidate");
|
|
6719
|
+
async function revalidate(tag, ...args) {
|
|
6720
|
+
const provider = getCacheProvider();
|
|
6721
|
+
const entry = Array.from(fnStore.values()).find(
|
|
6722
|
+
(v) => v.key === tag || v.hash === tag
|
|
6723
|
+
);
|
|
6724
|
+
if (!entry) return void 0;
|
|
6725
|
+
await provider.delete(entry.key);
|
|
6726
|
+
return entry.memo(...args);
|
|
6727
|
+
}
|
|
6728
|
+
__name(revalidate, "revalidate");
|
|
6729
|
+
function isCachedFunction(fn) {
|
|
6730
|
+
return Object.prototype.hasOwnProperty.call(fn, CACHED_FN_SYMBOL);
|
|
6731
|
+
}
|
|
6732
|
+
__name(isCachedFunction, "isCachedFunction");
|
|
6733
|
+
var zxcvbnm____ = useCache;
|
|
6668
6734
|
|
|
6669
6735
|
// src/app/index.ts
|
|
6670
6736
|
init_cjs_shims();
|
|
@@ -6809,12 +6875,12 @@ var index_default = CommandKit;
|
|
|
6809
6875
|
TextInput,
|
|
6810
6876
|
UserSelectMenu,
|
|
6811
6877
|
UserSelectMenuKit,
|
|
6812
|
-
|
|
6878
|
+
after,
|
|
6813
6879
|
bootstrapCommandkitCLI,
|
|
6814
6880
|
cache,
|
|
6815
6881
|
cacheLife,
|
|
6816
6882
|
cacheTag,
|
|
6817
|
-
|
|
6883
|
+
cancelAfter,
|
|
6818
6884
|
commandkit,
|
|
6819
6885
|
createElement,
|
|
6820
6886
|
createLogger,
|
|
@@ -6846,6 +6912,6 @@ var index_default = CommandKit;
|
|
|
6846
6912
|
revalidate,
|
|
6847
6913
|
useEnvironment,
|
|
6848
6914
|
version,
|
|
6849
|
-
|
|
6915
|
+
zxcvbnm____
|
|
6850
6916
|
});
|
|
6851
6917
|
//# sourceMappingURL=index.js.map
|