bakit 1.0.0-beta.10 → 1.0.0-beta.12

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