vimcord 1.0.54 → 1.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -113,7 +113,9 @@ interface BaseCommandConfig<T extends CommandType> {
113
113
  /** Log whenever a command is executed? @defaultValue true */
114
114
  logExecution?: boolean;
115
115
  /** Executed before the main command logic */
116
- beforeExecute?: (...args: BaseCommandParameters<T>) => any;
116
+ beforeExecute?: (ctx: {
117
+ cancel: () => void;
118
+ }, ...args: BaseCommandParameters<T>) => any;
117
119
  /** The main command function that will be executed */
118
120
  execute?: (...args: BaseCommandParameters<T>) => any;
119
121
  /** Executed after successful execution */
@@ -381,7 +383,9 @@ interface EventConfig<T extends keyof ClientEvents> {
381
383
  /** Rate limiting options */
382
384
  rateLimit?: EventRateLimitOptions<T>;
383
385
  /** Before event execution */
384
- beforeExecute?: (...args: EventParameters<T>) => any;
386
+ beforeExecute?: (ctx: {
387
+ cancel: () => void;
388
+ }, ...args: EventParameters<T>) => any;
385
389
  /** The function that will be executed */
386
390
  execute?: (...args: EventParameters<T>) => any;
387
391
  /** After successful execution */
@@ -401,7 +405,9 @@ declare class EventBuilder<T extends keyof ClientEvents = keyof ClientEvents> im
401
405
  metadata: EventMetadata | undefined;
402
406
  deployment: EventDeployment | undefined;
403
407
  rateLimit: EventRateLimitOptions<T> | undefined;
404
- beforeExecute: ((client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
408
+ beforeExecute: ((ctx: {
409
+ cancel: () => void;
410
+ }, client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
405
411
  execute: ((client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
406
412
  afterExecute: ((result: any, client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
407
413
  onError: ((error: Error, client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
@@ -952,7 +958,9 @@ declare const createContextCommandConfig: (options?: {
952
958
  onRateLimit?: ((client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
953
959
  } | undefined;
954
960
  logExecution?: boolean | undefined;
955
- beforeExecute?: ((client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
961
+ beforeExecute?: ((ctx: {
962
+ cancel: () => void;
963
+ }, client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
956
964
  execute?: ((client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
957
965
  afterExecute?: ((result: any, client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
958
966
  onMissingPermissions?: ((results: CommandPermissionResults, client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
@@ -1317,7 +1325,9 @@ declare const createPrefixCommandConfig: (options?: {
1317
1325
  onRateLimit?: ((client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1318
1326
  } | undefined;
1319
1327
  logExecution?: boolean | undefined;
1320
- beforeExecute?: ((client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1328
+ beforeExecute?: ((ctx: {
1329
+ cancel: () => void;
1330
+ }, client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1321
1331
  execute?: ((client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1322
1332
  afterExecute?: ((result: any, client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1323
1333
  onMissingPermissions?: ((results: CommandPermissionResults, client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
@@ -1667,7 +1677,9 @@ declare const createSlashCommandConfig: (options?: {
1667
1677
  onRateLimit?: ((client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1668
1678
  } | undefined;
1669
1679
  logExecution?: boolean | undefined;
1670
- beforeExecute?: ((client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1680
+ beforeExecute?: ((ctx: {
1681
+ cancel: () => void;
1682
+ }, client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1671
1683
  execute?: ((client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1672
1684
  afterExecute?: ((result: any, client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1673
1685
  onMissingPermissions?: ((results: CommandPermissionResults, client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
package/dist/index.d.ts CHANGED
@@ -113,7 +113,9 @@ interface BaseCommandConfig<T extends CommandType> {
113
113
  /** Log whenever a command is executed? @defaultValue true */
114
114
  logExecution?: boolean;
115
115
  /** Executed before the main command logic */
116
- beforeExecute?: (...args: BaseCommandParameters<T>) => any;
116
+ beforeExecute?: (ctx: {
117
+ cancel: () => void;
118
+ }, ...args: BaseCommandParameters<T>) => any;
117
119
  /** The main command function that will be executed */
118
120
  execute?: (...args: BaseCommandParameters<T>) => any;
119
121
  /** Executed after successful execution */
@@ -381,7 +383,9 @@ interface EventConfig<T extends keyof ClientEvents> {
381
383
  /** Rate limiting options */
382
384
  rateLimit?: EventRateLimitOptions<T>;
383
385
  /** Before event execution */
384
- beforeExecute?: (...args: EventParameters<T>) => any;
386
+ beforeExecute?: (ctx: {
387
+ cancel: () => void;
388
+ }, ...args: EventParameters<T>) => any;
385
389
  /** The function that will be executed */
386
390
  execute?: (...args: EventParameters<T>) => any;
387
391
  /** After successful execution */
@@ -401,7 +405,9 @@ declare class EventBuilder<T extends keyof ClientEvents = keyof ClientEvents> im
401
405
  metadata: EventMetadata | undefined;
402
406
  deployment: EventDeployment | undefined;
403
407
  rateLimit: EventRateLimitOptions<T> | undefined;
404
- beforeExecute: ((client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
408
+ beforeExecute: ((ctx: {
409
+ cancel: () => void;
410
+ }, client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
405
411
  execute: ((client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
406
412
  afterExecute: ((result: any, client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
407
413
  onError: ((error: Error, client: Vimcord<true>, ...args: ClientEvents[T]) => any) | undefined;
@@ -952,7 +958,9 @@ declare const createContextCommandConfig: (options?: {
952
958
  onRateLimit?: ((client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
953
959
  } | undefined;
954
960
  logExecution?: boolean | undefined;
955
- beforeExecute?: ((client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
961
+ beforeExecute?: ((ctx: {
962
+ cancel: () => void;
963
+ }, client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
956
964
  execute?: ((client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
957
965
  afterExecute?: ((result: any, client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
958
966
  onMissingPermissions?: ((results: CommandPermissionResults, client: Vimcord<true>, interaction: discord_js.ContextMenuCommandInteraction<discord_js.CacheType>) => any) | undefined;
@@ -1317,7 +1325,9 @@ declare const createPrefixCommandConfig: (options?: {
1317
1325
  onRateLimit?: ((client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1318
1326
  } | undefined;
1319
1327
  logExecution?: boolean | undefined;
1320
- beforeExecute?: ((client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1328
+ beforeExecute?: ((ctx: {
1329
+ cancel: () => void;
1330
+ }, client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1321
1331
  execute?: ((client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1322
1332
  afterExecute?: ((result: any, client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
1323
1333
  onMissingPermissions?: ((results: CommandPermissionResults, client: Vimcord<true>, message: discord_js.Message<boolean>) => any) | undefined;
@@ -1667,7 +1677,9 @@ declare const createSlashCommandConfig: (options?: {
1667
1677
  onRateLimit?: ((client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1668
1678
  } | undefined;
1669
1679
  logExecution?: boolean | undefined;
1670
- beforeExecute?: ((client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1680
+ beforeExecute?: ((ctx: {
1681
+ cancel: () => void;
1682
+ }, client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1671
1683
  execute?: ((client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1672
1684
  afterExecute?: ((result: any, client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
1673
1685
  onMissingPermissions?: ((results: CommandPermissionResults, client: Vimcord<true>, interaction: discord_js.ChatInputCommandInteraction<discord_js.CacheType>) => any) | undefined;
package/dist/index.js CHANGED
@@ -204,6 +204,8 @@ var BaseCommandBuilder = class {
204
204
  async run(client, ...args) {
205
205
  const config = this.resolveConfig(client);
206
206
  const ctx = this.extractContext(args);
207
+ let canceled = false;
208
+ const cancel = () => canceled = true;
207
209
  try {
208
210
  if (!config.enabled) {
209
211
  return await config.onUsedWhenDisabled?.(...args);
@@ -218,7 +220,10 @@ var BaseCommandBuilder = class {
218
220
  if (!await this.checkConditions(config, ...args)) {
219
221
  return await config.onConditionsNotMet?.(...args);
220
222
  }
221
- await config.beforeExecute?.(...args);
223
+ if (config.beforeExecute) {
224
+ await config.beforeExecute?.({ cancel }, ...args);
225
+ if (canceled) return;
226
+ }
222
227
  if (config.logExecution !== false) {
223
228
  const cmdName = this.options.name || this.builder?.name || "Unknown";
224
229
  const location = ctx.guild ? `${ctx.guild.name} (${ctx.guild.id})` : "Direct Messages";
@@ -668,6 +673,8 @@ var EventBuilder = class _EventBuilder {
668
673
  return results.every(Boolean);
669
674
  }
670
675
  async executeEvent(...args) {
676
+ let canceled = false;
677
+ const cancel = () => canceled = true;
671
678
  try {
672
679
  if (!this.enabled) {
673
680
  return;
@@ -683,7 +690,8 @@ var EventBuilder = class _EventBuilder {
683
690
  return;
684
691
  }
685
692
  if (this.beforeExecute) {
686
- await this.beforeExecute(...args);
693
+ await this.beforeExecute({ cancel }, ...args);
694
+ if (canceled) return;
687
695
  }
688
696
  const result = await this.execute?.(...args);
689
697
  if (this.afterExecute) {
@@ -1693,7 +1701,7 @@ var VimcordErrorHandler = class {
1693
1701
  import chalk2 from "chalk";
1694
1702
 
1695
1703
  // package.json
1696
- var version = "1.0.54";
1704
+ var version = "1.0.55";
1697
1705
 
1698
1706
  // src/client/vimcord.logger.ts
1699
1707
  var clientLoggerFactory = (client) => new Logger({ prefixEmoji: "\u26A1", prefix: `vimcord (i${client.clientId})` }).extend({