bakit 2.0.0-alpha.32 → 2.0.0-alpha.34
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/LICENSE +21 -0
- package/dist/index.d.ts +1 -673
- package/dist/index.js +0 -1195
- package/package.json +61 -54
- package/README.md +0 -35
- package/dist/cli.js +0 -77
- package/dist/hooks.js +0 -82
- package/dist/register.js +0 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,674 +1,2 @@
|
|
|
1
|
-
import * as discord_js from 'discord.js';
|
|
2
|
-
import { ChatInputCommandInteraction, CacheType, Message, User, MessageCreateOptions, InteractionReplyOptions, Awaitable, Collection, Events, IntentsBitField, ClientEvents, Client, ClientOptions, GatewayIntentBits } from 'discord.js';
|
|
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';
|
|
8
1
|
|
|
9
|
-
|
|
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>;
|
|
42
|
-
|
|
43
|
-
declare class Context {
|
|
44
|
-
canceled: boolean;
|
|
45
|
-
cancel(): void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type ChatInputContextSendOptions = string | InteractionReplyOptions;
|
|
49
|
-
type MessageContextSendOptions = string | MessageCreateOptions;
|
|
50
|
-
type ContextSendOptions = ChatInputContextSendOptions | MessageContextSendOptions;
|
|
51
|
-
declare abstract class BaseCommandContext<Cached extends boolean, InGuild extends boolean> extends Context {
|
|
52
|
-
source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType> | Message<InGuild>;
|
|
53
|
-
constructor(source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType> | Message<InGuild>);
|
|
54
|
-
get client(): BakitClient<true>;
|
|
55
|
-
get channel(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.GuildTextBasedChannel | null, discord_js.GuildTextBasedChannel | null, discord_js.GuildTextBasedChannel | null, discord_js.TextBasedChannel | null> | discord_js.If<InGuild, discord_js.GuildTextBasedChannel, discord_js.TextBasedChannel>;
|
|
56
|
-
get channelId(): string;
|
|
57
|
-
get guild(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.Guild, null, discord_js.Guild | null, discord_js.Guild | null> | discord_js.If<InGuild, discord_js.Guild, null>;
|
|
58
|
-
get guildId(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, string, string, string, string | null> | discord_js.If<InGuild, string, null>;
|
|
59
|
-
get member(): discord_js.GuildMember | discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.GuildMember, discord_js.APIInteractionGuildMember, discord_js.GuildMember | discord_js.APIInteractionGuildMember, discord_js.GuildMember | discord_js.APIInteractionGuildMember | null> | null;
|
|
60
|
-
inGuild(): this is CommandContext<Cached, true>;
|
|
61
|
-
inCachedGuild(): this is CommandContext<true, true>;
|
|
62
|
-
get user(): User;
|
|
63
|
-
isChatInput(): this is ChatInputContext;
|
|
64
|
-
isMessage(): this is MessageContext;
|
|
65
|
-
abstract send(options: ContextSendOptions): Promise<Message<InGuild>>;
|
|
66
|
-
}
|
|
67
|
-
declare class ChatInputContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> extends BaseCommandContext<Cached, InGuild> {
|
|
68
|
-
source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType>;
|
|
69
|
-
send(options: ContextSendOptions): Promise<Message<InGuild>>;
|
|
70
|
-
}
|
|
71
|
-
declare class MessageContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> extends BaseCommandContext<Cached, InGuild> {
|
|
72
|
-
source: Message<InGuild>;
|
|
73
|
-
send(options: string | MessageCreateOptions): Promise<Message<InGuild>>;
|
|
74
|
-
}
|
|
75
|
-
type CommandContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> = ChatInputContext<Cached, InGuild> | MessageContext<Cached, InGuild>;
|
|
76
|
-
|
|
77
|
-
type ParamResolvedOutputType<OutputType, Required extends boolean = true> = Required extends true ? OutputType : OutputType | null;
|
|
78
|
-
declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, Required extends boolean = true> {
|
|
79
|
-
private schema;
|
|
80
|
-
options: Options & {
|
|
81
|
-
required: Required;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* **Internal Phantom Type**
|
|
85
|
-
*
|
|
86
|
-
* Used strictly for TypeScript type inference to determine the runtime value
|
|
87
|
-
* of this parameter. This property does not exist at runtime.
|
|
88
|
-
*
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
readonly _type: Required extends true ? OutputType : OutputType | null;
|
|
92
|
-
constructor(options: Options, schema: z.ZodObject);
|
|
93
|
-
protected setOption(key: keyof Options, value: any): this;
|
|
94
|
-
name(value: string): this;
|
|
95
|
-
description(value: string): this;
|
|
96
|
-
required<V extends boolean>(value: V): BaseParam<Options, OutputType, V>;
|
|
97
|
-
resolve(context: CommandContext, value?: string): Promise<ParamResolvedOutputType<OutputType, Required>>;
|
|
98
|
-
abstract resolveMessage(context: MessageContext, value: string): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
|
|
99
|
-
abstract resolveChatInput(context: ChatInputContext): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
|
|
100
|
-
/**
|
|
101
|
-
* Helper to normalize string inputs into an options object.
|
|
102
|
-
*/
|
|
103
|
-
protected static getOptions<Options>(options: Options | string): Options;
|
|
104
|
-
}
|
|
105
|
-
declare class StringParam<Required extends boolean = true> extends BaseParam<StringOptions, string, Required> {
|
|
106
|
-
constructor(options: string | StringOptions);
|
|
107
|
-
required<V extends boolean>(value: V): StringParam<V>;
|
|
108
|
-
resolveMessage(_context: CommandContext, value: string): ParamResolvedOutputType<string, Required>;
|
|
109
|
-
resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<string, Required>;
|
|
110
|
-
/**
|
|
111
|
-
* Sets the minimum allowed length for this string.
|
|
112
|
-
* Pass `null` to remove this constraint.
|
|
113
|
-
*/
|
|
114
|
-
min(length: number | null): this;
|
|
115
|
-
/**
|
|
116
|
-
* Sets the maximum allowed length for this string.
|
|
117
|
-
* Pass `null` to remove this constraint.
|
|
118
|
-
*/
|
|
119
|
-
max(length: number | null): this;
|
|
120
|
-
}
|
|
121
|
-
declare class NumberParam<Required extends boolean = true> extends BaseParam<NumberOptions, number, Required> {
|
|
122
|
-
constructor(options: string | NumberOptions);
|
|
123
|
-
required<V extends boolean>(value: V): NumberParam<V>;
|
|
124
|
-
resolveMessage(_context: CommandContext, value: string): ParamResolvedOutputType<number, Required>;
|
|
125
|
-
resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<number, Required>;
|
|
126
|
-
/**
|
|
127
|
-
* Sets the minimum allowed value for this number.
|
|
128
|
-
* Pass `null` to remove this constraint.
|
|
129
|
-
*/
|
|
130
|
-
min(value: number | null): this;
|
|
131
|
-
/**
|
|
132
|
-
* Sets the maximum allowed value for this number.
|
|
133
|
-
* Pass `null` to remove this constraint.
|
|
134
|
-
*/
|
|
135
|
-
max(value: number | null): this;
|
|
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
|
-
}
|
|
143
|
-
type AnyParam<Required extends boolean = true> = BaseParam<any, any, Required>;
|
|
144
|
-
/**
|
|
145
|
-
* Helper type to extract the runtime value of a Param instance.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* const p = new StringParam("name").required(false);
|
|
149
|
-
* type T = InferParamValue<typeof p>; // string | null
|
|
150
|
-
*/
|
|
151
|
-
type InferParamValue<P extends AnyParam<any>> = P["_type"];
|
|
152
|
-
type InferParamTuple<T extends readonly BaseParam<any, any, any>[]> = {
|
|
153
|
-
[K in keyof T]: T[K] extends AnyParam<any> ? InferParamValue<T[K]> : never;
|
|
154
|
-
};
|
|
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;
|
|
185
|
-
declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
|
|
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<{
|
|
190
|
-
name: string;
|
|
191
|
-
description?: string | undefined;
|
|
192
|
-
required?: boolean | undefined;
|
|
193
|
-
}, unknown, boolean>, BaseParam<{
|
|
194
|
-
name: string;
|
|
195
|
-
description?: string | undefined;
|
|
196
|
-
required?: boolean | undefined;
|
|
197
|
-
}, unknown, boolean>>>>>;
|
|
198
|
-
quotes: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
|
|
199
|
-
}, z.z.core.$strip>, z.ZodTransform<{
|
|
200
|
-
description: string;
|
|
201
|
-
name: string;
|
|
202
|
-
nsfw: boolean;
|
|
203
|
-
params: readonly BaseParam<{
|
|
204
|
-
name: string;
|
|
205
|
-
description?: string | undefined;
|
|
206
|
-
required?: boolean | undefined;
|
|
207
|
-
}, unknown, boolean>[];
|
|
208
|
-
quotes: boolean;
|
|
209
|
-
}, {
|
|
210
|
-
name: string;
|
|
211
|
-
nsfw: boolean;
|
|
212
|
-
params: readonly BaseParam<{
|
|
213
|
-
name: string;
|
|
214
|
-
description?: string | undefined;
|
|
215
|
-
required?: boolean | undefined;
|
|
216
|
-
}, unknown, boolean>[];
|
|
217
|
-
quotes: boolean;
|
|
218
|
-
description?: string | undefined;
|
|
219
|
-
}>>;
|
|
220
|
-
type CommandOptionsInput = z.input<typeof CommandOptionsSchema>;
|
|
221
|
-
type CommandOptions = z.output<typeof CommandOptionsSchema>;
|
|
222
|
-
/**
|
|
223
|
-
* The command entry, used for registering command.
|
|
224
|
-
*/
|
|
225
|
-
declare class Command<ParamsList extends readonly AnyParam<any>[] = any[]> extends LifecycleManager<CommandContext, [
|
|
226
|
-
...args: InferParamTuple<ParamsList>
|
|
227
|
-
]> {
|
|
228
|
-
options: CommandOptions;
|
|
229
|
-
constructor(options: (Omit<CommandOptionsInput, "params"> & {
|
|
230
|
-
params?: ParamsList;
|
|
231
|
-
}) | string);
|
|
232
|
-
private handleSyntaxError;
|
|
233
|
-
toSlashCommandJSON(): discord_js.RESTPostAPIChatInputApplicationCommandsJSONBody;
|
|
234
|
-
private initSlashCommandOptions;
|
|
235
|
-
private initSlashCommandOption;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Define command entry, usually for modules.
|
|
239
|
-
* @param options The command options.
|
|
240
|
-
* @returns The entry of the command to deploy or register hooks.
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* import { defineCommand } from "bakit";
|
|
244
|
-
*
|
|
245
|
-
* const command = defineCommand({
|
|
246
|
-
* name: "ping",
|
|
247
|
-
* description: "Displays bot's latency.",
|
|
248
|
-
* });
|
|
249
|
-
*
|
|
250
|
-
* command.main(async (context) => {
|
|
251
|
-
* await context.send(`Pong! ${context.client.ws.ping}ms!`);
|
|
252
|
-
* });
|
|
253
|
-
*
|
|
254
|
-
* export default command;
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
declare function defineCommand<const ParamsList extends readonly AnyParam<any>[] = any[]>(options: (Omit<CommandOptionsInput, "params"> & {
|
|
258
|
-
params?: ParamsList;
|
|
259
|
-
}) | string): Command<ParamsList>;
|
|
260
|
-
|
|
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
|
-
}
|
|
269
|
-
|
|
270
|
-
declare class CommandManager extends HotReloadable {
|
|
271
|
-
client: BakitClient;
|
|
272
|
-
commands: Collection<string, Command<any[]>>;
|
|
273
|
-
entries: Collection<string, Command<any[]>>;
|
|
274
|
-
constructor(client: BakitClient);
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
305
|
-
get(name: string): Command<any[]> | undefined;
|
|
306
|
-
}
|
|
307
|
-
|
|
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"> & {
|
|
313
|
-
name: K;
|
|
314
|
-
};
|
|
315
|
-
type EventKey = keyof BakitClientEvents;
|
|
316
|
-
declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [
|
|
317
|
-
...args: BakitClientEvents[K]
|
|
318
|
-
]> {
|
|
319
|
-
options: ListenerOptions<K>;
|
|
320
|
-
constructor(options: K | ListenerOptions<K>);
|
|
321
|
-
}
|
|
322
|
-
declare function defineListener<const K extends EventKey = EventKey>(options: K | ListenerOptions<K>): Listener<K>;
|
|
323
|
-
|
|
324
|
-
declare class ListenerManager extends HotReloadable {
|
|
325
|
-
client: BakitClient;
|
|
326
|
-
listeners: Listener[];
|
|
327
|
-
entries: Collection<string, Listener<keyof BakitClientEvents>>;
|
|
328
|
-
private executors;
|
|
329
|
-
constructor(client: BakitClient);
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
354
|
-
remove(target: string | Listener): Listener[];
|
|
355
|
-
/**
|
|
356
|
-
* Get a list of required intents for Bakit to run correctly.
|
|
357
|
-
* @returns Used intents.
|
|
358
|
-
*/
|
|
359
|
-
getBaseIntents(): IntentsBitField;
|
|
360
|
-
/**
|
|
361
|
-
* Get a list of needed intents based on registered listeners to receive needed events.
|
|
362
|
-
* @returns Used intents.
|
|
363
|
-
*/
|
|
364
|
-
getNeededIntents(): IntentsBitField;
|
|
365
|
-
}
|
|
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
|
-
|
|
390
|
-
type GetPrefixFunction = (message: Message) => Awaitable<string[] | string>;
|
|
391
|
-
interface BakitClientEvents extends ClientEvents {
|
|
392
|
-
ready: [BakitClient<true>];
|
|
393
|
-
clientReady: [BakitClient<true>];
|
|
394
|
-
}
|
|
395
|
-
declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
396
|
-
instance: Instance;
|
|
397
|
-
managers: {
|
|
398
|
-
commands: CommandManager;
|
|
399
|
-
listeners: ListenerManager;
|
|
400
|
-
};
|
|
401
|
-
constructor(options: ClientOptions, instance: Instance);
|
|
402
|
-
/**
|
|
403
|
-
* Check if the client is connected to gateway successfully and finished initialization.
|
|
404
|
-
*/
|
|
405
|
-
isReady(): this is BakitClient<true>;
|
|
406
|
-
on<K extends keyof BakitClientEvents>(event: K, listener: (...args: BakitClientEvents[K]) => void): this;
|
|
407
|
-
once<K extends keyof BakitClientEvents>(event: K, listener: (...args: BakitClientEvents[K]) => void): this;
|
|
408
|
-
off<K extends keyof BakitClientEvents>(event: K, listener: (...args: BakitClientEvents[K]) => void): this;
|
|
409
|
-
removeAllListeners(event?: keyof BakitClientEvents): this;
|
|
410
|
-
removeListener<K extends keyof BakitClientEvents>(event: K, listener: (...args: BakitClientEvents[K]) => void): this;
|
|
411
|
-
emit<K extends keyof BakitClientEvents>(event: K, ...args: BakitClientEvents[K]): boolean;
|
|
412
|
-
/**
|
|
413
|
-
* Override BakitClient output when using logger for security concern.
|
|
414
|
-
* @returns `BakitClient {}`
|
|
415
|
-
*/
|
|
416
|
-
[inspect.custom](): string;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
declare class BaseClientManager {
|
|
420
|
-
client: BakitClient;
|
|
421
|
-
constructor(client: BakitClient);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
declare const Params: {
|
|
425
|
-
readonly string: <Required extends boolean = true>(options: string | {
|
|
426
|
-
name: string;
|
|
427
|
-
description?: string | undefined;
|
|
428
|
-
required?: boolean | undefined;
|
|
429
|
-
maxLength?: number | undefined;
|
|
430
|
-
minLength?: number | undefined;
|
|
431
|
-
}) => StringParam<Required>;
|
|
432
|
-
readonly number: <Required extends boolean = true>(options: string | {
|
|
433
|
-
name: string;
|
|
434
|
-
description?: string | undefined;
|
|
435
|
-
required?: boolean | undefined;
|
|
436
|
-
maxValue?: number | undefined;
|
|
437
|
-
minValue?: number | undefined;
|
|
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>;
|
|
444
|
-
};
|
|
445
|
-
|
|
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 };
|
|
2
|
+
export { }
|