bakit 2.0.0-alpha.3 → 2.0.0-alpha.30

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.ts CHANGED
@@ -1,34 +1,44 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { GatewayIntentBits, ClientOptions, ChatInputCommandInteraction, CacheType, Message, User, MessageCreateOptions, InteractionReplyOptions, Awaitable, Collection, ClientEvents, Events, IntentsBitField, 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
+ import EventEmitter from 'node:events';
6
+ import { Serializable, ChildProcess } from 'node:child_process';
7
+ import { MessagePort as MessagePort$1 } from 'node:worker_threads';
5
8
 
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
- prefixes: z.ZodDefault<z.ZodArray<z.ZodString>>;
11
- token: z.ZodString;
12
- }, z.core.$strip>;
13
- type ProjectConfigInput = z.input<typeof ProjectConfigSchema>;
14
- type ProjectConfig = z.output<typeof ProjectConfigSchema>;
15
- /**
16
- * Define config object for your project. This is just a cleaner way to define config.
17
- * @param config The partial version of project config.
18
- * @returns The same config you provided earlier.
19
- */
20
- declare function defineConfig(config: ProjectConfigInput): ProjectConfigInput;
21
- /**
22
- * Load the config file and save them for later usage.
23
- * @param cwd The location of the config file, uses root by default.
24
- * @returns The complete config with default values from the validation.
25
- */
26
- declare function loadConfig(cwd?: string): Promise<ProjectConfig>;
27
- /**
28
- * Get the loaded config of the project.
29
- * @returns The project config.
30
- */
31
- declare function getConfig(): ProjectConfig;
9
+ declare enum ParamUserType {
10
+ Bot = "bot",
11
+ Normal = "normal",
12
+ Any = "any"
13
+ }
14
+ declare const BaseParamSchema: z.ZodObject<{
15
+ name: z.ZodString;
16
+ description: z.ZodOptional<z.ZodString>;
17
+ required: z.ZodDefault<z.ZodBoolean>;
18
+ }, z.z.core.$strip>;
19
+ declare const StringParamSchema: z.ZodObject<{
20
+ name: z.ZodString;
21
+ description: z.ZodOptional<z.ZodString>;
22
+ required: z.ZodDefault<z.ZodBoolean>;
23
+ maxLength: z.ZodOptional<z.ZodNumber>;
24
+ minLength: z.ZodOptional<z.ZodNumber>;
25
+ }, z.z.core.$strip>;
26
+ declare const NumberParamSchema: z.ZodObject<{
27
+ name: z.ZodString;
28
+ description: z.ZodOptional<z.ZodString>;
29
+ required: z.ZodDefault<z.ZodBoolean>;
30
+ maxValue: z.ZodOptional<z.ZodNumber>;
31
+ minValue: z.ZodOptional<z.ZodNumber>;
32
+ }, z.z.core.$strip>;
33
+ declare const UserParamSchema: z.ZodObject<{
34
+ name: z.ZodString;
35
+ description: z.ZodOptional<z.ZodString>;
36
+ required: z.ZodDefault<z.ZodBoolean>;
37
+ }, z.z.core.$strip>;
38
+ type BaseParamOptions = z.input<typeof BaseParamSchema>;
39
+ type StringOptions = z.input<typeof StringParamSchema>;
40
+ type NumberOptions = z.input<typeof NumberParamSchema>;
41
+ type UserOptions = z.input<typeof UserParamSchema>;
32
42
 
33
43
  declare class Context {
34
44
  canceled: boolean;
@@ -64,64 +74,9 @@ declare class MessageContext<Cached extends boolean = boolean, InGuild extends b
64
74
  }
65
75
  type CommandContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> = ChatInputContext<Cached, InGuild> | MessageContext<Cached, InGuild>;
66
76
 
67
- declare enum HookState {
68
- Pre = "PRE",
69
- Main = "MAIN",
70
- Post = "POST",
71
- Error = "ERROR"
72
- }
73
- declare enum HookOrder {
74
- First = 0,
75
- Last = 1
76
- }
77
- type MainHookCallback<C extends Context, Args extends unknown[]> = (context: C, ...args: Args) => Awaitable<void>;
78
- type ErrorHookCallback<C extends Context, Args extends unknown[]> = (context: C, error: unknown, ...args: Args) => Awaitable<void>;
79
- declare class LifecycleManager<C extends Context, Args extends unknown[]> {
80
- id: string;
81
- private readonly hooks;
82
- constructor(id: string);
83
- getName(name: string): string;
84
- setHook(name: string, state: HookState.Post, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
85
- setHook(name: string, state: HookState.Main, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
86
- setHook(name: string, state: HookState.Pre, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
87
- setHook(name: string, state: HookState.Error, callback: ErrorHookCallback<C, Args>, order?: HookOrder): this;
88
- main(callback: MainHookCallback<C, Args>): this;
89
- pre(callback: MainHookCallback<C, Args>): this;
90
- post(callback: MainHookCallback<C, Args>): this;
91
- error(callback: ErrorHookCallback<C, Args>): this;
92
- execute(context: C, ...args: Args): Promise<void>;
93
- }
94
-
95
- declare enum ParamUserType {
96
- Bot = "bot",
97
- Normal = "normal",
98
- Any = "any"
99
- }
100
- declare const BaseParamSchema: z.ZodObject<{
101
- name: z.ZodString;
102
- description: z.ZodOptional<z.ZodString>;
103
- required: z.ZodDefault<z.ZodBoolean>;
104
- }, z.core.$strip>;
105
- declare const StringParamSchema: z.ZodObject<{
106
- name: z.ZodString;
107
- description: z.ZodOptional<z.ZodString>;
108
- required: z.ZodDefault<z.ZodBoolean>;
109
- maxLength: z.ZodOptional<z.ZodNumber>;
110
- minLength: z.ZodOptional<z.ZodNumber>;
111
- }, z.core.$strip>;
112
- declare const NumberParamSchema: z.ZodObject<{
113
- name: z.ZodString;
114
- description: z.ZodOptional<z.ZodString>;
115
- required: z.ZodDefault<z.ZodBoolean>;
116
- maxValue: z.ZodOptional<z.ZodNumber>;
117
- minValue: z.ZodOptional<z.ZodNumber>;
118
- }, z.core.$strip>;
119
- type BaseParamOptions = z.input<typeof BaseParamSchema>;
120
- type StringOptions = z.input<typeof StringParamSchema>;
121
- type NumberOptions = z.input<typeof NumberParamSchema>;
122
-
123
77
  type ParamResolvedOutputType<OutputType, Required extends boolean = true> = Required extends true ? OutputType : OutputType | null;
124
78
  declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, Required extends boolean = true> {
79
+ private schema;
125
80
  options: Options & {
126
81
  required: Required;
127
82
  };
@@ -134,13 +89,13 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
134
89
  * @internal
135
90
  */
136
91
  readonly _type: Required extends true ? OutputType : OutputType | null;
137
- constructor(options: Options);
92
+ constructor(options: Options, schema: z.ZodObject);
138
93
  protected setOption(key: keyof Options, value: any): this;
139
94
  name(value: string): this;
140
95
  description(value: string): this;
141
96
  required<V extends boolean>(value: V): BaseParam<Options, OutputType, V>;
142
97
  resolve(context: CommandContext, value?: string): Promise<ParamResolvedOutputType<OutputType, Required>>;
143
- abstract resolveMessage(context: MessageContext, value: string | undefined): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
98
+ abstract resolveMessage(context: MessageContext, value: string): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
144
99
  abstract resolveChatInput(context: ChatInputContext): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
145
100
  /**
146
101
  * Helper to normalize string inputs into an options object.
@@ -150,7 +105,7 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
150
105
  declare class StringParam<Required extends boolean = true> extends BaseParam<StringOptions, string, Required> {
151
106
  constructor(options: string | StringOptions);
152
107
  required<V extends boolean>(value: V): StringParam<V>;
153
- resolveMessage(_context: CommandContext, value: string | undefined): ParamResolvedOutputType<string, Required>;
108
+ resolveMessage(_context: CommandContext, value: string): ParamResolvedOutputType<string, Required>;
154
109
  resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<string, Required>;
155
110
  /**
156
111
  * Sets the minimum allowed length for this string.
@@ -166,7 +121,7 @@ declare class StringParam<Required extends boolean = true> extends BaseParam<Str
166
121
  declare class NumberParam<Required extends boolean = true> extends BaseParam<NumberOptions, number, Required> {
167
122
  constructor(options: string | NumberOptions);
168
123
  required<V extends boolean>(value: V): NumberParam<V>;
169
- resolveMessage(ctx: CommandContext, value: string | undefined): ParamResolvedOutputType<number, Required>;
124
+ resolveMessage(_context: CommandContext, value: string): ParamResolvedOutputType<number, Required>;
170
125
  resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<number, Required>;
171
126
  /**
172
127
  * Sets the minimum allowed value for this number.
@@ -179,6 +134,12 @@ declare class NumberParam<Required extends boolean = true> extends BaseParam<Num
179
134
  */
180
135
  max(value: number | null): this;
181
136
  }
137
+ declare class UserParam<Required extends boolean = true> extends BaseParam<UserOptions, User, Required> {
138
+ constructor(options: string | UserOptions);
139
+ required<V extends boolean>(value: V): UserParam<V>;
140
+ resolveMessage(context: CommandContext, value: string): Promise<ParamResolvedOutputType<User, Required>>;
141
+ resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<User, Required>;
142
+ }
182
143
  type AnyParam<Required extends boolean = true> = BaseParam<any, any, Required>;
183
144
  /**
184
145
  * Helper type to extract the runtime value of a Param instance.
@@ -192,10 +153,40 @@ type InferParamTuple<T extends readonly BaseParam<any, any, any>[]> = {
192
153
  [K in keyof T]: T[K] extends AnyParam<any> ? InferParamValue<T[K]> : never;
193
154
  };
194
155
 
156
+ declare enum HookState {
157
+ Pre = "PRE",
158
+ Main = "MAIN",
159
+ Post = "POST",
160
+ Error = "ERROR"
161
+ }
162
+ declare enum HookOrder {
163
+ First = 0,
164
+ Last = 1
165
+ }
166
+ type MainHookCallback<C extends Context, Args extends unknown[]> = (context: C, ...args: Args) => Awaitable<void>;
167
+ type ErrorHookCallback<C extends Context, Args extends unknown[]> = (context: C, error: unknown, ...args: Args) => Awaitable<void>;
168
+ declare class LifecycleManager<C extends Context, Args extends unknown[]> {
169
+ id: string;
170
+ private readonly hooks;
171
+ constructor(id: string);
172
+ getName(name: string): string;
173
+ setHook(name: string, state: HookState.Post, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
174
+ setHook(name: string, state: HookState.Main, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
175
+ setHook(name: string, state: HookState.Pre, callback: MainHookCallback<C, Args>, order?: HookOrder): this;
176
+ setHook(name: string, state: HookState.Error, callback: ErrorHookCallback<C, Args>, order?: HookOrder): this;
177
+ main(callback: MainHookCallback<C, Args>): this;
178
+ pre(callback: MainHookCallback<C, Args>): this;
179
+ post(callback: MainHookCallback<C, Args>): this;
180
+ error(callback: ErrorHookCallback<C, Args>): this;
181
+ execute(context: C, ...args: Args): Promise<void>;
182
+ }
183
+
184
+ declare function validateParamsOrder(params: readonly AnyParam<boolean>[]): boolean;
195
185
  declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
196
- name: z.ZodString;
197
- description: z.ZodOptional<z.ZodString>;
198
- params: z.ZodDefault<z.ZodArray<z.ZodCustom<BaseParam<{
186
+ name: z.ZodReadonly<z.ZodString>;
187
+ description: z.ZodReadonly<z.ZodOptional<z.ZodString>>;
188
+ nsfw: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
189
+ params: z.ZodReadonly<z.ZodDefault<z.ZodArray<z.ZodCustom<BaseParam<{
199
190
  name: string;
200
191
  description?: string | undefined;
201
192
  required?: boolean | undefined;
@@ -203,12 +194,13 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
203
194
  name: string;
204
195
  description?: string | undefined;
205
196
  required?: boolean | undefined;
206
- }, unknown, boolean>>>>;
207
- quotes: z.ZodDefault<z.ZodBoolean>;
208
- }, z.core.$strip>, z.ZodTransform<{
197
+ }, unknown, boolean>>>>>;
198
+ quotes: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
199
+ }, z.z.core.$strip>, z.ZodTransform<{
209
200
  description: string;
210
201
  name: string;
211
- params: BaseParam<{
202
+ nsfw: boolean;
203
+ params: readonly BaseParam<{
212
204
  name: string;
213
205
  description?: string | undefined;
214
206
  required?: boolean | undefined;
@@ -216,7 +208,8 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
216
208
  quotes: boolean;
217
209
  }, {
218
210
  name: string;
219
- params: BaseParam<{
211
+ nsfw: boolean;
212
+ params: readonly BaseParam<{
220
213
  name: string;
221
214
  description?: string | undefined;
222
215
  required?: boolean | undefined;
@@ -237,6 +230,9 @@ declare class Command<ParamsList extends readonly AnyParam<any>[] = any[]> exten
237
230
  params?: ParamsList;
238
231
  }) | string);
239
232
  private handleSyntaxError;
233
+ toSlashCommandJSON(): discord_js.RESTPostAPIChatInputApplicationCommandsJSONBody;
234
+ private initSlashCommandOptions;
235
+ private initSlashCommandOption;
240
236
  }
241
237
  /**
242
238
  * Define command entry, usually for modules.
@@ -262,54 +258,147 @@ declare function defineCommand<const ParamsList extends readonly AnyParam<any>[]
262
258
  params?: ParamsList;
263
259
  }) | string): Command<ParamsList>;
264
260
 
265
- declare class BaseClientManager {
266
- client: BakitClient;
267
- constructor(client: BakitClient);
261
+ declare abstract class HotReloadable {
262
+ entryDirectory: string;
263
+ constructor(entryDirectory: string);
264
+ abstract unload(path: string): Promise<unknown>;
265
+ abstract load(path: string): Promise<unknown>;
266
+ abstract reload(path: string): Promise<unknown>;
267
+ protected unloadFile(path: string): Promise<boolean>;
268
268
  }
269
269
 
270
- declare class CommandManager extends BaseClientManager {
270
+ declare class CommandManager extends HotReloadable {
271
+ client: BakitClient;
271
272
  commands: Collection<string, Command<any[]>>;
273
+ entries: Collection<string, Command<any[]>>;
274
+ constructor(client: BakitClient);
272
275
  loadModules(): Promise<Command[]>;
276
+ /**
277
+ * Load the file and add the command to the registry.
278
+ * @param path The path to the command file.
279
+ * @returns The command object if added successfully.
280
+ */
281
+ load(path: string): Promise<Command | undefined>;
282
+ /**
283
+ * Unload the file and remove the command from the registry.
284
+ * @param path The path to the command file.
285
+ * @returns The command object if unloaded successfully.
286
+ */
287
+ unload(path: string): Promise<Command | undefined>;
288
+ reload(path: string): Promise<Command<any[]> | undefined>;
289
+ /**
290
+ * Add a command to the registry.
291
+ * @param command Command to add.
292
+ */
273
293
  add(command: Command): void;
294
+ /**
295
+ * Remove a command from the registry.
296
+ * @param target Command name or object to remove.
297
+ * @returns The command object if removed successfully.
298
+ */
274
299
  remove(target: string | Command): Command | undefined;
300
+ /**
301
+ * Get a command using its name.
302
+ * @param name The command to get.
303
+ * @returns The command object.
304
+ */
275
305
  get(name: string): Command<any[]> | undefined;
276
306
  }
277
307
 
278
- declare const ListenerOptionsSchema: z$1.ZodObject<{
279
- name: z$1.ZodEnum<typeof Events>;
280
- once: z$1.ZodDefault<z$1.ZodBoolean>;
281
- }, z$1.z.core.$strip>;
282
- type ListenerOptions<K extends EventKey = EventKey> = Omit<z$1.input<typeof ListenerOptionsSchema>, "name"> & {
308
+ declare const ListenerOptionsSchema: z.ZodObject<{
309
+ name: z.ZodEnum<typeof Events>;
310
+ once: z.ZodDefault<z.ZodBoolean>;
311
+ }, z.z.core.$strip>;
312
+ type ListenerOptions<K extends EventKey = EventKey> = Omit<z.input<typeof ListenerOptionsSchema>, "name"> & {
283
313
  name: K;
284
314
  };
285
- type EventKey = keyof ClientEvents;
286
- declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [...args: ClientEvents[K]]> {
315
+ type EventKey = keyof BakitClientEvents;
316
+ declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [
317
+ ...args: BakitClientEvents[K]
318
+ ]> {
287
319
  options: ListenerOptions<K>;
288
320
  constructor(options: K | ListenerOptions<K>);
289
321
  }
290
322
  declare function defineListener<const K extends EventKey = EventKey>(options: K | ListenerOptions<K>): Listener<K>;
291
323
 
292
- declare class ListenerManager extends BaseClientManager {
324
+ declare class ListenerManager extends HotReloadable {
325
+ client: BakitClient;
293
326
  listeners: Listener[];
327
+ entries: Collection<string, Listener<keyof BakitClientEvents>>;
294
328
  private executors;
329
+ constructor(client: BakitClient);
295
330
  loadModules(): Promise<Listener[]>;
331
+ /**
332
+ * Load the file and add the listener to the registry.
333
+ * @param path The path to the listener file.
334
+ * @returns The listener object if added successfully.
335
+ */
336
+ load(path: string): Promise<Listener | undefined>;
337
+ /**
338
+ * Unload the file and remove the listener from the registry.
339
+ * @param path The path to the listener file.
340
+ * @returns The listener object if unloaded successfully.
341
+ */
342
+ unload(path: string): Promise<Listener | undefined>;
343
+ reload(path: string): Promise<Listener<keyof BakitClientEvents> | undefined>;
344
+ /**
345
+ * Add a listener to the registry and create a listener for client.
346
+ * @param listener Listener to add.
347
+ */
296
348
  add(listener: Listener): void;
349
+ /**
350
+ * Remove a listener from the registry and client.
351
+ * @param target Listener name or object to remove.
352
+ * @returns The list of listener objects if removed successfully.
353
+ */
297
354
  remove(target: string | Listener): Listener[];
355
+ /**
356
+ * Get a list of required intents for Bakit to run correctly.
357
+ * @returns Used intents.
358
+ */
298
359
  getBaseIntents(): IntentsBitField;
360
+ /**
361
+ * Get a list of needed intents based on registered listeners to receive needed events.
362
+ * @returns Used intents.
363
+ */
299
364
  getNeededIntents(): IntentsBitField;
300
365
  }
301
366
 
367
+ declare class ProjectCacheManager {
368
+ private readonly rootDir;
369
+ constructor(root?: string);
370
+ private ensureRoot;
371
+ getHash(data: unknown): string;
372
+ write(path: string, data: unknown): Promise<void>;
373
+ read<T>(path: string): Promise<T | null>;
374
+ clear(): Promise<void>;
375
+ clearSync(): void;
376
+ }
377
+
378
+ declare class Instance {
379
+ client: BakitClient;
380
+ cache: ProjectCacheManager;
381
+ constructor();
382
+ start(): Promise<void>;
383
+ private initProcess;
384
+ private loadModules;
385
+ private initIntents;
386
+ shutdown(): Promise<void>;
387
+ }
388
+ declare function useApp(): Instance;
389
+
302
390
  type GetPrefixFunction = (message: Message) => Awaitable<string[] | string>;
303
391
  interface BakitClientEvents extends ClientEvents {
304
392
  ready: [BakitClient<true>];
305
393
  clientReady: [BakitClient<true>];
306
394
  }
307
395
  declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready> {
396
+ instance: Instance;
308
397
  managers: {
309
398
  commands: CommandManager;
310
399
  listeners: ListenerManager;
311
400
  };
312
- constructor(options: ClientOptions);
401
+ constructor(options: ClientOptions, instance: Instance);
313
402
  /**
314
403
  * Check if the client is connected to gateway successfully and finished initialization.
315
404
  */
@@ -327,6 +416,11 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
327
416
  [inspect.custom](): string;
328
417
  }
329
418
 
419
+ declare class BaseClientManager {
420
+ client: BakitClient;
421
+ constructor(client: BakitClient);
422
+ }
423
+
330
424
  declare const Params: {
331
425
  readonly string: <Required extends boolean = true>(options: string | {
332
426
  name: string;
@@ -342,6 +436,239 @@ declare const Params: {
342
436
  maxValue?: number | undefined;
343
437
  minValue?: number | undefined;
344
438
  }) => NumberParam<Required>;
439
+ readonly user: <Required extends boolean = true>(options: string | {
440
+ name: string;
441
+ description?: string | undefined;
442
+ required?: boolean | undefined;
443
+ }) => UserParam<Required>;
345
444
  };
346
445
 
347
- 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, type ParamResolvedOutputType, ParamUserType, Params, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig };
446
+ declare const EVENT_INTENT_MAPPING: Record<string, number[]>;
447
+
448
+ declare class BakitError extends Error {
449
+ constructor(message: string);
450
+ }
451
+
452
+ declare class ArgumentError extends BakitError {
453
+ target: string;
454
+ reason: string;
455
+ constructor(target: string, reason: string);
456
+ }
457
+
458
+ declare function tokenize(content: string): string[];
459
+ /**
460
+ * Extracts a valid Discord Snowflake (User ID, Channel ID, etc.) from a string.
461
+ * @param input The raw string to parse
462
+ * @returns The extracted ID string, or null if invalid
463
+ */
464
+ declare function extractSnowflakeId(input: string): string | null;
465
+
466
+ declare function getTopLevelDirectory(path: string, entryDir: string): string | null;
467
+ declare function getEntryDirectory(): string;
468
+ declare function getEntryFile(): string;
469
+
470
+ declare const hotReloaders: Collection<string, HotReloadable>;
471
+ /**
472
+ * Initliazie the loader
473
+ */
474
+ declare function init(): void;
475
+ /**
476
+ * Register a reloader for HMR.
477
+ * @param reloader Reloader extended from HotReloadable.
478
+ */
479
+ declare function addHotReloader(reloader: HotReloadable): void;
480
+ /**
481
+ * Remove the previous version of the file.
482
+ * @param path Path to unload.
483
+ * @returns `true` for unloaded successfully, `false` for unload failed.
484
+ */
485
+ declare function unload(path: string): Promise<boolean>;
486
+ /**
487
+ * Get a list of the files which imported the target.
488
+ * @param path Target file path to get.
489
+ * @param createNew Create a new Set cache for the target path.
490
+ */
491
+ declare function getImporters(path: string, createNew?: false): Set<string> | undefined;
492
+ declare function getImporters(path: string, createNew: true): Set<string>;
493
+ /**
494
+ * Get a list of the files which imported the target.
495
+ * @param path Target file path to get.
496
+ * @param createNew Create a new Set cache for the target path.
497
+ */
498
+ declare function getImports(path: string): string[];
499
+ /**
500
+ * Get a chain of dependencies for affected files.
501
+ * @param path
502
+ * @returns An array of affected dependencies.
503
+ */
504
+ declare function getDependencyChain(path: string): string[];
505
+ /**
506
+ * Checks if the target file imports any of the files in the 'targets' set.
507
+ * @param path The file path to check.
508
+ * @param targets The list of the files to check.
509
+ */
510
+ declare function importsAny(path: string, targets: Set<string>): boolean;
511
+ /**
512
+ * Check if the file is imported by the others.
513
+ * @param path The path of the file to check.
514
+ * @returns `boolean`
515
+ */
516
+ declare function isImported(path: string): boolean;
517
+ /**
518
+ * Check if the file is imported by a specific target.
519
+ * @param path The path of the file to check.
520
+ * @param matcher The target condition to match.
521
+ * @returns `boolean`
522
+ */
523
+ declare function isImportedBy(path: string, matcher: string | RegExp | ((path: string) => boolean)): boolean;
524
+ /**
525
+ * Check if the file is under a hmr directory.
526
+ * @param path The path of the file to check.
527
+ * @returns `boolean`
528
+ */
529
+ declare function isInHotDirectory(path: string): boolean | undefined;
530
+ /**
531
+ * Check if the file is the entry file (e.g, index.ts)
532
+ * @param path The path of the file to check.
533
+ * @returns `boolean`
534
+ */
535
+ declare function isEntryFile(path: string): boolean;
536
+ /**
537
+ * Check if the file chain includes the entry file (e.g, index.ts)
538
+ * @param path The chain of the files to check.
539
+ * @returns `boolean`
540
+ */
541
+ declare function containsEntryFile(chain: string[]): boolean;
542
+ /**
543
+ * Check if the file chain includes hmr files (e.g, index.ts)
544
+ * @param path The chain of the files to check.
545
+ * @returns `boolean`
546
+ */
547
+ declare function containsHotModule(chain: string[]): boolean;
548
+ /**
549
+ * Request to dev process manager to restart the process.
550
+ */
551
+ declare function restartProcess(): void;
552
+
553
+ declare const loader_addHotReloader: typeof addHotReloader;
554
+ declare const loader_containsEntryFile: typeof containsEntryFile;
555
+ declare const loader_containsHotModule: typeof containsHotModule;
556
+ declare const loader_getDependencyChain: typeof getDependencyChain;
557
+ declare const loader_getImporters: typeof getImporters;
558
+ declare const loader_getImports: typeof getImports;
559
+ declare const loader_hotReloaders: typeof hotReloaders;
560
+ declare const loader_importsAny: typeof importsAny;
561
+ declare const loader_init: typeof init;
562
+ declare const loader_isEntryFile: typeof isEntryFile;
563
+ declare const loader_isImported: typeof isImported;
564
+ declare const loader_isImportedBy: typeof isImportedBy;
565
+ declare const loader_isInHotDirectory: typeof isInHotDirectory;
566
+ declare const loader_restartProcess: typeof restartProcess;
567
+ declare const loader_unload: typeof unload;
568
+ declare namespace loader {
569
+ export { loader_addHotReloader as addHotReloader, loader_containsEntryFile as containsEntryFile, loader_containsHotModule as containsHotModule, loader_getDependencyChain as getDependencyChain, loader_getImporters as getImporters, loader_getImports as getImports, loader_hotReloaders as hotReloaders, loader_importsAny as importsAny, loader_init as init, loader_isEntryFile as isEntryFile, loader_isImported as isImported, loader_isImportedBy as isImportedBy, loader_isInHotDirectory as isInHotDirectory, loader_restartProcess as restartProcess, loader_unload as unload };
570
+ }
571
+
572
+ declare const RPC_RESPONSE_MARK = "$DONE:";
573
+ declare const RPC_RESPONSE_TIMEOUT = 5000;
574
+ interface BaseRPCMessage {
575
+ id: string;
576
+ }
577
+ interface BaseRPCResponse {
578
+ id: `${typeof RPC_RESPONSE_MARK}${string}`;
579
+ }
580
+ interface RPCRequest<Data extends Serializable = Serializable> extends BaseRPCMessage {
581
+ type: string;
582
+ data: Data;
583
+ }
584
+ interface RPCSuccessResponse<Data extends Serializable = Serializable> extends BaseRPCResponse {
585
+ data: Data;
586
+ }
587
+ interface RPCErrorResponse extends BaseRPCResponse {
588
+ error: string;
589
+ }
590
+ type RPCResponse<Data extends Serializable = Serializable> = RPCSuccessResponse<Data> | RPCErrorResponse;
591
+ type RPCMessage<Data extends Serializable = Serializable> = RPCRequest<Data> | RPCResponse<Data>;
592
+ interface RPCPendingPromise {
593
+ resolve: (data: any) => void;
594
+ reject: (error: unknown) => void;
595
+ timeout: NodeJS.Timeout;
596
+ }
597
+ declare class RPC extends EventEmitter {
598
+ transport: MessagePort$1 | NodeJS.Process | ChildProcess;
599
+ requests: Map<string, RPCPendingPromise>;
600
+ constructor(transport: MessagePort$1 | NodeJS.Process | ChildProcess);
601
+ postMessage(message: Serializable): void;
602
+ private onMessage;
603
+ private handleResponseMessage;
604
+ private handleRequestMessage;
605
+ send<Data extends Serializable>(type: string, data?: Data, id?: string): void;
606
+ success<Data extends Serializable>(id: string, data: Data): void;
607
+ error(id: string, error: string): void;
608
+ request<Data extends Serializable, Output extends Serializable>(type: string, data: Data, id?: string): Promise<Output>;
609
+ }
610
+
611
+ declare const messageCommandHandler: Listener<Events.MessageCreate>;
612
+ declare const chatInputCommandHandler: Listener<Events.InteractionCreate>;
613
+ declare const registerCommandsHandler: Listener<Events.ClientReady>;
614
+
615
+ declare const ProjectConfigSchema: z.ZodObject<{
616
+ intents: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodBigInt, z.ZodArray<z.ZodEnum<typeof GatewayIntentBits>>]>>;
617
+ clientOptions: z.ZodOptional<z.ZodCustom<Omit<ClientOptions, "intents">, Omit<ClientOptions, "intents">>>;
618
+ prefixes: z.ZodDefault<z.ZodArray<z.ZodString>>;
619
+ token: z.ZodString;
620
+ entryDirectory: z.ZodDefault<z.ZodString>;
621
+ }, z.z.core.$strip>;
622
+ type ProjectConfigInput = z.input<typeof ProjectConfigSchema>;
623
+ type ProjectConfig = z.output<typeof ProjectConfigSchema>;
624
+ /**
625
+ * Define config object for your project. This is just a cleaner way to define config.
626
+ * @param config The partial version of project config.
627
+ * @returns The same config you provided earlier.
628
+ */
629
+ declare function defineConfig(config: ProjectConfigInput): ProjectConfigInput;
630
+ /**
631
+ * Load the config file and save them for later usage.
632
+ * @param cwd The location of the config file, uses root by default.
633
+ * @returns The complete config with default values from the validation.
634
+ */
635
+ declare function loadConfig(cwd?: string): Promise<ProjectConfig>;
636
+ /**
637
+ * Get the loaded config of the project.
638
+ * @returns The project config.
639
+ */
640
+ declare function getConfig(): ProjectConfig;
641
+
642
+ interface InitializeData {
643
+ port: MessagePort;
644
+ }
645
+
646
+ interface ResolveContext {
647
+ conditions: string[];
648
+ importAttributes: Record<string, string>;
649
+ parentURL?: string;
650
+ }
651
+
652
+ interface ResolveResult {
653
+ url: string;
654
+ shortCircuit?: boolean;
655
+ format?: string | null | undefined;
656
+ importAttributes?: Record<string, string>;
657
+ }
658
+
659
+ interface LoadContext {
660
+ conditions: string[];
661
+ format: string | null | undefined;
662
+ importAttributes: Record<string, string>;
663
+ }
664
+
665
+ interface LoadResult {
666
+ source: string | ArrayBuffer | Uint8Array;
667
+ format: string;
668
+ shortCircuit?: boolean;
669
+ }
670
+
671
+ type NextResolve = (specifier: string, context: ResolveContext) => Promise<ResolveResult>;
672
+ type NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;
673
+
674
+ export { type AnyParam, ArgumentError, BakitClient, type BakitClientEvents, BakitError, BaseClientManager, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, type BaseRPCMessage, type BaseRPCResponse, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, Context, type ContextSendOptions, EVENT_INTENT_MAPPING, type ErrorHookCallback, type GetPrefixFunction, HookOrder, HookState, HotReloadable, type InferParamTuple, type InferParamValue, type InitializeData, Instance, LifecycleManager, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, type LoadContext, type LoadResult, loader as Loader, type MainHookCallback, MessageContext, type MessageContextSendOptions, type NextLoad, type NextResolve, type NumberOptions, NumberParam, NumberParamSchema, type ParamResolvedOutputType, ParamUserType, Params, ProjectCacheManager, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, RPC, type RPCErrorResponse, type RPCMessage, type RPCPendingPromise, type RPCRequest, type RPCResponse, type RPCSuccessResponse, RPC_RESPONSE_MARK, RPC_RESPONSE_TIMEOUT, type ResolveContext, type ResolveResult, type StringOptions, StringParam, StringParamSchema, type UserOptions, UserParam, UserParamSchema, chatInputCommandHandler, defineCommand, defineConfig, defineListener, extractSnowflakeId, getConfig, getEntryDirectory, getEntryFile, getTopLevelDirectory, loadConfig, messageCommandHandler, registerCommandsHandler, tokenize, useApp, validateParamsOrder };