bakit 2.0.0-alpha.2 → 2.0.0-alpha.4
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 +44 -7
- package/dist/index.js +222 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
2
|
+
import { GatewayIntentBits, ClientOptions, ChatInputCommandInteraction, CacheType, Message, User, MessageCreateOptions, InteractionReplyOptions, Awaitable, Collection, ClientEvents, Events, IntentsBitField, Client } from 'discord.js';
|
|
3
3
|
import z$1, { z } from 'zod';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
|
|
@@ -7,6 +7,8 @@ declare const ProjectConfigSchema: z.ZodObject<{
|
|
|
7
7
|
intents: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodBigInt, z.ZodArray<z.ZodEnum<typeof GatewayIntentBits>>]>>;
|
|
8
8
|
clientOptions: z.ZodOptional<z.ZodCustom<Omit<ClientOptions, "intents">, Omit<ClientOptions, "intents">>>;
|
|
9
9
|
entryDir: z.ZodDefault<z.ZodString>;
|
|
10
|
+
prefixes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
11
|
+
token: z.ZodString;
|
|
10
12
|
}, z.core.$strip>;
|
|
11
13
|
type ProjectConfigInput = z.input<typeof ProjectConfigSchema>;
|
|
12
14
|
type ProjectConfig = z.output<typeof ProjectConfigSchema>;
|
|
@@ -118,6 +120,7 @@ type BaseParamOptions = z.input<typeof BaseParamSchema>;
|
|
|
118
120
|
type StringOptions = z.input<typeof StringParamSchema>;
|
|
119
121
|
type NumberOptions = z.input<typeof NumberParamSchema>;
|
|
120
122
|
|
|
123
|
+
type ParamResolvedOutputType<OutputType, Required extends boolean = true> = Required extends true ? OutputType : OutputType | null;
|
|
121
124
|
declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, Required extends boolean = true> {
|
|
122
125
|
options: Options & {
|
|
123
126
|
required: Required;
|
|
@@ -136,6 +139,9 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
|
|
|
136
139
|
name(value: string): this;
|
|
137
140
|
description(value: string): this;
|
|
138
141
|
required<V extends boolean>(value: V): BaseParam<Options, OutputType, V>;
|
|
142
|
+
resolve(context: CommandContext, value?: string): Promise<ParamResolvedOutputType<OutputType, Required>>;
|
|
143
|
+
abstract resolveMessage(context: MessageContext, value: string | undefined): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
|
|
144
|
+
abstract resolveChatInput(context: ChatInputContext): Awaitable<ParamResolvedOutputType<OutputType, Required>>;
|
|
139
145
|
/**
|
|
140
146
|
* Helper to normalize string inputs into an options object.
|
|
141
147
|
*/
|
|
@@ -144,6 +150,8 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
|
|
|
144
150
|
declare class StringParam<Required extends boolean = true> extends BaseParam<StringOptions, string, Required> {
|
|
145
151
|
constructor(options: string | StringOptions);
|
|
146
152
|
required<V extends boolean>(value: V): StringParam<V>;
|
|
153
|
+
resolveMessage(_context: CommandContext, value: string | undefined): ParamResolvedOutputType<string, Required>;
|
|
154
|
+
resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<string, Required>;
|
|
147
155
|
/**
|
|
148
156
|
* Sets the minimum allowed length for this string.
|
|
149
157
|
* Pass `null` to remove this constraint.
|
|
@@ -158,6 +166,8 @@ declare class StringParam<Required extends boolean = true> extends BaseParam<Str
|
|
|
158
166
|
declare class NumberParam<Required extends boolean = true> extends BaseParam<NumberOptions, number, Required> {
|
|
159
167
|
constructor(options: string | NumberOptions);
|
|
160
168
|
required<V extends boolean>(value: V): NumberParam<V>;
|
|
169
|
+
resolveMessage(ctx: CommandContext, value: string | undefined): ParamResolvedOutputType<number, Required>;
|
|
170
|
+
resolveChatInput(context: ChatInputContext): ParamResolvedOutputType<number, Required>;
|
|
161
171
|
/**
|
|
162
172
|
* Sets the minimum allowed value for this number.
|
|
163
173
|
* Pass `null` to remove this constraint.
|
|
@@ -194,6 +204,7 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
194
204
|
description?: string | undefined;
|
|
195
205
|
required?: boolean | undefined;
|
|
196
206
|
}, unknown, boolean>>>>;
|
|
207
|
+
quotes: z.ZodDefault<z.ZodBoolean>;
|
|
197
208
|
}, z.core.$strip>, z.ZodTransform<{
|
|
198
209
|
description: string;
|
|
199
210
|
name: string;
|
|
@@ -202,6 +213,7 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
202
213
|
description?: string | undefined;
|
|
203
214
|
required?: boolean | undefined;
|
|
204
215
|
}, unknown, boolean>[];
|
|
216
|
+
quotes: boolean;
|
|
205
217
|
}, {
|
|
206
218
|
name: string;
|
|
207
219
|
params: BaseParam<{
|
|
@@ -209,6 +221,7 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
209
221
|
description?: string | undefined;
|
|
210
222
|
required?: boolean | undefined;
|
|
211
223
|
}, unknown, boolean>[];
|
|
224
|
+
quotes: boolean;
|
|
212
225
|
description?: string | undefined;
|
|
213
226
|
}>>;
|
|
214
227
|
type CommandOptionsInput = z.input<typeof CommandOptionsSchema>;
|
|
@@ -216,13 +229,14 @@ type CommandOptions = z.output<typeof CommandOptionsSchema>;
|
|
|
216
229
|
/**
|
|
217
230
|
* The command entry, used for registering command.
|
|
218
231
|
*/
|
|
219
|
-
declare class Command<ParamsList extends readonly AnyParam<any>[] = []> extends LifecycleManager<CommandContext, [
|
|
232
|
+
declare class Command<ParamsList extends readonly AnyParam<any>[] = any[]> extends LifecycleManager<CommandContext, [
|
|
220
233
|
...args: InferParamTuple<ParamsList>
|
|
221
234
|
]> {
|
|
222
235
|
options: CommandOptions;
|
|
223
236
|
constructor(options: (Omit<CommandOptionsInput, "params"> & {
|
|
224
237
|
params?: ParamsList;
|
|
225
238
|
}) | string);
|
|
239
|
+
private handleSyntaxError;
|
|
226
240
|
}
|
|
227
241
|
/**
|
|
228
242
|
* Define command entry, usually for modules.
|
|
@@ -244,7 +258,7 @@ declare class Command<ParamsList extends readonly AnyParam<any>[] = []> extends
|
|
|
244
258
|
* export default command;
|
|
245
259
|
* ```
|
|
246
260
|
*/
|
|
247
|
-
declare function defineCommand<const ParamsList extends readonly AnyParam<any>[] = []>(options: (Omit<CommandOptionsInput, "params"> & {
|
|
261
|
+
declare function defineCommand<const ParamsList extends readonly AnyParam<any>[] = any[]>(options: (Omit<CommandOptionsInput, "params"> & {
|
|
248
262
|
params?: ParamsList;
|
|
249
263
|
}) | string): Command<ParamsList>;
|
|
250
264
|
|
|
@@ -254,11 +268,11 @@ declare class BaseClientManager {
|
|
|
254
268
|
}
|
|
255
269
|
|
|
256
270
|
declare class CommandManager extends BaseClientManager {
|
|
257
|
-
commands: Collection<string, Command<[]>>;
|
|
271
|
+
commands: Collection<string, Command<any[]>>;
|
|
258
272
|
loadModules(): Promise<Command[]>;
|
|
259
273
|
add(command: Command): void;
|
|
260
274
|
remove(target: string | Command): Command | undefined;
|
|
261
|
-
get(name: string): Command<[]> | undefined;
|
|
275
|
+
get(name: string): Command<any[]> | undefined;
|
|
262
276
|
}
|
|
263
277
|
|
|
264
278
|
declare const ListenerOptionsSchema: z$1.ZodObject<{
|
|
@@ -281,6 +295,8 @@ declare class ListenerManager extends BaseClientManager {
|
|
|
281
295
|
loadModules(): Promise<Listener[]>;
|
|
282
296
|
add(listener: Listener): void;
|
|
283
297
|
remove(target: string | Listener): Listener[];
|
|
298
|
+
getBaseIntents(): IntentsBitField;
|
|
299
|
+
getNeededIntents(): IntentsBitField;
|
|
284
300
|
}
|
|
285
301
|
|
|
286
302
|
type GetPrefixFunction = (message: Message) => Awaitable<string[] | string>;
|
|
@@ -294,7 +310,6 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
|
|
|
294
310
|
listeners: ListenerManager;
|
|
295
311
|
};
|
|
296
312
|
constructor(options: ClientOptions);
|
|
297
|
-
start(token?: string): Promise<string>;
|
|
298
313
|
/**
|
|
299
314
|
* Check if the client is connected to gateway successfully and finished initialization.
|
|
300
315
|
*/
|
|
@@ -312,6 +327,28 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
|
|
|
312
327
|
[inspect.custom](): string;
|
|
313
328
|
}
|
|
314
329
|
|
|
330
|
+
declare class Instance {
|
|
331
|
+
client: BakitClient;
|
|
332
|
+
start(): Promise<void>;
|
|
333
|
+
private loadModules;
|
|
334
|
+
private initIntents;
|
|
335
|
+
}
|
|
336
|
+
declare function useApp(): Instance;
|
|
337
|
+
|
|
338
|
+
declare const EVENT_INTENT_MAPPING: Record<string, number[]>;
|
|
339
|
+
|
|
340
|
+
declare function tokenize(content: string): string[];
|
|
341
|
+
|
|
342
|
+
declare class BakitError extends Error {
|
|
343
|
+
constructor(message: string);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
declare class ArgumentError extends BakitError {
|
|
347
|
+
target: string;
|
|
348
|
+
reason: string;
|
|
349
|
+
constructor(target: string, reason: string);
|
|
350
|
+
}
|
|
351
|
+
|
|
315
352
|
declare const Params: {
|
|
316
353
|
readonly string: <Required extends boolean = true>(options: string | {
|
|
317
354
|
name: string;
|
|
@@ -329,4 +366,4 @@ declare const Params: {
|
|
|
329
366
|
}) => NumberParam<Required>;
|
|
330
367
|
};
|
|
331
368
|
|
|
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 };
|
|
369
|
+
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, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig, tokenize, useApp };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GatewayIntentBits, Events, Client, Collection, ChatInputCommandInteraction, Message } from 'discord.js';
|
|
1
|
+
import { GatewayIntentBits, Events, Client, IntentsBitField, Collection, ChatInputCommandInteraction, Message } from 'discord.js';
|
|
2
2
|
import z3, { z } from 'zod';
|
|
3
3
|
import { pathToFileURL } from 'url';
|
|
4
4
|
import glob from 'tiny-glob';
|
|
@@ -30,7 +30,9 @@ var ProjectConfigSchema = z.object({
|
|
|
30
30
|
*
|
|
31
31
|
* @defaultvalue `src`
|
|
32
32
|
*/
|
|
33
|
-
entryDir: z.string().default("src")
|
|
33
|
+
entryDir: z.string().default("src"),
|
|
34
|
+
prefixes: z.array(z.string()).default([]),
|
|
35
|
+
token: z.string()
|
|
34
36
|
});
|
|
35
37
|
function defineConfig(config) {
|
|
36
38
|
return config;
|
|
@@ -128,7 +130,7 @@ var BaseCommandContext = class extends Context {
|
|
|
128
130
|
return await channel.send(options);
|
|
129
131
|
}
|
|
130
132
|
};
|
|
131
|
-
var LifecycleManager = class {
|
|
133
|
+
var HookState = /* @__PURE__ */ ((HookState2) => (HookState2.Pre = "PRE", HookState2.Main = "MAIN", HookState2.Post = "POST", HookState2.Error = "ERROR", HookState2))(HookState || {}), HookOrder = /* @__PURE__ */ ((HookOrder2) => (HookOrder2[HookOrder2.First = 0] = "First", HookOrder2[HookOrder2.Last = 1] = "Last", HookOrder2))(HookOrder || {}), LifecycleManager = class {
|
|
132
134
|
constructor(id) {
|
|
133
135
|
this.id = id;
|
|
134
136
|
}
|
|
@@ -199,6 +201,22 @@ var LifecycleManager = class {
|
|
|
199
201
|
}
|
|
200
202
|
};
|
|
201
203
|
|
|
204
|
+
// src/errors/BakitError.ts
|
|
205
|
+
var BakitError = class extends Error {
|
|
206
|
+
constructor(message) {
|
|
207
|
+
super(message), this.name = this.constructor.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/errors/ArgumentError.ts
|
|
212
|
+
var ArgumentError = class extends BakitError {
|
|
213
|
+
constructor(target, reason) {
|
|
214
|
+
super(`Invalid argument for '${target}': ${reason}`);
|
|
215
|
+
this.target = target;
|
|
216
|
+
this.reason = reason;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
202
220
|
// src/command/param/Param.ts
|
|
203
221
|
var BaseParam = class {
|
|
204
222
|
options;
|
|
@@ -218,6 +236,13 @@ var BaseParam = class {
|
|
|
218
236
|
required(value) {
|
|
219
237
|
return this.setOption("required", value);
|
|
220
238
|
}
|
|
239
|
+
async resolve(context, value) {
|
|
240
|
+
if (context.isChatInput())
|
|
241
|
+
return await this.resolveChatInput(context);
|
|
242
|
+
if (context.isMessage())
|
|
243
|
+
return await this.resolveMessage(context, value);
|
|
244
|
+
throw new Error("Invalid context type provided");
|
|
245
|
+
}
|
|
221
246
|
/**
|
|
222
247
|
* Helper to normalize string inputs into an options object.
|
|
223
248
|
*/
|
|
@@ -231,6 +256,23 @@ var BaseParam = class {
|
|
|
231
256
|
required(value) {
|
|
232
257
|
return super.required(value);
|
|
233
258
|
}
|
|
259
|
+
resolveMessage(_context, value) {
|
|
260
|
+
let { required, minLength, maxLength, name } = this.options;
|
|
261
|
+
if (value === void 0) {
|
|
262
|
+
if (required)
|
|
263
|
+
throw new ArgumentError(name, "is required");
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
if (minLength && value.length < minLength)
|
|
267
|
+
throw new ArgumentError(name, `must be at least ${minLength} chars long`);
|
|
268
|
+
if (maxLength && value.length > maxLength)
|
|
269
|
+
throw new ArgumentError(name, `must be at most ${maxLength} chars long`);
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
resolveChatInput(context) {
|
|
273
|
+
let { name, required } = this.options;
|
|
274
|
+
return context.source.options.getString(name, required);
|
|
275
|
+
}
|
|
234
276
|
/**
|
|
235
277
|
* Sets the minimum allowed length for this string.
|
|
236
278
|
* Pass `null` to remove this constraint.
|
|
@@ -252,6 +294,26 @@ var BaseParam = class {
|
|
|
252
294
|
required(value) {
|
|
253
295
|
return super.required(value);
|
|
254
296
|
}
|
|
297
|
+
resolveMessage(ctx, value) {
|
|
298
|
+
let { required, minValue, maxValue, name } = this.options;
|
|
299
|
+
if (value === void 0) {
|
|
300
|
+
if (required)
|
|
301
|
+
throw new ArgumentError(name, "is required");
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
let num = Number(value);
|
|
305
|
+
if (isNaN(num))
|
|
306
|
+
throw new ArgumentError(name, "must be a number");
|
|
307
|
+
if (minValue !== void 0 && num < minValue)
|
|
308
|
+
throw new ArgumentError(name, `must be greater than ${minValue}`);
|
|
309
|
+
if (maxValue !== void 0 && num > maxValue)
|
|
310
|
+
throw new ArgumentError(name, `must be less than ${minValue}`);
|
|
311
|
+
return num;
|
|
312
|
+
}
|
|
313
|
+
resolveChatInput(context) {
|
|
314
|
+
let { name, required } = this.options;
|
|
315
|
+
return context.source.options.getString(name, required);
|
|
316
|
+
}
|
|
255
317
|
/**
|
|
256
318
|
* Sets the minimum allowed value for this number.
|
|
257
319
|
* Pass `null` to remove this constraint.
|
|
@@ -272,14 +334,20 @@ var BaseParam = class {
|
|
|
272
334
|
var CommandOptionsSchema = z.object({
|
|
273
335
|
name: z.string(),
|
|
274
336
|
description: z.string().min(1).max(100).optional(),
|
|
275
|
-
params: z.array(z.instanceof(BaseParam)).default([])
|
|
337
|
+
params: z.array(z.instanceof(BaseParam)).default([]),
|
|
338
|
+
quotes: z.boolean().default(true)
|
|
276
339
|
}).transform((data) => ({
|
|
277
340
|
...data,
|
|
278
341
|
description: data.description ?? `Command ${data.name}`
|
|
279
342
|
})), Command = class extends LifecycleManager {
|
|
280
343
|
constructor(options) {
|
|
281
344
|
let _options = CommandOptionsSchema.parse(typeof options == "string" ? { name: options } : options);
|
|
282
|
-
super(`command:${_options.name}`), this.options = _options
|
|
345
|
+
super(`command:${_options.name}`), this.options = _options, this.setHook("syntaxError", "ERROR" /* Error */, async (ctx, error, ...args) => {
|
|
346
|
+
await this.handleSyntaxError(ctx, error, args);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
async handleSyntaxError(context, error, _args) {
|
|
350
|
+
error instanceof BakitError && await context.send(error.message);
|
|
283
351
|
}
|
|
284
352
|
};
|
|
285
353
|
function defineCommand(options) {
|
|
@@ -343,12 +411,107 @@ var ListenerOptionsSchema = z3.object({
|
|
|
343
411
|
options;
|
|
344
412
|
constructor(options) {
|
|
345
413
|
let _options = ListenerOptionsSchema.parse(typeof options == "string" ? { name: options } : options);
|
|
346
|
-
super(`listener:${_options.name}`), this.options =
|
|
414
|
+
super(`listener:${_options.name}`), this.options = _options;
|
|
347
415
|
}
|
|
348
416
|
};
|
|
349
417
|
function defineListener(options) {
|
|
350
418
|
return new Listener(options);
|
|
351
419
|
}
|
|
420
|
+
var INTENT_GROUPS = {
|
|
421
|
+
[GatewayIntentBits.Guilds]: [
|
|
422
|
+
Events.GuildCreate,
|
|
423
|
+
Events.GuildDelete,
|
|
424
|
+
Events.GuildUpdate,
|
|
425
|
+
Events.GuildUnavailable,
|
|
426
|
+
Events.GuildRoleCreate,
|
|
427
|
+
Events.GuildRoleDelete,
|
|
428
|
+
Events.GuildRoleUpdate,
|
|
429
|
+
Events.ChannelCreate,
|
|
430
|
+
Events.ChannelDelete,
|
|
431
|
+
Events.ChannelUpdate,
|
|
432
|
+
Events.ChannelPinsUpdate,
|
|
433
|
+
Events.ThreadCreate,
|
|
434
|
+
Events.ThreadDelete,
|
|
435
|
+
Events.ThreadUpdate,
|
|
436
|
+
Events.ThreadListSync,
|
|
437
|
+
Events.ThreadMemberUpdate,
|
|
438
|
+
Events.ThreadMembersUpdate,
|
|
439
|
+
Events.StageInstanceCreate,
|
|
440
|
+
Events.StageInstanceUpdate,
|
|
441
|
+
Events.StageInstanceDelete
|
|
442
|
+
],
|
|
443
|
+
[GatewayIntentBits.GuildMembers]: [
|
|
444
|
+
Events.GuildMemberAdd,
|
|
445
|
+
Events.GuildMemberUpdate,
|
|
446
|
+
Events.GuildMemberRemove,
|
|
447
|
+
Events.ThreadMembersUpdate
|
|
448
|
+
],
|
|
449
|
+
[GatewayIntentBits.GuildModeration]: [Events.GuildAuditLogEntryCreate, Events.GuildBanAdd, Events.GuildBanRemove],
|
|
450
|
+
[GatewayIntentBits.GuildExpressions]: [
|
|
451
|
+
Events.GuildEmojiCreate,
|
|
452
|
+
Events.GuildEmojiDelete,
|
|
453
|
+
Events.GuildEmojiUpdate,
|
|
454
|
+
Events.GuildStickerCreate,
|
|
455
|
+
Events.GuildStickerDelete,
|
|
456
|
+
Events.GuildStickerUpdate,
|
|
457
|
+
Events.GuildSoundboardSoundCreate,
|
|
458
|
+
Events.GuildSoundboardSoundUpdate,
|
|
459
|
+
Events.GuildSoundboardSoundDelete,
|
|
460
|
+
Events.GuildSoundboardSoundsUpdate
|
|
461
|
+
],
|
|
462
|
+
[GatewayIntentBits.GuildIntegrations]: [Events.GuildIntegrationsUpdate],
|
|
463
|
+
[GatewayIntentBits.GuildWebhooks]: [Events.WebhooksUpdate],
|
|
464
|
+
[GatewayIntentBits.GuildInvites]: [Events.InviteCreate, Events.InviteDelete],
|
|
465
|
+
[GatewayIntentBits.GuildVoiceStates]: [Events.VoiceStateUpdate],
|
|
466
|
+
[GatewayIntentBits.GuildPresences]: [Events.PresenceUpdate],
|
|
467
|
+
[GatewayIntentBits.GuildMessages]: [
|
|
468
|
+
Events.MessageCreate,
|
|
469
|
+
Events.MessageUpdate,
|
|
470
|
+
Events.MessageDelete,
|
|
471
|
+
Events.MessageBulkDelete
|
|
472
|
+
],
|
|
473
|
+
[GatewayIntentBits.GuildMessageReactions]: [
|
|
474
|
+
Events.MessageReactionAdd,
|
|
475
|
+
Events.MessageReactionRemove,
|
|
476
|
+
Events.MessageReactionRemoveAll,
|
|
477
|
+
Events.MessageReactionRemoveEmoji
|
|
478
|
+
],
|
|
479
|
+
[GatewayIntentBits.GuildMessageTyping]: [Events.TypingStart],
|
|
480
|
+
[GatewayIntentBits.DirectMessages]: [
|
|
481
|
+
Events.MessageCreate,
|
|
482
|
+
Events.MessageUpdate,
|
|
483
|
+
Events.MessageDelete,
|
|
484
|
+
Events.ChannelPinsUpdate
|
|
485
|
+
],
|
|
486
|
+
[GatewayIntentBits.DirectMessageReactions]: [
|
|
487
|
+
Events.MessageReactionAdd,
|
|
488
|
+
Events.MessageReactionRemove,
|
|
489
|
+
Events.MessageReactionRemoveAll,
|
|
490
|
+
Events.MessageReactionRemoveEmoji
|
|
491
|
+
],
|
|
492
|
+
[GatewayIntentBits.DirectMessageTyping]: [Events.TypingStart],
|
|
493
|
+
[GatewayIntentBits.MessageContent]: [Events.MessageCreate, Events.MessageUpdate],
|
|
494
|
+
[GatewayIntentBits.GuildScheduledEvents]: [
|
|
495
|
+
Events.GuildScheduledEventCreate,
|
|
496
|
+
Events.GuildScheduledEventDelete,
|
|
497
|
+
Events.GuildScheduledEventUpdate,
|
|
498
|
+
Events.GuildScheduledEventUserAdd,
|
|
499
|
+
Events.GuildScheduledEventUserRemove
|
|
500
|
+
],
|
|
501
|
+
[GatewayIntentBits.AutoModerationConfiguration]: [
|
|
502
|
+
Events.AutoModerationRuleCreate,
|
|
503
|
+
Events.AutoModerationRuleDelete,
|
|
504
|
+
Events.AutoModerationRuleUpdate
|
|
505
|
+
],
|
|
506
|
+
[GatewayIntentBits.AutoModerationExecution]: [Events.AutoModerationActionExecution],
|
|
507
|
+
[GatewayIntentBits.GuildMessagePolls]: [Events.MessagePollVoteAdd, Events.MessagePollVoteRemove],
|
|
508
|
+
[GatewayIntentBits.DirectMessagePolls]: [Events.MessagePollVoteAdd, Events.MessagePollVoteRemove]
|
|
509
|
+
}, EVENT_INTENT_MAPPING = {};
|
|
510
|
+
for (let [intentStr, events] of Object.entries(INTENT_GROUPS)) {
|
|
511
|
+
let intent = Number(intentStr);
|
|
512
|
+
for (let event of events)
|
|
513
|
+
EVENT_INTENT_MAPPING[event] ??= [], EVENT_INTENT_MAPPING[event].includes(intent) || EVENT_INTENT_MAPPING[event].push(intent);
|
|
514
|
+
}
|
|
352
515
|
|
|
353
516
|
// src/listener/ListenerManager.ts
|
|
354
517
|
var ListenerManager = class extends BaseClientManager {
|
|
@@ -396,6 +559,17 @@ var ListenerManager = class extends BaseClientManager {
|
|
|
396
559
|
return execute && (this.client.removeListener(listener.options.name, execute), this.executors.delete(listener)), false;
|
|
397
560
|
}), removed;
|
|
398
561
|
}
|
|
562
|
+
getBaseIntents() {
|
|
563
|
+
return new IntentsBitField([GatewayIntentBits.Guilds]);
|
|
564
|
+
}
|
|
565
|
+
getNeededIntents() {
|
|
566
|
+
let result = this.getBaseIntents();
|
|
567
|
+
for (let listener of this.listeners) {
|
|
568
|
+
let eventName = listener.options.name, requiredIntents = EVENT_INTENT_MAPPING[eventName];
|
|
569
|
+
requiredIntents && result.add(requiredIntents);
|
|
570
|
+
}
|
|
571
|
+
return result;
|
|
572
|
+
}
|
|
399
573
|
};
|
|
400
574
|
|
|
401
575
|
// src/BakitClient.ts
|
|
@@ -407,10 +581,6 @@ var BakitClient3 = class extends Client {
|
|
|
407
581
|
listeners: new ListenerManager(this)
|
|
408
582
|
};
|
|
409
583
|
}
|
|
410
|
-
async start(token) {
|
|
411
|
-
let { commands, listeners } = this.managers;
|
|
412
|
-
return await Promise.all([commands.loadModules(), listeners.loadModules()]), await this.login(token);
|
|
413
|
-
}
|
|
414
584
|
/**
|
|
415
585
|
* Check if the client is connected to gateway successfully and finished initialization.
|
|
416
586
|
*/
|
|
@@ -443,6 +613,47 @@ var BakitClient3 = class extends Client {
|
|
|
443
613
|
return `${this.constructor.name} {}`;
|
|
444
614
|
}
|
|
445
615
|
};
|
|
616
|
+
var Instance = class {
|
|
617
|
+
client;
|
|
618
|
+
async start() {
|
|
619
|
+
await loadConfig();
|
|
620
|
+
let config = getConfig();
|
|
621
|
+
this.client = new BakitClient3({
|
|
622
|
+
intents: []
|
|
623
|
+
}), await this.loadModules(), this.initIntents(), await this.client.login(config.token);
|
|
624
|
+
}
|
|
625
|
+
loadModules() {
|
|
626
|
+
let { managers } = this.client, { commands, listeners } = managers;
|
|
627
|
+
return Promise.all([commands.loadModules(), listeners.loadModules()]);
|
|
628
|
+
}
|
|
629
|
+
initIntents() {
|
|
630
|
+
let config = getConfig(), { options, managers } = this.client, { listeners } = managers, intents;
|
|
631
|
+
config.intents === "auto" ? intents = listeners.getNeededIntents() : (intents = listeners.getBaseIntents(), typeof config.intents == "bigint" ? intents.bitfield = Number(config.intents) : intents.add(...config.intents)), options.intents = intents;
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
function useApp() {
|
|
635
|
+
return new Instance();
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// src/utils/string.ts
|
|
639
|
+
function tokenize(content) {
|
|
640
|
+
let args = [], current = "", quoteChar = null, isEscaped = false;
|
|
641
|
+
for (let i = 0; i < content.length; i++) {
|
|
642
|
+
let char = content[i];
|
|
643
|
+
if (char === void 0)
|
|
644
|
+
break;
|
|
645
|
+
if (isEscaped) {
|
|
646
|
+
current += char, isEscaped = false;
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
if (char === "\\") {
|
|
650
|
+
isEscaped = true;
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
quoteChar ? char === quoteChar ? quoteChar = null : current += char : char === '"' ? quoteChar = char : /\s/.test(char) ? current.length > 0 && (args.push(current), current = "") : current += char;
|
|
654
|
+
}
|
|
655
|
+
return current.length > 0 && args.push(current), args;
|
|
656
|
+
}
|
|
446
657
|
var ParamUserType = /* @__PURE__ */ ((ParamUserType2) => (ParamUserType2.Bot = "bot", ParamUserType2.Normal = "normal", ParamUserType2.Any = "any", ParamUserType2))(ParamUserType || {}), BaseParamSchema = z.object({
|
|
447
658
|
name: z.string(),
|
|
448
659
|
description: z.string().optional(),
|
|
@@ -464,4 +675,4 @@ var Params = {
|
|
|
464
675
|
number: createFactory(NumberParam)
|
|
465
676
|
};
|
|
466
677
|
|
|
467
|
-
export { BakitClient3 as BakitClient, BaseCommandContext, BaseParam, BaseParamSchema, ChatInputContext, Command, CommandManager, CommandOptionsSchema, Listener, ListenerManager, ListenerOptionsSchema, MessageContext, NumberParam, NumberParamSchema, ParamUserType, Params, ProjectConfigSchema, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig };
|
|
678
|
+
export { ArgumentError, BakitClient3 as BakitClient, BakitError, BaseClientManager, BaseCommandContext, BaseParam, BaseParamSchema, ChatInputContext, Command, CommandManager, CommandOptionsSchema, Context, EVENT_INTENT_MAPPING, HookOrder, HookState, Instance, LifecycleManager, Listener, ListenerManager, ListenerOptionsSchema, MessageContext, NumberParam, NumberParamSchema, ParamUserType, Params, ProjectConfigSchema, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig, tokenize, useApp };
|