bakit 2.0.0-alpha.5 → 2.0.0-alpha.7

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/bin/bakit.js ADDED
@@ -0,0 +1,39 @@
1
+ // @ts-check
2
+ import { config as useEnv } from "dotenv";
3
+ import { program } from "commander";
4
+
5
+ program.name("bakit");
6
+
7
+ program.command("dev").action(async () => {
8
+ useEnv({
9
+ path: [".env.local", ".env"],
10
+ quiet: true,
11
+ });
12
+ const { default: nodemon } = await import("nodemon");
13
+
14
+ nodemon({
15
+ script: "src/index.ts",
16
+ exec: `${process.execPath} --import tsx`,
17
+ ext: "ts,js",
18
+ watch: ["src"],
19
+ env: {
20
+ ...process.env,
21
+ FORCE_COLOR: "1",
22
+ NODE_ENV: "development",
23
+ },
24
+ });
25
+
26
+ nodemon.on("start", () => {
27
+ console.log("Starting bakit app...");
28
+ });
29
+
30
+ nodemon.on("restart", () => {
31
+ console.log("Bakit detected changes! Restarting...");
32
+ });
33
+
34
+ nodemon.on("quit", () => {
35
+ process.exit();
36
+ });
37
+ });
38
+
39
+ program.parse();
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
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';
2
+ import { GatewayIntentBits, ClientOptions, ChatInputCommandInteraction, CacheType, Message, User, MessageCreateOptions, InteractionReplyOptions, Awaitable, Collection, Events, IntentsBitField, ClientEvents, Client } from 'discord.js';
3
3
  import z$1, { z } from 'zod';
4
4
  import { inspect } from 'node:util';
5
+ import * as jiti from 'jiti';
5
6
 
6
7
  declare const ProjectConfigSchema: z.ZodObject<{
7
8
  intents: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodBigInt, z.ZodArray<z.ZodEnum<typeof GatewayIntentBits>>]>>;
@@ -102,20 +103,48 @@ declare const BaseParamSchema: z.ZodObject<{
102
103
  description: z.ZodOptional<z.ZodString>;
103
104
  required: z.ZodDefault<z.ZodBoolean>;
104
105
  }, z.core.$strip>;
105
- declare const StringParamSchema: z.ZodObject<{
106
+ declare const StringParamSchema: z.ZodPipe<z.ZodObject<{
106
107
  name: z.ZodString;
107
108
  description: z.ZodOptional<z.ZodString>;
108
109
  required: z.ZodDefault<z.ZodBoolean>;
109
110
  maxLength: z.ZodOptional<z.ZodNumber>;
110
111
  minLength: z.ZodOptional<z.ZodNumber>;
111
- }, z.core.$strip>;
112
- declare const NumberParamSchema: z.ZodObject<{
112
+ }, z.core.$strip>, z.ZodTransform<{
113
+ name: string;
114
+ required: boolean;
115
+ description?: string | undefined;
116
+ maxLength?: number | undefined;
117
+ minLength?: number | undefined;
118
+ } & {
119
+ description: string;
120
+ }, {
121
+ name: string;
122
+ required: boolean;
123
+ description?: string | undefined;
124
+ maxLength?: number | undefined;
125
+ minLength?: number | undefined;
126
+ }>>;
127
+ declare const NumberParamSchema: z.ZodPipe<z.ZodObject<{
113
128
  name: z.ZodString;
114
129
  description: z.ZodOptional<z.ZodString>;
115
130
  required: z.ZodDefault<z.ZodBoolean>;
116
131
  maxValue: z.ZodOptional<z.ZodNumber>;
117
132
  minValue: z.ZodOptional<z.ZodNumber>;
118
- }, z.core.$strip>;
133
+ }, z.core.$strip>, z.ZodTransform<{
134
+ name: string;
135
+ required: boolean;
136
+ description?: string | undefined;
137
+ maxValue?: number | undefined;
138
+ minValue?: number | undefined;
139
+ } & {
140
+ description: string;
141
+ }, {
142
+ name: string;
143
+ required: boolean;
144
+ description?: string | undefined;
145
+ maxValue?: number | undefined;
146
+ minValue?: number | undefined;
147
+ }>>;
119
148
  type BaseParamOptions = z.input<typeof BaseParamSchema>;
120
149
  type StringOptions = z.input<typeof StringParamSchema>;
121
150
  type NumberOptions = z.input<typeof NumberParamSchema>;
@@ -192,10 +221,12 @@ type InferParamTuple<T extends readonly BaseParam<any, any, any>[]> = {
192
221
  [K in keyof T]: T[K] extends AnyParam<any> ? InferParamValue<T[K]> : never;
193
222
  };
194
223
 
224
+ declare function validateParamsOrder(params: readonly AnyParam<boolean>[]): boolean;
195
225
  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<{
226
+ name: z.ZodReadonly<z.ZodString>;
227
+ description: z.ZodReadonly<z.ZodOptional<z.ZodString>>;
228
+ nsfw: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
229
+ params: z.ZodReadonly<z.ZodDefault<z.ZodArray<z.ZodCustom<BaseParam<{
199
230
  name: string;
200
231
  description?: string | undefined;
201
232
  required?: boolean | undefined;
@@ -203,12 +234,13 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
203
234
  name: string;
204
235
  description?: string | undefined;
205
236
  required?: boolean | undefined;
206
- }, unknown, boolean>>>>;
207
- quotes: z.ZodDefault<z.ZodBoolean>;
237
+ }, unknown, boolean>>>>>;
238
+ quotes: z.ZodReadonly<z.ZodDefault<z.ZodBoolean>>;
208
239
  }, z.core.$strip>, z.ZodTransform<{
209
240
  description: string;
210
241
  name: string;
211
- params: BaseParam<{
242
+ nsfw: boolean;
243
+ params: readonly BaseParam<{
212
244
  name: string;
213
245
  description?: string | undefined;
214
246
  required?: boolean | undefined;
@@ -216,7 +248,8 @@ declare const CommandOptionsSchema: z.ZodPipe<z.ZodObject<{
216
248
  quotes: boolean;
217
249
  }, {
218
250
  name: string;
219
- params: BaseParam<{
251
+ nsfw: boolean;
252
+ params: readonly BaseParam<{
220
253
  name: string;
221
254
  description?: string | undefined;
222
255
  required?: boolean | undefined;
@@ -237,6 +270,9 @@ declare class Command<ParamsList extends readonly AnyParam<any>[] = any[]> exten
237
270
  params?: ParamsList;
238
271
  }) | string);
239
272
  private handleSyntaxError;
273
+ toSlashCommandJSON(): discord_js.RESTPostAPIChatInputApplicationCommandsJSONBody;
274
+ private initSlashCommandOptions;
275
+ private initSlashCommandOption;
240
276
  }
241
277
  /**
242
278
  * Define command entry, usually for modules.
@@ -282,8 +318,10 @@ declare const ListenerOptionsSchema: z$1.ZodObject<{
282
318
  type ListenerOptions<K extends EventKey = EventKey> = Omit<z$1.input<typeof ListenerOptionsSchema>, "name"> & {
283
319
  name: K;
284
320
  };
285
- type EventKey = keyof ClientEvents;
286
- declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [...args: ClientEvents[K]]> {
321
+ type EventKey = keyof BakitClientEvents;
322
+ declare class Listener<K extends EventKey = EventKey> extends LifecycleManager<Context, [
323
+ ...args: BakitClientEvents[K]
324
+ ]> {
287
325
  options: ListenerOptions<K>;
288
326
  constructor(options: K | ListenerOptions<K>);
289
327
  }
@@ -339,6 +377,8 @@ declare const EVENT_INTENT_MAPPING: Record<string, number[]>;
339
377
 
340
378
  declare function tokenize(content: string): string[];
341
379
 
380
+ declare const $jiti: jiti.Jiti;
381
+
342
382
  declare class BakitError extends Error {
343
383
  constructor(message: string);
344
384
  }
@@ -366,4 +406,4 @@ declare const Params: {
366
406
  }) => NumberParam<Required>;
367
407
  };
368
408
 
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 };
409
+ export { $jiti, 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, validateParamsOrder };
package/dist/index.js CHANGED
@@ -1,12 +1,131 @@
1
- import 'dotenv/config';
2
- import { GatewayIntentBits, Events, Client, IntentsBitField, Collection, ChatInputCommandInteraction, Message } from 'discord.js';
1
+ import { GatewayIntentBits, Events, Client, IntentsBitField, Collection, SlashCommandBuilder, SlashCommandStringOption, SlashCommandNumberOption, ChatInputCommandInteraction, Message } from 'discord.js';
3
2
  import z3, { z } from 'zod';
4
- import { pathToFileURL } from 'url';
5
3
  import glob from 'tiny-glob';
4
+ import { createJiti } from 'jiti';
6
5
  import { inspect } from 'util';
7
6
  import { posix } from 'path';
8
7
 
9
- // src/index.ts
8
+ // src/config.ts
9
+ var INTENT_GROUPS = {
10
+ [GatewayIntentBits.Guilds]: [
11
+ Events.GuildCreate,
12
+ Events.GuildDelete,
13
+ Events.GuildUpdate,
14
+ Events.GuildUnavailable,
15
+ Events.GuildRoleCreate,
16
+ Events.GuildRoleDelete,
17
+ Events.GuildRoleUpdate,
18
+ Events.ChannelCreate,
19
+ Events.ChannelDelete,
20
+ Events.ChannelUpdate,
21
+ Events.ChannelPinsUpdate,
22
+ Events.ThreadCreate,
23
+ Events.ThreadDelete,
24
+ Events.ThreadUpdate,
25
+ Events.ThreadListSync,
26
+ Events.ThreadMemberUpdate,
27
+ Events.ThreadMembersUpdate,
28
+ Events.StageInstanceCreate,
29
+ Events.StageInstanceUpdate,
30
+ Events.StageInstanceDelete
31
+ ],
32
+ [GatewayIntentBits.GuildMembers]: [
33
+ Events.GuildMemberAdd,
34
+ Events.GuildMemberUpdate,
35
+ Events.GuildMemberRemove,
36
+ Events.ThreadMembersUpdate
37
+ ],
38
+ [GatewayIntentBits.GuildModeration]: [Events.GuildAuditLogEntryCreate, Events.GuildBanAdd, Events.GuildBanRemove],
39
+ [GatewayIntentBits.GuildExpressions]: [
40
+ Events.GuildEmojiCreate,
41
+ Events.GuildEmojiDelete,
42
+ Events.GuildEmojiUpdate,
43
+ Events.GuildStickerCreate,
44
+ Events.GuildStickerDelete,
45
+ Events.GuildStickerUpdate,
46
+ Events.GuildSoundboardSoundCreate,
47
+ Events.GuildSoundboardSoundUpdate,
48
+ Events.GuildSoundboardSoundDelete,
49
+ Events.GuildSoundboardSoundsUpdate
50
+ ],
51
+ [GatewayIntentBits.GuildIntegrations]: [Events.GuildIntegrationsUpdate],
52
+ [GatewayIntentBits.GuildWebhooks]: [Events.WebhooksUpdate],
53
+ [GatewayIntentBits.GuildInvites]: [Events.InviteCreate, Events.InviteDelete],
54
+ [GatewayIntentBits.GuildVoiceStates]: [Events.VoiceStateUpdate],
55
+ [GatewayIntentBits.GuildPresences]: [Events.PresenceUpdate],
56
+ [GatewayIntentBits.GuildMessages]: [
57
+ Events.MessageCreate,
58
+ Events.MessageUpdate,
59
+ Events.MessageDelete,
60
+ Events.MessageBulkDelete
61
+ ],
62
+ [GatewayIntentBits.GuildMessageReactions]: [
63
+ Events.MessageReactionAdd,
64
+ Events.MessageReactionRemove,
65
+ Events.MessageReactionRemoveAll,
66
+ Events.MessageReactionRemoveEmoji
67
+ ],
68
+ [GatewayIntentBits.GuildMessageTyping]: [Events.TypingStart],
69
+ [GatewayIntentBits.DirectMessages]: [
70
+ Events.MessageCreate,
71
+ Events.MessageUpdate,
72
+ Events.MessageDelete,
73
+ Events.ChannelPinsUpdate
74
+ ],
75
+ [GatewayIntentBits.DirectMessageReactions]: [
76
+ Events.MessageReactionAdd,
77
+ Events.MessageReactionRemove,
78
+ Events.MessageReactionRemoveAll,
79
+ Events.MessageReactionRemoveEmoji
80
+ ],
81
+ [GatewayIntentBits.DirectMessageTyping]: [Events.TypingStart],
82
+ [GatewayIntentBits.MessageContent]: [Events.MessageCreate, Events.MessageUpdate],
83
+ [GatewayIntentBits.GuildScheduledEvents]: [
84
+ Events.GuildScheduledEventCreate,
85
+ Events.GuildScheduledEventDelete,
86
+ Events.GuildScheduledEventUpdate,
87
+ Events.GuildScheduledEventUserAdd,
88
+ Events.GuildScheduledEventUserRemove
89
+ ],
90
+ [GatewayIntentBits.AutoModerationConfiguration]: [
91
+ Events.AutoModerationRuleCreate,
92
+ Events.AutoModerationRuleDelete,
93
+ Events.AutoModerationRuleUpdate
94
+ ],
95
+ [GatewayIntentBits.AutoModerationExecution]: [Events.AutoModerationActionExecution],
96
+ [GatewayIntentBits.GuildMessagePolls]: [Events.MessagePollVoteAdd, Events.MessagePollVoteRemove],
97
+ [GatewayIntentBits.DirectMessagePolls]: [Events.MessagePollVoteAdd, Events.MessagePollVoteRemove]
98
+ }, EVENT_INTENT_MAPPING = {};
99
+ for (let [intentStr, events] of Object.entries(INTENT_GROUPS)) {
100
+ let intent = Number(intentStr);
101
+ for (let event of events)
102
+ EVENT_INTENT_MAPPING[event] ??= [], EVENT_INTENT_MAPPING[event].includes(intent) || EVENT_INTENT_MAPPING[event].push(intent);
103
+ }
104
+
105
+ // src/utils/string.ts
106
+ function tokenize(content) {
107
+ let args = [], current = "", quoteChar = null, isEscaped = false;
108
+ for (let i = 0; i < content.length; i++) {
109
+ let char = content[i];
110
+ if (char === void 0)
111
+ break;
112
+ if (isEscaped) {
113
+ current += char, isEscaped = false;
114
+ continue;
115
+ }
116
+ if (char === "\\") {
117
+ isEscaped = true;
118
+ continue;
119
+ }
120
+ quoteChar ? char === quoteChar ? quoteChar = null : current += char : char === '"' ? quoteChar = char : /\s/.test(char) ? current.length > 0 && (args.push(current), current = "") : current += char;
121
+ }
122
+ return current.length > 0 && args.push(current), args;
123
+ }
124
+
125
+ // src/utils/index.ts
126
+ var $jiti = createJiti(import.meta.url);
127
+
128
+ // src/config.ts
10
129
  var ProjectConfigSchema = z.object({
11
130
  /**
12
131
  * The gateway intents to use for the Discord client.
@@ -50,7 +169,7 @@ async function loadConfig(cwd = process.cwd()) {
50
169
  if (!configPath)
51
170
  throw new Error("Missing config file");
52
171
  other && console.warn(`Multiple config files found in ${cwd}. Using ${configPath}.`);
53
- let configFileURL = pathToFileURL(configPath).toString(), { default: config } = await import(configFileURL);
172
+ let config = await $jiti.import(configPath, { default: true });
54
173
  return _config = Object.freeze(await ProjectConfigSchema.parseAsync(config)), _config;
55
174
  }
56
175
  function getConfig() {
@@ -330,17 +449,29 @@ var BaseParam = class {
330
449
  return this.setOption("maxValue", value);
331
450
  }
332
451
  };
333
-
334
- // src/command/Command.ts
452
+ function validateParamsOrder(params) {
453
+ let seenOptional = false;
454
+ for (let param of params)
455
+ if (param.options.required) {
456
+ if (seenOptional)
457
+ return false;
458
+ } else
459
+ seenOptional = true;
460
+ return true;
461
+ }
335
462
  var CommandOptionsSchema = z.object({
336
- name: z.string(),
337
- description: z.string().min(1).max(100).optional(),
338
- params: z.array(z.instanceof(BaseParam)).default([]),
339
- quotes: z.boolean().default(true)
463
+ name: z.string().readonly(),
464
+ description: z.string().min(1).max(100).optional().readonly(),
465
+ nsfw: z.boolean().default(false).readonly(),
466
+ params: z.array(z.instanceof(BaseParam)).default([]).readonly(),
467
+ quotes: z.boolean().default(true).readonly()
340
468
  }).transform((data) => ({
341
469
  ...data,
342
470
  description: data.description ?? `Command ${data.name}`
343
- })), Command = class extends LifecycleManager {
471
+ })).refine(({ params }) => validateParamsOrder(params), {
472
+ path: ["params"],
473
+ error: "Required params must be placed before optional params"
474
+ }), Command = class extends LifecycleManager {
344
475
  constructor(options) {
345
476
  let _options = CommandOptionsSchema.parse(typeof options == "string" ? { name: options } : options);
346
477
  super(`command:${_options.name}`), this.options = _options, this.setHook("syntaxError", "ERROR" /* Error */, async (ctx, error, ...args) => {
@@ -350,6 +481,30 @@ var CommandOptionsSchema = z.object({
350
481
  async handleSyntaxError(context, error, _args) {
351
482
  error instanceof BakitError && await context.send(error.message);
352
483
  }
484
+ toSlashCommandJSON() {
485
+ let { name, description, nsfw, params } = this.options, builder = new SlashCommandBuilder().setName(name).setDescription(description).setNSFW(nsfw);
486
+ return this.initSlashCommandOptions(builder, params), builder.toJSON();
487
+ }
488
+ initSlashCommandOptions(builder, params) {
489
+ for (let param of params)
490
+ this.initSlashCommandOption(builder, param);
491
+ }
492
+ initSlashCommandOption(builder, param) {
493
+ let initOption = (builder2) => {
494
+ let { name, description, required } = param.options;
495
+ return builder2.setName(name).setDescription(description).setRequired(required);
496
+ };
497
+ if (param instanceof StringParam) {
498
+ let { maxLength, minLength } = param.options, option = initOption(new SlashCommandStringOption());
499
+ maxLength && option.setMaxLength(maxLength), minLength && option.setMinLength(minLength), builder.addStringOption(option);
500
+ return;
501
+ }
502
+ if (param instanceof NumberParam) {
503
+ let { maxValue, minValue } = param.options, option = initOption(new SlashCommandNumberOption());
504
+ maxValue && option.setMaxValue(maxValue), minValue && option.setMinValue(minValue), builder.addNumberOption(option);
505
+ return;
506
+ }
507
+ }
353
508
  };
354
509
  function defineCommand(options) {
355
510
  return new Command(options);
@@ -367,10 +522,11 @@ var CommandManager = class extends BaseClientManager {
367
522
  commands = new Collection();
368
523
  async loadModules() {
369
524
  let entryDir = posix.resolve(getConfig().entryDir), pattern = posix.join(entryDir, "commands", "**/*.{ts,js}"), loads = (await glob(pattern, {
370
- cwd: process.cwd()
525
+ cwd: process.cwd(),
526
+ absolute: true
371
527
  })).map(async (file) => {
372
528
  try {
373
- let { default: command } = await import(pathToFileURL(file).toString());
529
+ let command = await $jiti.import(file, { default: !0 });
374
530
  if (!command) {
375
531
  console.warn(`[Loader] File has no default export: ${file}`);
376
532
  return;
@@ -418,113 +574,17 @@ var ListenerOptionsSchema = z3.object({
418
574
  function defineListener(options) {
419
575
  return new Listener(options);
420
576
  }
421
- var INTENT_GROUPS = {
422
- [GatewayIntentBits.Guilds]: [
423
- Events.GuildCreate,
424
- Events.GuildDelete,
425
- Events.GuildUpdate,
426
- Events.GuildUnavailable,
427
- Events.GuildRoleCreate,
428
- Events.GuildRoleDelete,
429
- Events.GuildRoleUpdate,
430
- Events.ChannelCreate,
431
- Events.ChannelDelete,
432
- Events.ChannelUpdate,
433
- Events.ChannelPinsUpdate,
434
- Events.ThreadCreate,
435
- Events.ThreadDelete,
436
- Events.ThreadUpdate,
437
- Events.ThreadListSync,
438
- Events.ThreadMemberUpdate,
439
- Events.ThreadMembersUpdate,
440
- Events.StageInstanceCreate,
441
- Events.StageInstanceUpdate,
442
- Events.StageInstanceDelete
443
- ],
444
- [GatewayIntentBits.GuildMembers]: [
445
- Events.GuildMemberAdd,
446
- Events.GuildMemberUpdate,
447
- Events.GuildMemberRemove,
448
- Events.ThreadMembersUpdate
449
- ],
450
- [GatewayIntentBits.GuildModeration]: [Events.GuildAuditLogEntryCreate, Events.GuildBanAdd, Events.GuildBanRemove],
451
- [GatewayIntentBits.GuildExpressions]: [
452
- Events.GuildEmojiCreate,
453
- Events.GuildEmojiDelete,
454
- Events.GuildEmojiUpdate,
455
- Events.GuildStickerCreate,
456
- Events.GuildStickerDelete,
457
- Events.GuildStickerUpdate,
458
- Events.GuildSoundboardSoundCreate,
459
- Events.GuildSoundboardSoundUpdate,
460
- Events.GuildSoundboardSoundDelete,
461
- Events.GuildSoundboardSoundsUpdate
462
- ],
463
- [GatewayIntentBits.GuildIntegrations]: [Events.GuildIntegrationsUpdate],
464
- [GatewayIntentBits.GuildWebhooks]: [Events.WebhooksUpdate],
465
- [GatewayIntentBits.GuildInvites]: [Events.InviteCreate, Events.InviteDelete],
466
- [GatewayIntentBits.GuildVoiceStates]: [Events.VoiceStateUpdate],
467
- [GatewayIntentBits.GuildPresences]: [Events.PresenceUpdate],
468
- [GatewayIntentBits.GuildMessages]: [
469
- Events.MessageCreate,
470
- Events.MessageUpdate,
471
- Events.MessageDelete,
472
- Events.MessageBulkDelete
473
- ],
474
- [GatewayIntentBits.GuildMessageReactions]: [
475
- Events.MessageReactionAdd,
476
- Events.MessageReactionRemove,
477
- Events.MessageReactionRemoveAll,
478
- Events.MessageReactionRemoveEmoji
479
- ],
480
- [GatewayIntentBits.GuildMessageTyping]: [Events.TypingStart],
481
- [GatewayIntentBits.DirectMessages]: [
482
- Events.MessageCreate,
483
- Events.MessageUpdate,
484
- Events.MessageDelete,
485
- Events.ChannelPinsUpdate
486
- ],
487
- [GatewayIntentBits.DirectMessageReactions]: [
488
- Events.MessageReactionAdd,
489
- Events.MessageReactionRemove,
490
- Events.MessageReactionRemoveAll,
491
- Events.MessageReactionRemoveEmoji
492
- ],
493
- [GatewayIntentBits.DirectMessageTyping]: [Events.TypingStart],
494
- [GatewayIntentBits.MessageContent]: [Events.MessageCreate, Events.MessageUpdate],
495
- [GatewayIntentBits.GuildScheduledEvents]: [
496
- Events.GuildScheduledEventCreate,
497
- Events.GuildScheduledEventDelete,
498
- Events.GuildScheduledEventUpdate,
499
- Events.GuildScheduledEventUserAdd,
500
- Events.GuildScheduledEventUserRemove
501
- ],
502
- [GatewayIntentBits.AutoModerationConfiguration]: [
503
- Events.AutoModerationRuleCreate,
504
- Events.AutoModerationRuleDelete,
505
- Events.AutoModerationRuleUpdate
506
- ],
507
- [GatewayIntentBits.AutoModerationExecution]: [Events.AutoModerationActionExecution],
508
- [GatewayIntentBits.GuildMessagePolls]: [Events.MessagePollVoteAdd, Events.MessagePollVoteRemove],
509
- [GatewayIntentBits.DirectMessagePolls]: [Events.MessagePollVoteAdd, Events.MessagePollVoteRemove]
510
- }, EVENT_INTENT_MAPPING = {};
511
- for (let [intentStr, events] of Object.entries(INTENT_GROUPS)) {
512
- let intent = Number(intentStr);
513
- for (let event of events)
514
- EVENT_INTENT_MAPPING[event] ??= [], EVENT_INTENT_MAPPING[event].includes(intent) || EVENT_INTENT_MAPPING[event].push(intent);
515
- }
516
-
517
- // src/listener/ListenerManager.ts
518
577
  var ListenerManager = class extends BaseClientManager {
519
578
  listeners = [];
520
579
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
521
580
  executors = /* @__PURE__ */ new WeakMap();
522
581
  async loadModules() {
523
582
  let entryDir = posix.resolve(getConfig().entryDir), pattern = posix.join(entryDir, "listeners", "**/*.{ts,js}"), loads = (await glob(pattern, {
524
- cwd: process.cwd()
583
+ cwd: process.cwd(),
584
+ absolute: true
525
585
  })).map(async (file) => {
526
586
  try {
527
- let { default: listener } = await import(pathToFileURL(file).toString());
587
+ let listener = await $jiti.import(file, { default: !0 });
528
588
  if (!listener) {
529
589
  console.warn(`[Loader] File has no default export: ${file}`);
530
590
  return;
@@ -614,37 +674,20 @@ var BakitClient3 = class extends Client {
614
674
  return `${this.constructor.name} {}`;
615
675
  }
616
676
  };
617
-
618
- // src/utils/string.ts
619
- function tokenize(content) {
620
- let args = [], current = "", quoteChar = null, isEscaped = false;
621
- for (let i = 0; i < content.length; i++) {
622
- let char = content[i];
623
- if (char === void 0)
624
- break;
625
- if (isEscaped) {
626
- current += char, isEscaped = false;
627
- continue;
628
- }
629
- if (char === "\\") {
630
- isEscaped = true;
631
- continue;
632
- }
633
- quoteChar ? char === quoteChar ? quoteChar = null : current += char : char === '"' ? quoteChar = char : /\s/.test(char) ? current.length > 0 && (args.push(current), current = "") : current += char;
634
- }
635
- return current.length > 0 && args.push(current), args;
636
- }
637
677
  var ParamUserType = /* @__PURE__ */ ((ParamUserType2) => (ParamUserType2.Bot = "bot", ParamUserType2.Normal = "normal", ParamUserType2.Any = "any", ParamUserType2))(ParamUserType || {}), BaseParamSchema = z.object({
638
678
  name: z.string(),
639
679
  description: z.string().optional(),
640
680
  required: z.boolean().default(true)
681
+ }), withDefaultDescription = (data) => ({
682
+ ...data,
683
+ description: data.description ?? `${data.name}`
641
684
  }), StringParamSchema = BaseParamSchema.extend({
642
685
  maxLength: z.number().min(1).optional(),
643
686
  minLength: z.number().min(1).optional()
644
- }), NumberParamSchema = BaseParamSchema.extend({
687
+ }).transform(withDefaultDescription), NumberParamSchema = BaseParamSchema.extend({
645
688
  maxValue: z.number().optional(),
646
689
  minValue: z.number().optional()
647
- });
690
+ }).transform(withDefaultDescription);
648
691
 
649
692
  // src/command/param/Params.ts
650
693
  function createFactory(ctor) {
@@ -656,7 +699,14 @@ var Params = {
656
699
  };
657
700
 
658
701
  // src/defaults/command.ts
659
- var messageCommandHandler = defineListener(Events.MessageCreate), chatInputCommandHandler = defineListener(Events.InteractionCreate);
702
+ var messageCommandHandler = defineListener(Events.MessageCreate), chatInputCommandHandler = defineListener(Events.InteractionCreate), registerCommandsHandler = defineListener({
703
+ name: Events.ClientReady,
704
+ once: true
705
+ });
706
+ registerCommandsHandler.main(async (_, client) => {
707
+ let { commands } = client.managers, data = commands.commands.map((cmd) => cmd.toSlashCommandJSON()), result = await client.application.commands.set(data);
708
+ console.log(`Registered ${result.size} application command(s)`);
709
+ });
660
710
  messageCommandHandler.main(async (_, message) => {
661
711
  let config = getConfig();
662
712
  if (message.author.bot)
@@ -717,4 +767,4 @@ function useApp() {
717
767
  return new Instance();
718
768
  }
719
769
 
720
- 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 };
770
+ export { $jiti, 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, validateParamsOrder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.7",
4
4
  "description": "A framework for discord.js",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -10,6 +10,9 @@
10
10
  "type-check": "tsc --noEmit",
11
11
  "test": "vitest run --pass-with-no-tests"
12
12
  },
13
+ "bin": {
14
+ "bakit": "./bin/bakit.js"
15
+ },
13
16
  "files": [
14
17
  "dist"
15
18
  ],
@@ -34,7 +37,10 @@
34
37
  "discord.js": "^14.0.0"
35
38
  },
36
39
  "dependencies": {
40
+ "commander": "^14.0.2",
37
41
  "dotenv": "^17.2.1",
42
+ "jiti": "^2.6.1",
43
+ "nodemon": "^3.1.11",
38
44
  "tiny-glob": "^0.2.9",
39
45
  "type-fest": "^4.41.0",
40
46
  "zod": "^4.1.12"