bakit 2.0.0-alpha.2 → 2.0.0-alpha.21

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/cli.js ADDED
@@ -0,0 +1,81 @@
1
+ import { config } from 'dotenv';
2
+ import { program } from 'commander';
3
+ import { fork } from 'child_process';
4
+ import chokidar from 'chokidar';
5
+ import path, { relative, sep } from 'path';
6
+ import { pathToFileURL } from 'url';
7
+
8
+ // src/cli/bin.ts
9
+ function getTopLevelDirectory(path2, entryDir) {
10
+ return relative(entryDir, path2).split(sep)[0] ?? null;
11
+ }
12
+ var DevProcessManager = class {
13
+ constructor(options) {
14
+ this.options = options;
15
+ }
16
+ child = null;
17
+ restartTimer = null;
18
+ start() {
19
+ console.log("Starting bakit in dev mode..."), this.startChild(), this.startWatcher();
20
+ }
21
+ startChild() {
22
+ if (this.child) return;
23
+ let entry = path.resolve(this.options.entry);
24
+ this.child = fork(entry, {
25
+ execArgv: ["--import", "bakit/loader/register"],
26
+ stdio: "inherit",
27
+ env: {
28
+ ...process.env,
29
+ NODE_ENV: "development"
30
+ }
31
+ }), this.child.on("exit", () => {
32
+ this.child = null;
33
+ });
34
+ }
35
+ restartChild() {
36
+ if (!this.child)
37
+ return this.startChild();
38
+ let old = this.child;
39
+ old.once("exit", () => {
40
+ this.child = null, this.startChild();
41
+ }), old.kill("SIGTERM");
42
+ }
43
+ startWatcher() {
44
+ let { rootDir } = this.options;
45
+ chokidar.watch(rootDir, {
46
+ ignoreInitial: true,
47
+ awaitWriteFinish: {
48
+ stabilityThreshold: 200,
49
+ pollInterval: 50
50
+ }
51
+ }).on("change", (path2) => {
52
+ this.onFileChanged(path2);
53
+ });
54
+ }
55
+ onFileChanged(path2) {
56
+ if (!this.child)
57
+ return;
58
+ let top = getTopLevelDirectory(path2, this.options.rootDir);
59
+ if (top && this.options.hotDirs.includes(top)) {
60
+ this.child.connected && this.child.send({ type: `hmr:${top}`, url: pathToFileURL(path2).href });
61
+ return;
62
+ }
63
+ this.scheduleRestart();
64
+ }
65
+ scheduleRestart() {
66
+ this.restartTimer && clearTimeout(this.restartTimer), this.restartTimer = setTimeout(() => {
67
+ console.log("Detected changes, restarting..."), this.restartChild(), this.restartTimer = null;
68
+ }, 150);
69
+ }
70
+ };
71
+
72
+ // src/cli/bin.ts
73
+ program.name("bakit");
74
+ program.command("dev").action(() => {
75
+ config({ path: [".env.local", ".env"], quiet: true }), new DevProcessManager({
76
+ rootDir: "src",
77
+ entry: "src/index.ts",
78
+ hotDirs: ["commands", "listeners"]
79
+ }).start();
80
+ });
81
+ program.parse();
package/dist/index.d.ts CHANGED
@@ -1,32 +1,41 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { GatewayIntentBits, ClientOptions, ChatInputCommandInteraction, CacheType, Message, User, MessageCreateOptions, InteractionReplyOptions, Awaitable, Collection, ClientEvents, Events, Client } from 'discord.js';
3
- import z$1, { z } from 'zod';
2
+ import { ChatInputCommandInteraction, CacheType, Message, User, MessageCreateOptions, InteractionReplyOptions, Awaitable, Collection, Events, IntentsBitField, ClientEvents, Client, ClientOptions, GatewayIntentBits } from 'discord.js';
4
3
  import { inspect } from 'node:util';
4
+ import z from 'zod';
5
5
 
6
- declare const ProjectConfigSchema: z.ZodObject<{
7
- intents: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodBigInt, z.ZodArray<z.ZodEnum<typeof GatewayIntentBits>>]>>;
8
- clientOptions: z.ZodOptional<z.ZodCustom<Omit<ClientOptions, "intents">, Omit<ClientOptions, "intents">>>;
9
- entryDir: z.ZodDefault<z.ZodString>;
10
- }, z.core.$strip>;
11
- type ProjectConfigInput = z.input<typeof ProjectConfigSchema>;
12
- type ProjectConfig = z.output<typeof ProjectConfigSchema>;
13
- /**
14
- * Define config object for your project. This is just a cleaner way to define config.
15
- * @param config The partial version of project config.
16
- * @returns The same config you provided earlier.
17
- */
18
- declare function defineConfig(config: ProjectConfigInput): ProjectConfigInput;
19
- /**
20
- * Load the config file and save them for later usage.
21
- * @param cwd The location of the config file, uses root by default.
22
- * @returns The complete config with default values from the validation.
23
- */
24
- declare function loadConfig(cwd?: string): Promise<ProjectConfig>;
25
- /**
26
- * Get the loaded config of the project.
27
- * @returns The project config.
28
- */
29
- declare function getConfig(): ProjectConfig;
6
+ declare enum ParamUserType {
7
+ Bot = "bot",
8
+ Normal = "normal",
9
+ Any = "any"
10
+ }
11
+ declare const BaseParamSchema: z.ZodObject<{
12
+ name: z.ZodString;
13
+ description: z.ZodOptional<z.ZodString>;
14
+ required: z.ZodDefault<z.ZodBoolean>;
15
+ }, z.z.core.$strip>;
16
+ declare const StringParamSchema: z.ZodObject<{
17
+ name: z.ZodString;
18
+ description: z.ZodOptional<z.ZodString>;
19
+ required: z.ZodDefault<z.ZodBoolean>;
20
+ maxLength: z.ZodOptional<z.ZodNumber>;
21
+ minLength: z.ZodOptional<z.ZodNumber>;
22
+ }, z.z.core.$strip>;
23
+ declare const NumberParamSchema: z.ZodObject<{
24
+ name: z.ZodString;
25
+ description: z.ZodOptional<z.ZodString>;
26
+ required: z.ZodDefault<z.ZodBoolean>;
27
+ maxValue: z.ZodOptional<z.ZodNumber>;
28
+ minValue: z.ZodOptional<z.ZodNumber>;
29
+ }, z.z.core.$strip>;
30
+ declare const UserParamSchema: z.ZodObject<{
31
+ name: z.ZodString;
32
+ description: z.ZodOptional<z.ZodString>;
33
+ required: z.ZodDefault<z.ZodBoolean>;
34
+ }, z.z.core.$strip>;
35
+ type BaseParamOptions = z.input<typeof BaseParamSchema>;
36
+ type StringOptions = z.input<typeof StringParamSchema>;
37
+ type NumberOptions = z.input<typeof NumberParamSchema>;
38
+ type UserOptions = z.input<typeof UserParamSchema>;
30
39
 
31
40
  declare class Context {
32
41
  canceled: boolean;
@@ -62,63 +71,9 @@ declare class MessageContext<Cached extends boolean = boolean, InGuild extends b
62
71
  }
63
72
  type CommandContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> = ChatInputContext<Cached, InGuild> | MessageContext<Cached, InGuild>;
64
73
 
65
- declare enum HookState {
66
- Pre = "PRE",
67
- Main = "MAIN",
68
- Post = "POST",
69
- Error = "ERROR"
70
- }
71
- declare enum HookOrder {
72
- First = 0,
73
- Last = 1
74
- }
75
- type MainHookCallback<C extends Context, Args extends unknown[]> = (context: C, ...args: Args) => Awaitable<void>;
76
- type ErrorHookCallback<C extends Context, Args extends unknown[]> = (context: C, error: unknown, ...args: Args) => Awaitable<void>;
77
- declare class LifecycleManager<C extends Context, Args extends unknown[]> {
78
- id: string;
79
- private readonly hooks;
80
- constructor(id: string);
81
- getName(name: string): string;
82
- setHook(name: string, state: HookState.Post, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
83
- setHook(name: string, state: HookState.Main, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
84
- setHook(name: string, state: HookState.Pre, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
85
- setHook(name: string, state: HookState.Error, callback: ErrorHookCallback<C, Args>, order?: HookOrder): this;
86
- main(callback: MainHookCallback<C, Args>): this;
87
- pre(callback: MainHookCallback<C, Args>): this;
88
- post(callback: MainHookCallback<C, Args>): this;
89
- error(callback: ErrorHookCallback<C, Args>): this;
90
- execute(context: C, ...args: Args): Promise<void>;
91
- }
92
-
93
- declare enum ParamUserType {
94
- Bot = "bot",
95
- Normal = "normal",
96
- Any = "any"
97
- }
98
- declare const BaseParamSchema: z.ZodObject<{
99
- name: z.ZodString;
100
- description: z.ZodOptional<z.ZodString>;
101
- required: z.ZodDefault<z.ZodBoolean>;
102
- }, z.core.$strip>;
103
- declare const StringParamSchema: z.ZodObject<{
104
- name: z.ZodString;
105
- description: z.ZodOptional<z.ZodString>;
106
- required: z.ZodDefault<z.ZodBoolean>;
107
- maxLength: z.ZodOptional<z.ZodNumber>;
108
- minLength: z.ZodOptional<z.ZodNumber>;
109
- }, z.core.$strip>;
110
- declare const NumberParamSchema: z.ZodObject<{
111
- name: z.ZodString;
112
- description: z.ZodOptional<z.ZodString>;
113
- required: z.ZodDefault<z.ZodBoolean>;
114
- maxValue: z.ZodOptional<z.ZodNumber>;
115
- minValue: z.ZodOptional<z.ZodNumber>;
116
- }, z.core.$strip>;
117
- type BaseParamOptions = z.input<typeof BaseParamSchema>;
118
- type StringOptions = z.input<typeof StringParamSchema>;
119
- type NumberOptions = z.input<typeof NumberParamSchema>;
120
-
74
+ type ParamResolvedOutputType<OutputType, Required extends boolean = true> = Required extends true ? OutputType : OutputType | null;
121
75
  declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, Required extends boolean = true> {
76
+ private schema;
122
77
  options: Options & {
123
78
  required: Required;
124
79
  };
@@ -131,11 +86,14 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
131
86
  * @internal
132
87
  */
133
88
  readonly _type: Required extends true ? OutputType : OutputType | null;
134
- constructor(options: Options);
89
+ constructor(options: Options, schema: z.ZodObject);
135
90
  protected setOption(key: keyof Options, value: any): this;
136
91
  name(value: string): this;
137
92
  description(value: string): this;
138
93
  required<V extends boolean>(value: V): BaseParam<Options, OutputType, V>;
94
+ resolve(context: CommandContext, value?: string): Promise<ParamResolvedOutputType<OutputType, Required>>;
95
+ abstract resolveMessage(context: MessageContext, value: string): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
96
+ abstract resolveChatInput(context: ChatInputContext): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
139
97
  /**
140
98
  * Helper to normalize string inputs into an options object.
141
99
  */
@@ -144,6 +102,8 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
144
102
  declare class StringParam<Required extends boolean = true> extends BaseParam<StringOptions, string, Required> {
145
103
  constructor(options: string | StringOptions);
146
104
  required<V extends boolean>(value: V): StringParam<V>;
105
+ resolveMessage(_context: CommandContext, value: string): ParamResolvedOutputType<string, Required>;
106
+ resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<string, Required>;
147
107
  /**
148
108
  * Sets the minimum allowed length for this string.
149
109
  * Pass `null` to remove this constraint.
@@ -158,6 +118,8 @@ declare class StringParam<Required extends boolean = true> extends BaseParam<Str
158
118
  declare class NumberParam<Required extends boolean = true> extends BaseParam<NumberOptions, number, Required> {
159
119
  constructor(options: string | NumberOptions);
160
120
  required<V extends boolean>(value: V): NumberParam<V>;
121
+ resolveMessage(_context: CommandContext, value: string): ParamResolvedOutputType<number, Required>;
122
+ resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<number, Required>;
161
123
  /**
162
124
  * Sets the minimum allowed value for this number.
163
125
  * Pass `null` to remove this constraint.
@@ -169,6 +131,12 @@ declare class NumberParam<Required extends boolean = true> extends BaseParam<Num
169
131
  */
170
132
  max(value: number | null): this;
171
133
  }
134
+ declare class UserParam<Required extends boolean = true> extends BaseParam<UserOptions, User, Required> {
135
+ constructor(options: string | UserOptions);
136
+ required<V extends boolean>(value: V): UserParam<V>;
137
+ resolveMessage(context: CommandContext, value: string): Promise<ParamResolvedOutputType<User, Required>>;
138
+ resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<User, Required>;
139
+ }
172
140
  type AnyParam<Required extends boolean = true> = BaseParam<any, any, Required>;
173
141
  /**
174
142
  * Helper type to extract the runtime value of a Param instance.
@@ -182,10 +150,40 @@ type InferParamTuple<T extends readonly BaseParam<any, any, any>[]> = {
182
150
  [K in keyof T]: T[K] extends AnyParam<any> ? InferParamValue<T[K]> : never;
183
151
  };
184
152
 
153
+ declare enum HookState {
154
+ Pre = "PRE",
155
+ Main = "MAIN",
156
+ Post = "POST",
157
+ Error = "ERROR"
158
+ }
159
+ declare enum HookOrder {
160
+ First = 0,
161
+ Last = 1
162
+ }
163
+ type MainHookCallback<C extends Context, Args extends unknown[]> = (context: C, ...args: Args) => Awaitable<void>;
164
+ type ErrorHookCallback<C extends Context, Args extends unknown[]> = (context: C, error: unknown, ...args: Args) => Awaitable<void>;
165
+ declare class LifecycleManager<C extends Context, Args extends unknown[]> {
166
+ id: string;
167
+ private readonly hooks;
168
+ constructor(id: string);
169
+ getName(name: string): string;
170
+ setHook(name: string, state: HookState.Post, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
171
+ setHook(name: string, state: HookState.Main, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
172
+ setHook(name: string, state: HookState.Pre, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
173
+ setHook(name: string, state: HookState.Error, callback: ErrorHookCallback<C, Args>, order?: HookOrder): this;
174
+ main(callback: MainHookCallback<C, Args>): this;
175
+ pre(callback: MainHookCallback<C, Args>): this;
176
+ post(callback: MainHookCallback<C, Args>): this;
177
+ error(callback: ErrorHookCallback<C, Args>): this;
178
+ execute(context: C, ...args: Args): Promise<void>;
179
+ }
180
+
181
+ declare function validateParamsOrder(params: readonly AnyParam<boolean>[]): boolean;
185
182
  declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
186
- name: z.ZodString;
187
- description: z.ZodOptional<z.ZodString>;
188
- params: z.ZodDefault<z.ZodArray<z.ZodCustom<BaseParam<{
183
+ name: z.ZodReadonly<z.ZodString>;
184
+ description: z.ZodReadonly<z.ZodOptional<z.ZodString>>;
185
+ nsfw: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
186
+ params: z.ZodReadonly<z.ZodDefault<z.ZodArray<z.ZodCustom<BaseParam<{
189
187
  name: string;
190
188
  description?: string | undefined;
191
189
  required?: boolean | undefined;
@@ -193,22 +191,27 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
193
191
  name: string;
194
192
  description?: string | undefined;
195
193
  required?: boolean | undefined;
196
- }, unknown, boolean>>>>;
197
- }, z.core.$strip>, z.ZodTransform<{
194
+ }, unknown, boolean>>>>>;
195
+ quotes: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
196
+ }, z.z.core.$strip>, z.ZodTransform<{
198
197
  description: string;
199
198
  name: string;
200
- params: BaseParam<{
199
+ nsfw: boolean;
200
+ params: readonly BaseParam<{
201
201
  name: string;
202
202
  description?: string | undefined;
203
203
  required?: boolean | undefined;
204
204
  }, unknown, boolean>[];
205
+ quotes: boolean;
205
206
  }, {
206
207
  name: string;
207
- params: BaseParam<{
208
+ nsfw: boolean;
209
+ params: readonly BaseParam<{
208
210
  name: string;
209
211
  description?: string | undefined;
210
212
  required?: boolean | undefined;
211
213
  }, unknown, boolean>[];
214
+ quotes: boolean;
212
215
  description?: string | undefined;
213
216
  }>>;
214
217
  type CommandOptionsInput = z.input<typeof CommandOptionsSchema>;
@@ -216,13 +219,17 @@ type CommandOptions = z.output<typeof CommandOptionsSchema>;
216
219
  /**
217
220
  * The command entry, used for registering command.
218
221
  */
219
- declare class Command<ParamsList extends readonly AnyParam<any>[] = []> extends LifecycleManager<CommandContext, [
222
+ declare class Command<ParamsList extends readonly AnyParam<any>[] = any[]> extends LifecycleManager<CommandContext, [
220
223
  ...args: InferParamTuple<ParamsList>
221
224
  ]> {
222
225
  options: CommandOptions;
223
226
  constructor(options: (Omit<CommandOptionsInput, "params"> & {
224
227
  params?: ParamsList;
225
228
  }) | string);
229
+ private handleSyntaxError;
230
+ toSlashCommandJSON(): discord_js.RESTPostAPIChatInputApplicationCommandsJSONBody;
231
+ private initSlashCommandOptions;
232
+ private initSlashCommandOption;
226
233
  }
227
234
  /**
228
235
  * Define command entry, usually for modules.
@@ -244,7 +251,7 @@ declare class Command<ParamsList extends readonly AnyParam<any>[] = []> extends
244
251
  * export default command;
245
252
  * ```
246
253
  */
247
- declare function defineCommand<const ParamsList extends readonly AnyParam<any>[] = []>(options: (Omit<CommandOptionsInput, "params"> & {
254
+ declare function defineCommand<const ParamsList extends readonly AnyParam<any>[] = any[]>(options: (Omit<CommandOptionsInput, "params"> & {
248
255
  params?: ParamsList;
249
256
  }) | string): Command<ParamsList>;
250
257
 
@@ -254,22 +261,52 @@ declare class BaseClientManager {
254
261
  }
255
262
 
256
263
  declare class CommandManager extends BaseClientManager {
257
- commands: Collection<string, Command<[]>>;
258
- loadModules(): Promise<Command[]>;
264
+ commands: Collection<string, Command<any[]>>;
265
+ entries: Collection<string, Command<any[]>>;
266
+ loadModules(entryDir: string): Promise<Command[]>;
267
+ /**
268
+ * Load the file and add the command to the registry.
269
+ * @param path The path to the command file.
270
+ * @returns The command object if added successfully.
271
+ */
272
+ load(path: string): Promise<Command | undefined>;
273
+ /**
274
+ * Unload the file and remove the command from the registry.
275
+ * @param path The path to the command file.
276
+ * @returns The command object if unloaded successfully.
277
+ */
278
+ unload(path: string): Promise<Command | undefined>;
279
+ reload(path: string): Promise<Command<any[]> | undefined>;
280
+ /**
281
+ * Add a command to the registry.
282
+ * @param command Command to add.
283
+ */
259
284
  add(command: Command): void;
285
+ /**
286
+ * Remove a command from the registry.
287
+ * @param target Command name or object to remove.
288
+ * @returns The command object if removed successfully.
289
+ */
260
290
  remove(target: string | Command): Command | undefined;
261
- get(name: string): Command<[]> | undefined;
291
+ /**
292
+ * Get a command using its name.
293
+ * @param name The command to get.
294
+ * @returns The command object.
295
+ */
296
+ get(name: string): Command<any[]> | undefined;
262
297
  }
263
298
 
264
- declare const ListenerOptionsSchema: z$1.ZodObject<{
265
- name: z$1.ZodEnum<typeof Events>;
266
- once: z$1.ZodDefault<z$1.ZodBoolean>;
267
- }, z$1.z.core.$strip>;
268
- type ListenerOptions<K extends EventKey = EventKey> = Omit<z$1.input<typeof ListenerOptionsSchema>, "name"> & {
299
+ declare const ListenerOptionsSchema: z.ZodObject<{
300
+ name: z.ZodEnum<typeof Events>;
301
+ once: z.ZodDefault<z.ZodBoolean>;
302
+ }, z.z.core.$strip>;
303
+ type ListenerOptions<K extends EventKey = EventKey> = Omit<z.input<typeof ListenerOptionsSchema>, "name"> & {
269
304
  name: K;
270
305
  };
271
- type EventKey = keyof ClientEvents;
272
- declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [...args: ClientEvents[K]]> {
306
+ type EventKey = keyof BakitClientEvents;
307
+ declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [
308
+ ...args: BakitClientEvents[K]
309
+ ]> {
273
310
  options: ListenerOptions<K>;
274
311
  constructor(options: K | ListenerOptions<K>);
275
312
  }
@@ -277,11 +314,67 @@ declare function defineListener<const K extends EventKey = EventKey>(options: K
277
314
 
278
315
  declare class ListenerManager extends BaseClientManager {
279
316
  listeners: Listener[];
317
+ entries: Collection<string, Listener<keyof BakitClientEvents>>;
280
318
  private executors;
281
- loadModules(): Promise<Listener[]>;
319
+ loadModules(entryDir: string): Promise<Listener[]>;
320
+ /**
321
+ * Load the file and add the listener to the registry.
322
+ * @param path The path to the listener file.
323
+ * @returns The listener object if added successfully.
324
+ */
325
+ load(path: string): Promise<Listener | undefined>;
326
+ /**
327
+ * Unload the file and remove the listener from the registry.
328
+ * @param path The path to the listener file.
329
+ * @returns The listener object if unloaded successfully.
330
+ */
331
+ unload(path: string): Promise<Listener | undefined>;
332
+ reload(path: string): Promise<Listener<keyof BakitClientEvents> | undefined>;
333
+ /**
334
+ * Add a listener to the registry and create a listener for client.
335
+ * @param listener Listener to add.
336
+ */
282
337
  add(listener: Listener): void;
338
+ /**
339
+ * Remove a listener from the registry and client.
340
+ * @param target Listener name or object to remove.
341
+ * @returns The list of listener objects if removed successfully.
342
+ */
283
343
  remove(target: string | Listener): Listener[];
344
+ /**
345
+ * Get a list of required intents for Bakit to run correctly.
346
+ * @returns Used intents.
347
+ */
348
+ getBaseIntents(): IntentsBitField;
349
+ /**
350
+ * Get a list of needed intents based on registered listeners to receive needed events.
351
+ * @returns Used intents.
352
+ */
353
+ getNeededIntents(): IntentsBitField;
354
+ }
355
+
356
+ declare class ProjectCacheManager {
357
+ private readonly rootDir;
358
+ constructor(root?: string);
359
+ private ensureRoot;
360
+ getHash(data: unknown): string;
361
+ write(path: string, data: unknown): Promise<void>;
362
+ read<T>(path: string): Promise<T | null>;
363
+ clear(): Promise<void>;
364
+ clearSync(): void;
365
+ }
366
+
367
+ declare class Instance {
368
+ client: BakitClient;
369
+ cache: ProjectCacheManager;
370
+ constructor();
371
+ start(): Promise<void>;
372
+ private initProcess;
373
+ private loadModules;
374
+ private initIntents;
375
+ private onProcessMessage;
284
376
  }
377
+ declare function useApp(): Instance;
285
378
 
286
379
  type GetPrefixFunction = (message: Message) => Awaitable<string[] | string>;
287
380
  interface BakitClientEvents extends ClientEvents {
@@ -289,12 +382,12 @@ interface BakitClientEvents extends ClientEvents {
289
382
  clientReady: [BakitClient<true>];
290
383
  }
291
384
  declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready> {
385
+ instance: Instance;
292
386
  managers: {
293
387
  commands: CommandManager;
294
388
  listeners: ListenerManager;
295
389
  };
296
- constructor(options: ClientOptions);
297
- start(token?: string): Promise<string>;
390
+ constructor(options: ClientOptions, instance: Instance);
298
391
  /**
299
392
  * Check if the client is connected to gateway successfully and finished initialization.
300
393
  */
@@ -327,6 +420,63 @@ declare const Params: {
327
420
  maxValue?: number | undefined;
328
421
  minValue?: number | undefined;
329
422
  }) => NumberParam<Required>;
423
+ readonly user: <Required extends boolean = true>(options: string | {
424
+ name: string;
425
+ description?: string | undefined;
426
+ required?: boolean | undefined;
427
+ }) => UserParam<Required>;
330
428
  };
331
429
 
332
- export { type AnyParam, BakitClient, type BakitClientEvents, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, type ContextSendOptions, type GetPrefixFunction, type InferParamTuple, type InferParamValue, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, MessageContext, type MessageContextSendOptions, type NumberOptions, NumberParam, NumberParamSchema, ParamUserType, Params, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig };
430
+ declare const EVENT_INTENT_MAPPING: Record<string, number[]>;
431
+
432
+ declare class BakitError extends Error {
433
+ constructor(message: string);
434
+ }
435
+
436
+ declare class ArgumentError extends BakitError {
437
+ target: string;
438
+ reason: string;
439
+ constructor(target: string, reason: string);
440
+ }
441
+
442
+ declare function tokenize(content: string): string[];
443
+ /**
444
+ * Extracts a valid Discord Snowflake (User ID, Channel ID, etc.) from a string.
445
+ * @param input The raw string to parse
446
+ * @returns The extracted ID string, or null if invalid
447
+ */
448
+ declare function extractSnowflakeId(input: string): string | null;
449
+
450
+ declare function getTopLevelDirectory(path: string, entryDir: string): string | null;
451
+
452
+ declare const messageCommandHandler: Listener<Events.MessageCreate>;
453
+ declare const chatInputCommandHandler: Listener<Events.InteractionCreate>;
454
+ declare const registerCommandsHandler: Listener<Events.ClientReady>;
455
+
456
+ declare const ProjectConfigSchema: z.ZodObject<{
457
+ intents: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodBigInt, z.ZodArray<z.ZodEnum<typeof GatewayIntentBits>>]>>;
458
+ clientOptions: z.ZodOptional<z.ZodCustom<Omit<ClientOptions, "intents">, Omit<ClientOptions, "intents">>>;
459
+ prefixes: z.ZodDefault<z.ZodArray<z.ZodString>>;
460
+ token: z.ZodString;
461
+ }, z.z.core.$strip>;
462
+ type ProjectConfigInput = z.input<typeof ProjectConfigSchema>;
463
+ type ProjectConfig = z.output<typeof ProjectConfigSchema>;
464
+ /**
465
+ * Define config object for your project. This is just a cleaner way to define config.
466
+ * @param config The partial version of project config.
467
+ * @returns The same config you provided earlier.
468
+ */
469
+ declare function defineConfig(config: ProjectConfigInput): ProjectConfigInput;
470
+ /**
471
+ * Load the config file and save them for later usage.
472
+ * @param cwd The location of the config file, uses root by default.
473
+ * @returns The complete config with default values from the validation.
474
+ */
475
+ declare function loadConfig(cwd?: string): Promise<ProjectConfig>;
476
+ /**
477
+ * Get the loaded config of the project.
478
+ * @returns The project config.
479
+ */
480
+ declare function getConfig(): ProjectConfig;
481
+
482
+ export { type AnyParam, ArgumentError, BakitClient, type BakitClientEvents, BakitError, BaseClientManager, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, Context, type ContextSendOptions, EVENT_INTENT_MAPPING, type ErrorHookCallback, type GetPrefixFunction, HookOrder, HookState, type InferParamTuple, type InferParamValue, Instance, LifecycleManager, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, type MainHookCallback, MessageContext, type MessageContextSendOptions, type NumberOptions, NumberParam, NumberParamSchema, type ParamResolvedOutputType, ParamUserType, Params, ProjectCacheManager, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, type UserOptions, UserParam, UserParamSchema, chatInputCommandHandler, defineCommand, defineConfig, defineListener, extractSnowflakeId, getConfig, getTopLevelDirectory, loadConfig, messageCommandHandler, registerCommandsHandler, tokenize, useApp, validateParamsOrder };