commandkit 0.1.11-dev.20250128160021 → 0.1.11-dev.20250128162551

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.
Files changed (188) hide show
  1. package/bin/index.mjs +2 -50
  2. package/dist/CommandKit.js +6 -6
  3. package/dist/CommandKit.js.map +1 -1
  4. package/dist/CommandKit.mjs +1 -1
  5. package/dist/cache/CacheProvider.js +1 -1
  6. package/dist/cache/CacheProvider.js.map +1 -1
  7. package/dist/cache/CacheProvider.mjs +1 -1
  8. package/dist/cache/MemoryCache.js +1 -1
  9. package/dist/cache/MemoryCache.js.map +1 -1
  10. package/dist/cache/MemoryCache.mjs +1 -1
  11. package/dist/cache/cache.js +6 -6
  12. package/dist/cache/cache.js.map +1 -1
  13. package/dist/cache/cache.mjs +1 -1
  14. package/dist/cache/index.js +6 -6
  15. package/dist/cache/index.js.map +1 -1
  16. package/dist/cache/index.mjs +1 -1
  17. package/dist/chunk-35OSBS47.mjs +2 -0
  18. package/dist/chunk-6ZU6MOKA.mjs +2 -0
  19. package/dist/chunk-73NFQRKA.mjs +7 -0
  20. package/dist/{chunk-XJCWZEWC.mjs.map → chunk-73NFQRKA.mjs.map} +1 -1
  21. package/dist/chunk-B5T552SB.mjs +2 -0
  22. package/dist/{chunk-4OV4GE7B.mjs.map → chunk-B5T552SB.mjs.map} +1 -1
  23. package/dist/{chunk-6AX5YJEO.mjs → chunk-BNTMQC76.mjs} +2 -2
  24. package/dist/{chunk-DW5KRS5H.mjs → chunk-DTKEXOZL.mjs} +3 -3
  25. package/dist/{chunk-DW5KRS5H.mjs.map → chunk-DTKEXOZL.mjs.map} +1 -1
  26. package/dist/chunk-FC5WQLBI.mjs +3 -0
  27. package/dist/chunk-FC5WQLBI.mjs.map +1 -0
  28. package/dist/{chunk-4CG7S6RY.mjs → chunk-ICJ4BBWI.mjs} +2 -2
  29. package/dist/chunk-IRBJOQ7G.mjs +2 -0
  30. package/dist/{chunk-CO2EZ53K.mjs.map → chunk-IRBJOQ7G.mjs.map} +1 -1
  31. package/dist/chunk-JYUG7HAX.mjs +2 -0
  32. package/dist/{chunk-Z4FBPRS6.mjs.map → chunk-JYUG7HAX.mjs.map} +1 -1
  33. package/dist/chunk-KAJRRZVI.mjs +2 -0
  34. package/dist/{chunk-5KRNT4BG.mjs.map → chunk-KAJRRZVI.mjs.map} +1 -1
  35. package/dist/chunk-LQPVE73I.mjs +2 -0
  36. package/dist/{chunk-RGQOLRR6.mjs.map → chunk-LQPVE73I.mjs.map} +1 -1
  37. package/dist/{chunk-6W2KY7FK.mjs → chunk-PTP2L33V.mjs} +2 -2
  38. package/dist/{chunk-C6WU57FQ.mjs → chunk-QXMWKQIO.mjs} +2 -2
  39. package/dist/{chunk-CKNUFVNV.mjs → chunk-R4SWJR4N.mjs} +2 -2
  40. package/dist/chunk-RQ3ABUE3.mjs +2 -0
  41. package/dist/chunk-RQ3ABUE3.mjs.map +1 -0
  42. package/dist/{chunk-6BSP7AD3.mjs → chunk-RVGLG66X.mjs} +2 -2
  43. package/dist/chunk-SI3L34FF.mjs +2 -0
  44. package/dist/{chunk-UPJYI5Q6.mjs.map → chunk-SI3L34FF.mjs.map} +1 -1
  45. package/dist/chunk-TEL2J6LT.mjs +2 -0
  46. package/dist/{chunk-WNEBLBID.mjs.map → chunk-TEL2J6LT.mjs.map} +1 -1
  47. package/dist/chunk-ULPF2QCW.mjs +2 -0
  48. package/dist/chunk-ULPF2QCW.mjs.map +1 -0
  49. package/dist/{chunk-J7CCGFUZ.mjs → chunk-UP6ACDGE.mjs} +2 -2
  50. package/dist/{chunk-J7CCGFUZ.mjs.map → chunk-UP6ACDGE.mjs.map} +1 -1
  51. package/dist/chunk-UYDZJJZT.mjs +4 -0
  52. package/dist/{chunk-K43A7OIY.mjs.map → chunk-UYDZJJZT.mjs.map} +1 -1
  53. package/dist/chunk-WZU7OSUV.mjs +13 -0
  54. package/dist/chunk-WZU7OSUV.mjs.map +1 -0
  55. package/dist/chunk-Y522NY4J.mjs +2 -0
  56. package/dist/chunk-Y522NY4J.mjs.map +1 -0
  57. package/dist/chunk-ZCUZ5ENB.mjs +2 -0
  58. package/dist/chunk-ZCUZ5ENB.mjs.map +1 -0
  59. package/dist/cli/build.d.mts +4 -0
  60. package/dist/cli/build.d.ts +4 -0
  61. package/dist/cli/build.js +14 -0
  62. package/dist/cli/build.js.map +1 -0
  63. package/dist/cli/build.mjs +2 -0
  64. package/dist/cli/build.mjs.map +1 -0
  65. package/dist/cli/common.d.mts +35 -0
  66. package/dist/cli/common.d.ts +35 -0
  67. package/dist/cli/common.js +3 -0
  68. package/dist/cli/common.js.map +1 -0
  69. package/dist/cli/common.mjs +2 -0
  70. package/dist/cli/common.mjs.map +1 -0
  71. package/dist/cli/development.d.mts +3 -0
  72. package/dist/cli/development.d.ts +3 -0
  73. package/dist/cli/development.js +17 -0
  74. package/dist/cli/development.js.map +1 -0
  75. package/dist/cli/development.mjs +7 -0
  76. package/dist/cli/development.mjs.map +1 -0
  77. package/dist/cli/esbuild-plugins/plugin.d.mts +10 -0
  78. package/dist/cli/esbuild-plugins/plugin.d.ts +10 -0
  79. package/dist/cli/esbuild-plugins/plugin.js +2 -0
  80. package/dist/cli/esbuild-plugins/plugin.js.map +1 -0
  81. package/dist/cli/esbuild-plugins/plugin.mjs +2 -0
  82. package/dist/cli/esbuild-plugins/plugin.mjs.map +1 -0
  83. package/dist/cli/esbuild-plugins/use-cache.d.mts +6 -0
  84. package/dist/cli/esbuild-plugins/use-cache.d.ts +6 -0
  85. package/dist/cli/esbuild-plugins/use-cache.js +2 -0
  86. package/dist/cli/esbuild-plugins/use-cache.js.map +1 -0
  87. package/dist/cli/esbuild-plugins/use-cache.mjs +2 -0
  88. package/dist/cli/esbuild-plugins/use-cache.mjs.map +1 -0
  89. package/dist/cli/init.d.mts +10 -0
  90. package/dist/cli/init.d.ts +10 -0
  91. package/dist/cli/init.js +20 -0
  92. package/dist/cli/init.js.map +1 -0
  93. package/dist/cli/init.mjs +2 -0
  94. package/dist/cli/init.mjs.map +1 -0
  95. package/dist/cli/parse-env.d.mts +3 -0
  96. package/dist/cli/parse-env.d.ts +3 -0
  97. package/dist/cli/parse-env.js +2 -0
  98. package/dist/cli/parse-env.js.map +1 -0
  99. package/dist/cli/parse-env.mjs +2 -0
  100. package/dist/cli/parse-env.mjs.map +1 -0
  101. package/dist/cli/production.d.mts +3 -0
  102. package/dist/cli/production.d.ts +3 -0
  103. package/dist/cli/production.js +4 -0
  104. package/dist/cli/production.js.map +1 -0
  105. package/dist/cli/production.mjs +3 -0
  106. package/dist/cli/production.mjs.map +1 -0
  107. package/dist/components/ButtonKit.js +1 -1
  108. package/dist/components/ButtonKit.js.map +1 -1
  109. package/dist/components/ButtonKit.mjs +1 -1
  110. package/dist/components/index.js +1 -1
  111. package/dist/components/index.js.map +1 -1
  112. package/dist/components/index.mjs +1 -1
  113. package/dist/config.mjs +1 -1
  114. package/dist/context/async-context.js +6 -6
  115. package/dist/context/async-context.js.map +1 -1
  116. package/dist/context/async-context.mjs +1 -1
  117. package/dist/context/environment.js +1 -1
  118. package/dist/context/environment.js.map +1 -1
  119. package/dist/context/environment.mjs +1 -1
  120. package/dist/handlers/command-handler/CommandHandler.js +6 -6
  121. package/dist/handlers/command-handler/CommandHandler.js.map +1 -1
  122. package/dist/handlers/command-handler/CommandHandler.mjs +1 -1
  123. package/dist/handlers/command-handler/functions/loadCommandsWithRest.js +2 -2
  124. package/dist/handlers/command-handler/functions/loadCommandsWithRest.js.map +1 -1
  125. package/dist/handlers/command-handler/functions/loadCommandsWithRest.mjs +1 -1
  126. package/dist/handlers/command-handler/functions/registerCommands.js +2 -2
  127. package/dist/handlers/command-handler/functions/registerCommands.js.map +1 -1
  128. package/dist/handlers/command-handler/functions/registerCommands.mjs +1 -1
  129. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.mjs +1 -1
  130. package/dist/handlers/command-handler/validations/devOnly.js +1 -1
  131. package/dist/handlers/command-handler/validations/devOnly.js.map +1 -1
  132. package/dist/handlers/command-handler/validations/devOnly.mjs +1 -1
  133. package/dist/handlers/command-handler/validations/index.js +1 -1
  134. package/dist/handlers/command-handler/validations/index.js.map +1 -1
  135. package/dist/handlers/command-handler/validations/index.mjs +1 -1
  136. package/dist/handlers/command-handler/validations/permissions.js +1 -1
  137. package/dist/handlers/command-handler/validations/permissions.js.map +1 -1
  138. package/dist/handlers/command-handler/validations/permissions.mjs +1 -1
  139. package/dist/handlers/event-handler/EventHandler.js +1 -1
  140. package/dist/handlers/event-handler/EventHandler.js.map +1 -1
  141. package/dist/handlers/event-handler/EventHandler.mjs +1 -1
  142. package/dist/handlers/index.js +6 -6
  143. package/dist/handlers/index.js.map +1 -1
  144. package/dist/handlers/index.mjs +1 -1
  145. package/dist/handlers/validation-handler/ValidationHandler.js +1 -1
  146. package/dist/handlers/validation-handler/ValidationHandler.js.map +1 -1
  147. package/dist/handlers/validation-handler/ValidationHandler.mjs +1 -1
  148. package/dist/index.d.mts +2 -0
  149. package/dist/index.d.ts +2 -0
  150. package/dist/index.js +24 -6
  151. package/dist/index.js.map +1 -1
  152. package/dist/index.mjs +1 -1
  153. package/dist/index.mjs.map +1 -1
  154. package/dist/types.mjs +1 -1
  155. package/dist/utils/clone.mjs +1 -1
  156. package/dist/utils/colors.mjs +1 -1
  157. package/dist/utils/constants.mjs +1 -1
  158. package/dist/utils/error-codes.mjs +1 -1
  159. package/dist/utils/get-paths.mjs +1 -1
  160. package/dist/utils/resolve-file-url.mjs +1 -1
  161. package/dist/utils/warn-unstable.mjs +1 -1
  162. package/package.json +3 -13
  163. package/bin/build.mjs +0 -129
  164. package/bin/common.mjs +0 -125
  165. package/bin/development.mjs +0 -187
  166. package/bin/esbuild-plugins/plugin.mjs +0 -74
  167. package/bin/esbuild-plugins/use-cache.mjs +0 -160
  168. package/bin/parse-env.mjs +0 -65
  169. package/bin/production.mjs +0 -86
  170. package/dist/chunk-4OV4GE7B.mjs +0 -2
  171. package/dist/chunk-5KRNT4BG.mjs +0 -2
  172. package/dist/chunk-6TIBWNPX.mjs +0 -2
  173. package/dist/chunk-6TIGKCSX.mjs +0 -2
  174. package/dist/chunk-CO2EZ53K.mjs +0 -2
  175. package/dist/chunk-K43A7OIY.mjs +0 -4
  176. package/dist/chunk-RGQOLRR6.mjs +0 -2
  177. package/dist/chunk-UPJYI5Q6.mjs +0 -2
  178. package/dist/chunk-WNEBLBID.mjs +0 -2
  179. package/dist/chunk-XJCWZEWC.mjs +0 -7
  180. package/dist/chunk-Z4FBPRS6.mjs +0 -2
  181. /package/dist/{chunk-6TIBWNPX.mjs.map → chunk-35OSBS47.mjs.map} +0 -0
  182. /package/dist/{chunk-6TIGKCSX.mjs.map → chunk-6ZU6MOKA.mjs.map} +0 -0
  183. /package/dist/{chunk-6AX5YJEO.mjs.map → chunk-BNTMQC76.mjs.map} +0 -0
  184. /package/dist/{chunk-4CG7S6RY.mjs.map → chunk-ICJ4BBWI.mjs.map} +0 -0
  185. /package/dist/{chunk-6W2KY7FK.mjs.map → chunk-PTP2L33V.mjs.map} +0 -0
  186. /package/dist/{chunk-C6WU57FQ.mjs.map → chunk-QXMWKQIO.mjs.map} +0 -0
  187. /package/dist/{chunk-CKNUFVNV.mjs.map → chunk-R4SWJR4N.mjs.map} +0 -0
  188. /package/dist/{chunk-6BSP7AD3.mjs.map → chunk-RVGLG66X.mjs.map} +0 -0
@@ -1,160 +0,0 @@
1
- import * as parser from '@babel/parser';
2
- import _traverse from '@babel/traverse';
3
- import _generate from '@babel/generator';
4
- import * as t from '@babel/types';
5
-
6
- const traverse = _traverse.default || _traverse;
7
- const generate = _generate.default || _generate;
8
-
9
- const IMPORT_PATH = 'commandkit';
10
- const DIRECTIVE = 'use cache';
11
- const CACHE_IDENTIFIER =
12
- 'super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai';
13
-
14
- const generateRandomString = (length = 6) => {
15
- const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
16
- return Array.from(
17
- { length },
18
- () => chars[Math.floor(Math.random() * chars.length)],
19
- ).join('');
20
- };
21
-
22
- export const cacheDirectivePlugin = async (source, args) => {
23
- const ast = parser.parse(source, {
24
- sourceType: 'module',
25
- plugins: ['typescript', 'jsx'],
26
- });
27
-
28
- let state = {
29
- needsImport: false,
30
- hasExistingImport: false,
31
- cacheIdentifierName: CACHE_IDENTIFIER,
32
- modifications: [],
33
- };
34
-
35
- // First pass: check for naming collisions and collect modifications
36
- traverse(ast, {
37
- Program: {
38
- enter(path) {
39
- const binding = path.scope.getBinding(CACHE_IDENTIFIER);
40
- if (binding) {
41
- state.cacheIdentifierName = `${CACHE_IDENTIFIER}_${generateRandomString()}`;
42
- }
43
- },
44
- },
45
-
46
- ImportDeclaration(path) {
47
- if (
48
- path.node.source.value === IMPORT_PATH &&
49
- path.node.specifiers.some(
50
- (spec) =>
51
- t.isImportSpecifier(spec) &&
52
- spec.imported.name === CACHE_IDENTIFIER,
53
- )
54
- ) {
55
- state.hasExistingImport = true;
56
- if (state.cacheIdentifierName !== CACHE_IDENTIFIER) {
57
- state.modifications.push(() => {
58
- path.node.specifiers.forEach((spec) => {
59
- if (
60
- t.isImportSpecifier(spec) &&
61
- spec.imported.name === CACHE_IDENTIFIER
62
- ) {
63
- spec.local.name = state.cacheIdentifierName;
64
- }
65
- });
66
- });
67
- }
68
- }
69
- },
70
-
71
- 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression'(path) {
72
- const body = t.isBlockStatement(path.node.body) ? path.node.body : null;
73
- const hasUseCache = body?.directives?.some(
74
- (d) => d.value.value === DIRECTIVE,
75
- );
76
-
77
- if (!hasUseCache && !t.isBlockStatement(path.node.body)) {
78
- const parentFunction = path.findParent(
79
- (p) => (p.isFunction() || p.isProgram()) && 'directives' in p.node,
80
- );
81
- if (
82
- !parentFunction?.node.directives?.some(
83
- (d) => d.value.value === DIRECTIVE,
84
- )
85
- ) {
86
- return;
87
- }
88
- }
89
-
90
- if (hasUseCache || !t.isBlockStatement(path.node.body)) {
91
- // Check if the function is async
92
- if (!path.node.async) {
93
- throw new Error(
94
- `"${DIRECTIVE}" directive may only be used in async functions at ${args.path}`,
95
- );
96
- }
97
-
98
- state.needsImport = true;
99
- const isDeclaration = t.isFunctionDeclaration(path.node);
100
- const name = isDeclaration ? path.node.id?.name : undefined;
101
-
102
- // Create a new body without the 'use cache' directive
103
- const newBody = t.isBlockStatement(path.node.body)
104
- ? t.blockStatement(
105
- path.node.body.body,
106
- path.node.body.directives.filter(
107
- (d) => d.value.value !== DIRECTIVE,
108
- ),
109
- )
110
- : path.node.body;
111
-
112
- const wrapped = t.callExpression(
113
- t.identifier(state.cacheIdentifierName),
114
- [t.arrowFunctionExpression(path.node.params, newBody, true)],
115
- );
116
-
117
- state.modifications.push(() => {
118
- if (name) {
119
- path.replaceWith(
120
- t.variableDeclaration('const', [
121
- t.variableDeclarator(t.identifier(name), wrapped),
122
- ]),
123
- );
124
- } else if (!t.isVariableDeclarator(path.parent)) {
125
- path.replaceWith(wrapped);
126
- } else {
127
- path.parent.init = wrapped;
128
- }
129
- });
130
- }
131
- },
132
- });
133
-
134
- // Apply all collected modifications
135
- if (state.modifications.length > 0) {
136
- // Add import if needed
137
- if (state.needsImport && !state.hasExistingImport) {
138
- ast.program.body.unshift(
139
- t.importDeclaration(
140
- [
141
- t.importSpecifier(
142
- t.identifier(state.cacheIdentifierName),
143
- t.identifier(CACHE_IDENTIFIER),
144
- ),
145
- ],
146
- t.stringLiteral(IMPORT_PATH),
147
- ),
148
- );
149
- }
150
-
151
- // Apply collected modifications
152
- state.modifications.forEach((modify) => modify());
153
- }
154
-
155
- const { code } = generate(ast);
156
- return {
157
- contents: code,
158
- loader: args.path.split('.').pop(),
159
- };
160
- };
package/bin/parse-env.mjs DELETED
@@ -1,65 +0,0 @@
1
- // @ts-check
2
-
3
- import { randomUUID } from 'node:crypto';
4
-
5
- const valuesMap = {
6
- true: true,
7
- false: false,
8
- null: null,
9
- undefined: undefined,
10
- __UUIDv4__: () => randomUUID(),
11
- };
12
-
13
- const VALUE_PREFIXES = {
14
- JSON: 'JSON::',
15
- DATE: 'DATE::',
16
- };
17
-
18
- function catcher(fn) {
19
- try {
20
- fn();
21
- return true;
22
- } catch {
23
- return false;
24
- }
25
- }
26
-
27
- export function parseEnv(src) {
28
- for (const key in src) {
29
- const value = src[key];
30
-
31
- if (typeof value !== 'string') continue;
32
-
33
- if (value.startsWith(VALUE_PREFIXES.JSON)) {
34
- catcher(
35
- () => (src[key] = JSON.parse(value.replace(VALUE_PREFIXES.JSON, ''))),
36
- );
37
- continue;
38
- }
39
-
40
- if (value.startsWith(VALUE_PREFIXES.DATE)) {
41
- src[key] = new Date(value.replace(VALUE_PREFIXES.DATE, ''));
42
- continue;
43
- }
44
-
45
- if (value.includes(',')) {
46
- src[key] = value.split(',').map((v) => v.trim());
47
- continue;
48
- }
49
-
50
- if (/^[0-9]+n$/.test(value)) {
51
- src[key] = BigInt(value);
52
- continue;
53
- }
54
-
55
- if (value in valuesMap) {
56
- src[key] =
57
- typeof valuesMap[value] === 'function'
58
- ? valuesMap[value]()
59
- : valuesMap[value];
60
- continue;
61
- }
62
- }
63
-
64
- return src;
65
- }
@@ -1,86 +0,0 @@
1
- // @ts-check
2
- import { config as dotenv } from 'dotenv';
3
- import { existsSync } from 'node:fs';
4
- import { join } from 'node:path';
5
- import { Colors, findCommandKitConfig, panic, write } from './common.mjs';
6
- import { parseEnv } from './parse-env.mjs';
7
- import child_process from 'node:child_process';
8
-
9
- export async function bootstrapProductionServer(config) {
10
- const {
11
- main,
12
- outDir = 'dist',
13
- envExtra = true,
14
- sourcemap,
15
- } = await findCommandKitConfig(config);
16
-
17
- if (!existsSync(join(process.cwd(), outDir, main))) {
18
- panic(
19
- 'Could not find production build, maybe run `commandkit build` first?',
20
- );
21
- }
22
-
23
- try {
24
- const processEnv = {};
25
-
26
- const env = dotenv({
27
- path: join(process.cwd(), '.env'),
28
- // @ts-expect-error
29
- processEnv,
30
- });
31
-
32
- if (envExtra) {
33
- parseEnv(processEnv);
34
- }
35
-
36
- if (env.error) {
37
- write(Colors.yellow(`[DOTENV] Warning: ${env.error.message}`));
38
- }
39
-
40
- if (env.parsed) {
41
- write(Colors.blue('[DOTENV] Loaded .env file!'));
42
- }
43
-
44
- /**
45
- * @type {child_process.ChildProcessWithoutNullStreams}
46
- */
47
- const ps = child_process.spawn(
48
- 'node',
49
- [
50
- sourcemap ? '--enable-source-maps' : '',
51
- join(process.cwd(), outDir, main),
52
- ].filter(Boolean),
53
- {
54
- env: {
55
- ...process.env,
56
- ...processEnv,
57
- NODE_ENV: 'production',
58
- // @ts-expect-error
59
- COMMANDKIT_DEV: false,
60
- // @ts-expect-error
61
- COMMANDKIT_PROD: true,
62
- },
63
- cwd: process.cwd(),
64
- },
65
- );
66
-
67
- ps.stdout.on('data', (data) => {
68
- write(data.toString());
69
- });
70
-
71
- ps.stderr.on('data', (data) => {
72
- write(Colors.red(data.toString()));
73
- });
74
-
75
- ps.on('close', (code) => {
76
- write('\n');
77
- process.exit(code ?? 0);
78
- });
79
-
80
- ps.on('error', (err) => {
81
- panic(err);
82
- });
83
- } catch (e) {
84
- panic(e);
85
- }
86
- }
@@ -1,2 +0,0 @@
1
- import{getFilePaths}from"./chunk-6BSP7AD3.mjs";import{toFileURL}from"./chunk-4CG7S6RY.mjs";import{clone}from"./chunk-MNPCM4QU.mjs";import{colors_default}from"./chunk-C6WU57FQ.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-4OV4GE7B.mjs.map
@@ -1,2 +0,0 @@
1
- import{ValidationHandler}from"./chunk-4OV4GE7B.mjs";import{loadCommandsWithRest}from"./chunk-DW5KRS5H.mjs";import{registerCommands}from"./chunk-XJCWZEWC.mjs";import{validations_default}from"./chunk-6TIGKCSX.mjs";import{CommandKitErrorCodes,isCommandKitError}from"./chunk-CKNUFVNV.mjs";import{EventHandler}from"./chunk-RGQOLRR6.mjs";import{getFilePaths}from"./chunk-6BSP7AD3.mjs";import{toFileURL}from"./chunk-4CG7S6RY.mjs";import{clone}from"./chunk-MNPCM4QU.mjs";import{colors_default}from"./chunk-C6WU57FQ.mjs";import{MemoryCache}from"./chunk-CO2EZ53K.mjs";import{CacheProvider}from"./chunk-UPJYI5Q6.mjs";import{__name,__require}from"./chunk-6TIBWNPX.mjs";import{AsyncLocalStorage}from"node:async_hooks";import EventEmitter from"node:events";import{randomUUID}from"node:crypto";var CommandKitEnvironment=class{constructor(commandkit){this.commandkit=commandkit}static{__name(this,"CommandKitEnvironment")}#data={executionError:null,type:null,variables:new Map,deferredFunctions:new Map,marker:"",markStart:0,markEnd:0};getExecutionError(){return this.#data.executionError}setExecutionError(error){if(this.#data.executionError)throw new Error("Execution error already set.");this.#data.executionError=error}getType(){let type=this.#data.type;if(!type)throw new Error("Environment type not set.");return type}setType(type){this.#data.type=type}get variables(){return this.#data.variables}registerDeferredFunction(fn){let id=randomUUID();return this.#data.deferredFunctions.set(id,fn),id}clearDeferredFunction(id){this.#data.deferredFunctions.delete(id)}async runDeferredFunctions(){for(let[id,fn]of this.#data.deferredFunctions)try{await fn(this)}catch(e){this.commandkit.emit("unhandledDeferredFunctionRejection",e)}finally{this.clearDeferredFunction(id)}}clearAllDeferredFunctions(){this.#data.deferredFunctions.clear()}markStart(marker){this.#data.marker=marker,this.#data.markStart=performance.now()}markEnd(){this.#data.markEnd||(this.#data.markEnd=performance.now())}getMarker(){return this.#data.marker}getExecutionTime(){return Math.abs(this.#data.markEnd-this.#data.markStart)}},CommandKitEnvironmentType=(CommandKitEnvironmentType2=>(CommandKitEnvironmentType2.CommandHandler="COMMAND_HANDLER",CommandKitEnvironmentType2))(CommandKitEnvironmentType||{});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");function cancelAfter(id){let env=getContext();if(!env)throw new Error("cancelAfter must be called inside commandkit handler.");env.clearDeferredFunction(id)}__name(cancelAfter,"cancelAfter");var CommandHandler=class{static{__name(this,"CommandHandler")}#data;constructor({...options}){this.#data={...options,builtInValidations:[],commands:[]}}async init(){await this.#buildCommands(),this.#buildBuiltInValidations();let devOnlyCommands=this.#data.commands.filter(cmd=>cmd.options?.devOnly);devOnlyCommands.length&&!this.#data.devGuildIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devGuildIds" have not been set.')),devOnlyCommands.length&&!this.#data.devUserIds.length&&!this.#data.devRoleIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devUserIds" or "devRoleIds" have not been set.')),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}),this.handleCommands()}async#buildCommands(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,commandFilePaths=(await getFilePaths(this.#data.commandsPath,!0)).filter(path=>allowedExtensions.test(path));for(let commandFilePath of commandFilePaths){let importedObj=await import(`${toFileURL(commandFilePath)}?t=${Date.now()}`),commandObj=clone(importedObj);typeof module<"u"&&typeof __require<"u"&&delete __require.cache[__require.resolve(commandFilePath)];let compactFilePath=commandFilePath.split(process.cwd())[1]||commandFilePath;if(commandObj.default&&(commandObj=commandObj.default),importedObj.default?commandObj.data=importedObj.default.data:commandObj.data=importedObj.data,!commandObj.data){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data".`));continue}if(!commandObj.data.name){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data.name".`));continue}if(!commandObj.run){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run".`));continue}if(typeof commandObj.run!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run" as a function.`));continue}commandObj.filePath=commandFilePath;let commandCategory=commandFilePath.split(this.#data.commandsPath)[1]?.replace(/\\\\|\\/g,"/").split("/")[1]||null;commandCategory&&allowedExtensions.test(commandCategory)?commandObj.category=null:commandObj.category=commandCategory,this.#data.commands.push(commandObj)}}#buildBuiltInValidations(){for(let builtInValidationFunction of validations_default)this.#data.builtInValidations.push(builtInValidationFunction)}async#commandFinalizer(){let env=useEnvironment();await env.runDeferredFunctions(),env.clearAllDeferredFunctions()}async#interactionHandler(interaction){if(!interaction.isChatInputCommand()&&!interaction.isContextMenuCommand()&&!interaction.isAutocomplete())return;let isAutocomplete=interaction.isAutocomplete(),targetCommand=this.#data.commands.find(cmd=>cmd.data.name===interaction.commandName);if(!targetCommand)return;let env=useEnvironment();env.variables.set("interaction",interaction);let{data,options,run,autocomplete,...rest}=targetCommand;return isAutocomplete&&!autocomplete?void 0:__name(async()=>{let commandObj={data:targetCommand.data,options:targetCommand.options,...rest};if(this.#data.validationHandler){let canRun2=!0;for(let validationFunction of this.#data.validationHandler.validations)if(await validationFunction({interaction,commandObj,client:this.#data.client,handler:this.#data.commandkitInstance})){canRun2=!1;break}if(!canRun2)return}let canRun=!0;if(!this.#data.skipBuiltInValidations){for(let validation of this.#data.builtInValidations)if(validation({targetCommand,interaction,handlerData:this.#data})){canRun=!1;break}}if(!canRun)return;let command=targetCommand[isAutocomplete?"autocomplete":"run"],context2={interaction,client:this.#data.client,handler:this.#data.commandkitInstance};if(!this.#data.commandkitInstance.isDebuggingCommands())return command(context2);after(env2=>{let error=env2.getExecutionError(),marker=env2.getMarker(),time=`${env2.getExecutionTime().toFixed(2)}ms`;if(error){console.error(colors_default.red(`[${marker} - ${time}] Error executing command: ${error}`));return}console.log(colors_default.green(`[${marker} - ${time}] Command executed successfully`))});try{return env.markStart(interaction.commandName),await command(context2)}finally{env.markEnd()}},"executor")()}handleCommands(){this.#data.client.on("interactionCreate",interaction=>{let env=new CommandKitEnvironment(this.#data.commandkitInstance);return env.setType("COMMAND_HANDLER"),makeContextAwareFunction(env,this.#interactionHandler.bind(this),this.#commandFinalizer.bind(this))(interaction)})}get commands(){return this.#data.commands}async reloadCommands(type){if(!this.#data.commandsPath)throw new Error(colors_default.red('Cannot reload commands as "commandsPath" was not provided when instantiating CommandKit.'));this.#data.commands=[],await this.#buildCommands(),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type})}};var CommandKit=class _CommandKit extends EventEmitter{static{__name(this,"CommandKit")}#data;static instance=void 0;constructor(options){if(_CommandKit.instance&&process.emitWarning("CommandKit instance already exists. Having multiple instance in same project is discouraged and it may lead to unexpected behavior.",{code:"MultiInstanceWarning"}),!options.client)throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));if(options.validationsPath&&!options.commandsPath)throw new Error(colors_default.red('"commandsPath" is required when "validationsPath" is set.'));super(),options.debugCommands??=process.env.NODE_ENV!=="production",options.cacheProvider!==null&&(!options.cacheProvider||!(options.cacheProvider instanceof CacheProvider))&&(options.cacheProvider=new MemoryCache),this.#data=options,this.#init().then(()=>{this.incrementClientListenersCount()}),_CommandKit.instance||(_CommandKit.instance=this)}getCacheProvider(){return this.#data.cacheProvider??null}isDebuggingCommands(){return this.#data.debugCommands||!1}get client(){return this.#data.client}get commandHandler(){return this.#data.commandHandler}async#init(){if(this.#data.eventsPath){let eventHandler=new EventHandler({client:this.#data.client,eventsPath:this.#data.eventsPath,commandKitInstance:this});await eventHandler.init(),this.#data.eventHandler=eventHandler}if(this.#data.validationsPath){let validationHandler=new ValidationHandler({validationsPath:this.#data.validationsPath});await validationHandler.init(),this.#data.validationHandler=validationHandler}if(this.#data.commandsPath){let commandHandler=new CommandHandler({client:this.#data.client,commandsPath:this.#data.commandsPath,devGuildIds:this.#data.devGuildIds||[],devUserIds:this.#data.devUserIds||[],devRoleIds:this.#data.devRoleIds||[],validationHandler:this.#data.validationHandler,skipBuiltInValidations:this.#data.skipBuiltInValidations||!1,commandkitInstance:this,bulkRegister:this.#data.bulkRegister||!1});await commandHandler.init(),this.#data.commandHandler=commandHandler}}async reloadCommands(type){this.#data.commandHandler&&await this.#data.commandHandler.reloadCommands(type)}async reloadEvents(){this.#data.eventHandler&&await this.#data.eventHandler.reloadEvents(this.#data.commandHandler)}async reloadValidations(){this.#data.validationHandler&&await this.#data.validationHandler.reloadValidations()}get commands(){return this.#data.commandHandler?this.#data.commandHandler.commands.map(cmd=>{let{run,autocomplete,...command}=cmd;return command}):[]}get commandsPath(){return this.#data.commandsPath}get eventsPath(){return this.#data.eventsPath}get validationsPath(){return this.#data.validationsPath}get devUserIds(){return this.#data.devUserIds||[]}get devGuildIds(){return this.#data.devGuildIds||[]}get devRoleIds(){return this.#data.devRoleIds||[]}incrementClientListenersCount(){this.#data.client.setMaxListeners(this.#data.client.getMaxListeners()+1)}decrementClientListenersCount(){this.#data.client.setMaxListeners(this.#data.client.getMaxListeners()-1)}};var context=new AsyncLocalStorage;function makeContextAwareFunction(env,fn,finalizer){return __name((...args)=>context.run(env,async()=>{try{return await fn(...args)}catch(e){if(isCommandKitError(e)){let code=Reflect.get(e,"code"),interaction=env.variables.get("interaction");if(!interaction)return;switch(code){case CommandKitErrorCodes.GuildOnlyException:{interaction.isRepliable()&&await interaction.reply({content:"This command is only available in guilds.",ephemeral:!0});return}case CommandKitErrorCodes.DMOnlyException:{interaction.isRepliable()&&await interaction.reply({content:"This command is only available in DMs.",ephemeral:!0});return}}return}env.setExecutionError(e)}finally{if(typeof finalizer=="function")try{await finalizer(...args)}catch{}}}),"_fn")}__name(makeContextAwareFunction,"makeContextAwareFunction");function getCommandKit(strict=!1){let kit=context.getStore()?.commandkit??CommandKit.instance;if(!kit&&strict)throw new Error("CommandKit instance not found.");return kit}__name(getCommandKit,"getCommandKit");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");function guildOnly(){let interaction=useEnvironment().variables.get("interaction");if(!interaction)throw new Error("No interaction found in environment.");if(!interaction.guild){let error=new Error("This command is only available in guilds.");throw Reflect.set(error,"code",CommandKitErrorCodes.GuildOnlyException),error}}__name(guildOnly,"guildOnly");function dmOnly(){let interaction=useEnvironment().variables.get("interaction");if(!interaction)throw new Error("No interaction found in environment.");if(interaction.guild){let error=new Error("This command is only available in DMs.");throw Reflect.set(error,"code",CommandKitErrorCodes.DMOnlyException),error}}__name(dmOnly,"dmOnly");export{makeContextAwareFunction,getCommandKit,getContext,useEnvironment,guildOnly,dmOnly,CommandKitEnvironment,CommandKitEnvironmentType,after,cancelAfter,CommandHandler,CommandKit};
2
- //# sourceMappingURL=chunk-5KRNT4BG.mjs.map
@@ -1,2 +0,0 @@
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-6TIBWNPX.mjs.map
@@ -1,2 +0,0 @@
1
- import{devOnly_default}from"./chunk-Z4FBPRS6.mjs";import{permissions_default}from"./chunk-K43A7OIY.mjs";var validations_default=[devOnly_default,permissions_default];export{validations_default};
2
- //# sourceMappingURL=chunk-6TIGKCSX.mjs.map
@@ -1,2 +0,0 @@
1
- import{CacheProvider}from"./chunk-UPJYI5Q6.mjs";import{__name}from"./chunk-6TIBWNPX.mjs";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}}async set(key,value,ttl){let entry={value,ttl:ttl!=null?Date.now()+ttl:void 0};this.#cache.set(key,entry)}async exists(key){return this.#cache.has(key)}async delete(key){this.#cache.delete(key)}async clear(){this.#cache.clear()}async expire(key,ttl){let entry=this.#cache.get(key);if(!entry)return;let _ttl=Date.now()+ttl;if(_ttl<Date.now()){this.#cache.delete(key);return}entry.ttl=_ttl}};export{MemoryCache};
2
- //# sourceMappingURL=chunk-CO2EZ53K.mjs.map
@@ -1,4 +0,0 @@
1
- import{__name}from"./chunk-6TIBWNPX.mjs";import{EmbedBuilder}from"discord.js";function permissions_default({interaction,targetCommand}){if(interaction.isAutocomplete())return;let userPermissions=interaction.memberPermissions,userPermissionsRequired=targetCommand.options?.userPermissions,missingUserPermissions=[];typeof userPermissionsRequired=="string"&&(userPermissionsRequired=[userPermissionsRequired]);let botPermissions=interaction.guild?.members.me?.permissions,botPermissionsRequired=targetCommand.options?.botPermissions,missingBotPermissions=[];if(typeof botPermissionsRequired=="string"&&(botPermissionsRequired=[botPermissionsRequired]),!userPermissionsRequired?.length&&!botPermissionsRequired?.length)return;if(userPermissions&&userPermissionsRequired)for(let permission of userPermissionsRequired)userPermissions.has(permission)||missingUserPermissions.push(permission);if(botPermissions&&botPermissionsRequired)for(let permission of botPermissionsRequired)botPermissions.has(permission)||missingBotPermissions.push(permission);if(!missingUserPermissions.length&&!missingBotPermissions.length)return;let pattern=/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g;missingUserPermissions=missingUserPermissions.map(str=>str.replace(pattern,"$1$3 $2$4")),missingBotPermissions=missingBotPermissions.map(str=>str.replace(pattern,"$1$3 $2$4"));let embedDescription="",formatter=new Intl.ListFormat("en",{style:"long",type:"conjunction"}),getPermissionWord=__name(permissions=>permissions.length===1?"permission":"permissions","getPermissionWord");if(missingUserPermissions.length){let formattedPermissions=missingUserPermissions.map(p=>`\`${p}\``),permissionsString=formatter.format(formattedPermissions);embedDescription+=`- You must have the ${permissionsString} ${getPermissionWord(missingUserPermissions)} to be able to run this command.
2
- `}if(missingBotPermissions.length){let formattedPermissions=missingBotPermissions.map(p=>`\`${p}\``),permissionsString=formatter.format(formattedPermissions);embedDescription+=`- I must have the ${permissionsString} ${getPermissionWord(missingBotPermissions)} to be able to execute this command.
3
- `}let embed=new EmbedBuilder().setTitle(":x: Missing permissions!").setDescription(embedDescription).setColor("Red");return interaction.reply({embeds:[embed],ephemeral:!0}),!0}__name(permissions_default,"default");export{permissions_default};
4
- //# sourceMappingURL=chunk-K43A7OIY.mjs.map
@@ -1,2 +0,0 @@
1
- import{getFilePaths,getFolderPaths}from"./chunk-6BSP7AD3.mjs";import{toFileURL}from"./chunk-4CG7S6RY.mjs";import{clone}from"./chunk-MNPCM4QU.mjs";import{colors_default}from"./chunk-C6WU57FQ.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-RGQOLRR6.mjs.map
@@ -1,2 +0,0 @@
1
- import{__name}from"./chunk-6TIBWNPX.mjs";var CacheProvider=class{static{__name(this,"CacheProvider")}};export{CacheProvider};
2
- //# sourceMappingURL=chunk-UPJYI5Q6.mjs.map
@@ -1,2 +0,0 @@
1
- import{__name}from"./chunk-6TIBWNPX.mjs";import{ButtonStyle,ButtonBuilder,ComponentType}from"discord.js";var ButtonKit=class extends ButtonBuilder{static{__name(this,"ButtonKit")}#onClickHandler=null;#onEndHandler=null;#contextData=null;#collector=null;onClick(handler,data){if(this.data.style===ButtonStyle.Link)throw new TypeError('Cannot setup "onClick" handler on link buttons.');if(!handler)throw new TypeError('Cannot setup "onClick" without a handler function parameter.');return this.#destroyCollector(),this.#onClickHandler=handler,data&&(this.#contextData=data),this.#setupInteractionCollector(),this}onEnd(handler){if(!handler)throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');return this.#onEndHandler=handler,this}#setupInteractionCollector(){if(!this.#contextData||!this.#onClickHandler)return;let message=this.#contextData.message;if(!message)throw new TypeError('Cannot setup "onClick" handler without a message in the context data.');if("customId"in this.data&&!this.data.customId)throw new TypeError('Cannot setup "onClick" handler on a button without a custom id.');let data={time:864e5,autoReset:!0,...this.#contextData},collector=this.#collector=message.createMessageComponentCollector({filter:__name(interaction=>interaction.customId===this.data.custom_id&&interaction.message.id===message.id,"filter"),componentType:ComponentType.Button,...data});this.#collector.on("collect",interaction=>{let handler=this.#onClickHandler;return handler?this.#collector?(data.autoReset&&this.#collector.resetTimer(),handler(interaction)):collector.stop("destroyed"):this.#destroyCollector()}),this.#collector.on("end",(_,reason)=>{this.#destroyCollector(),this.#onEndHandler?.(reason)})}dispose(){return this.#destroyCollector(),this.#onEndHandler?.("disposed"),this}#destroyCollector(){this.#collector?.stop("end"),this.#collector?.removeAllListeners(),this.#collector=null,this.#contextData=null,this.#onClickHandler=null}};export{ButtonKit};
2
- //# sourceMappingURL=chunk-WNEBLBID.mjs.map
@@ -1,7 +0,0 @@
1
- import{areSlashCommandsDifferent}from"./chunk-6AX5YJEO.mjs";import{colors_default}from"./chunk-C6WU57FQ.mjs";import{__name}from"./chunk-6TIBWNPX.mjs";async function registerCommands(props){if(props.reloading)if(props.client.isReady())await handleRegistration(props.client,props.commands,props.devGuildIds,props.type);else throw new Error(colors_default.red("Cannot reload commands when client is not ready."));else props.client.once("ready",async c=>{await handleRegistration(c,props.commands,props.devGuildIds,props.type)})}__name(registerCommands,"registerCommands");async function handleRegistration(client,commands,devGuildIds,type){let devOnlyCommands=commands.filter(cmd=>cmd.options?.devOnly),globalCommands=commands.filter(cmd=>!cmd.options?.devOnly);type==="dev"?await registerDevCommands(client,devOnlyCommands,devGuildIds):type==="global"?await registerGlobalCommands(client,globalCommands):(await registerDevCommands(client,devOnlyCommands,devGuildIds),await registerGlobalCommands(client,globalCommands))}__name(handleRegistration,"handleRegistration");async function registerGlobalCommands(client,commands){let appCommandsManager=client.application.commands;await appCommandsManager.fetch();for(let command of commands){let targetCommand=appCommandsManager.cache.find(cmd=>cmd.name===command.data.name);if(command.options?.deleted){targetCommand?(await targetCommand.delete().catch(error=>{throw new Error(colors_default.red(`Failed to delete command "${command.data.name}" globally.
2
- `),error)}),console.log(colors_default.green(`Deleted command "${command.data.name}" globally.`))):process.emitWarning(colors_default.yellow(`Ignoring: Command "${command.data.name}" is globally marked as deleted.`));continue}if(targetCommand&&areSlashCommandsDifferent(targetCommand,command.data)){await targetCommand.edit(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to edit command "${command.data.name}" globally.
3
- `),error)}),console.log(colors_default.green(`Edited command "${command.data.name}" globally.`));continue}targetCommand||(await appCommandsManager.create(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to register command "${command.data.name}" globally.
4
- `),error)}),console.log(colors_default.green(`Registered command "${command.data.name}" globally.`)))}}__name(registerGlobalCommands,"registerGlobalCommands");async function registerDevCommands(client,commands,guildIds){let devGuilds=[];for(let guildId of guildIds){let guild=client.guilds.cache.get(guildId)||await client.guilds.fetch(guildId);if(!guild){process.emitWarning(colors_default.yellow(`Ignoring: Guild ${guildId} doesn't exist or client isn't part of the guild.`));continue}devGuilds.push(guild)}let guildCommandsManagers=[];for(let guild of devGuilds){let guildCommandsManager=guild.commands;await guildCommandsManager.fetch(),guildCommandsManagers.push(guildCommandsManager)}for(let command of commands)for(let guildCommands of guildCommandsManagers){let targetCommand=guildCommands.cache.find(cmd=>cmd.name===command.data.name);if(command.options?.deleted){targetCommand?(await targetCommand.delete().catch(error=>{throw new Error(colors_default.red(`Failed to delete command "${command.data.name}" in ${guildCommands.guild.name}.`),error)}),console.log(colors_default.green(`Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`))):process.emitWarning(colors_default.yellow(`Ignoring: Command "${command.data.name}" is marked as deleted in ${guildCommands.guild.name}.`));continue}if(targetCommand&&areSlashCommandsDifferent(targetCommand,command.data)){await targetCommand.edit(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to edit command "${command.data.name}" in ${guildCommands.guild.name}.
5
- `),error)}),console.log(colors_default.green(`Edited command "${command.data.name}" in ${guildCommands.guild.name}.`));continue}targetCommand||(await guildCommands.create(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to register command "${command.data.name}" in ${guildCommands.guild.name}.
6
- `),error)}),console.log(colors_default.green(`Registered command "${command.data.name}" in ${guildCommands.guild.name}.`)))}}__name(registerDevCommands,"registerDevCommands");export{registerCommands};
7
- //# sourceMappingURL=chunk-XJCWZEWC.mjs.map
@@ -1,2 +0,0 @@
1
- import{__name}from"./chunk-6TIBWNPX.mjs";function devOnly_default({interaction,targetCommand,handlerData}){if(!interaction.isAutocomplete()&&targetCommand.options?.devOnly){if(interaction.inGuild()&&!handlerData.devGuildIds.includes(interaction.guildId))return interaction.reply({content:"\u274C This command can only be used inside development servers.",ephemeral:!0}),!0;let memberRoles=interaction.guild?.members.cache.get(interaction.user.id)?.roles.cache,hasDevRole=!1;if(memberRoles?.forEach(role=>{handlerData.devRoleIds.includes(role.id)&&(hasDevRole=!0)}),!(handlerData.devUserIds.includes(interaction.user.id)||hasDevRole))return interaction.reply({content:"\u274C This command can only be used by developers.",ephemeral:!0}),!0}}__name(devOnly_default,"default");export{devOnly_default};
2
- //# sourceMappingURL=chunk-Z4FBPRS6.mjs.map