@@ -15,13 +15,19 @@ import { CacheProvider } from './cache/CacheProvider';
15
15
import { MemoryCache } from './cache/MemoryCache' ;
16
16
import { createElement , Fragment } from './components' ;
17
17
import { EventInterceptor } from './components/common/EventInterceptor' ;
18
- import { Locale } from 'discord.js' ;
18
+ import { Awaitable , Locale , Message } from 'discord.js' ;
19
19
import { DefaultLocalizationStrategy } from './app/i18n/DefaultLocalizationStrategy' ;
20
20
import { findAppDirectory } from './utils/utilities' ;
21
21
import { join } from 'node:path' ;
22
22
import { CommandsRouter , EventsRouter } from '@commandkit/router' ;
23
- import { COMMANDKIT_IS_DEV } from './utils/constants' ;
24
23
import { AppCommandHandler } from './app/command-handler/AppCommandHandler' ;
24
+ import { LocalizationStrategy } from './app/i18n/LocalizationStrategy' ;
25
+
26
+ export interface CommandKitConfiguration {
27
+ defaultLocale : Locale ;
28
+ localizationStrategy : LocalizationStrategy ;
29
+ getMessageCommandPrefix : ( message : Message ) => Awaitable < string | string [ ] > ;
30
+ }
25
31
26
32
export class CommandKit extends EventEmitter {
27
33
#data: CommandKitData ;
@@ -30,9 +36,10 @@ export class CommandKit extends EventEmitter {
30
36
public static readonly createElement = createElement ;
31
37
public static readonly Fragment = Fragment ;
32
38
33
- public readonly config = {
39
+ public readonly config : CommandKitConfiguration = {
34
40
defaultLocale : Locale . EnglishUS ,
35
41
localizationStrategy : new DefaultLocalizationStrategy ( this ) ,
42
+ getMessageCommandPrefix : ( ) => '!' ,
36
43
} ;
37
44
38
45
public commandsRouter ! : CommandsRouter ;
@@ -95,6 +102,35 @@ export class CommandKit extends EventEmitter {
95
102
}
96
103
}
97
104
105
+ /**
106
+ * Sets the prefix resolver for the command handler.
107
+ * @param resolver The resolver function.
108
+ */
109
+ setPrefixResolver (
110
+ resolver : ( message : Message ) => Awaitable < string | string [ ] > ,
111
+ ) {
112
+ this . config . getMessageCommandPrefix = resolver ;
113
+ return this ;
114
+ }
115
+
116
+ /**
117
+ * Sets the default locale for the command handler.
118
+ * @param locale The default locale.
119
+ */
120
+ setDefaultLocale ( locale : Locale ) {
121
+ this . config . defaultLocale = locale ;
122
+ return this ;
123
+ }
124
+
125
+ /**
126
+ * Sets the localization strategy for the command handler.
127
+ * @param strategy The localization strategy.
128
+ */
129
+ setLocalizationStrategy ( strategy : LocalizationStrategy ) {
130
+ this . config . localizationStrategy = strategy ;
131
+ return this ;
132
+ }
133
+
98
134
/**
99
135
* Resolves the current cache provider.
100
136
*/
@@ -128,8 +164,6 @@ export class CommandKit extends EventEmitter {
128
164
* (Private) Initialize CommandKit.
129
165
*/
130
166
async #init( ) {
131
- await this . #initApp( ) ;
132
-
133
167
// <!-- Setup event handler -->
134
168
if ( this . #data. eventsPath ) {
135
169
const eventHandler = new EventHandler ( {
@@ -168,9 +202,10 @@ export class CommandKit extends EventEmitter {
168
202
bulkRegister : this . #data. bulkRegister || false ,
169
203
} ) ;
170
204
171
- await commandHandler . init ( ) ;
172
-
173
205
this . #data. commandHandler = commandHandler ;
206
+
207
+ await this . #initApp( ) ;
208
+ await commandHandler . init ( ) ;
174
209
}
175
210
}
176
211
@@ -197,6 +232,8 @@ export class CommandKit extends EventEmitter {
197
232
if ( this . commandsRouter . isValidPath ( ) ) {
198
233
await this . commandsRouter . scan ( ) ;
199
234
}
235
+
236
+ await this . appCommandsHandler . loadCommands ( ) ;
200
237
}
201
238
202
239
async #initEvents( ) {
0 commit comments