bakit 1.0.0-beta.12 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -252,7 +252,6 @@ declare class ListenerEntry<E extends EventsLike, K extends keyof E> extends Bas
252
252
  }
253
253
 
254
254
  declare namespace ListenerAPI {
255
- const ENTRY_KEY: unique symbol;
256
255
  function use<E extends EventsLike, K extends keyof E>(entry: ListenerEntry<E, K>): (target: ConstructorLike) => void;
257
256
  function getEntry<E extends EventsLike, K extends keyof E>(target: ConstructorLike): ListenerEntry<E, K> | undefined;
258
257
  }
package/dist/index.js CHANGED
@@ -1,14 +1,17 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/index.ts
5
- import "reflect-metadata";
6
-
7
1
  // src/BakitClient.ts
8
- import { Client, codeBlock, Events } from "discord.js";
2
+ import {
3
+ Client,
4
+ codeBlock,
5
+ Events
6
+ } from "discord.js";
9
7
 
10
8
  // src/command/CommandRegistry.ts
11
- import { Collection as Collection2, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js";
9
+ import {
10
+ Collection as Collection2,
11
+ SlashCommandBuilder,
12
+ SlashCommandSubcommandBuilder,
13
+ SlashCommandSubcommandGroupBuilder
14
+ } from "discord.js";
12
15
  import glob from "tiny-glob";
13
16
  import { pathToFileURL } from "url";
14
17
 
@@ -16,33 +19,23 @@ import { pathToFileURL } from "url";
16
19
  import { Collection } from "discord.js";
17
20
 
18
21
  // src/base/BaseEntry.ts
19
- var HookExecutionState = /* @__PURE__ */ (function(HookExecutionState2) {
20
- HookExecutionState2["Main"] = "MAIN";
21
- HookExecutionState2["Pre"] = "PRE";
22
- HookExecutionState2["Post"] = "POST";
23
- HookExecutionState2["Error"] = "ERROR";
24
- return HookExecutionState2;
25
- })({});
26
22
  var BaseEntry = class {
27
- static {
28
- __name(this, "BaseEntry");
29
- }
30
23
  target;
31
24
  hooks = {
32
- ["MAIN"]: void 0,
33
- ["ERROR"]: void 0,
34
- ["POST"]: void 0,
35
- ["PRE"]: void 0
25
+ ["MAIN" /* Main */]: void 0,
26
+ ["ERROR" /* Error */]: void 0,
27
+ ["POST" /* Post */]: void 0,
28
+ ["PRE" /* Pre */]: void 0
36
29
  };
37
30
  main;
38
31
  pre;
39
32
  post;
40
33
  error;
41
34
  constructor() {
42
- this.main = this.createMainHookDecorator("MAIN");
43
- this.pre = this.createMainHookDecorator("PRE");
44
- this.post = this.createMainHookDecorator("POST");
45
- this.error = this.createMainHookDecorator("ERROR");
35
+ this.main = this.createMainHookDecorator("MAIN" /* Main */);
36
+ this.pre = this.createMainHookDecorator("PRE" /* Pre */);
37
+ this.post = this.createMainHookDecorator("POST" /* Post */);
38
+ this.error = this.createMainHookDecorator("ERROR" /* Error */);
46
39
  }
47
40
  setTarget(target) {
48
41
  this.target = target;
@@ -76,27 +69,15 @@ var BaseEntry = class {
76
69
 
77
70
  // src/command/CommandEntry.ts
78
71
  var BaseCommandEntry = class extends BaseEntry {
79
- static {
80
- __name(this, "BaseCommandEntry");
81
- }
82
- options;
83
72
  constructor(options) {
84
- super(), this.options = options;
73
+ super();
74
+ this.options = options;
85
75
  }
86
76
  };
87
77
  var BaseCommandGroupEntry = class extends BaseCommandEntry {
88
- static {
89
- __name(this, "BaseCommandGroupEntry");
90
- }
91
78
  children = new Collection();
92
79
  subcommand(options) {
93
- const fullOptions = typeof options === "string" ? {
94
- name: options,
95
- description: `${options} command`
96
- } : {
97
- description: `${options.name} command`,
98
- ...options
99
- };
80
+ const fullOptions = typeof options === "string" ? { name: options, description: `${options} command` } : { description: `${options.name} command`, ...options };
100
81
  if (this.children.has(fullOptions.name)) {
101
82
  throw new Error(`Entry "${fullOptions.name}" is already existed.`);
102
83
  }
@@ -106,17 +87,8 @@ var BaseCommandGroupEntry = class extends BaseCommandEntry {
106
87
  }
107
88
  };
108
89
  var RootCommandEntry = class extends BaseCommandGroupEntry {
109
- static {
110
- __name(this, "RootCommandEntry");
111
- }
112
90
  group(options) {
113
- const fullOptions = typeof options === "string" ? {
114
- name: options,
115
- description: `${options} command`
116
- } : {
117
- description: `${options.name} command`,
118
- ...options
119
- };
91
+ const fullOptions = typeof options === "string" ? { name: options, description: `${options} command` } : { description: `${options.name} command`, ...options };
120
92
  if (this.children.has(fullOptions.name)) {
121
93
  throw new Error(`Entry "${fullOptions.name}" is already existed.`);
122
94
  }
@@ -126,26 +98,21 @@ var RootCommandEntry = class extends BaseCommandGroupEntry {
126
98
  }
127
99
  };
128
100
  var CommandGroupEntry = class extends BaseCommandGroupEntry {
129
- static {
130
- __name(this, "CommandGroupEntry");
131
- }
132
- parent;
133
101
  constructor(options, parent) {
134
- super(options), this.parent = parent;
102
+ super(options);
103
+ this.parent = parent;
135
104
  }
136
105
  };
137
106
  var SubcommandEntry = class extends BaseCommandEntry {
138
- static {
139
- __name(this, "SubcommandEntry");
140
- }
141
- parent;
142
107
  constructor(options, parent) {
143
- super(options), this.parent = parent;
108
+ super(options);
109
+ this.parent = parent;
144
110
  }
145
111
  };
146
112
 
147
113
  // src/command/Command.ts
148
- (function(CommandAPI2) {
114
+ var CommandAPI;
115
+ ((CommandAPI2) => {
149
116
  const rootEntries = /* @__PURE__ */ new WeakMap();
150
117
  function use(root) {
151
118
  return (target) => {
@@ -153,65 +120,49 @@ var SubcommandEntry = class extends BaseCommandEntry {
153
120
  rootEntries.set(target, root);
154
121
  };
155
122
  }
156
- __name(use, "use");
157
123
  CommandAPI2.use = use;
158
124
  function getRoot(constructor) {
159
125
  return rootEntries.get(constructor);
160
126
  }
161
- __name(getRoot, "getRoot");
162
127
  CommandAPI2.getRoot = getRoot;
163
128
  })(CommandAPI || (CommandAPI = {}));
164
129
  function CommandFactory(options) {
165
130
  if (typeof options === "string") {
166
- options = {
167
- name: options
168
- };
131
+ options = { name: options };
169
132
  }
170
133
  if (!options.description) {
171
134
  options.description = options.name;
172
135
  }
173
136
  return new RootCommandEntry(options);
174
137
  }
175
- __name(CommandFactory, "CommandFactory");
176
138
  var Command = Object.assign(CommandFactory, CommandAPI);
177
- var CommandAPI;
178
139
 
179
140
  // src/command/argument/Argument.ts
180
- var ArgumentType = /* @__PURE__ */ (function(ArgumentType2) {
141
+ var ArgumentType = /* @__PURE__ */ ((ArgumentType2) => {
181
142
  ArgumentType2["String"] = "string";
182
143
  ArgumentType2["Integer"] = "integer";
183
144
  ArgumentType2["Number"] = "number";
184
145
  ArgumentType2["User"] = "user";
185
146
  ArgumentType2["Member"] = "member";
186
147
  return ArgumentType2;
187
- })({});
148
+ })(ArgumentType || {});
188
149
 
189
150
  // src/command/argument/Arg.ts
190
- var ARGS_KEY = Symbol("args");
191
- var cache = /* @__PURE__ */ new WeakMap();
151
+ var store = /* @__PURE__ */ new WeakMap();
192
152
  function getMethodArguments(method, init = false) {
193
- let args = cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
153
+ let args = store.get(method);
194
154
  if (!args) {
195
155
  args = [];
196
156
  if (init) {
197
- Reflect.defineMetadata(ARGS_KEY, args, method);
198
- cache.set(method, args);
157
+ store.set(method, args);
199
158
  }
200
159
  }
201
- return init ? args : Object.freeze([
202
- ...args
203
- ]);
160
+ return init ? args : Object.freeze([...args]);
204
161
  }
205
- __name(getMethodArguments, "getMethodArguments");
206
162
  function createArgument(type) {
207
163
  return function(options) {
208
- const objOptions = typeof options === "string" ? {
209
- name: options
210
- } : options;
211
- const fullOptions = {
212
- ...objOptions,
213
- type
214
- };
164
+ const objOptions = typeof options === "string" ? { name: options } : options;
165
+ const fullOptions = { ...objOptions, type };
215
166
  if (!fullOptions.description) {
216
167
  fullOptions.description = fullOptions.name;
217
168
  }
@@ -228,18 +179,15 @@ function createArgument(type) {
228
179
  };
229
180
  };
230
181
  }
231
- __name(createArgument, "createArgument");
232
- var string = createArgument(ArgumentType.String);
233
- var integer = createArgument(ArgumentType.Integer);
234
- var number = createArgument(ArgumentType.Number);
235
- var user = createArgument(ArgumentType.User);
236
- var member = createArgument(ArgumentType.Member);
182
+ var string = createArgument("string" /* String */);
183
+ var integer = createArgument("integer" /* Integer */);
184
+ var number = createArgument("number" /* Number */);
185
+ var user = createArgument("user" /* User */);
186
+ var member = createArgument("member" /* Member */);
237
187
  function describeArgumentExpectation(arg) {
238
- const parts = [
239
- arg.type
240
- ];
188
+ const parts = [arg.type];
241
189
  switch (arg.type) {
242
- case ArgumentType.String: {
190
+ case "string" /* String */: {
243
191
  if (arg.minLength && !arg.maxLength) {
244
192
  parts.push(`\u2265 ${String(arg.minLength)}`);
245
193
  }
@@ -251,8 +199,8 @@ function describeArgumentExpectation(arg) {
251
199
  }
252
200
  break;
253
201
  }
254
- case ArgumentType.Number:
255
- case ArgumentType.Integer: {
202
+ case "number" /* Number */:
203
+ case "integer" /* Integer */: {
256
204
  if (arg.minValue !== void 0 && arg.maxValue === void 0) {
257
205
  parts.push(`\u2265 ${String(arg.minValue)}`);
258
206
  }
@@ -264,14 +212,9 @@ function describeArgumentExpectation(arg) {
264
212
  }
265
213
  break;
266
214
  }
267
- case ArgumentType.User:
268
- case ArgumentType.Member: {
269
- break;
270
- }
271
215
  }
272
216
  return parts.join(", ");
273
217
  }
274
- __name(describeArgumentExpectation, "describeArgumentExpectation");
275
218
  function format(arg) {
276
219
  const { name, required, tuple } = arg;
277
220
  const opening = required ? "<" : "[";
@@ -279,7 +222,6 @@ function format(arg) {
279
222
  const prefix = tuple ? "..." : "";
280
223
  return `${opening}${prefix}${name}: ${describeArgumentExpectation(arg)}${closing}`;
281
224
  }
282
- __name(format, "format");
283
225
  var Arg = {
284
226
  getMethodArguments,
285
227
  createArgument,
@@ -294,15 +236,12 @@ var Arg = {
294
236
 
295
237
  // src/command/CommandRegistry.ts
296
238
  var CommandRegistry = class _CommandRegistry {
297
- static {
298
- __name(this, "CommandRegistry");
299
- }
300
239
  static constructors = new Collection2();
301
240
  static instances = new Collection2();
302
241
  /**
303
- * Add a command to the registry.
304
- * @param constructor The command class you want to add.
305
- */
242
+ * Add a command to the registry.
243
+ * @param constructor The command class you want to add.
244
+ */
306
245
  static add(constructor) {
307
246
  const root = Command.getRoot(constructor);
308
247
  if (!root) {
@@ -313,11 +252,11 @@ var CommandRegistry = class _CommandRegistry {
313
252
  this.instances.set(options.name, new constructor());
314
253
  }
315
254
  /**
316
- * Load and add all commands which matched provided glob pattern to the registry.
317
- * @param pattern glob pattern to load.
318
- * @param parallel load all matched results in parallel, enabled by default.
319
- * @returns All loaded command constructors.
320
- */
255
+ * Load and add all commands which matched provided glob pattern to the registry.
256
+ * @param pattern glob pattern to load.
257
+ * @param parallel load all matched results in parallel, enabled by default.
258
+ * @returns All loaded command constructors.
259
+ */
321
260
  static async load(pattern, parallel = true) {
322
261
  const files = await glob(pattern);
323
262
  const loaders = files.map(async (file) => {
@@ -336,10 +275,10 @@ var CommandRegistry = class _CommandRegistry {
336
275
  return result;
337
276
  }
338
277
  /**
339
- * Build a command into application command data.
340
- * @param constructor The command class you want to build.
341
- * @returns a REST JSON version of the application command data.
342
- */
278
+ * Build a command into application command data.
279
+ * @param constructor The command class you want to build.
280
+ * @returns a REST JSON version of the application command data.
281
+ */
343
282
  static buildSlashCommand(constructor) {
344
283
  const root = Command.getRoot(constructor);
345
284
  if (!root) {
@@ -357,7 +296,7 @@ var CommandRegistry = class _CommandRegistry {
357
296
  }
358
297
  static getMainHookArguments(entry) {
359
298
  const { hooks } = entry;
360
- const mainHook = hooks[HookExecutionState.Main];
299
+ const mainHook = hooks["MAIN" /* Main */];
361
300
  return mainHook ? Arg.getMethodArguments(mainHook.method) : [];
362
301
  }
363
302
  static buildSlashCommandSubcommands(parent, entry, inheritedArgs) {
@@ -384,20 +323,17 @@ var CommandRegistry = class _CommandRegistry {
384
323
  }
385
324
  static buildSlashCommandOptions(builder, args) {
386
325
  const argGroup = Object.groupBy(args, ({ required }) => required ? "required" : "optional");
387
- const orderedArgs = [
388
- ...argGroup.required || [],
389
- ...argGroup.optional || []
390
- ];
326
+ const orderedArgs = [...argGroup.required || [], ...argGroup.optional || []];
391
327
  for (const arg of orderedArgs) {
392
328
  this.attachSlashCommandOption(builder, arg);
393
329
  }
394
330
  }
395
331
  static attachSlashCommandOption(builder, arg) {
396
- const setupOption = /* @__PURE__ */ __name((option) => {
332
+ const setupOption = (option) => {
397
333
  return option.setName(arg.name).setDescription(arg.description || arg.name).setRequired(Boolean(arg.required));
398
- }, "setupOption");
334
+ };
399
335
  switch (arg.type) {
400
- case ArgumentType.String: {
336
+ case "string" /* String */: {
401
337
  builder.addStringOption((data) => {
402
338
  const option = setupOption(data);
403
339
  if (arg.maxLength) {
@@ -410,7 +346,7 @@ var CommandRegistry = class _CommandRegistry {
410
346
  });
411
347
  break;
412
348
  }
413
- case ArgumentType.Integer: {
349
+ case "integer" /* Integer */: {
414
350
  builder.addIntegerOption((data) => {
415
351
  const option = setupOption(data);
416
352
  if (arg.maxValue) {
@@ -423,7 +359,7 @@ var CommandRegistry = class _CommandRegistry {
423
359
  });
424
360
  break;
425
361
  }
426
- case ArgumentType.Number: {
362
+ case "number" /* Number */: {
427
363
  builder.addNumberOption((data) => {
428
364
  const option = setupOption(data);
429
365
  if (arg.maxValue) {
@@ -436,8 +372,8 @@ var CommandRegistry = class _CommandRegistry {
436
372
  });
437
373
  break;
438
374
  }
439
- case ArgumentType.User:
440
- case ArgumentType.Member: {
375
+ case "user" /* User */:
376
+ case "member" /* Member */: {
441
377
  builder.addUserOption((option) => setupOption(option));
442
378
  break;
443
379
  }
@@ -446,12 +382,11 @@ var CommandRegistry = class _CommandRegistry {
446
382
  };
447
383
 
448
384
  // src/command/Context.ts
449
- import { ChatInputCommandInteraction, Message } from "discord.js";
385
+ import {
386
+ ChatInputCommandInteraction,
387
+ Message
388
+ } from "discord.js";
450
389
  var BaseContext = class {
451
- static {
452
- __name(this, "BaseContext");
453
- }
454
- source;
455
390
  constructor(source) {
456
391
  this.source = source;
457
392
  }
@@ -499,14 +434,9 @@ var BaseContext = class {
499
434
  }
500
435
  };
501
436
  var ChatInputContext = class extends BaseContext {
502
- static {
503
- __name(this, "ChatInputContext");
504
- }
505
437
  async send(options) {
506
438
  if (typeof options === "string") {
507
- options = {
508
- content: options
509
- };
439
+ options = { content: options };
510
440
  }
511
441
  const sendOptions = {
512
442
  ...options,
@@ -520,9 +450,6 @@ var ChatInputContext = class extends BaseContext {
520
450
  }
521
451
  };
522
452
  var MessageContext = class extends BaseContext {
523
- static {
524
- __name(this, "MessageContext");
525
- }
526
453
  async send(options) {
527
454
  const { channel } = this;
528
455
  if (!channel?.isSendable()) {
@@ -544,19 +471,15 @@ function extractId(value) {
544
471
  }
545
472
  return null;
546
473
  }
547
- __name(extractId, "extractId");
548
474
 
549
475
  // src/errors/CommandSyntaxError.ts
550
- var CommandSyntaxErrorType = /* @__PURE__ */ (function(CommandSyntaxErrorType2) {
476
+ var CommandSyntaxErrorType = /* @__PURE__ */ ((CommandSyntaxErrorType2) => {
551
477
  CommandSyntaxErrorType2["MissingRequireArgument"] = "MISSING_REQUIRE_ARGUMENT";
552
478
  CommandSyntaxErrorType2["InvalidArgument"] = "INVALID_ARGUMENT";
553
479
  CommandSyntaxErrorType2["InvalidVariadicArgumentValue"] = "INVALID_VARIADIC_ARGUMENT_VALUE";
554
480
  return CommandSyntaxErrorType2;
555
- })({});
481
+ })(CommandSyntaxErrorType || {});
556
482
  var CommandSyntaxError = class extends Error {
557
- static {
558
- __name(this, "CommandSyntaxError");
559
- }
560
483
  arg;
561
484
  type;
562
485
  expected;
@@ -566,14 +489,11 @@ var CommandSyntaxError = class extends Error {
566
489
  const { arg, type, received } = options;
567
490
  const expected = Arg.describeArgumentExpectation(arg);
568
491
  switch (type) {
569
- case "MISSING_REQUIRE_ARGUMENT": {
570
- message = [
571
- `Missing required argument "${arg.name}"`,
572
- `> Expected: ${expected}`
573
- ].join("\n");
492
+ case "MISSING_REQUIRE_ARGUMENT" /* MissingRequireArgument */: {
493
+ message = [`Missing required argument "${arg.name}"`, `> Expected: ${expected}`].join("\n");
574
494
  break;
575
495
  }
576
- case "INVALID_ARGUMENT": {
496
+ case "INVALID_ARGUMENT" /* InvalidArgument */: {
577
497
  message = [
578
498
  `Invalid value received for argument "${arg.name}"`,
579
499
  `> Expected: ${expected}`,
@@ -581,7 +501,7 @@ var CommandSyntaxError = class extends Error {
581
501
  ].join("\n");
582
502
  break;
583
503
  }
584
- case "INVALID_VARIADIC_ARGUMENT_VALUE": {
504
+ case "INVALID_VARIADIC_ARGUMENT_VALUE" /* InvalidVariadicArgumentValue */: {
585
505
  message = [
586
506
  `Invalid value received for variadic argument "${arg.name}"`,
587
507
  `> Expected: ${expected}`,
@@ -608,33 +528,27 @@ var CommandSyntaxError = class extends Error {
608
528
 
609
529
  // src/command/argument/ArgumentResolver.ts
610
530
  var ArgumentResolver = class _ArgumentResolver {
611
- static {
612
- __name(this, "ArgumentResolver");
613
- }
614
- options;
615
- parsedValues = [];
616
531
  constructor(options) {
617
532
  this.options = options;
618
533
  }
534
+ parsedValues = [];
619
535
  /**
620
- * Get the first value as the command trigger.
621
- */
536
+ * Get the first value as the command trigger.
537
+ */
622
538
  get trigger() {
623
539
  return this.options.values[0];
624
540
  }
625
541
  /**
626
- * Get amount of specified argument values.
627
- */
542
+ * Get amount of specified argument values.
543
+ */
628
544
  get specifiedAmount() {
629
545
  return this.options.values.length - this.options.startAt;
630
546
  }
631
547
  /**
632
- * Get parsed raw values from content.
633
- */
548
+ * Get parsed raw values from content.
549
+ */
634
550
  get values() {
635
- return [
636
- ...this.options.values
637
- ];
551
+ return [...this.options.values];
638
552
  }
639
553
  get client() {
640
554
  return this.options.message.client;
@@ -646,9 +560,7 @@ var ArgumentResolver = class _ArgumentResolver {
646
560
  // Custom prefixes specified in options
647
561
  ...client.options.prefixes ?? [],
648
562
  // Use bot mention as prefix if enabled
649
- ...enableMentionPrefix ? [
650
- client.user.toString()
651
- ] : []
563
+ ...enableMentionPrefix ? [client.user.toString()] : []
652
564
  ];
653
565
  const prefix = prefixes.find((p) => message.content.startsWith(p)) ?? null;
654
566
  if (!prefix) {
@@ -658,6 +570,7 @@ var ArgumentResolver = class _ArgumentResolver {
658
570
  return new _ArgumentResolver({
659
571
  message,
660
572
  startAt: 1,
573
+ // Skip the command trigger
661
574
  values,
662
575
  args: [],
663
576
  prefix
@@ -671,9 +584,7 @@ var ArgumentResolver = class _ArgumentResolver {
671
584
  args,
672
585
  startAt: this.options.startAt
673
586
  });
674
- child.parsedValues = [
675
- ...this.parsedValues
676
- ];
587
+ child.parsedValues = [...this.parsedValues];
677
588
  if (!child.options.args.length) {
678
589
  return child;
679
590
  }
@@ -699,7 +610,7 @@ var ArgumentResolver = class _ArgumentResolver {
699
610
  if (matchedValue === null) {
700
611
  throw new CommandSyntaxError({
701
612
  arg,
702
- type: CommandSyntaxErrorType.InvalidArgument,
613
+ type: "INVALID_ARGUMENT" /* InvalidArgument */,
703
614
  received: value
704
615
  });
705
616
  }
@@ -726,7 +637,7 @@ var ArgumentResolver = class _ArgumentResolver {
726
637
  } else if (arg.required) {
727
638
  throw new CommandSyntaxError({
728
639
  arg,
729
- type: CommandSyntaxErrorType.MissingRequireArgument,
640
+ type: "MISSING_REQUIRE_ARGUMENT" /* MissingRequireArgument */,
730
641
  received: value
731
642
  });
732
643
  }
@@ -737,7 +648,7 @@ var ArgumentResolver = class _ArgumentResolver {
737
648
  if (arg.required) {
738
649
  throw new CommandSyntaxError({
739
650
  arg,
740
- type: CommandSyntaxErrorType.MissingRequireArgument,
651
+ type: "MISSING_REQUIRE_ARGUMENT" /* MissingRequireArgument */,
741
652
  received: "nothing"
742
653
  });
743
654
  }
@@ -755,7 +666,7 @@ var ArgumentResolver = class _ArgumentResolver {
755
666
  if (matchedValue === null) {
756
667
  throw new CommandSyntaxError({
757
668
  arg,
758
- type: CommandSyntaxErrorType.InvalidVariadicArgumentValue,
669
+ type: "INVALID_VARIADIC_ARGUMENT_VALUE" /* InvalidVariadicArgumentValue */,
759
670
  received: rest
760
671
  });
761
672
  }
@@ -764,7 +675,7 @@ var ArgumentResolver = class _ArgumentResolver {
764
675
  if (values.length === 0 && arg.required) {
765
676
  throw new CommandSyntaxError({
766
677
  arg,
767
- type: CommandSyntaxErrorType.MissingRequireArgument,
678
+ type: "MISSING_REQUIRE_ARGUMENT" /* MissingRequireArgument */,
768
679
  received: "nothing"
769
680
  });
770
681
  }
@@ -772,13 +683,13 @@ var ArgumentResolver = class _ArgumentResolver {
772
683
  }
773
684
  async matchValue(arg, value) {
774
685
  switch (arg.type) {
775
- case ArgumentType.User:
686
+ case "user" /* User */:
776
687
  return await this.matchUserValue(arg, value);
777
- case ArgumentType.Integer:
688
+ case "integer" /* Integer */:
778
689
  return this.matchIntegerValue(arg, value);
779
- case ArgumentType.Number:
690
+ case "number" /* Number */:
780
691
  return this.matchNumberValue(arg, value);
781
- case ArgumentType.String:
692
+ case "string" /* String */:
782
693
  return this.matchStringValue(arg, value);
783
694
  default:
784
695
  return null;
@@ -832,15 +743,15 @@ var ArgumentResolver = class _ArgumentResolver {
832
743
  }
833
744
  static resolveChatInput(interaction, arg) {
834
745
  switch (arg.type) {
835
- case ArgumentType.String:
746
+ case "string" /* String */:
836
747
  return interaction.options.getString(arg.name, arg.required);
837
- case ArgumentType.Integer:
748
+ case "integer" /* Integer */:
838
749
  return interaction.options.getInteger(arg.name, arg.required);
839
- case ArgumentType.Number:
750
+ case "number" /* Number */:
840
751
  return interaction.options.getNumber(arg.name, arg.required);
841
- case ArgumentType.User:
752
+ case "user" /* User */:
842
753
  return interaction.options.getUser(arg.name, arg.required);
843
- case ArgumentType.Member:
754
+ case "member" /* Member */:
844
755
  return interaction.options.getMember(arg.name);
845
756
  default:
846
757
  return null;
@@ -851,9 +762,6 @@ var ArgumentResolver = class _ArgumentResolver {
851
762
  // src/libs/StateBox.ts
852
763
  import { AsyncLocalStorage } from "async_hooks";
853
764
  var StateBox = class _StateBox {
854
- static {
855
- __name(this, "StateBox");
856
- }
857
765
  static STATES_KEY = Symbol("states");
858
766
  static storage = new AsyncLocalStorage();
859
767
  static getState() {
@@ -863,8 +771,8 @@ var StateBox = class _StateBox {
863
771
  }
864
772
  return state;
865
773
  }
866
- static run(fn, store = {}) {
867
- return this.storage.run(store, fn);
774
+ static run(fn, store2 = {}) {
775
+ return this.storage.run(store2, fn);
868
776
  }
869
777
  static wrap(fn) {
870
778
  const currentStore = this.storage.getStore();
@@ -896,61 +804,46 @@ var StateBox = class _StateBox {
896
804
 
897
805
  // src/listener/ListenerEntry.ts
898
806
  var ListenerEntry = class extends BaseEntry {
899
- static {
900
- __name(this, "ListenerEntry");
901
- }
902
- options;
903
807
  constructor(options) {
904
- super(), this.options = options;
808
+ super();
809
+ this.options = options;
905
810
  }
906
811
  };
907
812
 
908
813
  // src/listener/Listener.ts
909
- (function(ListenerAPI2) {
910
- ListenerAPI2.ENTRY_KEY = Symbol("entry");
814
+ var ListenerAPI;
815
+ ((ListenerAPI2) => {
816
+ const entries = /* @__PURE__ */ new WeakMap();
911
817
  function use(entry) {
912
818
  return (target) => {
913
- Reflect.defineMetadata(ListenerAPI2.ENTRY_KEY, entry, target);
819
+ entries.set(target, entry);
914
820
  };
915
821
  }
916
- __name(use, "use");
917
822
  ListenerAPI2.use = use;
918
823
  function getEntry(target) {
919
- return Reflect.getMetadata(ListenerAPI2.ENTRY_KEY, target);
824
+ return entries.get(target);
920
825
  }
921
- __name(getEntry, "getEntry");
922
826
  ListenerAPI2.getEntry = getEntry;
923
827
  })(ListenerAPI || (ListenerAPI = {}));
924
828
  function ListenerFactory(options) {
925
- const fullOptions = typeof options !== "object" ? {
926
- name: options,
927
- once: false
928
- } : {
929
- once: false,
930
- ...options
931
- };
829
+ const fullOptions = typeof options !== "object" ? { name: options, once: false } : { once: false, ...options };
932
830
  return new ListenerEntry(fullOptions);
933
831
  }
934
- __name(ListenerFactory, "ListenerFactory");
935
832
  var Listener = Object.assign(ListenerFactory, ListenerAPI);
936
- var ListenerAPI;
937
833
 
938
834
  // src/listener/ListenerRegistry.ts
939
835
  import glob2 from "tiny-glob";
940
836
  import { pathToFileURL as pathToFileURL2 } from "url";
941
837
  var ListenerRegistry = class {
942
- static {
943
- __name(this, "ListenerRegistry");
944
- }
945
838
  static client;
946
839
  static constructors = /* @__PURE__ */ new Set();
947
840
  static instances = /* @__PURE__ */ new WeakMap();
948
841
  static executors = /* @__PURE__ */ new WeakMap();
949
842
  /**
950
- * Add and register a listener to the registry.
951
- * If `options.emitter` is not provided, the registry will use the base `client` by default.
952
- * @param constructor The listener class you want to add.
953
- */
843
+ * Add and register a listener to the registry.
844
+ * If `options.emitter` is not provided, the registry will use the base `client` by default.
845
+ * @param constructor The listener class you want to add.
846
+ */
954
847
  static add(constructor) {
955
848
  const entry = Listener.getEntry(constructor);
956
849
  if (!entry) {
@@ -973,10 +866,10 @@ var ListenerRegistry = class {
973
866
  });
974
867
  }
975
868
  /**
976
- * Remove and unregister a listener from the registry.
977
- * @param constructor The listener class you want to remove.
978
- * @returns `boolean`, returns `true` if the listener is removed successfully.
979
- */
869
+ * Remove and unregister a listener from the registry.
870
+ * @param constructor The listener class you want to remove.
871
+ * @returns `boolean`, returns `true` if the listener is removed successfully.
872
+ */
980
873
  static remove(constructor) {
981
874
  const entry = Listener.getEntry(constructor);
982
875
  if (!entry) {
@@ -998,9 +891,9 @@ var ListenerRegistry = class {
998
891
  return true;
999
892
  }
1000
893
  /**
1001
- * Remove and unregister all listeners from the registry.
1002
- * @returns Amount of removed listeners.
1003
- */
894
+ * Remove and unregister all listeners from the registry.
895
+ * @returns Amount of removed listeners.
896
+ */
1004
897
  static removeAll() {
1005
898
  let removedAmount = 0;
1006
899
  for (const constructor of this.constructors) {
@@ -1011,9 +904,9 @@ var ListenerRegistry = class {
1011
904
  return removedAmount;
1012
905
  }
1013
906
  /**
1014
- * Set base client for the registry to fallback as default emitter. This should be used only by BakitClient and stay untouched.
1015
- * @param newClient base client to set for the registry.
1016
- */
907
+ * Set base client for the registry to fallback as default emitter. This should be used only by BakitClient and stay untouched.
908
+ * @param newClient base client to set for the registry.
909
+ */
1017
910
  static setClient(newClient) {
1018
911
  this.client = newClient;
1019
912
  }
@@ -1024,10 +917,10 @@ var ListenerRegistry = class {
1024
917
  }
1025
918
  const { hooks } = entry;
1026
919
  return async function(...args) {
1027
- const mainHook = hooks[HookExecutionState.Main];
1028
- const preHook = hooks[HookExecutionState.Pre];
1029
- const postHook = hooks[HookExecutionState.Post];
1030
- const errorHook = hooks[HookExecutionState.Error];
920
+ const mainHook = hooks["MAIN" /* Main */];
921
+ const preHook = hooks["PRE" /* Pre */];
922
+ const postHook = hooks["POST" /* Post */];
923
+ const errorHook = hooks["ERROR" /* Error */];
1031
924
  if (!mainHook) {
1032
925
  return;
1033
926
  }
@@ -1041,7 +934,11 @@ var ListenerRegistry = class {
1041
934
  }
1042
935
  } catch (error) {
1043
936
  if (errorHook) {
1044
- await errorHook.method.call(instance, error, ...args);
937
+ await errorHook.method.call(
938
+ instance,
939
+ error,
940
+ ...args
941
+ );
1045
942
  } else {
1046
943
  throw error;
1047
944
  }
@@ -1049,11 +946,11 @@ var ListenerRegistry = class {
1049
946
  };
1050
947
  }
1051
948
  /**
1052
- * Load and add all listeners which matched provided glob pattern to the registry.
1053
- * @param pattern glob pattern to load.
1054
- * @param parallel load all matched results in parallel, enabled by default.
1055
- * @returns All loaded listener constructors.
1056
- */
949
+ * Load and add all listeners which matched provided glob pattern to the registry.
950
+ * @param pattern glob pattern to load.
951
+ * @param parallel load all matched results in parallel, enabled by default.
952
+ * @returns All loaded listener constructors.
953
+ */
1057
954
  static async load(pattern, parallel = true) {
1058
955
  const files = await glob2(pattern);
1059
956
  const loaders = files.map(async (file) => {
@@ -1075,20 +972,20 @@ var ListenerRegistry = class {
1075
972
 
1076
973
  // src/BakitClient.ts
1077
974
  var BakitClient = class _BakitClient extends Client {
1078
- static {
1079
- __name(this, "BakitClient");
1080
- }
1081
975
  constructor(options) {
1082
976
  if (options.getSyntaxErrorMessage === void 0) {
1083
977
  options.getSyntaxErrorMessage = _BakitClient.getSyntaxErrorMessage;
1084
978
  }
1085
979
  super(options);
1086
980
  ListenerRegistry["setClient"](this);
1087
- this.once(Events.ClientReady, (client) => void this.registerApplicationCommands(client));
981
+ this.once(
982
+ Events.ClientReady,
983
+ (client) => void this.registerApplicationCommands(client)
984
+ );
1088
985
  this.on(Events.InteractionCreate, (interaction) => void this.handleInteraction(interaction));
1089
986
  this.on(Events.MessageCreate, (message) => void this.handleMessage(message));
1090
987
  }
1091
- static getSyntaxErrorMessage = /* @__PURE__ */ __name((command, error, context, args, prefix) => {
988
+ static getSyntaxErrorMessage = (command, error, context, args, prefix) => {
1092
989
  const requiredSyntax = args.map((x) => Arg.format(x)).join(" ");
1093
990
  const root = Command.getRoot(command.constructor);
1094
991
  if (!root) {
@@ -1102,7 +999,7 @@ var BakitClient = class _BakitClient extends Client {
1102
999
  return {
1103
1000
  content
1104
1001
  };
1105
- }, "getSyntaxErrorMessage");
1002
+ };
1106
1003
  async registerApplicationCommands(client) {
1107
1004
  const commands = CommandRegistry.constructors.map((c) => CommandRegistry.buildSlashCommand(c));
1108
1005
  await client.application.commands.set(commands);
@@ -1138,11 +1035,7 @@ var BakitClient = class _BakitClient extends Client {
1138
1035
  async handleChatInputHooks(context, instance) {
1139
1036
  const targetHooks = this.getChatInputTargetHooks(context.source, instance);
1140
1037
  let inheritedArgs = [];
1141
- for (const hooks of [
1142
- targetHooks.root,
1143
- targetHooks.group,
1144
- targetHooks.subcommand
1145
- ]) {
1038
+ for (const hooks of [targetHooks.root, targetHooks.group, targetHooks.subcommand]) {
1146
1039
  if (!hooks) {
1147
1040
  continue;
1148
1041
  }
@@ -1182,7 +1075,7 @@ var BakitClient = class _BakitClient extends Client {
1182
1075
  }
1183
1076
  }
1184
1077
  async runMessageHooks(context, instance, hooks, resolver) {
1185
- const mainHook = hooks[HookExecutionState.Main];
1078
+ const mainHook = hooks["MAIN" /* Main */];
1186
1079
  if (!mainHook) {
1187
1080
  return resolver;
1188
1081
  }
@@ -1191,7 +1084,13 @@ var BakitClient = class _BakitClient extends Client {
1191
1084
  resolver = await resolver.resolve(args);
1192
1085
  } catch (error) {
1193
1086
  if (error instanceof CommandSyntaxError) {
1194
- const errorContent = await this.options.getSyntaxErrorMessage?.(instance, error, context, args, resolver.options.prefix);
1087
+ const errorContent = await this.options.getSyntaxErrorMessage?.(
1088
+ instance,
1089
+ error,
1090
+ context,
1091
+ args,
1092
+ resolver.options.prefix
1093
+ );
1195
1094
  if (errorContent) {
1196
1095
  await context.send(errorContent);
1197
1096
  }
@@ -1203,36 +1102,35 @@ var BakitClient = class _BakitClient extends Client {
1203
1102
  return resolver;
1204
1103
  }
1205
1104
  async runChatInputHooks(context, instance, hooks, inheritedArgs) {
1206
- const mainHook = hooks[HookExecutionState.Main];
1105
+ const mainHook = hooks["MAIN" /* Main */];
1207
1106
  if (!mainHook) {
1208
1107
  return;
1209
1108
  }
1210
- const newArgs = Arg.getMethodArguments(mainHook.method).map((arg) => ArgumentResolver.resolveChatInput(context.source, arg));
1211
- const argValues = [
1212
- ...inheritedArgs,
1213
- ...newArgs
1214
- ];
1109
+ const newArgs = Arg.getMethodArguments(mainHook.method).map(
1110
+ (arg) => ArgumentResolver.resolveChatInput(context.source, arg)
1111
+ );
1112
+ const argValues = [...inheritedArgs, ...newArgs];
1215
1113
  await this.runHooks(context, instance, hooks, argValues);
1216
1114
  return argValues;
1217
1115
  }
1218
1116
  async runHooks(context, instance, hooks, args) {
1219
- const mainHook = hooks[HookExecutionState.Main];
1220
- const preHook = hooks[HookExecutionState.Pre];
1221
- const postHook = hooks[HookExecutionState.Post];
1222
- const errorHook = hooks[HookExecutionState.Error];
1117
+ const mainHook = hooks["MAIN" /* Main */];
1118
+ const preHook = hooks["PRE" /* Pre */];
1119
+ const postHook = hooks["POST" /* Post */];
1120
+ const errorHook = hooks["ERROR" /* Error */];
1223
1121
  if (!mainHook) {
1224
1122
  return;
1225
1123
  }
1226
- const execute = /* @__PURE__ */ __name(async (hook, error) => {
1124
+ const execute = async (hook, error) => {
1227
1125
  if (!hook) {
1228
1126
  return;
1229
1127
  }
1230
- if (hook.state === HookExecutionState.Error) {
1128
+ if (hook.state === "ERROR" /* Error */) {
1231
1129
  await hook.method.call(instance, error, context, ...args);
1232
1130
  } else {
1233
1131
  await hook.method.call(instance, context, ...args);
1234
1132
  }
1235
- }, "execute");
1133
+ };
1236
1134
  try {
1237
1135
  await execute(preHook);
1238
1136
  await execute(mainHook);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
4
4
  "description": "A framework for discord.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,7 +38,6 @@
38
38
  "discord.js": "^14.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "reflect-metadata": "^0.2.2",
42
41
  "tiny-glob": "^0.2.9",
43
42
  "type-fest": "^4.41.0"
44
43
  },