commandkit 1.2.0-dev.20250823124655 → 1.2.0-dev.20250826015841

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 (169) hide show
  1. package/dist/ActionRow-CmTHbo2t.js.map +1 -1
  2. package/dist/CommandKitEventsChannel-Bgw0XCOl.js.map +1 -1
  3. package/dist/CommandsRouter-tMAivEfv.js.map +1 -1
  4. package/dist/CompilerPlugin-CjoZAAR8.js.map +1 -1
  5. package/dist/{DefaultLogger-Cy55-uPl.d.ts → DefaultLogger-XCOl5nLd.d.ts} +19 -12
  6. package/dist/EventInterceptor-CQ4PBpBJ.js.map +1 -1
  7. package/dist/{EventWorkerContext-DiMpRt1P.d.ts → EventWorkerContext-BEezHh5-.d.ts} +2 -2
  8. package/dist/{EventWorkerContext-CSlD9rbx.js → EventWorkerContext-TZIKxVCu.js} +1 -1
  9. package/dist/{EventWorkerContext-CSlD9rbx.js.map → EventWorkerContext-TZIKxVCu.js.map} +1 -1
  10. package/dist/EventsRouter-C_J0M3uO.js.map +1 -1
  11. package/dist/ILogger-BW8GM-YZ.d.ts +64 -0
  12. package/dist/{Logger-iSjA-DWN.d.ts → Logger-DyfkPk7u.d.ts} +2 -2
  13. package/dist/{MessageCommandParser-B_BEQ3p8.js → MessageCommandParser-TPEPhjvx.js} +2 -2
  14. package/dist/{MessageCommandParser-B_BEQ3p8.js.map → MessageCommandParser-TPEPhjvx.js.map} +1 -1
  15. package/dist/PluginCommon-Di1xIa8d.js.map +1 -1
  16. package/dist/RuntimePlugin-CBgBLXTG.js.map +1 -1
  17. package/dist/analytics/analytics-engine.d.ts +2 -2
  18. package/dist/analytics/analytics-engine.js +6 -6
  19. package/dist/analytics/analytics-provider.d.ts +2 -2
  20. package/dist/analytics/constants.js +1 -1
  21. package/dist/analytics/utils.js +6 -6
  22. package/dist/{analytics-engine-Ddw9axi4.d.ts → analytics-engine-Iu_1uJop.d.ts} +2 -17
  23. package/dist/app/commands/AppCommandRunner.d.ts +2 -2
  24. package/dist/app/commands/AppCommandRunner.js +6 -6
  25. package/dist/app/commands/Context.d.ts +2 -2
  26. package/dist/app/commands/Context.js +6 -6
  27. package/dist/app/commands/MessageCommandParser.js +2 -2
  28. package/dist/app/events/EventWorkerContext.d.ts +3 -3
  29. package/dist/app/events/EventWorkerContext.js +1 -1
  30. package/dist/app/handlers/AppCommandHandler.d.ts +2 -2
  31. package/dist/app/handlers/AppCommandHandler.js +6 -6
  32. package/dist/app/handlers/AppEventsHandler.d.ts +2 -2
  33. package/dist/app/handlers/AppEventsHandler.js +6 -6
  34. package/dist/app/index.d.ts +3 -3
  35. package/dist/app/index.js +8 -8
  36. package/dist/app/interrupt/signals.d.ts +2 -2
  37. package/dist/app/interrupt/signals.js +5 -5
  38. package/dist/app/middlewares/permissions.d.ts +2 -2
  39. package/dist/app/middlewares/permissions.js +6 -6
  40. package/dist/app/register/CommandRegistrar.d.ts +2 -2
  41. package/dist/app/register/CommandRegistrar.js +6 -6
  42. package/dist/app-process-CjMovpoZ.js.map +1 -1
  43. package/dist/{build-BmDzPe4V.js → build-Yhb1VjD0.js} +2 -2
  44. package/dist/build-Yhb1VjD0.js.map +1 -0
  45. package/dist/cli/build.d.ts +2 -2
  46. package/dist/cli/build.js +7 -7
  47. package/dist/cli/common.d.ts +2 -2
  48. package/dist/cli/development.js +8 -8
  49. package/dist/cli/development.js.map +1 -1
  50. package/dist/cli/generators.js.map +1 -1
  51. package/dist/cli/information.js +1 -1
  52. package/dist/cli/information.js.map +1 -1
  53. package/dist/cli/init.js +7 -7
  54. package/dist/cli/production.js +7 -7
  55. package/dist/cli/production.js.map +1 -1
  56. package/dist/{commandkit-C0BuNRSN.js → commandkit-c0sAaK0G.js} +169 -175
  57. package/dist/commandkit-c0sAaK0G.js.map +1 -0
  58. package/dist/commandkit.d.ts +2 -2
  59. package/dist/commandkit.js +6 -6
  60. package/dist/common-DNADUU3_.js.map +1 -1
  61. package/dist/common-vnMIelAE.js.map +1 -1
  62. package/dist/components/index.js +6 -6
  63. package/dist/components/v1/button/Button.js +6 -6
  64. package/dist/components/v1/button/ButtonKit.js +6 -6
  65. package/dist/components/v1/modal/Modal.js +6 -6
  66. package/dist/components/v1/modal/ModalKit.js +6 -6
  67. package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +6 -6
  68. package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +6 -6
  69. package/dist/components/v1/select-menu/RoleSelectMenuKit.js +6 -6
  70. package/dist/components/v1/select-menu/SelectMenu.js +6 -6
  71. package/dist/components/v1/select-menu/StringSelectMenuKit.js +6 -6
  72. package/dist/components/v1/select-menu/UserSelectMenuKit.js +6 -6
  73. package/dist/config/config.d.ts +3 -3
  74. package/dist/config/config.js +6 -6
  75. package/dist/config/default.d.ts +2 -2
  76. package/dist/config/default.js +6 -6
  77. package/dist/config/loader.d.ts +2 -2
  78. package/dist/config/loader.js +6 -6
  79. package/dist/config/types.d.ts +2 -2
  80. package/dist/config/utils.d.ts +2 -2
  81. package/dist/{config-C4nHXErw.d.ts → config-ClEaYnf1.d.ts} +2 -2
  82. package/dist/constants-4oxxvaJA.js.map +1 -1
  83. package/dist/constants-B5_Ta7PR.js.map +1 -1
  84. package/dist/{constants-CUND8XkG.js → constants-DxfYtA6t.js} +1 -1
  85. package/dist/{constants-CUND8XkG.js.map → constants-DxfYtA6t.js.map} +1 -1
  86. package/dist/container-z621KfH5.js.map +1 -1
  87. package/dist/context/async-context.d.ts +2 -2
  88. package/dist/context/async-context.js +6 -6
  89. package/dist/context/environment.d.ts +2 -2
  90. package/dist/context/environment.js +6 -6
  91. package/dist/dotprops-C_4L7RPD.js.map +1 -1
  92. package/dist/element-Bak9llw_.js.map +1 -1
  93. package/dist/env-_68PRRoA.js.map +1 -1
  94. package/dist/{error-codes-BzoEctmD.d.ts → error-codes-B4TyW4Ct.d.ts} +2 -2
  95. package/dist/{error-codes-C-ViHyu-.js → error-codes-Ds0bnPvT.js} +2 -2
  96. package/dist/error-codes-Ds0bnPvT.js.map +1 -0
  97. package/dist/events/CommandKitEventsChannel.d.ts +2 -2
  98. package/dist/{feature-flags-BZMExGfA.js → feature-flags-Dxi9TI2e.js} +5 -5
  99. package/dist/{feature-flags-BZMExGfA.js.map → feature-flags-Dxi9TI2e.js.map} +1 -1
  100. package/dist/file-DVZC0QXI.js.map +1 -1
  101. package/dist/flags/FlagProvider.d.ts +2 -2
  102. package/dist/flags/FlagProvider.js.map +1 -1
  103. package/dist/flags/feature-flags.d.ts +2 -2
  104. package/dist/flags/feature-flags.js +7 -7
  105. package/dist/flags/store.d.ts +2 -2
  106. package/dist/helpers-BUlN3lIz.js.map +1 -1
  107. package/dist/index.d.ts +9 -9
  108. package/dist/index.js +19 -14
  109. package/dist/index.js.map +1 -0
  110. package/dist/{init-D20FhDjn.js → init-CrFvqdxZ.js} +2 -2
  111. package/dist/{init-D20FhDjn.js.map → init-CrFvqdxZ.js.map} +1 -1
  112. package/dist/kv/kv.js.map +1 -1
  113. package/dist/logger/DefaultLogger.d.ts +2 -2
  114. package/dist/logger/DefaultLogger.js +6 -6
  115. package/dist/logger/ILogger.d.ts +1 -1
  116. package/dist/logger/Logger.d.ts +2 -2
  117. package/dist/logger/Logger.js +6 -6
  118. package/dist/logger/NoopLogger.d.ts +41 -11
  119. package/dist/logger/NoopLogger.js +5 -25
  120. package/dist/logger/NoopLogger.js.map +1 -1
  121. package/dist/media-gallery-CIKypjbJ.js.map +1 -1
  122. package/dist/plugins/CompilerPlugin.d.ts +2 -2
  123. package/dist/plugins/PluginCommon.d.ts +2 -2
  124. package/dist/plugins/RuntimePlugin.d.ts +2 -2
  125. package/dist/plugins/index.d.ts +2 -2
  126. package/dist/plugins/index.js +6 -6
  127. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +2 -2
  128. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +6 -6
  129. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +2 -2
  130. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +6 -6
  131. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +2 -2
  132. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +6 -6
  133. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +2 -2
  134. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +6 -6
  135. package/dist/plugins/plugin-runtime/runtime.d.ts +2 -2
  136. package/dist/plugins/types.d.ts +2 -2
  137. package/dist/resolve-file-url-DHTQj2mU.js.map +1 -1
  138. package/dist/section-CuYr0Inu.js.map +1 -1
  139. package/dist/separator-DLdWBjSN.js.map +1 -1
  140. package/dist/serde-CHySNpFr.js.map +1 -1
  141. package/dist/{signals-BQbEfy3X.d.ts → signals-SHg7J1U_.d.ts} +4 -7
  142. package/dist/{signals-DHdYrd-n.js → signals-r7qPAvOR.js} +12 -15
  143. package/dist/signals-r7qPAvOR.js.map +1 -0
  144. package/dist/store-CiqLHedg.js.map +1 -1
  145. package/dist/text-display--p2-BoUa.js.map +1 -1
  146. package/dist/type-checker-1Iu1jJcy.js.map +1 -1
  147. package/dist/types-package-DrnIdWLg.js.map +1 -1
  148. package/dist/types.d.ts +2 -2
  149. package/dist/utils/dev-hooks.d.ts +2 -2
  150. package/dist/utils/dev-hooks.js +6 -6
  151. package/dist/utils/error-codes.d.ts +1 -1
  152. package/dist/utils/error-codes.js +1 -1
  153. package/dist/utils/useful-stuff/async-queue.js.map +1 -1
  154. package/dist/utils/useful-stuff/mutex.js.map +1 -1
  155. package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
  156. package/dist/utils/useful-stuff/semaphore.js.map +1 -1
  157. package/dist/utils/utilities.js +6 -6
  158. package/dist/utils/warn-unstable.js.map +1 -1
  159. package/dist/utils-BnXM4eKk.js.map +1 -1
  160. package/dist/utils-DCSnVAZ6.js.map +1 -1
  161. package/dist/{version-vOikuVFD.js → version-Dye7khwD.js} +2 -2
  162. package/dist/{version-vOikuVFD.js.map → version-Dye7khwD.js.map} +1 -1
  163. package/dist/version.js +1 -1
  164. package/package.json +60 -59
  165. package/dist/ILogger-DBGON5wx.d.ts +0 -34
  166. package/dist/build-BmDzPe4V.js.map +0 -1
  167. package/dist/commandkit-C0BuNRSN.js.map +0 -1
  168. package/dist/error-codes-C-ViHyu-.js.map +0 -1
  169. package/dist/signals-DHdYrd-n.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('./chunk-nOFOJqeH.js');
2
2
  const require_colors = require('./colors-Cd4Oz-r-.js');
3
- const require_error_codes = require('./error-codes-C-ViHyu-.js');
3
+ const require_error_codes = require('./error-codes-Ds0bnPvT.js');
4
4
  const require_element = require('./element-Bak9llw_.js');
5
5
  const require_EventInterceptor = require('./EventInterceptor-CQ4PBpBJ.js');
6
6
  const require_constants = require('./constants-B5_Ta7PR.js');
@@ -9,10 +9,10 @@ const require_RuntimePlugin = require('./RuntimePlugin-CBgBLXTG.js');
9
9
  const require_utils = require('./utils-BnXM4eKk.js');
10
10
  const require_resolve_file_url = require('./resolve-file-url-DHTQj2mU.js');
11
11
  const require_types_package = require('./types-package-DrnIdWLg.js');
12
- const require_EventWorkerContext = require('./EventWorkerContext-CSlD9rbx.js');
13
- const require_signals = require('./signals-DHdYrd-n.js');
14
- const require_constants$1 = require('./constants-CUND8XkG.js');
15
- const require_MessageCommandParser = require('./MessageCommandParser-B_BEQ3p8.js');
12
+ const require_constants$1 = require('./constants-DxfYtA6t.js');
13
+ const require_EventWorkerContext = require('./EventWorkerContext-TZIKxVCu.js');
14
+ const require_signals = require('./signals-r7qPAvOR.js');
15
+ const require_MessageCommandParser = require('./MessageCommandParser-TPEPhjvx.js');
16
16
  const require_CommandsRouter = require('./CommandsRouter-tMAivEfv.js');
17
17
  const require_EventsRouter = require('./EventsRouter-C_J0M3uO.js');
18
18
  const require_common = require('./common-DNADUU3_.js');
@@ -24,6 +24,7 @@ const node_async_hooks = require_chunk.__toESM(require("node:async_hooks"));
24
24
  const node_fs = require_chunk.__toESM(require("node:fs"));
25
25
  const node_path = require_chunk.__toESM(require("node:path"));
26
26
  const node_crypto = require_chunk.__toESM(require("node:crypto"));
27
+ const util = require_chunk.__toESM(require("util"));
27
28
  const __rollup_plugin_json = require_chunk.__toESM(require("@rollup/plugin-json"));
28
29
 
29
30
  //#region src/context/async-context.ts
@@ -65,6 +66,7 @@ function makeContextAwareFunction(env, fn, finalizer) {
65
66
  return result;
66
67
  } catch (e) {
67
68
  if (!require_error_codes.isCommandKitError(e)) env.setExecutionError(e);
69
+ else throw e;
68
70
  } finally {
69
71
  if (typeof finalizer === "function") setImmediate(async () => {
70
72
  try {
@@ -1285,47 +1287,57 @@ var DefaultLogger = class {
1285
1287
  const label = this._getLevelLabel(level);
1286
1288
  return `${label}${require_colors.colors_default.dim(BoxChars.vertical)} ${require_colors.colors_default.dim(timestamp)}`;
1287
1289
  }
1288
- _log(level, ...args) {
1290
+ _log(level, message) {
1289
1291
  const prefix = this._getPrefix(level);
1290
1292
  const context$1 = this._getContext();
1291
1293
  const colorFn = TextColorMap[level];
1292
- if (context$1) this.logger.log(`${prefix}\n${context$1} ${require_colors.colors_default.dim(BoxChars.corner)}`, ...args.map((arg) => colorFn(arg)));
1293
- else this.logger.log(`${prefix} ${require_colors.colors_default.dim(BoxChars.corner)}`, ...args.map((arg) => colorFn(arg)));
1294
+ let processedMessage = message;
1295
+ if (message instanceof Error) processedMessage = `${message.message}\n${message.stack}`;
1296
+ if (context$1) this.logger.log(`${prefix}\n${context$1} ${require_colors.colors_default.dim(BoxChars.corner)}`, colorFn(processedMessage));
1297
+ else this.logger.log(`${prefix} ${require_colors.colors_default.dim(BoxChars.corner)}`, colorFn(processedMessage));
1294
1298
  }
1295
- /**
1296
- * Logs a debug message.
1297
- * @param args The message arguments to log.
1298
- */
1299
- debug(...args) {
1300
- this._log(LogLevel.DEBUG, ...args);
1299
+ _logTemplate(level, strings, ...values) {
1300
+ const prefix = this._getPrefix(level);
1301
+ const context$1 = this._getContext();
1302
+ const colorFn = TextColorMap[level];
1303
+ let result = "";
1304
+ for (let i = 0; i < strings.length; i++) {
1305
+ result += strings[i];
1306
+ if (i < values.length) {
1307
+ const value = values[i];
1308
+ if (value instanceof Error) result += `${value.message}\n${value.stack}`;
1309
+ else if (value !== null && typeof value === "object") result += (0, util.inspect)(value, {
1310
+ colors: true,
1311
+ depth: 2
1312
+ });
1313
+ else result += value;
1314
+ }
1315
+ }
1316
+ if (context$1) this.logger.log(`${prefix}\n${context$1} ${require_colors.colors_default.dim(BoxChars.corner)}`, colorFn(result));
1317
+ else this.logger.log(`${prefix} ${require_colors.colors_default.dim(BoxChars.corner)}`, colorFn(result));
1301
1318
  }
1302
- /**
1303
- * Logs an error message.
1304
- * @param args The message arguments to log.
1305
- */
1306
- error(...args) {
1307
- this._log(LogLevel.ERROR, ...args);
1319
+ debug(messageOrStrings, ...values) {
1320
+ if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(LogLevel.DEBUG, messageOrStrings, ...values);
1321
+ else this._log(LogLevel.DEBUG, messageOrStrings);
1308
1322
  }
1309
- /**
1310
- * Logs a default message.
1311
- * @param args The message arguments to log.
1312
- */
1313
- log(...args) {
1314
- this._log(LogLevel.DEFAULT, ...args);
1323
+ error(messageOrStrings, ...values) {
1324
+ if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(LogLevel.ERROR, messageOrStrings, ...values);
1325
+ else this._log(LogLevel.ERROR, messageOrStrings);
1315
1326
  }
1316
- /**
1317
- * Logs an info message.
1318
- * @param args The message arguments to log.
1319
- */
1320
- info(...args) {
1321
- this._log(LogLevel.INFO, ...args);
1327
+ log(messageOrStrings, ...values) {
1328
+ if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(LogLevel.DEFAULT, messageOrStrings, ...values);
1329
+ else this._log(LogLevel.DEFAULT, messageOrStrings);
1322
1330
  }
1323
- /**
1324
- * Logs a warning message.
1325
- * @param args The message arguments to log.
1326
- */
1327
- warn(...args) {
1328
- this._log(LogLevel.WARN, ...args);
1331
+ info(messageOrStrings, ...values) {
1332
+ if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(LogLevel.INFO, messageOrStrings, ...values);
1333
+ else this._log(LogLevel.INFO, messageOrStrings);
1334
+ }
1335
+ warn(messageOrStrings, ...values) {
1336
+ if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(LogLevel.WARN, messageOrStrings, ...values);
1337
+ else this._log(LogLevel.WARN, messageOrStrings);
1338
+ }
1339
+ _isTemplateStringsArray(value) {
1340
+ return Array.isArray(value) && "raw" in value && Array.isArray(value.raw);
1329
1341
  }
1330
1342
  };
1331
1343
 
@@ -1349,8 +1361,8 @@ function createLogger(options) {
1349
1361
  const impl = { configure(options$1) {
1350
1362
  opt = options$1;
1351
1363
  } };
1352
- for (const method of methods) impl[method] = (...args) => {
1353
- opt.provider[method](...args);
1364
+ for (const method of methods) impl[method] = (...message) => {
1365
+ opt.provider[method](...message);
1354
1366
  };
1355
1367
  return impl;
1356
1368
  }
@@ -1464,7 +1476,7 @@ var CommandKitPluginRuntime = class {
1464
1476
  result = await f(this, plugin);
1465
1477
  } catch (e) {
1466
1478
  if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.PluginCaptureHandle)) return true;
1467
- Logger.error(`Plugin "${plugin.name}" failed`, (e === null || e === void 0 ? void 0 : e.stack) || e);
1479
+ Logger.error`Plugin "${plugin.name}" failed: ${(e === null || e === void 0 ? void 0 : e.stack) || e}`;
1468
1480
  }
1469
1481
  return result;
1470
1482
  }
@@ -1602,7 +1614,7 @@ var CompilerPluginRuntime = class {
1602
1614
  await ((_plugin$activate = plugin.activate) === null || _plugin$activate === void 0 ? void 0 : _plugin$activate.call(plugin, this));
1603
1615
  });
1604
1616
  } catch (e) {
1605
- console.error(`Plugin ${plugin.name} failed to activate with ${(e === null || e === void 0 ? void 0 : e.stack) || e}`);
1617
+ Logger.error`Plugin ${plugin.name} failed to activate with ${e}`;
1606
1618
  }
1607
1619
  this.initialized = true;
1608
1620
  }
@@ -1621,7 +1633,7 @@ var CompilerPluginRuntime = class {
1621
1633
  await ((_plugin$deactivate = plugin.deactivate) === null || _plugin$deactivate === void 0 ? void 0 : _plugin$deactivate.call(plugin, this));
1622
1634
  });
1623
1635
  } catch (e) {
1624
- console.error(`Plugin ${plugin.name} failed to deactivate with ${(e === null || e === void 0 ? void 0 : e.stack) || e}`);
1636
+ Logger.error`Plugin ${plugin.name} failed to deactivate with ${e}`;
1625
1637
  }
1626
1638
  this.initialized = false;
1627
1639
  }
@@ -2417,37 +2429,11 @@ var Context = class Context {
2417
2429
  if (this.isMessage()) return this.config.messageCommandParser.getArgs();
2418
2430
  return [];
2419
2431
  }
2420
- /**
2421
- * Stops upcoming middleware or current command execution.
2422
- * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
2423
- * If this is called inside a command itself, it will skip all post-stage middlewares.
2424
- * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
2425
- */
2426
- exit() {
2427
- require_signals.exitMiddleware();
2428
- }
2429
2432
  };
2430
2433
  /**
2431
2434
  * Extended context class for middleware execution with additional control methods.
2432
2435
  */
2433
2436
  var MiddlewareContext = class extends Context {
2434
- /**
2435
- * @private
2436
- * @internal
2437
- */
2438
- #cancel = false;
2439
- /**
2440
- * Whether the command execution was cancelled.
2441
- */
2442
- get cancelled() {
2443
- return this.#cancel;
2444
- }
2445
- /**
2446
- * Cancels the command execution.
2447
- */
2448
- cancel() {
2449
- this.#cancel = true;
2450
- }
2451
2437
  /**
2452
2438
  * Sets command runner function to wrap the command execution.
2453
2439
  * @param fn The function to set.
@@ -2482,6 +2468,7 @@ var AppCommandRunner = class {
2482
2468
  * Handles the complete command lifecycle including before/after middleware execution.
2483
2469
  * @param prepared - The prepared command execution data
2484
2470
  * @param source - The source interaction or message that triggered the command
2471
+ * @param options - The options for running the command
2485
2472
  */
2486
2473
  async runCommand(prepared, source, options) {
2487
2474
  const { commandkit: commandkit$1 } = this.handler;
@@ -2494,119 +2481,126 @@ var AppCommandRunner = class {
2494
2481
  env.variables.set("currentCommandName", prepared.command.command.name);
2495
2482
  env.variables.set("execHandlerKind", executionMode);
2496
2483
  env.variables.set("customHandler", (options === null || options === void 0 ? void 0 : options.handler) ?? null);
2497
- const ctx = new MiddlewareContext(commandkit$1, {
2498
- command: prepared.command,
2499
- environment: env,
2500
- executionMode,
2501
- interaction: !(source instanceof discord_js.Message) ? source : null,
2502
- message: source instanceof discord_js.Message ? source : null,
2503
- forwarded: false,
2504
- customArgs: { setCommandRunner: (fn) => {
2505
- runCommand = fn;
2506
- } },
2507
- messageCommandParser: prepared.messageCommandParser
2508
- });
2509
- let middlewaresCanceled = false;
2510
- if (prepared.middlewares.length) await provideContext(env, async () => {
2511
- for (const middleware of prepared.middlewares) {
2512
- if (!middleware.data.beforeExecute) continue;
2513
- try {
2514
- await middleware.data.beforeExecute(ctx);
2484
+ try {
2485
+ const middlewareCtx = new MiddlewareContext(commandkit$1, {
2486
+ command: prepared.command,
2487
+ environment: env,
2488
+ executionMode,
2489
+ interaction: !(source instanceof discord_js.Message) ? source : null,
2490
+ message: source instanceof discord_js.Message ? source : null,
2491
+ forwarded: false,
2492
+ customArgs: { setCommandRunner: (fn) => {
2493
+ runCommand = fn;
2494
+ } },
2495
+ messageCommandParser: prepared.messageCommandParser
2496
+ });
2497
+ const beforeMiddlewares = prepared.middlewares.filter((m) => m.data.beforeExecute);
2498
+ let beforeMiddlewaresStopped = false;
2499
+ if (beforeMiddlewares.length) await provideContext(env, async () => {
2500
+ for (const middleware of beforeMiddlewares) try {
2501
+ await middleware.data.beforeExecute(middlewareCtx);
2515
2502
  } catch (e) {
2516
- if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ExitMiddleware)) {
2517
- middlewaresCanceled = true;
2518
- return;
2503
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.StopMiddlewares)) {
2504
+ beforeMiddlewaresStopped = true;
2505
+ Logger.debug(`Middleware propagation stopped for command "${middlewareCtx.commandName}". stopMiddlewares() was called inside a beforeExecute function at "${middleware.middleware.relativePath}"`);
2506
+ break;
2519
2507
  }
2520
2508
  if (require_error_codes.isErrorType(e, [require_error_codes.CommandKitErrorCodes.ForwardedCommand, require_error_codes.CommandKitErrorCodes.InvalidCommandPrefix])) continue;
2521
2509
  throw e;
2522
2510
  }
2523
- }
2524
- });
2525
- let result;
2526
- if (!ctx.cancelled) {
2527
- const targetData = prepared.command.data;
2528
- const fn = targetData[(options === null || options === void 0 ? void 0 : options.handler) || executionMode];
2529
- if (!fn) Logger.warn(`Command ${prepared.command.command.name} has no handler for ${executionMode}`);
2530
- const analytics = commandkit$1.analytics;
2531
- if (fn) try {
2532
- const _executeCommand = makeContextAwareFunction(env, async () => {
2533
- env.registerDeferredFunction(async (env$1) => {
2534
- var _prepared$command2;
2535
- env$1.markEnd();
2536
- const error = env$1.getExecutionError();
2537
- const marker = env$1.getMarker();
2538
- const time = `${env$1.getExecutionTime().toFixed(2)}ms`;
2539
- if (error) {
2540
- var _prepared$command;
2541
- Logger.error(`[${marker} - ${time}] Error executing command: ${error.stack || error}`);
2542
- const commandName$1 = ((_prepared$command = prepared.command) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.data) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.command) === null || _prepared$command === void 0 ? void 0 : _prepared$command.name) ?? prepared.command.command.name;
2511
+ });
2512
+ let result;
2513
+ let stopMiddlewaresCalledInCmd = false;
2514
+ if (!beforeMiddlewaresStopped) {
2515
+ const targetData = prepared.command.data;
2516
+ const fn = targetData[(options === null || options === void 0 ? void 0 : options.handler) || executionMode];
2517
+ if (!fn) Logger.warn(`Command ${prepared.command.command.name} has no handler for ${executionMode}`);
2518
+ const analytics = commandkit$1.analytics;
2519
+ if (fn) try {
2520
+ const _executeCommand = makeContextAwareFunction(env, async () => {
2521
+ env.registerDeferredFunction(async (env$1) => {
2522
+ var _prepared$command2;
2523
+ env$1.markEnd();
2524
+ const error = env$1.getExecutionError();
2525
+ const marker = env$1.getMarker();
2526
+ const time = `${env$1.getExecutionTime().toFixed(2)}ms`;
2527
+ if (error) {
2528
+ var _prepared$command;
2529
+ Logger.error`[${marker} - ${time}] Error executing command: ${error}`;
2530
+ const commandName$1 = ((_prepared$command = prepared.command) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.data) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.command) === null || _prepared$command === void 0 ? void 0 : _prepared$command.name) ?? prepared.command.command.name;
2531
+ await analytics.track({
2532
+ name: require_constants$1.AnalyticsEvents.COMMAND_EXECUTION,
2533
+ id: commandName$1,
2534
+ data: {
2535
+ error: true,
2536
+ executionTime: env$1.getExecutionTime().toFixed(2),
2537
+ type: executionMode,
2538
+ command: commandName$1
2539
+ }
2540
+ });
2541
+ return;
2542
+ }
2543
+ Logger.info(`[${marker} - ${time}] Command executed successfully`);
2544
+ const commandName = ((_prepared$command2 = prepared.command) === null || _prepared$command2 === void 0 || (_prepared$command2 = _prepared$command2.data) === null || _prepared$command2 === void 0 || (_prepared$command2 = _prepared$command2.command) === null || _prepared$command2 === void 0 ? void 0 : _prepared$command2.name) ?? prepared.command.command.name;
2543
2545
  await analytics.track({
2544
2546
  name: require_constants$1.AnalyticsEvents.COMMAND_EXECUTION,
2545
- id: commandName$1,
2547
+ id: commandName,
2546
2548
  data: {
2547
- error: true,
2549
+ error: false,
2548
2550
  executionTime: env$1.getExecutionTime().toFixed(2),
2549
2551
  type: executionMode,
2550
- command: commandName$1
2552
+ command: commandName
2551
2553
  }
2552
2554
  });
2553
- return;
2554
- }
2555
- Logger.info(`[${marker} - ${time}] Command executed successfully`);
2556
- const commandName = ((_prepared$command2 = prepared.command) === null || _prepared$command2 === void 0 || (_prepared$command2 = _prepared$command2.data) === null || _prepared$command2 === void 0 || (_prepared$command2 = _prepared$command2.command) === null || _prepared$command2 === void 0 ? void 0 : _prepared$command2.name) ?? prepared.command.command.name;
2557
- await analytics.track({
2558
- name: require_constants$1.AnalyticsEvents.COMMAND_EXECUTION,
2559
- id: commandName,
2560
- data: {
2561
- error: false,
2562
- executionTime: env$1.getExecutionTime().toFixed(2),
2563
- type: executionMode,
2564
- command: commandName
2565
- }
2566
2555
  });
2556
+ return fn(middlewareCtx.clone());
2557
+ }, this.#finalizer.bind(this));
2558
+ const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
2559
+ env.markStart(prepared.command.data.command.name);
2560
+ const res = await commandkit$1.plugins.execute(async (ctx, plugin) => {
2561
+ return plugin.executeCommand(ctx, env, source, prepared, executeCommand);
2567
2562
  });
2568
- return fn(ctx.clone());
2569
- }, this.#finalizer.bind(this));
2570
- const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
2571
- env.markStart(prepared.command.data.command.name);
2572
- const res = await commandkit$1.plugins.execute(async (ctx$1, plugin) => {
2573
- return plugin.executeCommand(ctx$1, env, source, prepared, executeCommand);
2574
- });
2575
- if (!res) result = await executeCommand();
2576
- } catch (e) {
2577
- if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ExitMiddleware)) middlewaresCanceled = true;
2578
- if (!require_error_codes.isErrorType(e, [require_error_codes.CommandKitErrorCodes.ForwardedCommand, require_error_codes.CommandKitErrorCodes.ExitMiddleware])) {
2579
- if (shouldThrowOnError) throw e;
2580
- Logger.error(e);
2563
+ if (!res) result = await executeCommand();
2564
+ } catch (e) {
2565
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.StopMiddlewares)) {
2566
+ stopMiddlewaresCalledInCmd = true;
2567
+ Logger.debug(`Middleware propagation stopped for command "${middlewareCtx.commandName}". stopMiddlewares() was called by the command itself`);
2568
+ } else if (!require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ForwardedCommand)) {
2569
+ if (shouldThrowOnError) throw e;
2570
+ Logger.error`${e}`;
2571
+ }
2581
2572
  }
2582
- }
2583
- } else result = {
2584
- error: true,
2585
- message: "Command execution was cancelled by the middleware."
2586
- };
2587
- if (!middlewaresCanceled && prepared.middlewares.length) await provideContext(env, async () => {
2588
- for (const middleware of prepared.middlewares) {
2589
- if (!middleware.data.afterExecute) continue;
2590
- try {
2591
- await middleware.data.afterExecute(ctx);
2573
+ } else result = {
2574
+ error: true,
2575
+ message: "Command execution was cancelled by a beforeExecute middleware."
2576
+ };
2577
+ const afterMiddlewares = prepared.middlewares.filter((m) => m.data.afterExecute);
2578
+ if (!beforeMiddlewaresStopped && !stopMiddlewaresCalledInCmd && afterMiddlewares.length) await provideContext(env, async () => {
2579
+ for (const middleware of afterMiddlewares) try {
2580
+ await middleware.data.afterExecute(middlewareCtx);
2592
2581
  } catch (e) {
2593
- if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.ExitMiddleware)) return;
2582
+ if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.StopMiddlewares)) {
2583
+ Logger.debug(`Middleware propagation stopped for command "${middlewareCtx.commandName}". stopMiddlewares() was called inside an afterExecute function at "${middleware.middleware.relativePath}"`);
2584
+ break;
2585
+ }
2594
2586
  throw e;
2595
2587
  }
2596
- }
2597
- });
2598
- return result;
2588
+ });
2589
+ return result;
2590
+ } finally {
2591
+ await this.#finalizer(env, false);
2592
+ }
2599
2593
  }
2600
2594
  /**
2601
2595
  * @private
2602
2596
  * @internal
2603
2597
  * Finalizes command execution by running deferred functions and plugin cleanup.
2604
2598
  */
2605
- async #finalizer() {
2606
- const env = useEnvironment();
2599
+ async #finalizer(env, runPlugins = true) {
2600
+ env ??= useEnvironment();
2607
2601
  await env.runDeferredFunctions();
2608
2602
  env.clearAllDeferredFunctions();
2609
- await this.handler.commandkit.plugins.execute(async (ctx, plugin) => {
2603
+ if (runPlugins) await this.handler.commandkit.plugins.execute(async (ctx, plugin) => {
2610
2604
  await plugin.onAfterCommand(ctx, env);
2611
2605
  });
2612
2606
  }
@@ -2734,7 +2728,7 @@ var CommandRegistrar = class {
2734
2728
  })) });
2735
2729
  Logger.info(`✨ Refreshed ${data.length} global application (/) commands`);
2736
2730
  } catch (e) {
2737
- Logger.error("Failed to update global application (/) commands", e);
2731
+ Logger.error`Failed to update global application (/) commands: ${e}`;
2738
2732
  }
2739
2733
  }
2740
2734
  /**
@@ -2787,7 +2781,7 @@ var CommandRegistrar = class {
2787
2781
  }
2788
2782
  Logger.info(`✨ Refreshed ${count} guild application (/) commands`);
2789
2783
  } catch (e) {
2790
- Logger.error("Failed to update guild application (/) commands", e);
2784
+ Logger.error`Failed to update guild application (/) commands: ${e}`;
2791
2785
  }
2792
2786
  }
2793
2787
  };
@@ -2814,9 +2808,9 @@ async function beforeExecute(ctx) {
2814
2808
  });
2815
2809
  else await message.reply({ embeds: [embed$1] });
2816
2810
  } catch (error) {
2817
- Logger.error(`Could not send 'Server-only command' DM to user ${(interaction === null || interaction === void 0 ? void 0 : interaction.user.id) ?? (message === null || message === void 0 ? void 0 : message.author.id)} for command ${command.command.name}.`, error);
2811
+ Logger.error`Could not send 'Server-only command' DM to user ${(interaction === null || interaction === void 0 ? void 0 : interaction.user.id) ?? (message === null || message === void 0 ? void 0 : message.author.id)} for command ${command.command.name}: ${error}`;
2818
2812
  }
2819
- return ctx.cancel();
2813
+ require_signals.stopMiddlewares();
2820
2814
  }
2821
2815
  const userPermissions = (interaction === null || interaction === void 0 ? void 0 : interaction.memberPermissions) ?? (message === null || message === void 0 || (_message$member = message.member) === null || _message$member === void 0 ? void 0 : _message$member.permissions);
2822
2816
  let userPermissionsRequired = ((_command$metadata = command.metadata) === null || _command$metadata === void 0 ? void 0 : _command$metadata.userPermissions) ?? [];
@@ -2864,9 +2858,9 @@ async function beforeExecute(ctx) {
2864
2858
  });
2865
2859
  else if (message && ((_message$channel2 = message.channel) === null || _message$channel2 === void 0 ? void 0 : _message$channel2.isSendable())) await message.reply({ embeds: [embed] });
2866
2860
  } catch (error) {
2867
- Logger.error(`Could not send 'Not enough permissions' reply to user ${(interaction === null || interaction === void 0 ? void 0 : interaction.user.id) ?? (message === null || message === void 0 ? void 0 : message.author.id)} for command ${command.command.name}.`, error);
2861
+ Logger.error`Could not send 'Not enough permissions' reply to user ${(interaction === null || interaction === void 0 ? void 0 : interaction.user.id) ?? (message === null || message === void 0 ? void 0 : message.author.id)} for command ${command.command.name}: ${error}`;
2868
2862
  }
2869
- return ctx.cancel();
2863
+ require_signals.stopMiddlewares();
2870
2864
  }
2871
2865
 
2872
2866
  //#endregion
@@ -3078,7 +3072,7 @@ var AppCommandHandler = class {
3078
3072
  var _loadedCommand$metada, _loadedCommand$metada2, _json$options;
3079
3073
  const loadedCommand$1 = this.findCommandByName(command);
3080
3074
  if (!loadedCommand$1) {
3081
- if (require_constants.COMMANDKIT_IS_DEV && this.commandkit.config.showUnknownPrefixCommandsWarning) Logger.error(`Prefix command "${command}" was not found.\nNote: This warning is only shown in development mode as an alert to help you find the command. If you wish to remove this warning, set \`showUnknownPrefixCommandsWarning\` to \`false\` in your commandkit config.`);
3075
+ if (require_constants.COMMANDKIT_IS_DEV && this.commandkit.config.showUnknownPrefixCommandsWarning) Logger.error`Prefix command "${command}" was not found.\nNote: This warning is only shown in development mode as an alert to help you find the command. If you wish to remove this warning, set \`showUnknownPrefixCommandsWarning\` to \`false\` in your commandkit config.`;
3082
3076
  return null;
3083
3077
  }
3084
3078
  if (source.guildId && ((_loadedCommand$metada = loadedCommand$1.metadata) === null || _loadedCommand$metada === void 0 || (_loadedCommand$metada = _loadedCommand$metada.guilds) === null || _loadedCommand$metada === void 0 ? void 0 : _loadedCommand$metada.length) && !((_loadedCommand$metada2 = loadedCommand$1.metadata) === null || _loadedCommand$metada2 === void 0 ? void 0 : _loadedCommand$metada2.guilds.includes(source.guildId))) return null;
@@ -3094,7 +3088,7 @@ var AppCommandHandler = class {
3094
3088
  cmdName = parts[0];
3095
3089
  } catch (e) {
3096
3090
  if (require_error_codes.isErrorType(e, require_error_codes.CommandKitErrorCodes.InvalidCommandPrefix)) return null;
3097
- Logger.error(e);
3091
+ Logger.error`${e}`;
3098
3092
  return null;
3099
3093
  }
3100
3094
  } else {
@@ -3228,7 +3222,7 @@ var AppCommandHandler = class {
3228
3222
  data
3229
3223
  });
3230
3224
  } catch (error) {
3231
- Logger.error(`Failed to load middleware ${id}`, error);
3225
+ Logger.error`Failed to load middleware ${id}: ${error}`;
3232
3226
  }
3233
3227
  }
3234
3228
  /**
@@ -3306,7 +3300,7 @@ var AppCommandHandler = class {
3306
3300
  }
3307
3301
  });
3308
3302
  } catch (error) {
3309
- Logger.error(`Failed to load command ${command.name} (${id})`, error);
3303
+ Logger.error`Failed to load command ${command.name} (${id}): ${error}`;
3310
3304
  }
3311
3305
  }
3312
3306
  /**
@@ -3379,7 +3373,7 @@ var AppEventsHandler = class {
3379
3373
  const listeners = [];
3380
3374
  for (const listener of event.listeners) {
3381
3375
  const handler = await import(require_resolve_file_url.toFileURL(listener, true));
3382
- if (!handler.default || typeof handler.default !== "function") Logger.error(`Event handler for ${event.event}${event.namespace ? ` of namespace ${event.namespace}` : ""} does not have a default export or is not a function`);
3376
+ if (!handler.default || typeof handler.default !== "function") Logger.error`Event handler for ${event.event}${event.namespace ? ` of namespace ${event.namespace}` : ""} does not have a default export or is not a function`;
3383
3377
  listeners.push({
3384
3378
  handler: handler.default,
3385
3379
  once: !!handler.once
@@ -3451,7 +3445,7 @@ var AppEventsHandler = class {
3451
3445
  Logger.debug(`Event propagation stopped for ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
3452
3446
  break;
3453
3447
  }
3454
- Logger.error(`Error handling event ${name}${namespace ? ` of namespace ${namespace}` : ""}`, e);
3448
+ Logger.error`Error handling event ${name}${namespace ? ` of namespace ${namespace}` : ""}: ${e}`;
3455
3449
  }
3456
3450
  });
3457
3451
  };
@@ -3493,7 +3487,7 @@ var AppEventsHandler = class {
3493
3487
  Logger.debug(`Event propagation stopped for ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
3494
3488
  broken = true;
3495
3489
  }
3496
- Logger.error(`Error handling event ${name}${namespace ? ` of namespace ${namespace}` : ""}`, e);
3490
+ Logger.error`Error handling event ${name}${namespace ? ` of namespace ${namespace}` : ""}: ${e}`;
3497
3491
  }
3498
3492
  });
3499
3493
  }
@@ -3729,7 +3723,7 @@ var AnalyticsEngine = class {
3729
3723
  var _identify, _ref;
3730
3724
  await ((_identify = (_ref = this.#provider).identify) === null || _identify === void 0 ? void 0 : _identify.call(_ref, this, event));
3731
3725
  } catch (error) {
3732
- Logger.error(`Error identifying with provider ${this.#provider.name}`, error);
3726
+ Logger.error`Error identifying with provider ${this.#provider.name}: ${error}`;
3733
3727
  }
3734
3728
  }
3735
3729
  /**
@@ -3744,7 +3738,7 @@ var AnalyticsEngine = class {
3744
3738
  if (await this.#doNotTrack(event)) return;
3745
3739
  await this.#provider.track(this, event);
3746
3740
  } catch (error) {
3747
- Logger.error(`Error tracking ${event.name} event with provider ${this.#provider.name}`, error);
3741
+ Logger.error`Error tracking ${event.name} event with provider ${this.#provider.name}: ${error}`;
3748
3742
  }
3749
3743
  }
3750
3744
  async #doNotTrack(event) {
@@ -3883,7 +3877,7 @@ var CommandKit = class CommandKit extends node_events.default {
3883
3877
  for (const hook of bootstrapHooks) try {
3884
3878
  await hook(this);
3885
3879
  } catch (e) {
3886
- Logger.error("Error while executing bootstrap hook: ", e);
3880
+ Logger.error`Error while executing bootstrap hook: ${e}`;
3887
3881
  } finally {
3888
3882
  bootstrapHooks.delete(hook);
3889
3883
  }
@@ -3893,7 +3887,7 @@ var CommandKit = class CommandKit extends node_events.default {
3893
3887
  for (const hook of onApplicationBootstrapHooks) try {
3894
3888
  await hook(this);
3895
3889
  } catch (e) {
3896
- Logger.error("Error while executing application bootstrap hook: ", e);
3890
+ Logger.error`Error while executing application bootstrap hook: ${e}`;
3897
3891
  } finally {
3898
3892
  onApplicationBootstrapHooks.delete(hook);
3899
3893
  }
@@ -3911,7 +3905,7 @@ var CommandKit = class CommandKit extends node_events.default {
3911
3905
  registerDevHooks(this);
3912
3906
  await require_types_package.generateTypesPackage();
3913
3907
  } catch (e) {
3914
- if (process.env.COMMANDKIT_DEBUG_TYPEGEN) Logger.error(e);
3908
+ if (process.env.COMMANDKIT_DEBUG_TYPEGEN) Logger.error`${e}`;
3915
3909
  }
3916
3910
  await this.loadPlugins();
3917
3911
  await this.#init();
@@ -4468,4 +4462,4 @@ Object.defineProperty(exports, 'useEnvironment', {
4468
4462
  return useEnvironment;
4469
4463
  }
4470
4464
  });
4471
- //# sourceMappingURL=commandkit-C0BuNRSN.js.map
4465
+ //# sourceMappingURL=commandkit-c0sAaK0G.js.map