commandkit 0.1.11-dev.20250104131827 → 0.1.11-dev.20250111094526
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/bin/build.mjs +3 -0
- package/bin/development.mjs +1 -0
- package/dist/{CommandKit-8KZkBcWO.d.ts → CommandKit-DW5Fy2uM.d.ts} +28 -1
- package/dist/{CommandKit-eNQRmrvH.d.mts → CommandKit-oiAWcISu.d.mts} +28 -1
- package/dist/CommandKit.d.mts +3 -1
- package/dist/CommandKit.d.ts +3 -1
- package/dist/CommandKit.js +2 -2
- package/dist/CommandKit.js.map +1 -1
- package/dist/CommandKit.mjs +1 -1
- package/dist/async-context-B85N7tuZ.d.ts +156 -0
- package/dist/async-context-C45rxdEH.d.mts +156 -0
- package/dist/cache/CacheProvider.d.mts +9 -0
- package/dist/cache/CacheProvider.d.ts +9 -0
- package/dist/cache/CacheProvider.js +2 -0
- package/dist/cache/CacheProvider.js.map +1 -0
- package/dist/cache/CacheProvider.mjs +2 -0
- package/dist/cache/MemoryCache.d.mts +17 -0
- package/dist/cache/MemoryCache.d.ts +17 -0
- package/dist/cache/MemoryCache.js +2 -0
- package/dist/cache/MemoryCache.js.map +1 -0
- package/dist/cache/MemoryCache.mjs +2 -0
- package/dist/cache/MemoryCache.mjs.map +1 -0
- package/dist/cache/index.d.mts +26 -0
- package/dist/cache/index.d.ts +26 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/index.mjs +2 -0
- package/dist/cache/index.mjs.map +1 -0
- package/dist/{chunk-J3ZMR7KK.mjs → chunk-3ENTJANI.mjs} +2 -2
- package/dist/chunk-4BV475NY.mjs +2 -0
- package/dist/chunk-4BV475NY.mjs.map +1 -0
- package/dist/{chunk-D7RDGUPK.mjs → chunk-4CG7S6RY.mjs} +2 -2
- package/dist/{chunk-UXQFRVAB.mjs → chunk-6AX5YJEO.mjs} +2 -2
- package/dist/{chunk-JFCJXIOI.mjs → chunk-6BSP7AD3.mjs} +2 -2
- package/dist/{chunk-E2KEPOOS.mjs → chunk-6IFRWFZE.mjs} +2 -2
- package/dist/{chunk-7KD7ZCH6.mjs → chunk-6TIBWNPX.mjs} +1 -1
- package/dist/chunk-6TIBWNPX.mjs.map +1 -0
- package/dist/chunk-6TIGKCSX.mjs +2 -0
- package/dist/{chunk-GS3Q7VW7.mjs → chunk-6W2KY7FK.mjs} +2 -2
- package/dist/chunk-C6WU57FQ.mjs +2 -0
- package/dist/{chunk-ZE7AC2HG.mjs.map → chunk-C6WU57FQ.mjs.map} +1 -1
- package/dist/{chunk-YSVQ45EN.mjs → chunk-DW5KRS5H.mjs} +2 -2
- package/dist/chunk-GOXZZ7GU.mjs +2 -0
- package/dist/chunk-GOXZZ7GU.mjs.map +1 -0
- package/dist/{chunk-SFWUUQXC.mjs → chunk-K43A7OIY.mjs} +2 -2
- package/dist/chunk-LTI3V2K4.mjs +2 -0
- package/dist/chunk-LTI3V2K4.mjs.map +1 -0
- package/dist/chunk-M2MFP4HH.mjs +2 -0
- package/dist/chunk-M2MFP4HH.mjs.map +1 -0
- package/dist/chunk-MVPNDXHU.mjs +2 -0
- package/dist/chunk-MVPNDXHU.mjs.map +1 -0
- package/dist/chunk-UOPZOWKS.mjs +2 -0
- package/dist/chunk-UOPZOWKS.mjs.map +1 -0
- package/dist/chunk-VRGHCTCP.mjs +2 -0
- package/dist/chunk-VRGHCTCP.mjs.map +1 -0
- package/dist/{chunk-4IWEG3WI.mjs → chunk-WNEBLBID.mjs} +2 -2
- package/dist/{chunk-4IWEG3WI.mjs.map → chunk-WNEBLBID.mjs.map} +1 -1
- package/dist/chunk-XHS5CRG6.mjs +2 -0
- package/dist/chunk-XHS5CRG6.mjs.map +1 -0
- package/dist/{chunk-I2MRY4KL.mjs → chunk-XJCWZEWC.mjs} +2 -2
- package/dist/chunk-YTD7MZPP.mjs +2 -0
- package/dist/chunk-YTD7MZPP.mjs.map +1 -0
- package/dist/{chunk-4U6VHAPY.mjs → chunk-Z4FBPRS6.mjs} +2 -2
- package/dist/components/ButtonKit.js +1 -1
- package/dist/components/ButtonKit.js.map +1 -1
- package/dist/components/ButtonKit.mjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/context/async-context.d.mts +7 -0
- package/dist/context/async-context.d.ts +7 -0
- package/dist/context/async-context.js +2 -0
- package/dist/context/async-context.js.map +1 -0
- package/dist/context/async-context.mjs +2 -0
- package/dist/context/async-context.mjs.map +1 -0
- package/dist/context/environment.d.mts +7 -0
- package/dist/context/environment.d.ts +7 -0
- package/dist/context/environment.js +2 -0
- package/dist/context/environment.js.map +1 -0
- package/dist/context/environment.mjs +2 -0
- package/dist/context/environment.mjs.map +1 -0
- package/dist/handlers/command-handler/CommandHandler.d.mts +3 -1
- package/dist/handlers/command-handler/CommandHandler.d.ts +3 -1
- package/dist/handlers/command-handler/CommandHandler.js +2 -2
- package/dist/handlers/command-handler/CommandHandler.js.map +1 -1
- package/dist/handlers/command-handler/CommandHandler.mjs +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.d.mts +3 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.d.ts +3 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.js +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.js.map +1 -1
- package/dist/handlers/command-handler/functions/loadCommandsWithRest.mjs +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.d.mts +3 -1
- package/dist/handlers/command-handler/functions/registerCommands.d.ts +3 -1
- package/dist/handlers/command-handler/functions/registerCommands.js +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.js.map +1 -1
- package/dist/handlers/command-handler/functions/registerCommands.mjs +1 -1
- package/dist/handlers/command-handler/typings.d.mts +3 -1
- package/dist/handlers/command-handler/typings.d.ts +3 -1
- package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.mjs +1 -1
- package/dist/handlers/command-handler/validations/devOnly.d.mts +3 -1
- package/dist/handlers/command-handler/validations/devOnly.d.ts +3 -1
- package/dist/handlers/command-handler/validations/devOnly.mjs +1 -1
- package/dist/handlers/command-handler/validations/index.d.mts +3 -1
- package/dist/handlers/command-handler/validations/index.d.ts +3 -1
- package/dist/handlers/command-handler/validations/index.mjs +1 -1
- package/dist/handlers/command-handler/validations/permissions.d.mts +3 -1
- package/dist/handlers/command-handler/validations/permissions.d.ts +3 -1
- package/dist/handlers/command-handler/validations/permissions.mjs +1 -1
- package/dist/handlers/event-handler/EventHandler.d.mts +3 -1
- package/dist/handlers/event-handler/EventHandler.d.ts +3 -1
- package/dist/handlers/event-handler/EventHandler.js +1 -1
- package/dist/handlers/event-handler/EventHandler.js.map +1 -1
- package/dist/handlers/event-handler/EventHandler.mjs +1 -1
- package/dist/handlers/event-handler/typings.d.mts +3 -1
- package/dist/handlers/event-handler/typings.d.ts +3 -1
- package/dist/handlers/index.d.mts +3 -1
- package/dist/handlers/index.d.ts +3 -1
- package/dist/handlers/index.js +2 -2
- package/dist/handlers/index.js.map +1 -1
- package/dist/handlers/index.mjs +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.js +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.js.map +1 -1
- package/dist/handlers/validation-handler/ValidationHandler.mjs +1 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +3 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/clone.mjs +1 -1
- package/dist/utils/colors.js +1 -1
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/colors.mjs +1 -1
- package/dist/utils/error-codes.d.mts +10 -0
- package/dist/utils/error-codes.d.ts +10 -0
- package/dist/utils/error-codes.js +2 -0
- package/dist/utils/error-codes.js.map +1 -0
- package/dist/utils/error-codes.mjs +2 -0
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/get-paths.mjs +1 -1
- package/dist/utils/resolve-file-url.mjs +1 -1
- package/dist/utils/warn-unstable.d.mts +3 -0
- package/dist/utils/warn-unstable.d.ts +3 -0
- package/dist/utils/warn-unstable.js +2 -0
- package/dist/utils/warn-unstable.js.map +1 -0
- package/dist/utils/warn-unstable.mjs +2 -0
- package/dist/utils/warn-unstable.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-FXJNQE5B.mjs +0 -2
- package/dist/chunk-FXJNQE5B.mjs.map +0 -1
- package/dist/chunk-IHC5YX2R.mjs +0 -2
- package/dist/chunk-IHC5YX2R.mjs.map +0 -1
- package/dist/chunk-YZT2CEWE.mjs +0 -2
- package/dist/chunk-ZE7AC2HG.mjs +0 -2
- /package/dist/{chunk-7KD7ZCH6.mjs.map → cache/CacheProvider.mjs.map} +0 -0
- /package/dist/{chunk-J3ZMR7KK.mjs.map → chunk-3ENTJANI.mjs.map} +0 -0
- /package/dist/{chunk-D7RDGUPK.mjs.map → chunk-4CG7S6RY.mjs.map} +0 -0
- /package/dist/{chunk-UXQFRVAB.mjs.map → chunk-6AX5YJEO.mjs.map} +0 -0
- /package/dist/{chunk-JFCJXIOI.mjs.map → chunk-6BSP7AD3.mjs.map} +0 -0
- /package/dist/{chunk-E2KEPOOS.mjs.map → chunk-6IFRWFZE.mjs.map} +0 -0
- /package/dist/{chunk-YZT2CEWE.mjs.map → chunk-6TIGKCSX.mjs.map} +0 -0
- /package/dist/{chunk-GS3Q7VW7.mjs.map → chunk-6W2KY7FK.mjs.map} +0 -0
- /package/dist/{chunk-YSVQ45EN.mjs.map → chunk-DW5KRS5H.mjs.map} +0 -0
- /package/dist/{chunk-SFWUUQXC.mjs.map → chunk-K43A7OIY.mjs.map} +0 -0
- /package/dist/{chunk-I2MRY4KL.mjs.map → chunk-XJCWZEWC.mjs.map} +0 -0
- /package/dist/{chunk-4U6VHAPY.mjs.map → chunk-Z4FBPRS6.mjs.map} +0 -0
package/dist/CommandKit.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{CommandKit}from"./chunk-
|
|
1
|
+
import{CommandKit}from"./chunk-LTI3V2K4.mjs";import"./chunk-PFU3PH6M.mjs";import"./chunk-M2MFP4HH.mjs";import"./chunk-DW5KRS5H.mjs";import"./chunk-XJCWZEWC.mjs";import"./chunk-6TIGKCSX.mjs";import"./chunk-Z4FBPRS6.mjs";import"./chunk-K43A7OIY.mjs";import"./chunk-6AX5YJEO.mjs";import"./chunk-3ENTJANI.mjs";import"./chunk-6IFRWFZE.mjs";import"./chunk-4CG7S6RY.mjs";import"./chunk-MNPCM4QU.mjs";import"./chunk-C6WU57FQ.mjs";import"./chunk-6BSP7AD3.mjs";import"./chunk-VRGHCTCP.mjs";import"./chunk-UOPZOWKS.mjs";import"./chunk-4BV475NY.mjs";import"./chunk-XHS5CRG6.mjs";import"./chunk-GOXZZ7GU.mjs";import"./chunk-6TIBWNPX.mjs";export{CommandKit};
|
|
2
2
|
//# sourceMappingURL=CommandKit.mjs.map
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { C as CommandKit } from './CommandKit-DW5Fy2uM.js';
|
|
2
|
+
|
|
3
|
+
interface CommandKitEnvironmentInternalData {
|
|
4
|
+
executionError: Error | null;
|
|
5
|
+
type: CommandKitEnvironmentType | null;
|
|
6
|
+
variables: Map<string, any>;
|
|
7
|
+
deferredFunctions: Map<string, GenericFunction<[CommandKitEnvironment]>>;
|
|
8
|
+
marker: string;
|
|
9
|
+
markStart: number;
|
|
10
|
+
markEnd: number;
|
|
11
|
+
captureResult: boolean;
|
|
12
|
+
result: any;
|
|
13
|
+
}
|
|
14
|
+
declare class CommandKitEnvironment {
|
|
15
|
+
#private;
|
|
16
|
+
readonly commandkit: CommandKit;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the commandkit execution environment.
|
|
19
|
+
* @param commandkit - The commandkit instance.
|
|
20
|
+
*/
|
|
21
|
+
constructor(commandkit: CommandKit);
|
|
22
|
+
/**
|
|
23
|
+
* Capture the result of the command execution
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
captureResult(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the result of the command execution is being captured.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
isCapturingResult(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Set the result of the command execution
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
setResult(result: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get the result of the command execution
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
getResult(): any;
|
|
42
|
+
/**
|
|
43
|
+
* Get the execution error.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
getExecutionError(): Error | null;
|
|
47
|
+
/**
|
|
48
|
+
* Set the execution error.
|
|
49
|
+
* @param error - The error to set.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
setExecutionError(error: Error): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get the environment type.
|
|
55
|
+
*/
|
|
56
|
+
getType(): CommandKitEnvironmentType;
|
|
57
|
+
/**
|
|
58
|
+
* Set the environment type.
|
|
59
|
+
* @param type - The environment type to set.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
setType(type: CommandKitEnvironmentType): void;
|
|
63
|
+
/**
|
|
64
|
+
* The variables store for this environment.
|
|
65
|
+
*/
|
|
66
|
+
get variables(): Map<string, any>;
|
|
67
|
+
/**
|
|
68
|
+
* Register a deferred function.
|
|
69
|
+
* @param fn - The deferred function to register.
|
|
70
|
+
* @returns The deferred function id.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
registerDeferredFunction(fn: GenericFunction<[CommandKitEnvironment]>): string;
|
|
74
|
+
/**
|
|
75
|
+
* Clear a deferred function by id.
|
|
76
|
+
* @param id - The deferred function id to clear.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
clearDeferredFunction(id: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Run all deferred functions sequentially.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
runDeferredFunctions(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Clear all deferred functions.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
clearAllDeferredFunctions(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Mark the start of a command execution.
|
|
92
|
+
* @param marker - The marker to set.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
markStart(marker: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Mark the end of a command execution.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
markEnd(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get the marker.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
getMarker(): string;
|
|
106
|
+
/**
|
|
107
|
+
* Get the execution time in milliseconds.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
getExecutionTime(): number;
|
|
111
|
+
}
|
|
112
|
+
declare enum CommandKitEnvironmentType {
|
|
113
|
+
CommandHandler = "COMMAND_HANDLER"
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Runs the given function after the current handler has finished executing.
|
|
117
|
+
* @param fn The function to run after the current handler.
|
|
118
|
+
* @returns The deferred function id. This can be used to cancel the deferred function.
|
|
119
|
+
*/
|
|
120
|
+
declare function after(fn: GenericFunction<[CommandKitEnvironment]>): string;
|
|
121
|
+
/**
|
|
122
|
+
* Cancels a deferred function registered with `after`.
|
|
123
|
+
* @param id The deferred function id to cancel.
|
|
124
|
+
*/
|
|
125
|
+
declare function cancelAfter(id: string): void;
|
|
126
|
+
|
|
127
|
+
type GenericFunction<A extends any[] = any[]> = (...args: A) => any;
|
|
128
|
+
/**
|
|
129
|
+
* Returns a context-aware version of the given function.
|
|
130
|
+
* @param env - The commandkit environment data.
|
|
131
|
+
* @param fn - The target function.
|
|
132
|
+
* @param finalizer - An optional finalizer function to run after the target function. This function will be context-aware.
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
declare function makeContextAwareFunction<R extends GenericFunction, F extends GenericFunction>(env: CommandKitEnvironment, fn: R, finalizer?: F): R;
|
|
136
|
+
/**
|
|
137
|
+
* Get the current commandkit context.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
declare function getContext(): CommandKitEnvironment | void;
|
|
141
|
+
/**
|
|
142
|
+
* Use current commandkit context. Throws an error if no context is found.
|
|
143
|
+
*/
|
|
144
|
+
declare function useEnvironment(): CommandKitEnvironment;
|
|
145
|
+
/**
|
|
146
|
+
* Ensures the command is only available in guilds.
|
|
147
|
+
* Note: do not wrap this function in a try/catch block.
|
|
148
|
+
*/
|
|
149
|
+
declare function guildOnly(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Ensures the command is only available in DMs.
|
|
152
|
+
* Note: do not wrap this function in a try/catch block.
|
|
153
|
+
*/
|
|
154
|
+
declare function dmOnly(): void;
|
|
155
|
+
|
|
156
|
+
export { type CommandKitEnvironmentInternalData as C, type GenericFunction as G, guildOnly as a, CommandKitEnvironment as b, CommandKitEnvironmentType as c, dmOnly as d, after as e, cancelAfter as f, getContext as g, makeContextAwareFunction as m, useEnvironment as u };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { C as CommandKit } from './CommandKit-oiAWcISu.mjs';
|
|
2
|
+
|
|
3
|
+
interface CommandKitEnvironmentInternalData {
|
|
4
|
+
executionError: Error | null;
|
|
5
|
+
type: CommandKitEnvironmentType | null;
|
|
6
|
+
variables: Map<string, any>;
|
|
7
|
+
deferredFunctions: Map<string, GenericFunction<[CommandKitEnvironment]>>;
|
|
8
|
+
marker: string;
|
|
9
|
+
markStart: number;
|
|
10
|
+
markEnd: number;
|
|
11
|
+
captureResult: boolean;
|
|
12
|
+
result: any;
|
|
13
|
+
}
|
|
14
|
+
declare class CommandKitEnvironment {
|
|
15
|
+
#private;
|
|
16
|
+
readonly commandkit: CommandKit;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the commandkit execution environment.
|
|
19
|
+
* @param commandkit - The commandkit instance.
|
|
20
|
+
*/
|
|
21
|
+
constructor(commandkit: CommandKit);
|
|
22
|
+
/**
|
|
23
|
+
* Capture the result of the command execution
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
captureResult(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the result of the command execution is being captured.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
isCapturingResult(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Set the result of the command execution
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
setResult(result: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get the result of the command execution
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
getResult(): any;
|
|
42
|
+
/**
|
|
43
|
+
* Get the execution error.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
getExecutionError(): Error | null;
|
|
47
|
+
/**
|
|
48
|
+
* Set the execution error.
|
|
49
|
+
* @param error - The error to set.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
setExecutionError(error: Error): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get the environment type.
|
|
55
|
+
*/
|
|
56
|
+
getType(): CommandKitEnvironmentType;
|
|
57
|
+
/**
|
|
58
|
+
* Set the environment type.
|
|
59
|
+
* @param type - The environment type to set.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
setType(type: CommandKitEnvironmentType): void;
|
|
63
|
+
/**
|
|
64
|
+
* The variables store for this environment.
|
|
65
|
+
*/
|
|
66
|
+
get variables(): Map<string, any>;
|
|
67
|
+
/**
|
|
68
|
+
* Register a deferred function.
|
|
69
|
+
* @param fn - The deferred function to register.
|
|
70
|
+
* @returns The deferred function id.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
registerDeferredFunction(fn: GenericFunction<[CommandKitEnvironment]>): string;
|
|
74
|
+
/**
|
|
75
|
+
* Clear a deferred function by id.
|
|
76
|
+
* @param id - The deferred function id to clear.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
clearDeferredFunction(id: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Run all deferred functions sequentially.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
runDeferredFunctions(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Clear all deferred functions.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
clearAllDeferredFunctions(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Mark the start of a command execution.
|
|
92
|
+
* @param marker - The marker to set.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
markStart(marker: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Mark the end of a command execution.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
markEnd(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get the marker.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
getMarker(): string;
|
|
106
|
+
/**
|
|
107
|
+
* Get the execution time in milliseconds.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
getExecutionTime(): number;
|
|
111
|
+
}
|
|
112
|
+
declare enum CommandKitEnvironmentType {
|
|
113
|
+
CommandHandler = "COMMAND_HANDLER"
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Runs the given function after the current handler has finished executing.
|
|
117
|
+
* @param fn The function to run after the current handler.
|
|
118
|
+
* @returns The deferred function id. This can be used to cancel the deferred function.
|
|
119
|
+
*/
|
|
120
|
+
declare function after(fn: GenericFunction<[CommandKitEnvironment]>): string;
|
|
121
|
+
/**
|
|
122
|
+
* Cancels a deferred function registered with `after`.
|
|
123
|
+
* @param id The deferred function id to cancel.
|
|
124
|
+
*/
|
|
125
|
+
declare function cancelAfter(id: string): void;
|
|
126
|
+
|
|
127
|
+
type GenericFunction<A extends any[] = any[]> = (...args: A) => any;
|
|
128
|
+
/**
|
|
129
|
+
* Returns a context-aware version of the given function.
|
|
130
|
+
* @param env - The commandkit environment data.
|
|
131
|
+
* @param fn - The target function.
|
|
132
|
+
* @param finalizer - An optional finalizer function to run after the target function. This function will be context-aware.
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
declare function makeContextAwareFunction<R extends GenericFunction, F extends GenericFunction>(env: CommandKitEnvironment, fn: R, finalizer?: F): R;
|
|
136
|
+
/**
|
|
137
|
+
* Get the current commandkit context.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
declare function getContext(): CommandKitEnvironment | void;
|
|
141
|
+
/**
|
|
142
|
+
* Use current commandkit context. Throws an error if no context is found.
|
|
143
|
+
*/
|
|
144
|
+
declare function useEnvironment(): CommandKitEnvironment;
|
|
145
|
+
/**
|
|
146
|
+
* Ensures the command is only available in guilds.
|
|
147
|
+
* Note: do not wrap this function in a try/catch block.
|
|
148
|
+
*/
|
|
149
|
+
declare function guildOnly(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Ensures the command is only available in DMs.
|
|
152
|
+
* Note: do not wrap this function in a try/catch block.
|
|
153
|
+
*/
|
|
154
|
+
declare function dmOnly(): void;
|
|
155
|
+
|
|
156
|
+
export { type CommandKitEnvironmentInternalData as C, type GenericFunction as G, guildOnly as a, CommandKitEnvironment as b, CommandKitEnvironmentType as c, dmOnly as d, after as e, cancelAfter as f, getContext as g, makeContextAwareFunction as m, useEnvironment as u };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare abstract class CacheProvider {
|
|
2
|
+
abstract get<T>(key: string): Promise<T | undefined>;
|
|
3
|
+
abstract set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
4
|
+
abstract exists(key: string): Promise<boolean>;
|
|
5
|
+
abstract delete(key: string): Promise<void>;
|
|
6
|
+
abstract clear(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { CacheProvider };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare abstract class CacheProvider {
|
|
2
|
+
abstract get<T>(key: string): Promise<T | undefined>;
|
|
3
|
+
abstract set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
4
|
+
abstract exists(key: string): Promise<boolean>;
|
|
5
|
+
abstract delete(key: string): Promise<void>;
|
|
6
|
+
abstract clear(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { CacheProvider };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var CacheProvider_exports={};__export(CacheProvider_exports,{CacheProvider:()=>CacheProvider});module.exports=__toCommonJS(CacheProvider_exports);var CacheProvider=class{static{__name(this,"CacheProvider")}};0&&(module.exports={CacheProvider});
|
|
2
|
+
//# sourceMappingURL=CacheProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cache/CacheProvider.ts"],"sourcesContent":["export abstract class CacheProvider {\n abstract get<T>(key: string): Promise<T | undefined>;\n abstract set<T>(key: string, value: T, ttl?: number): Promise<void>;\n abstract exists(key: string): Promise<boolean>;\n abstract delete(key: string): Promise<void>;\n abstract clear(): Promise<void>;\n}"],"mappings":"ouBAAA,kJAAO,IAAe,cAAf,KAA6B,CAApC,MAAoC,8BAMpC","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CacheProvider } from './CacheProvider.mjs';
|
|
2
|
+
|
|
3
|
+
interface MemoryCacheEntry {
|
|
4
|
+
key: string;
|
|
5
|
+
value: any;
|
|
6
|
+
ttl?: number;
|
|
7
|
+
}
|
|
8
|
+
declare class MemoryCache extends CacheProvider {
|
|
9
|
+
#private;
|
|
10
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
12
|
+
exists(key: string): Promise<boolean>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { MemoryCache, type MemoryCacheEntry };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CacheProvider } from './CacheProvider.js';
|
|
2
|
+
|
|
3
|
+
interface MemoryCacheEntry {
|
|
4
|
+
key: string;
|
|
5
|
+
value: any;
|
|
6
|
+
ttl?: number;
|
|
7
|
+
}
|
|
8
|
+
declare class MemoryCache extends CacheProvider {
|
|
9
|
+
#private;
|
|
10
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
12
|
+
exists(key: string): Promise<boolean>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { MemoryCache, type MemoryCacheEntry };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var MemoryCache_exports={};__export(MemoryCache_exports,{MemoryCache:()=>MemoryCache});module.exports=__toCommonJS(MemoryCache_exports);var CacheProvider=class{static{__name(this,"CacheProvider")}};var MemoryCache=class extends CacheProvider{static{__name(this,"MemoryCache")}#cache=new Map;async get(key){let entry=this.#cache.get(key);if(entry){if(entry.ttl&&Date.now()>entry.ttl){this.#cache.delete(key);return}return entry.value}}async set(key,value,ttl){this.#cache.set(key,{key,value,ttl:ttl!=null?Date.now()+ttl:void 0})}async exists(key){return this.#cache.has(key)}async delete(key){this.#cache.delete(key)}async clear(){this.#cache.clear()}};0&&(module.exports={MemoryCache});
|
|
2
|
+
//# sourceMappingURL=MemoryCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cache/MemoryCache.ts","../../src/cache/CacheProvider.ts"],"sourcesContent":["import { CacheProvider } from './CacheProvider';\n\nexport interface MemoryCacheEntry {\n key: string;\n value: any;\n ttl?: number;\n}\n\nexport class MemoryCache extends CacheProvider {\n #cache = new Map<string, MemoryCacheEntry>();\n\n public async get<T>(key: string): Promise<T | undefined> {\n const entry = this.#cache.get(key);\n\n if (!entry) {\n return undefined;\n }\n\n if (entry.ttl && Date.now() > entry.ttl) {\n this.#cache.delete(key);\n return undefined;\n }\n\n return entry.value;\n }\n\n public async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n this.#cache.set(key, {\n key,\n value,\n ttl: ttl != null ? Date.now() + ttl : undefined\n });\n }\n\n public async exists(key: string): Promise<boolean> {\n return this.#cache.has(key);\n }\n\n public async delete(key: string): Promise<void> {\n this.#cache.delete(key);\n }\n\n public async clear(): Promise<void> {\n this.#cache.clear();\n }\n}","export abstract class CacheProvider {\n abstract get<T>(key: string): Promise<T | undefined>;\n abstract set<T>(key: string, value: T, ttl?: number): Promise<void>;\n abstract exists(key: string): Promise<boolean>;\n abstract delete(key: string): Promise<void>;\n abstract clear(): Promise<void>;\n}"],"mappings":"ouBAAA,wICAO,IAAe,cAAf,KAA6B,CAApC,MAAoC,8BAMpC,EDEO,IAAM,YAAN,cAA0B,aAAc,CAR/C,MAQ+C,4BAC7C,OAAS,IAAI,IAEb,MAAa,IAAO,IAAqC,CACvD,IAAM,MAAQ,KAAK,OAAO,IAAI,GAAG,EAEjC,GAAK,MAIL,IAAI,MAAM,KAAO,KAAK,IAAI,EAAI,MAAM,IAAK,CACvC,KAAK,OAAO,OAAO,GAAG,EACtB,MACF,CAEA,OAAO,MAAM,MACf,CAEA,MAAa,IAAO,IAAa,MAAU,IAA6B,CACtE,KAAK,OAAO,IAAI,IAAK,CACnB,IACA,MACA,IAAK,KAAO,KAAO,KAAK,IAAI,EAAI,IAAM,MACxC,CAAC,CACH,CAEA,MAAa,OAAO,IAA+B,CACjD,OAAO,KAAK,OAAO,IAAI,GAAG,CAC5B,CAEA,MAAa,OAAO,IAA4B,CAC9C,KAAK,OAAO,OAAO,GAAG,CACxB,CAEA,MAAa,OAAuB,CAClC,KAAK,OAAO,MAAM,CACpB,CACF","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { CacheProvider } from './CacheProvider.mjs';
|
|
2
|
+
export { MemoryCache, MemoryCacheEntry } from './MemoryCache.mjs';
|
|
3
|
+
|
|
4
|
+
interface CacheOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the cache key.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The time-to-live of the cache key in milliseconds.
|
|
11
|
+
*/
|
|
12
|
+
ttl?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Cache a value.
|
|
16
|
+
* @param options The cache options.
|
|
17
|
+
*/
|
|
18
|
+
declare function unstable_cache(options: string): Promise<void>;
|
|
19
|
+
declare function unstable_cache(options: CacheOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Manually expire a cache by its key.
|
|
22
|
+
* @param name The name of the cache key.
|
|
23
|
+
*/
|
|
24
|
+
declare function unstable_expire(name: string): Promise<void>;
|
|
25
|
+
|
|
26
|
+
export { type CacheOptions, unstable_cache, unstable_expire };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { CacheProvider } from './CacheProvider.js';
|
|
2
|
+
export { MemoryCache, MemoryCacheEntry } from './MemoryCache.js';
|
|
3
|
+
|
|
4
|
+
interface CacheOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the cache key.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The time-to-live of the cache key in milliseconds.
|
|
11
|
+
*/
|
|
12
|
+
ttl?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Cache a value.
|
|
16
|
+
* @param options The cache options.
|
|
17
|
+
*/
|
|
18
|
+
declare function unstable_cache(options: string): Promise<void>;
|
|
19
|
+
declare function unstable_cache(options: CacheOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Manually expire a cache by its key.
|
|
22
|
+
* @param name The name of the cache key.
|
|
23
|
+
*/
|
|
24
|
+
declare function unstable_expire(name: string): Promise<void>;
|
|
25
|
+
|
|
26
|
+
export { type CacheOptions, unstable_cache, unstable_expire };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var cache_exports={};__export(cache_exports,{CacheProvider:()=>CacheProvider,MemoryCache:()=>MemoryCache,unstable_cache:()=>unstable_cache,unstable_expire:()=>unstable_expire});module.exports=__toCommonJS(cache_exports);var import_discord=require("discord.js");var import_node_async_hooks=require("async_hooks");var CommandKitErrorCodes={GuildOnlyException:Symbol("kGuildOnlyException"),DMOnlyException:Symbol("kDMOnlyException"),CacheHit:Symbol("kCacheHit")};var context=new import_node_async_hooks.AsyncLocalStorage;function getContext(){return context.getStore()}__name(getContext,"getContext");function useEnvironment(){let ctx=context.getStore();if(!ctx)throw new Error("No commandkit environment found. Please make sure you are inside commandkit handler.");return ctx}__name(useEnvironment,"useEnvironment");var import_node_crypto=require("crypto");function after(fn){let env=getContext();if(!env)throw new Error("after must be called inside commandkit handler.");return env.registerDeferredFunction(fn)}__name(after,"after");var WARNED_KEYS=new Set;function warnUnstable(name){WARNED_KEYS.has(name)||(WARNED_KEYS.add(name),process.emitWarning(`${name} is unstable and may change in future versions.`,{code:"CommandKitUnstableWarning"}))}__name(warnUnstable,"warnUnstable");var CacheProvider=class{static{__name(this,"CacheProvider")}};var MemoryCache=class extends CacheProvider{static{__name(this,"MemoryCache")}#cache=new Map;async get(key){let entry=this.#cache.get(key);if(entry){if(entry.ttl&&Date.now()>entry.ttl){this.#cache.delete(key);return}return entry.value}}async set(key,value,ttl){this.#cache.set(key,{key,value,ttl:ttl!=null?Date.now()+ttl:void 0})}async exists(key){return this.#cache.has(key)}async delete(key){this.#cache.delete(key)}async clear(){this.#cache.clear()}};async function unstable_cache(options){warnUnstable("unstable_cache()");let env=useEnvironment(),commandkit=env.commandkit,cache=commandkit.getCacheProvider();if(!cache)throw new Error("cache() cannot be used without a cache provider.");let params=typeof options=="string"?{name:options}:options,data=await cache.get(params.name);if(data){let error=new Error("Cache hit exception");throw Reflect.set(error,"data",data),Reflect.set(error,"code",CommandKitErrorCodes.CacheHit),error}env.captureResult(),after(async env2=>{try{let result=await env2.getResult();if(result==null)return;if(result instanceof import_discord.InteractionResponse){let message=await result.fetch();await cache.set(params.name,{content:message.content,embeds:message.embeds,components:message.components},params.ttl)}else if(result instanceof import_discord.Message)await cache.set(params.name,{content:result.content,embeds:result.embeds,components:result.components},params.ttl);else{let json="toJSON"in result?result.toJSON():result;await cache.set(params.name,json,params.ttl)}}catch(e){commandkit.emit("cacheError",e)}})}__name(unstable_cache,"unstable_cache");async function unstable_expire(name){warnUnstable("unstable_expire()");let cache=useEnvironment().commandkit.getCacheProvider();if(!cache)throw new Error("expire() cannot be used without a cache provider.");await cache.delete(name)}__name(unstable_expire,"unstable_expire");0&&(module.exports={CacheProvider,MemoryCache,unstable_cache,unstable_expire});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cache/index.ts","../../src/context/async-context.ts","../../src/utils/error-codes.ts","../../src/context/environment.ts","../../src/utils/warn-unstable.ts","../../src/cache/CacheProvider.ts","../../src/cache/MemoryCache.ts"],"sourcesContent":["import { InteractionResponse, Message } from 'discord.js';\nimport { useEnvironment } from '../context/async-context';\nimport { after } from '../context/environment';\nimport { CommandKitErrorCodes } from '../utils/error-codes';\nimport { warnUnstable } from '../utils/warn-unstable';\n\nexport * from './CacheProvider';\nexport * from './MemoryCache';\n\nexport interface CacheOptions {\n /**\n * The name of the cache key.\n */\n name: string;\n /**\n * The time-to-live of the cache key in milliseconds.\n */\n ttl?: number;\n}\n\n/**\n * Cache a value.\n * @param options The cache options.\n */\nexport async function unstable_cache(options: string): Promise<void>;\nexport async function unstable_cache(options: CacheOptions): Promise<void>;\nexport async function unstable_cache(\noptions: string | CacheOptions)\n: Promise<void> {\n warnUnstable('unstable_cache()');\n const env = useEnvironment();\n const commandkit = env.commandkit;\n const cache = commandkit.getCacheProvider();\n\n if (!cache) {\n throw new Error('cache() cannot be used without a cache provider.');\n }\n\n const params = typeof options === 'string' ? { name: options } : options;\n\n // check cache\n const data = await cache.get(params.name);\n\n if (data) {\n const error = new Error('Cache hit exception');\n Reflect.set(error, 'data', data);\n Reflect.set(error, 'code', CommandKitErrorCodes.CacheHit);\n\n throw error;\n }\n\n env.captureResult();\n\n after(async (env) => {\n try {\n const result = await env.getResult();\n\n if (result == null) return;\n\n if (result instanceof InteractionResponse) {\n const message = await result.fetch();\n await cache.set(\n params.name,\n {\n content: message.content,\n embeds: message.embeds,\n components: message.components\n },\n params.ttl\n );\n } else if (result instanceof Message) {\n await cache.set(\n params.name,\n {\n content: result.content,\n embeds: result.embeds,\n components: result.components\n },\n params.ttl\n );\n } else {\n const json = 'toJSON' in result ? result.toJSON() : result;\n\n await cache.set(params.name, json, params.ttl);\n }\n } catch (e) {\n commandkit.emit('cacheError', e);\n }\n });\n}\n\n/**\n * Manually expire a cache by its key.\n * @param name The name of the cache key.\n */\nexport async function unstable_expire(name: string): Promise<void> {\n warnUnstable('unstable_expire()');\n const env = useEnvironment();\n const commandkit = env.commandkit;\n const cache = commandkit.getCacheProvider();\n\n if (!cache) {\n throw new Error('expire() cannot be used without a cache provider.');\n }\n\n await cache.delete(name);\n}","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { CommandKitEnvironment } from './environment';\nimport { CommandKitErrorCodes, isCommandKitError } from '../utils/error-codes';\nimport { Interaction } from 'discord.js';\nimport { warnUnstable } from '../utils/warn-unstable';\n\nconst context = new AsyncLocalStorage<CommandKitEnvironment>();\n\nexport type GenericFunction<A extends any[] = any[]> = (...args: A) => any;\n\n/**\n * Returns a context-aware version of the given function.\n * @param env - The commandkit environment data.\n * @param fn - The target function.\n * @param finalizer - An optional finalizer function to run after the target function. This function will be context-aware.\n * @internal\n */\nexport function makeContextAwareFunction<\n R extends GenericFunction,\n F extends GenericFunction>(\nenv: CommandKitEnvironment, fn: R, finalizer?: F): R {\n const _fn = (...args: any[]) => {\n return context.run(env, async () => {\n try {\n // execute the target function\n const result = await fn(...args);\n\n if (env.isCapturingResult() && result != null) {\n env.setResult(result);\n }\n\n return result;\n } catch (e) {\n // set the error in the environment data\n if (isCommandKitError(e)) {\n const code = Reflect.get(e, 'code');\n const interaction = env.variables.get('interaction') as Interaction;\n if (!interaction) return;\n\n switch (code) {\n case CommandKitErrorCodes.CacheHit:{\n const data = Reflect.get(e, 'data');\n env.variables.set('cacheHit', true);\n\n if (interaction.isCommand()) {\n if (interaction.deferred) {\n await interaction.editReply(data);\n } else if (interaction.isRepliable()) {\n await interaction.reply(data);\n }\n }\n\n return;\n }\n case CommandKitErrorCodes.GuildOnlyException:{\n if (interaction.isRepliable()) {\n await interaction.reply({\n content: 'This command is only available in guilds.',\n ephemeral: true\n });\n }\n return;\n }\n case CommandKitErrorCodes.DMOnlyException:{\n if (interaction.isRepliable()) {\n await interaction.reply({\n content: 'This command is only available in DMs.',\n ephemeral: true\n });\n }\n return;\n }\n }\n\n return;\n }\n\n env.setExecutionError(e as Error);\n } finally {\n if (typeof finalizer === 'function') {\n // execute the finalizer function\n try {\n await finalizer(...args);\n } catch {\n\n // no-op\n }}\n }\n });\n };\n\n return _fn as R;\n}\n\n/**\n * Get the current commandkit context.\n * @internal\n */\nexport function getContext(): CommandKitEnvironment | void {\n const ctx = context.getStore();\n return ctx;\n}\n\n/**\n * Use current commandkit context. Throws an error if no context is found.\n */\nexport function useEnvironment(): CommandKitEnvironment {\n const ctx = context.getStore();\n if (!ctx) {\n throw new Error(\n 'No commandkit environment found. Please make sure you are inside commandkit handler.'\n );\n }\n\n return ctx;\n}\n\n/**\n * Ensures the command is only available in guilds.\n * Note: do not wrap this function in a try/catch block.\n */\nexport function guildOnly() {\n const env = useEnvironment();\n const interaction: Interaction = env.variables.get('interaction');\n\n if (!interaction) {\n throw new Error('No interaction found in environment.');\n }\n\n if (!interaction.guild) {\n const error = new Error('This command is only available in guilds.');\n Reflect.set(error, 'code', CommandKitErrorCodes.GuildOnlyException);\n\n throw error;\n }\n}\n\n/**\n * Ensures the command is only available in DMs.\n * Note: do not wrap this function in a try/catch block.\n */\nexport function dmOnly() {\n const env = useEnvironment();\n const interaction: Interaction = env.variables.get('interaction');\n\n if (!interaction) {\n throw new Error('No interaction found in environment.');\n }\n\n if (interaction.guild) {\n const error = new Error('This command is only available in DMs.');\n Reflect.set(error, 'code', CommandKitErrorCodes.DMOnlyException);\n\n throw error;\n }\n}","export const CommandKitErrorCodes = {\n GuildOnlyException: Symbol('kGuildOnlyException'),\n DMOnlyException: Symbol('kDMOnlyException'),\n CacheHit: Symbol('kCacheHit')\n} as const;\n\nexport function isCommandKitError(\nerror: unknown)\n: error is Error & {code: symbol;} {\n if (!(error instanceof Error)) return false;\n const code = Reflect.get(error, 'code');\n\n for (const key in CommandKitErrorCodes) {\n if (CommandKitErrorCodes[key as keyof typeof CommandKitErrorCodes] === code)\n return true;\n }\n\n return false;\n}","import { randomUUID } from 'node:crypto';\nimport { CommandKit } from '../CommandKit';\nimport { GenericFunction, getContext } from './async-context';\n\nexport interface CommandKitEnvironmentInternalData {\n executionError: Error | null;\n type: CommandKitEnvironmentType | null;\n variables: Map<string, any>;\n deferredFunctions: Map<string, GenericFunction<[CommandKitEnvironment]>>;\n marker: string;\n markStart: number;\n markEnd: number;\n captureResult: boolean;\n result: any;\n}\n\nexport class CommandKitEnvironment {\n #data: CommandKitEnvironmentInternalData = {\n executionError: null,\n type: null,\n variables: new Map(),\n deferredFunctions: new Map(),\n marker: '',\n markStart: 0,\n markEnd: 0,\n captureResult: false,\n result: null\n };\n\n /**\n * Creates the commandkit execution environment.\n * @param commandkit - The commandkit instance.\n */\n public constructor(public readonly commandkit: CommandKit) {}\n\n /**\n * Capture the result of the command execution\n * @internal\n */\n public captureResult(): void {\n this.#data.captureResult = true;\n }\n\n /**\n * Whether the result of the command execution is being captured.\n * @internal\n */\n public isCapturingResult(): boolean {\n return this.#data.captureResult;\n }\n\n /**\n * Set the result of the command execution\n * @internal\n */\n public setResult(result: any): void {\n this.#data.result = result;\n }\n\n /**\n * Get the result of the command execution\n * @internal\n */\n public getResult(): any {\n return this.#data.result;\n }\n\n /**\n * Get the execution error.\n * @internal\n */\n public getExecutionError(): Error | null {\n return this.#data.executionError;\n }\n\n /**\n * Set the execution error.\n * @param error - The error to set.\n * @internal\n */\n public setExecutionError(error: Error): void {\n if (this.#data.executionError) {\n throw new Error('Execution error already set.');\n }\n\n this.#data.executionError = error;\n }\n\n /**\n * Get the environment type.\n */\n public getType(): CommandKitEnvironmentType {\n const type = this.#data.type;\n\n if (!type) {\n throw new Error('Environment type not set.');\n }\n\n return type;\n }\n\n /**\n * Set the environment type.\n * @param type - The environment type to set.\n * @internal\n */\n public setType(type: CommandKitEnvironmentType): void {\n this.#data.type = type;\n }\n\n /**\n * The variables store for this environment.\n */\n public get variables(): Map<string, any> {\n return this.#data.variables;\n }\n\n /**\n * Register a deferred function.\n * @param fn - The deferred function to register.\n * @returns The deferred function id.\n * @internal\n */\n public registerDeferredFunction(\n fn: GenericFunction<[CommandKitEnvironment]>)\n : string {\n const id = randomUUID();\n this.#data.deferredFunctions.set(id, fn);\n return id;\n }\n\n /**\n * Clear a deferred function by id.\n * @param id - The deferred function id to clear.\n * @internal\n */\n public clearDeferredFunction(id: string): void {\n this.#data.deferredFunctions.delete(id);\n }\n\n /**\n * Run all deferred functions sequentially.\n * @internal\n */\n public async runDeferredFunctions(): Promise<void> {\n for (const [id, fn] of this.#data.deferredFunctions) {\n try {\n await fn(this);\n } catch (e) {\n this.commandkit.emit('unhandledDeferredFunctionRejection', e);\n } finally {\n this.clearDeferredFunction(id);\n }\n }\n }\n\n /**\n * Clear all deferred functions.\n * @internal\n */\n public clearAllDeferredFunctions(): void {\n this.#data.deferredFunctions.clear();\n }\n\n /**\n * Mark the start of a command execution.\n * @param marker - The marker to set.\n * @internal\n */\n public markStart(marker: string): void {\n this.#data.marker = marker;\n this.#data.markStart = performance.now();\n }\n\n /**\n * Mark the end of a command execution.\n * @internal\n */\n public markEnd(): void {\n if (!this.#data.markEnd) this.#data.markEnd = performance.now();\n }\n\n /**\n * Get the marker.\n * @internal\n */\n public getMarker(): string {\n return this.#data.marker;\n }\n\n /**\n * Get the execution time in milliseconds.\n * @internal\n */\n public getExecutionTime(): number {\n return Math.abs(this.#data.markEnd - this.#data.markStart);\n }\n}\n\nexport enum CommandKitEnvironmentType {\n CommandHandler = 'COMMAND_HANDLER',\n}\n\n/**\n * Runs the given function after the current handler has finished executing.\n * @param fn The function to run after the current handler.\n * @returns The deferred function id. This can be used to cancel the deferred function.\n */\nexport function after(fn: GenericFunction<[CommandKitEnvironment]>): string {\n const env = getContext();\n\n if (!env) {\n throw new Error('after must be called inside commandkit handler.');\n }\n\n return env.registerDeferredFunction(fn);\n}\n\n/**\n * Cancels a deferred function registered with `after`.\n * @param id The deferred function id to cancel.\n */\nexport function cancelAfter(id: string): void {\n const env = getContext();\n\n if (!env) {\n throw new Error('cancelAfter must be called inside commandkit handler.');\n }\n\n env.clearDeferredFunction(id);\n}","import colors from './colors';\n\nconst WARNED_KEYS = new Set<string>();\n\nexport function warnUnstable(name: string) {\n if (WARNED_KEYS.has(name)) return;\n\n WARNED_KEYS.add(name);\n\n process.emitWarning(\n `${name} is unstable and may change in future versions.`,\n {\n code: 'CommandKitUnstableWarning'\n }\n );\n}","export abstract class CacheProvider {\n abstract get<T>(key: string): Promise<T | undefined>;\n abstract set<T>(key: string, value: T, ttl?: number): Promise<void>;\n abstract exists(key: string): Promise<boolean>;\n abstract delete(key: string): Promise<void>;\n abstract clear(): Promise<void>;\n}","import { CacheProvider } from './CacheProvider';\n\nexport interface MemoryCacheEntry {\n key: string;\n value: any;\n ttl?: number;\n}\n\nexport class MemoryCache extends CacheProvider {\n #cache = new Map<string, MemoryCacheEntry>();\n\n public async get<T>(key: string): Promise<T | undefined> {\n const entry = this.#cache.get(key);\n\n if (!entry) {\n return undefined;\n }\n\n if (entry.ttl && Date.now() > entry.ttl) {\n this.#cache.delete(key);\n return undefined;\n }\n\n return entry.value;\n }\n\n public async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n this.#cache.set(key, {\n key,\n value,\n ttl: ttl != null ? Date.now() + ttl : undefined\n });\n }\n\n public async exists(key: string): Promise<boolean> {\n return this.#cache.has(key);\n }\n\n public async delete(key: string): Promise<void> {\n this.#cache.delete(key);\n }\n\n public async clear(): Promise<void> {\n this.#cache.clear();\n }\n}"],"mappings":"ouBAAA,4NAAA,mBAA6C,sBCA7C,4BAAkC,uBCA3B,IAAM,qBAAuB,CAClC,mBAAoB,OAAO,qBAAqB,EAChD,gBAAiB,OAAO,kBAAkB,EAC1C,SAAU,OAAO,WAAW,CAC9B,EDEA,IAAM,QAAU,IAAI,0CA4Fb,SAAS,YAA2C,CAEzD,OADY,QAAQ,SAAS,CAE/B,CAHgB,gCAQT,SAAS,gBAAwC,CACtD,IAAM,IAAM,QAAQ,SAAS,EAC7B,GAAI,CAAC,IACH,MAAM,IAAI,MACR,sFACF,EAGF,OAAO,GACT,CATgB,wCE1GhB,uBAA2B,kBAgNpB,SAAS,MAAM,GAAsD,CAC1E,IAAM,IAAM,WAAW,EAEvB,GAAI,CAAC,IACH,MAAM,IAAI,MAAM,iDAAiD,EAGnE,OAAO,IAAI,yBAAyB,EAAE,CACxC,CARgB,sBC9MhB,IAAM,YAAc,IAAI,IAEjB,SAAS,aAAa,KAAc,CACrC,YAAY,IAAI,IAAI,IAExB,YAAY,IAAI,IAAI,EAEpB,QAAQ,YACN,GAAG,IAAI,kDACP,CACE,KAAM,2BACR,CACF,EACF,CAXgB,oCCJT,IAAe,cAAf,KAA6B,CAApC,MAAoC,8BAMpC,ECEO,IAAM,YAAN,cAA0B,aAAc,CAR/C,MAQ+C,4BAC7C,OAAS,IAAI,IAEb,MAAa,IAAO,IAAqC,CACvD,IAAM,MAAQ,KAAK,OAAO,IAAI,GAAG,EAEjC,GAAK,MAIL,IAAI,MAAM,KAAO,KAAK,IAAI,EAAI,MAAM,IAAK,CACvC,KAAK,OAAO,OAAO,GAAG,EACtB,MACF,CAEA,OAAO,MAAM,MACf,CAEA,MAAa,IAAO,IAAa,MAAU,IAA6B,CACtE,KAAK,OAAO,IAAI,IAAK,CACnB,IACA,MACA,IAAK,KAAO,KAAO,KAAK,IAAI,EAAI,IAAM,MACxC,CAAC,CACH,CAEA,MAAa,OAAO,IAA+B,CACjD,OAAO,KAAK,OAAO,IAAI,GAAG,CAC5B,CAEA,MAAa,OAAO,IAA4B,CAC9C,KAAK,OAAO,OAAO,GAAG,CACxB,CAEA,MAAa,OAAuB,CAClC,KAAK,OAAO,MAAM,CACpB,CACF,ENnBA,eAAsB,eACtB,QACgB,CACd,aAAa,kBAAkB,EAC/B,IAAM,IAAM,eAAe,EACrB,WAAa,IAAI,WACjB,MAAQ,WAAW,iBAAiB,EAE1C,GAAI,CAAC,MACH,MAAM,IAAI,MAAM,kDAAkD,EAGpE,IAAM,OAAS,OAAO,SAAY,SAAW,CAAE,KAAM,OAAQ,EAAI,QAG3D,KAAO,MAAM,MAAM,IAAI,OAAO,IAAI,EAExC,GAAI,KAAM,CACR,IAAM,MAAQ,IAAI,MAAM,qBAAqB,EAC7C,cAAQ,IAAI,MAAO,OAAQ,IAAI,EAC/B,QAAQ,IAAI,MAAO,OAAQ,qBAAqB,QAAQ,EAElD,KACR,CAEA,IAAI,cAAc,EAElB,MAAM,MAAOA,MAAQ,CACnB,GAAI,CACF,IAAM,OAAS,MAAMA,KAAI,UAAU,EAEnC,GAAI,QAAU,KAAM,OAEpB,GAAI,kBAAkB,mCAAqB,CACzC,IAAM,QAAU,MAAM,OAAO,MAAM,EACnC,MAAM,MAAM,IACV,OAAO,KACP,CACE,QAAS,QAAQ,QACjB,OAAQ,QAAQ,OAChB,WAAY,QAAQ,UACtB,EACA,OAAO,GACT,CACF,SAAW,kBAAkB,uBAC3B,MAAM,MAAM,IACV,OAAO,KACP,CACE,QAAS,OAAO,QAChB,OAAQ,OAAO,OACf,WAAY,OAAO,UACrB,EACA,OAAO,GACT,MACK,CACL,IAAM,KAAO,WAAY,OAAS,OAAO,OAAO,EAAI,OAEpD,MAAM,MAAM,IAAI,OAAO,KAAM,KAAM,OAAO,GAAG,CAC/C,CACF,OAAS,EAAG,CACV,WAAW,KAAK,aAAc,CAAC,CACjC,CACF,CAAC,CACH,CA/DsB,wCAqEtB,eAAsB,gBAAgB,KAA6B,CACjE,aAAa,mBAAmB,EAGhC,IAAM,MAFM,eAAe,EACJ,WACE,iBAAiB,EAE1C,GAAI,CAAC,MACH,MAAM,IAAI,MAAM,mDAAmD,EAGrE,MAAM,MAAM,OAAO,IAAI,CACzB,CAXsB","names":["env"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{unstable_cache,unstable_expire}from"../chunk-YTD7MZPP.mjs";import"../chunk-MVPNDXHU.mjs";import"../chunk-VRGHCTCP.mjs";import"../chunk-UOPZOWKS.mjs";import"../chunk-4BV475NY.mjs";import{MemoryCache}from"../chunk-XHS5CRG6.mjs";import{CacheProvider}from"../chunk-GOXZZ7GU.mjs";import"../chunk-6TIBWNPX.mjs";export{CacheProvider,MemoryCache,unstable_cache,unstable_expire};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{toFileURL}from"./chunk-4CG7S6RY.mjs";import{clone}from"./chunk-MNPCM4QU.mjs";import{colors_default}from"./chunk-C6WU57FQ.mjs";import{getFilePaths}from"./chunk-6BSP7AD3.mjs";import{__name,__require}from"./chunk-6TIBWNPX.mjs";var ValidationHandler=class{static{__name(this,"ValidationHandler")}#data;constructor({...options}){this.#data={...options,validations:[]}}async init(){this.#data.validations=await this.#buildValidations()}async#buildValidations(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,validationFilePaths=(await getFilePaths(this.#data.validationsPath,!0)).filter(path=>allowedExtensions.test(path)),validationFunctions=[];for(let validationFilePath of validationFilePaths){let importedFunction=(await import(`${toFileURL(validationFilePath)}?t=${Date.now()}`)).default,validationFunction=clone(importedFunction);typeof module<"u"&&typeof __require<"u"&&delete __require.cache[__require.resolve(validationFilePath)],validationFunction?.default&&(validationFunction=validationFunction.default);let compactFilePath=validationFilePath.split(process.cwd())[1]||validationFilePath;if(typeof validationFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Validation file ${compactFilePath} does not export a function.`));continue}validationFunctions.push(validationFunction)}return validationFunctions}get validations(){return this.#data.validations}async reloadValidations(){if(!this.#data.validationsPath)throw new Error(colors_default.red('Cannot reload validations as "validationsPath" was not provided when instantiating CommandKit.'));let newValidations=await this.#buildValidations();this.#data.validations=newValidations}};export{ValidationHandler};
|
|
2
|
+
//# sourceMappingURL=chunk-3ENTJANI.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__name}from"./chunk-6TIBWNPX.mjs";var CommandKitErrorCodes={GuildOnlyException:Symbol("kGuildOnlyException"),DMOnlyException:Symbol("kDMOnlyException"),CacheHit:Symbol("kCacheHit")};function isCommandKitError(error){if(!(error instanceof Error))return!1;let code=Reflect.get(error,"code");for(let key in CommandKitErrorCodes)if(CommandKitErrorCodes[key]===code)return!0;return!1}__name(isCommandKitError,"isCommandKitError");export{CommandKitErrorCodes,isCommandKitError};
|
|
2
|
+
//# sourceMappingURL=chunk-4BV475NY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/error-codes.ts"],"sourcesContent":["export const CommandKitErrorCodes = {\n GuildOnlyException: Symbol('kGuildOnlyException'),\n DMOnlyException: Symbol('kDMOnlyException'),\n CacheHit: Symbol('kCacheHit')\n} as const;\n\nexport function isCommandKitError(\nerror: unknown)\n: error is Error & {code: symbol;} {\n if (!(error instanceof Error)) return false;\n const code = Reflect.get(error, 'code');\n\n for (const key in CommandKitErrorCodes) {\n if (CommandKitErrorCodes[key as keyof typeof CommandKitErrorCodes] === code)\n return true;\n }\n\n return false;\n}"],"mappings":"yCAAO,IAAM,qBAAuB,CAClC,mBAAoB,OAAO,qBAAqB,EAChD,gBAAiB,OAAO,kBAAkB,EAC1C,SAAU,OAAO,WAAW,CAC9B,EAEO,SAAS,kBAChB,MACmC,CACjC,GAAI,EAAE,iBAAiB,OAAQ,MAAO,GACtC,IAAM,KAAO,QAAQ,IAAI,MAAO,MAAM,EAEtC,QAAW,OAAO,qBAChB,GAAI,qBAAqB,GAAwC,IAAM,KACvE,MAAO,GAGT,MAAO,EACT,CAZgB","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__name}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{__name}from"./chunk-6TIBWNPX.mjs";import path from"path";function toFileURL(filePath){return"file://"+path.resolve(filePath).replace(/\\\\|\\/g,"/")}__name(toFileURL,"toFileURL");export{toFileURL};
|
|
2
|
+
//# sourceMappingURL=chunk-4CG7S6RY.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__name}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{__name}from"./chunk-6TIBWNPX.mjs";function areSlashCommandsDifferent(appCommand,localCommand){if(appCommand.options||(appCommand.options=[]),localCommand.options||(localCommand.options=[]),appCommand.description||(appCommand.description=""),localCommand.description||(localCommand.description=""),localCommand.description!==appCommand.description||localCommand.options.length!==appCommand.options.length)return!0}__name(areSlashCommandsDifferent,"areSlashCommandsDifferent");export{areSlashCommandsDifferent};
|
|
2
|
+
//# sourceMappingURL=chunk-6AX5YJEO.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__name}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{__name}from"./chunk-6TIBWNPX.mjs";import path from"path";import fs from"fs/promises";async function getFilePaths(directory,nesting){let filePaths=[];if(!directory)return filePaths;let files=await fs.readdir(directory,{withFileTypes:!0});for(let file of files){let filePath=path.join(directory,file.name);file.isFile()&&filePaths.push(filePath),nesting&&file.isDirectory()&&(filePaths=[...filePaths,...await getFilePaths(filePath,!0)])}return filePaths}__name(getFilePaths,"getFilePaths");async function getFolderPaths(directory,nesting){let folderPaths=[];if(!directory)return folderPaths;let folders=await fs.readdir(directory,{withFileTypes:!0});for(let folder of folders){let folderPath=path.join(directory,folder.name);folder.isDirectory()&&(folderPaths.push(folderPath),nesting&&(folderPaths=[...folderPaths,...await getFolderPaths(folderPath,!0)]))}return folderPaths}__name(getFolderPaths,"getFolderPaths");export{getFilePaths,getFolderPaths};
|
|
2
|
+
//# sourceMappingURL=chunk-6BSP7AD3.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{toFileURL}from"./chunk-4CG7S6RY.mjs";import{clone}from"./chunk-MNPCM4QU.mjs";import{colors_default}from"./chunk-C6WU57FQ.mjs";import{getFilePaths,getFolderPaths}from"./chunk-6BSP7AD3.mjs";import{__name,__require}from"./chunk-6TIBWNPX.mjs";var EventHandler=class{static{__name(this,"EventHandler")}#data;constructor({...options}){this.#data={...options,events:[]}}async init(){await this.#buildEvents(),this.#registerEvents()}async#buildEvents(){let eventFolderPaths=await getFolderPaths(this.#data.eventsPath);for(let eventFolderPath of eventFolderPaths){let eventName=eventFolderPath.replace(/\\\\|\\/g,"/").split("/").pop(),allowedExtensions=/\.(js|mjs|cjs|ts)$/i,eventFilePaths=(await getFilePaths(eventFolderPath,!0)).filter(path=>allowedExtensions.test(path)),eventObj={name:eventName,functions:[]};this.#data.events.push(eventObj);for(let eventFilePath of eventFilePaths){let importedFunction=(await import(`${toFileURL(eventFilePath)}?t=${Date.now()}`)).default,eventFunction=clone(importedFunction);typeof module<"u"&&typeof __require<"u"&&delete __require.cache[__require.resolve(eventFilePath)],eventFunction?.default&&(eventFunction=eventFunction.default);let compactFilePath=eventFilePath.split(process.cwd())[1]||eventFilePath;if(typeof eventFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Event file ${compactFilePath} does not export a function.`));continue}eventObj.functions.push(eventFunction)}}}#registerEvents(){let client=this.#data.client,handler=this.#data.commandKitInstance;for(let eventObj of this.#data.events)client.on(eventObj.name,async(...params)=>{for(let eventFunction of eventObj.functions)if(await eventFunction(...params,client,handler))break})}get events(){return this.#data.events}async reloadEvents(commandHandler){if(!this.#data.eventsPath)throw new Error(colors_default.red('Cannot reload events as "eventsPath" was not provided when instantiating CommandKit.'));this.#data.events=[],await this.#buildEvents(),this.#data.client.removeAllListeners(),this.#registerEvents(),commandHandler?.handleCommands()}};export{EventHandler};
|
|
2
|
+
//# sourceMappingURL=chunk-6IFRWFZE.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0}),__require=(x=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(x,{get:(a,b)=>(typeof require<"u"?require:a)[b]}):x)(function(x){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});export{__name,__require};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-6TIBWNPX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__name}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{__name}from"./chunk-6TIBWNPX.mjs";var globalConfig={envExtra:!0,outDir:"dist",watch:!0,clearRestartLogs:!0,minify:!1,sourcemap:!1,nodeOptions:[],antiCrash:!0,requirePolyfill:!0};function getConfig(){return globalConfig}__name(getConfig,"getConfig");var requiredProps=["src","main"];function defineConfig(config){for(let prop of requiredProps)if(!config[prop])throw new Error(`[CommandKit Config] Missing required config property: ${prop}`);return globalConfig={...globalConfig,...config},globalConfig}__name(defineConfig,"defineConfig");export{getConfig,defineConfig};
|
|
2
|
+
//# sourceMappingURL=chunk-6W2KY7FK.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__name}from"./chunk-6TIBWNPX.mjs";var resetColor="\x1B[0m",colors_default={reset:__name(text=>`${text}${resetColor}`,"reset"),bright:__name(text=>`\x1B[1m${text}${resetColor}`,"bright"),dim:__name(text=>`\x1B[2m${text}${resetColor}`,"dim"),underscore:__name(text=>`\x1B[4m${text}${resetColor}`,"underscore"),blink:__name(text=>`\x1B[5m${text}${resetColor}`,"blink"),reverse:__name(text=>`\x1B[7m${text}${resetColor}`,"reverse"),hidden:__name(text=>`\x1B[8m${text}${resetColor}`,"hidden"),black:__name(text=>`\x1B[30m${text}${resetColor}`,"black"),red:__name(text=>`\x1B[31m${text}${resetColor}`,"red"),green:__name(text=>`\x1B[32m${text}${resetColor}`,"green"),yellow:__name(text=>`\x1B[33m${text}${resetColor}`,"yellow"),blue:__name(text=>`\x1B[34m${text}${resetColor}`,"blue"),magenta:__name(text=>`\x1B[35m${text}${resetColor}`,"magenta"),cyan:__name(text=>`\x1B[36m${text}${resetColor}`,"cyan"),white:__name(text=>`\x1B[37m${text}${resetColor}`,"white"),bgBlack:__name(text=>`\x1B[40m${text}${resetColor}`,"bgBlack"),bgRed:__name(text=>`\x1B[41m${text}${resetColor}`,"bgRed"),bgGreen:__name(text=>`\x1B[42m${text}${resetColor}`,"bgGreen"),bgYellow:__name(text=>`\x1B[43m${text}${resetColor}`,"bgYellow"),bgBlue:__name(text=>`\x1B[44m${text}${resetColor}`,"bgBlue"),bgMagenta:__name(text=>`\x1B[45m${text}${resetColor}`,"bgMagenta"),bgCyan:__name(text=>`\x1B[46m${text}${resetColor}`,"bgCyan"),bgWhite:__name(text=>`\x1B[47m${text}${resetColor}`,"bgWhite")};export{colors_default};
|
|
2
|
+
//# sourceMappingURL=chunk-C6WU57FQ.mjs.map
|