Skip to content

Commit e7ca4a9

Browse files
authored
Merge pull request #261 from underctrl-io/disable-prefix-command-option
feat: add option to disable prefix commands
2 parents 5f2854f + a75ccc0 commit e7ca4a9

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

packages/commandkit/src/CommandKit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const onApplicationBootstrapHooks = new Set<BootstrapFunction>();
5353
/**
5454
* Registers a bootstrap hook that will be called when the CommandKit instance is created.
5555
* This is useful for plugins that need to run some code after the CommandKit instance is fully initialized.
56-
* Note that not all commandkit dependiencs are available at this point. It is recommended to use the `onApplicationBootstrap` hook instead,
56+
* Note that not all commandkit dependencies are available at this point. It is recommended to use the `onApplicationBootstrap` hook instead,
5757
* if you need access to the commandkit dependencies.
5858
* @param fn The bootstrap function to register.
5959
* @example ```ts

packages/commandkit/src/app/handlers/AppCommandHandler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Context } from '../commands/Context';
2424
import { MessageCommandParser } from '../commands/MessageCommandParser';
2525
import { CommandRegistrar } from '../register/CommandRegistrar';
2626
import { Command, Middleware } from '../router';
27+
import { getConfig } from '../../config/config';
2728

2829
/**
2930
* Function type for wrapping command execution with custom logic.
@@ -419,6 +420,12 @@ export class AppCommandHandler {
419420
source: Interaction | Message,
420421
cmdName?: string,
421422
): Promise<PreparedAppCommandExecution | null> {
423+
const config = getConfig();
424+
425+
if (config.disablePrefixCommands && source instanceof Message) {
426+
return null;
427+
}
428+
422429
let parser: MessageCommandParser | undefined;
423430

424431
// Extract command name (and possibly subcommand) from the source
@@ -429,6 +436,8 @@ export class AppCommandHandler {
429436
const prefix =
430437
await this.commandkit.config.getMessageCommandPrefix(source);
431438

439+
if (!prefix || !prefix.length) return null;
440+
432441
parser = new MessageCommandParser(
433442
source,
434443
Array.isArray(prefix) ? prefix : [prefix],

packages/commandkit/src/config/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export function defineConfig(
5454
...defaultConfig.typescript,
5555
...config.typescript,
5656
},
57+
disablePrefixCommands:
58+
config.disablePrefixCommands ?? defaultConfig.disablePrefixCommands,
5759
};
5860

5961
return defined;

packages/commandkit/src/config/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export const defaultConfig: ResolvedCommandKitConfig = {
2424
production: true,
2525
},
2626
typedCommands: true,
27+
disablePrefixCommands: false,
2728
};

packages/commandkit/src/config/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@ export interface CommandKitConfig {
6666
* @default true
6767
*/
6868
typedCommands?: boolean;
69+
/**
70+
* Whether or not to disable the prefix commands.
71+
* @default false
72+
*/
73+
disablePrefixCommands?: boolean;
6974
}

0 commit comments

Comments
 (0)