bakit 1.0.0-beta.1 → 1.0.0-beta.3

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.
@@ -31,13 +31,15 @@ declare class MessageContext<Cached extends boolean = boolean, InGuild extends b
31
31
  type Context<Cached extends boolean = boolean, InGuild extends boolean = boolean> = ChatInputContext<Cached, InGuild> | MessageContext<Cached, InGuild>;
32
32
 
33
33
  type CommandConstructor = new (...args: unknown[]) => object;
34
- declare abstract class Command {
35
- static create(options: CreateOptions<BaseCommandEntryOptions>): RootCommandEntry;
36
- static use(command: RootCommandEntry): (target: CommandConstructor) => void;
37
- static getRoot(constructor: CommandConstructor): RootCommandEntry | undefined;
38
- }
34
+ declare function use(command: RootCommandEntry): (target: CommandConstructor) => void;
35
+ declare function getRoot(constructor: CommandConstructor): RootCommandEntry | undefined;
36
+ declare function CommandFactory(options: CreateCommandOptions<BaseCommandEntryOptions> | string): RootCommandEntry;
37
+ declare const Command: typeof CommandFactory & {
38
+ use: typeof use;
39
+ getRoot: typeof getRoot;
40
+ };
39
41
 
40
- declare enum HookExecutionState {
42
+ declare enum CommandHookExecutionState {
41
43
  Main = "main",
42
44
  Pre = "pre",
43
45
  Post = "post",
@@ -45,7 +47,7 @@ declare enum HookExecutionState {
45
47
  }
46
48
  type CommandHookMethod = (ctx: Context, ...args: any[]) => Awaitable<void>;
47
49
  interface CommandHook {
48
- state: HookExecutionState;
50
+ state: CommandHookExecutionState;
49
51
  method: CommandHookMethod;
50
52
  entry: CommandEntry;
51
53
  }
@@ -54,7 +56,7 @@ interface BaseCommandEntryOptions {
54
56
  description: string;
55
57
  nsfw?: boolean;
56
58
  }
57
- type CreateOptions<T extends BaseCommandEntryOptions> = SetOptional<T, "description"> | string;
59
+ type CreateCommandOptions<T extends BaseCommandEntryOptions> = SetOptional<T, "description"> | string;
58
60
  declare const HOOKS_KEY: unique symbol;
59
61
  declare abstract class BaseCommandEntry {
60
62
  options: BaseCommandEntryOptions;
@@ -72,7 +74,7 @@ declare abstract class BaseCommandEntry {
72
74
  }
73
75
  declare abstract class BaseCommandGroupEntry extends BaseCommandEntry {
74
76
  children: Collection<string, CommandGroupEntry | SubcommandEntry>;
75
- subcommand(options: CreateOptions<BaseCommandEntryOptions>): SubcommandEntry;
77
+ subcommand(options: CreateCommandOptions<BaseCommandEntryOptions>): SubcommandEntry;
76
78
  }
77
79
  declare class CommandGroupEntry extends BaseCommandGroupEntry {
78
80
  options: BaseCommandEntryOptions;
@@ -83,7 +85,7 @@ declare class CommandGroupEntry extends BaseCommandGroupEntry {
83
85
  declare class RootCommandEntry extends BaseCommandGroupEntry {
84
86
  options: BaseCommandEntryOptions;
85
87
  constructor(options: BaseCommandEntryOptions);
86
- group(options: CreateOptions<BaseCommandEntryOptions>): CommandGroupEntry;
88
+ group(options: CreateCommandOptions<BaseCommandEntryOptions>): CommandGroupEntry;
87
89
  }
88
90
  declare class SubcommandEntry extends BaseCommandEntry {
89
91
  options: BaseCommandEntryOptions;
@@ -129,19 +131,22 @@ interface MemberArgumentOptions extends BaseArgumentOptions {
129
131
  }
130
132
  type ArgumentOptions = StringArgumentOptions | IntegerArgumentOptions | NumberArgumentOptions | UserArgumentOptions | MemberArgumentOptions;
131
133
 
132
- declare abstract class Arg {
133
- private static cache;
134
- static string: (options: string | Omit<StringArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
135
- static integer: (options: string | Omit<IntegerArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
136
- static number: (options: string | Omit<NumberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
137
- static user: (options: string | Omit<UserArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
138
- static member: (options: string | Omit<MemberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
139
- static getMethodArguments(method: CommandHook["method"]): readonly ArgumentOptions[];
140
- static getMethodArguments(method: CommandHook["method"], init: true): ArgumentOptions[];
141
- static format(arg: ArgumentOptions): string;
142
- static describeArgumentExpectation(arg: ArgumentOptions): string;
143
- protected static createArgument<Options extends ArgumentOptions>(type: Options["type"]): (options: Omit<Options, "type"> | string) => (target: object, key: string | symbol, _index: number) => void;
144
- }
134
+ declare function getMethodArguments(method: CommandHook["method"]): readonly ArgumentOptions[];
135
+ declare function getMethodArguments(method: CommandHook["method"], init: true): ArgumentOptions[];
136
+ declare function createArgument<Options extends ArgumentOptions>(type: Options["type"]): (options: Omit<Options, "type"> | string) => (target: object, key: string | symbol, _index: number) => void;
137
+ declare function describeArgumentExpectation(arg: ArgumentOptions): string;
138
+ declare function format(arg: ArgumentOptions): string;
139
+ declare const Arg: {
140
+ getMethodArguments: typeof getMethodArguments;
141
+ createArgument: typeof createArgument;
142
+ describeArgumentExpectation: typeof describeArgumentExpectation;
143
+ format: typeof format;
144
+ string: (options: string | Omit<StringArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
145
+ number: (options: string | Omit<NumberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
146
+ integer: (options: string | Omit<IntegerArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
147
+ user: (options: string | Omit<UserArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
148
+ member: (options: string | Omit<MemberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
149
+ };
145
150
 
146
151
  declare class CommandRegistry {
147
152
  static constructors: Collection<string, CommandConstructor>;
@@ -196,4 +201,4 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
196
201
  private createHookRecord;
197
202
  }
198
203
 
199
- export { Arg as A, type BakitClientOptions as B, type CommandHookMethod as C, type GetSyntaxErrorMessageFunction as G, HookExecutionState as H, type IntegerArgumentOptions as I, type MemberArgumentOptions as M, type NumberArgumentOptions as N, RootCommandEntry as R, type StringArgumentOptions as S, type UserArgumentOptions as U, BakitClient as a, ArgumentType as b, type BaseArgumentOptions as c, type ArgumentOptions as d, type CommandHook as e, type BaseCommandEntryOptions as f, type CreateOptions as g, HOOKS_KEY as h, BaseCommandEntry as i, BaseCommandGroupEntry as j, CommandGroupEntry as k, SubcommandEntry as l, type CommandEntry as m, type CommandConstructor as n, Command as o, CommandRegistry as p, type ChatInputContextSendOptions as q, type MessageContextSendOptions as r, type ContextSendOptions as s, BaseContext as t, ChatInputContext as u, MessageContext as v, type Context as w, CommandSyntaxErrorType as x, type CommandSyntaxErrorOptions as y, CommandSyntaxError as z };
204
+ export { Arg as A, type BakitClientOptions as B, CommandHookExecutionState as C, CommandSyntaxErrorType as D, type CommandSyntaxErrorOptions as E, CommandSyntaxError as F, type GetSyntaxErrorMessageFunction as G, HOOKS_KEY as H, type IntegerArgumentOptions as I, type MemberArgumentOptions as M, type NumberArgumentOptions as N, RootCommandEntry as R, type StringArgumentOptions as S, type UserArgumentOptions as U, BakitClient as a, ArgumentType as b, type BaseArgumentOptions as c, type ArgumentOptions as d, type CommandHookMethod as e, type CommandHook as f, type BaseCommandEntryOptions as g, type CreateCommandOptions as h, BaseCommandEntry as i, BaseCommandGroupEntry as j, CommandGroupEntry as k, SubcommandEntry as l, type CommandEntry as m, type CommandConstructor as n, getRoot as o, CommandFactory as p, Command as q, CommandRegistry as r, type ChatInputContextSendOptions as s, type MessageContextSendOptions as t, use as u, type ContextSendOptions as v, BaseContext as w, ChatInputContext as x, MessageContext as y, type Context as z };
@@ -1,3 +1,3 @@
1
- export { A as Arg, d as ArgumentOptions, b as ArgumentType, c as BaseArgumentOptions, i as BaseCommandEntry, f as BaseCommandEntryOptions, j as BaseCommandGroupEntry, t as BaseContext, u as ChatInputContext, q as ChatInputContextSendOptions, o as Command, n as CommandConstructor, m as CommandEntry, k as CommandGroupEntry, e as CommandHook, C as CommandHookMethod, p as CommandRegistry, w as Context, s as ContextSendOptions, g as CreateOptions, h as HOOKS_KEY, H as HookExecutionState, I as IntegerArgumentOptions, M as MemberArgumentOptions, v as MessageContext, r as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions } from '../BakitClient-BWxRFtSg.js';
1
+ export { A as Arg, d as ArgumentOptions, b as ArgumentType, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, w as BaseContext, x as ChatInputContext, s as ChatInputContextSendOptions, q as Command, n as CommandConstructor, m as CommandEntry, p as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, r as CommandRegistry, z as Context, v as ContextSendOptions, h as CreateCommandOptions, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, y as MessageContext, t as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions, o as getRoot, u as use } from '../BakitClient-BWs93qO-.js';
2
2
  import 'discord.js';
3
3
  import 'type-fest';
@@ -13,97 +13,106 @@ var ArgumentType = /* @__PURE__ */ ((ArgumentType2) => {
13
13
 
14
14
  // src/command/argument/Arg.ts
15
15
  var ARGS_KEY = Symbol("args");
16
- var Arg = class _Arg {
17
- static cache = /* @__PURE__ */ new WeakMap();
18
- static string = _Arg.createArgument("string" /* String */);
19
- static integer = _Arg.createArgument("integer" /* Integer */);
20
- static number = _Arg.createArgument("number" /* Number */);
21
- static user = _Arg.createArgument("user" /* User */);
22
- static member = _Arg.createArgument("member" /* Member */);
23
- static getMethodArguments(method, init = false) {
24
- let args = this.cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
25
- if (!args) {
26
- args = [];
27
- if (init) {
28
- Reflect.defineMetadata(ARGS_KEY, args, method);
29
- this.cache.set(method, args);
30
- }
16
+ var cache = /* @__PURE__ */ new WeakMap();
17
+ function getMethodArguments(method, init = false) {
18
+ let args = cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
19
+ if (!args) {
20
+ args = [];
21
+ if (init) {
22
+ Reflect.defineMetadata(ARGS_KEY, args, method);
23
+ cache.set(method, args);
31
24
  }
32
- return init ? args : Object.freeze([...args]);
33
25
  }
34
- static format(arg) {
35
- const { name, required, tuple } = arg;
36
- const opening = required ? "<" : "[";
37
- const closing = required ? ">" : "]";
38
- const prefix = tuple ? "..." : "";
39
- return `${opening}${prefix}${name}: ${this.describeArgumentExpectation(arg)}${closing}`;
40
- }
41
- static describeArgumentExpectation(arg) {
42
- const parts = [arg.type];
43
- switch (arg.type) {
44
- case "string" /* String */: {
45
- if (arg.minLength && !arg.maxLength) {
46
- parts.push(`\u2265 ${String(arg.minLength)}`);
47
- }
48
- if (!arg.minLength && arg.maxLength) {
49
- parts.push(`\u2264 ${String(arg.maxLength)}`);
50
- }
51
- if (arg.minLength && arg.maxLength) {
52
- parts.push(`${String(arg.minLength)} - ${String(arg.maxLength)}`);
53
- }
54
- break;
26
+ return init ? args : Object.freeze([...args]);
27
+ }
28
+ function createArgument(type) {
29
+ return function(options) {
30
+ const objOptions = typeof options === "string" ? { name: options } : options;
31
+ const fullOptions = { ...objOptions, type };
32
+ if (!fullOptions.description) {
33
+ fullOptions.description = fullOptions.name;
34
+ }
35
+ if (!("required" in fullOptions)) {
36
+ fullOptions.required = true;
37
+ }
38
+ return function(target, key, _index) {
39
+ const method = Object.getOwnPropertyDescriptor(target, key)?.value;
40
+ if (!method) {
41
+ throw new Error("No method found");
55
42
  }
56
- case "number" /* Number */:
57
- case "integer" /* Integer */: {
58
- if (arg.minValue !== void 0 && arg.maxValue === void 0) {
59
- parts.push(`\u2265 ${String(arg.minValue)}`);
60
- }
61
- if (arg.minValue === void 0 && arg.maxValue !== void 0) {
62
- parts.push(`\u2264 ${String(arg.maxValue)}`);
63
- }
64
- if (arg.minValue !== void 0 && arg.maxValue !== void 0) {
65
- parts.push(`${String(arg.minValue)} - ${String(arg.maxValue)}`);
66
- }
67
- break;
43
+ const args = getMethodArguments(method, true);
44
+ args.unshift(fullOptions);
45
+ };
46
+ };
47
+ }
48
+ var string = createArgument("string" /* String */);
49
+ var integer = createArgument("integer" /* Integer */);
50
+ var number = createArgument("number" /* Number */);
51
+ var user = createArgument("user" /* User */);
52
+ var member = createArgument("member" /* Member */);
53
+ function describeArgumentExpectation(arg) {
54
+ const parts = [arg.type];
55
+ switch (arg.type) {
56
+ case "string" /* String */: {
57
+ if (arg.minLength && !arg.maxLength) {
58
+ parts.push(`\u2265 ${String(arg.minLength)}`);
68
59
  }
69
- case "user" /* User */:
70
- case "member" /* Member */: {
71
- break;
60
+ if (!arg.minLength && arg.maxLength) {
61
+ parts.push(`\u2264 ${String(arg.maxLength)}`);
62
+ }
63
+ if (arg.minLength && arg.maxLength) {
64
+ parts.push(`${String(arg.minLength)} - ${String(arg.maxLength)}`);
72
65
  }
66
+ break;
73
67
  }
74
- return parts.join(", ");
75
- }
76
- static createArgument(type) {
77
- return function(options) {
78
- const objOptions = typeof options === "string" ? { name: options } : options;
79
- const fullOptions = { ...objOptions, type };
80
- if (!fullOptions.description) {
81
- fullOptions.description = fullOptions.name;
68
+ case "number" /* Number */:
69
+ case "integer" /* Integer */: {
70
+ if (arg.minValue !== void 0 && arg.maxValue === void 0) {
71
+ parts.push(`\u2265 ${String(arg.minValue)}`);
82
72
  }
83
- if (!("required" in fullOptions)) {
84
- fullOptions.required = true;
73
+ if (arg.minValue === void 0 && arg.maxValue !== void 0) {
74
+ parts.push(`\u2264 ${String(arg.maxValue)}`);
85
75
  }
86
- return function(target, key, _index) {
87
- const method = Object.getOwnPropertyDescriptor(target, key)?.value;
88
- if (!method) {
89
- throw new Error("No method found");
90
- }
91
- const args = _Arg.getMethodArguments(method, true);
92
- args.unshift(fullOptions);
93
- };
94
- };
76
+ if (arg.minValue !== void 0 && arg.maxValue !== void 0) {
77
+ parts.push(`${String(arg.minValue)} - ${String(arg.maxValue)}`);
78
+ }
79
+ break;
80
+ }
81
+ case "user" /* User */:
82
+ case "member" /* Member */: {
83
+ break;
84
+ }
95
85
  }
86
+ return parts.join(", ");
87
+ }
88
+ function format(arg) {
89
+ const { name, required, tuple } = arg;
90
+ const opening = required ? "<" : "[";
91
+ const closing = required ? ">" : "]";
92
+ const prefix = tuple ? "..." : "";
93
+ return `${opening}${prefix}${name}: ${describeArgumentExpectation(arg)}${closing}`;
94
+ }
95
+ var Arg = {
96
+ getMethodArguments,
97
+ createArgument,
98
+ describeArgumentExpectation,
99
+ format,
100
+ string,
101
+ number,
102
+ integer,
103
+ user,
104
+ member
96
105
  };
97
106
 
98
107
  // src/command/CommandEntry.ts
99
108
  import { Collection } from "discord.js";
100
- var HookExecutionState = /* @__PURE__ */ ((HookExecutionState2) => {
101
- HookExecutionState2["Main"] = "main";
102
- HookExecutionState2["Pre"] = "pre";
103
- HookExecutionState2["Post"] = "post";
104
- HookExecutionState2["Error"] = "error";
105
- return HookExecutionState2;
106
- })(HookExecutionState || {});
109
+ var CommandHookExecutionState = /* @__PURE__ */ ((CommandHookExecutionState2) => {
110
+ CommandHookExecutionState2["Main"] = "main";
111
+ CommandHookExecutionState2["Pre"] = "pre";
112
+ CommandHookExecutionState2["Post"] = "post";
113
+ CommandHookExecutionState2["Error"] = "error";
114
+ return CommandHookExecutionState2;
115
+ })(CommandHookExecutionState || {});
107
116
  var HOOKS_KEY = Symbol("hooks");
108
117
  var BaseCommandEntry = class _BaseCommandEntry {
109
118
  constructor(options) {
@@ -221,25 +230,27 @@ var SubcommandEntry = class extends BaseCommandEntry {
221
230
 
222
231
  // src/command/Command.ts
223
232
  var ROOT_KEY = Symbol("root");
224
- var Command = class {
225
- static create(options) {
226
- if (typeof options === "string") {
227
- options = { name: options };
228
- }
229
- if (!options.description) {
230
- options.description = options.name;
231
- }
232
- return new RootCommandEntry(options);
233
- }
234
- static use(command) {
235
- return (target) => {
236
- Reflect.defineMetadata(ROOT_KEY, command, target);
237
- };
238
- }
239
- static getRoot(constructor) {
240
- return Reflect.getMetadata(ROOT_KEY, constructor);
241
- }
242
- };
233
+ function use(command) {
234
+ return (target) => {
235
+ Reflect.defineMetadata(ROOT_KEY, command, target);
236
+ };
237
+ }
238
+ function getRoot(constructor) {
239
+ return Reflect.getMetadata(ROOT_KEY, constructor);
240
+ }
241
+ function CommandFactory(options) {
242
+ if (typeof options === "string") {
243
+ options = { name: options };
244
+ }
245
+ if (!options.description) {
246
+ options.description = options.name;
247
+ }
248
+ return new RootCommandEntry(options);
249
+ }
250
+ var Command = Object.assign(CommandFactory, {
251
+ use,
252
+ getRoot
253
+ });
243
254
 
244
255
  // src/command/CommandRegistry.ts
245
256
  import {
@@ -454,11 +465,14 @@ export {
454
465
  BaseContext,
455
466
  ChatInputContext,
456
467
  Command,
468
+ CommandFactory,
457
469
  CommandGroupEntry,
470
+ CommandHookExecutionState,
458
471
  CommandRegistry,
459
472
  HOOKS_KEY,
460
- HookExecutionState,
461
473
  MessageContext,
462
474
  RootCommandEntry,
463
- SubcommandEntry
475
+ SubcommandEntry,
476
+ getRoot,
477
+ use
464
478
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Arg, d as ArgumentOptions, b as ArgumentType, a as BakitClient, B as BakitClientOptions, c as BaseArgumentOptions, i as BaseCommandEntry, f as BaseCommandEntryOptions, j as BaseCommandGroupEntry, t as BaseContext, u as ChatInputContext, q as ChatInputContextSendOptions, o as Command, n as CommandConstructor, m as CommandEntry, k as CommandGroupEntry, e as CommandHook, C as CommandHookMethod, p as CommandRegistry, z as CommandSyntaxError, y as CommandSyntaxErrorOptions, x as CommandSyntaxErrorType, w as Context, s as ContextSendOptions, g as CreateOptions, G as GetSyntaxErrorMessageFunction, h as HOOKS_KEY, H as HookExecutionState, I as IntegerArgumentOptions, M as MemberArgumentOptions, v as MessageContext, r as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions } from './BakitClient-BWxRFtSg.js';
1
+ export { A as Arg, d as ArgumentOptions, b as ArgumentType, a as BakitClient, B as BakitClientOptions, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, w as BaseContext, x as ChatInputContext, s as ChatInputContextSendOptions, q as Command, n as CommandConstructor, m as CommandEntry, p as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, r as CommandRegistry, F as CommandSyntaxError, E as CommandSyntaxErrorOptions, D as CommandSyntaxErrorType, z as Context, v as ContextSendOptions, h as CreateCommandOptions, G as GetSyntaxErrorMessageFunction, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, y as MessageContext, t as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions, o as getRoot, u as use } from './BakitClient-BWs93qO-.js';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import 'discord.js';
4
4
  import 'type-fest';
package/dist/index.js CHANGED
@@ -30,96 +30,105 @@ var ArgumentType = /* @__PURE__ */ ((ArgumentType2) => {
30
30
 
31
31
  // src/command/argument/Arg.ts
32
32
  var ARGS_KEY = Symbol("args");
33
- var Arg = class _Arg {
34
- static cache = /* @__PURE__ */ new WeakMap();
35
- static string = _Arg.createArgument("string" /* String */);
36
- static integer = _Arg.createArgument("integer" /* Integer */);
37
- static number = _Arg.createArgument("number" /* Number */);
38
- static user = _Arg.createArgument("user" /* User */);
39
- static member = _Arg.createArgument("member" /* Member */);
40
- static getMethodArguments(method, init = false) {
41
- let args = this.cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
42
- if (!args) {
43
- args = [];
44
- if (init) {
45
- Reflect.defineMetadata(ARGS_KEY, args, method);
46
- this.cache.set(method, args);
47
- }
33
+ var cache = /* @__PURE__ */ new WeakMap();
34
+ function getMethodArguments(method, init = false) {
35
+ let args = cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
36
+ if (!args) {
37
+ args = [];
38
+ if (init) {
39
+ Reflect.defineMetadata(ARGS_KEY, args, method);
40
+ cache.set(method, args);
48
41
  }
49
- return init ? args : Object.freeze([...args]);
50
42
  }
51
- static format(arg) {
52
- const { name, required, tuple } = arg;
53
- const opening = required ? "<" : "[";
54
- const closing = required ? ">" : "]";
55
- const prefix = tuple ? "..." : "";
56
- return `${opening}${prefix}${name}: ${this.describeArgumentExpectation(arg)}${closing}`;
57
- }
58
- static describeArgumentExpectation(arg) {
59
- const parts = [arg.type];
60
- switch (arg.type) {
61
- case "string" /* String */: {
62
- if (arg.minLength && !arg.maxLength) {
63
- parts.push(`\u2265 ${String(arg.minLength)}`);
64
- }
65
- if (!arg.minLength && arg.maxLength) {
66
- parts.push(`\u2264 ${String(arg.maxLength)}`);
67
- }
68
- if (arg.minLength && arg.maxLength) {
69
- parts.push(`${String(arg.minLength)} - ${String(arg.maxLength)}`);
70
- }
71
- break;
43
+ return init ? args : Object.freeze([...args]);
44
+ }
45
+ function createArgument(type) {
46
+ return function(options) {
47
+ const objOptions = typeof options === "string" ? { name: options } : options;
48
+ const fullOptions = { ...objOptions, type };
49
+ if (!fullOptions.description) {
50
+ fullOptions.description = fullOptions.name;
51
+ }
52
+ if (!("required" in fullOptions)) {
53
+ fullOptions.required = true;
54
+ }
55
+ return function(target, key, _index) {
56
+ const method = Object.getOwnPropertyDescriptor(target, key)?.value;
57
+ if (!method) {
58
+ throw new Error("No method found");
72
59
  }
73
- case "number" /* Number */:
74
- case "integer" /* Integer */: {
75
- if (arg.minValue !== void 0 && arg.maxValue === void 0) {
76
- parts.push(`\u2265 ${String(arg.minValue)}`);
77
- }
78
- if (arg.minValue === void 0 && arg.maxValue !== void 0) {
79
- parts.push(`\u2264 ${String(arg.maxValue)}`);
80
- }
81
- if (arg.minValue !== void 0 && arg.maxValue !== void 0) {
82
- parts.push(`${String(arg.minValue)} - ${String(arg.maxValue)}`);
83
- }
84
- break;
60
+ const args = getMethodArguments(method, true);
61
+ args.unshift(fullOptions);
62
+ };
63
+ };
64
+ }
65
+ var string = createArgument("string" /* String */);
66
+ var integer = createArgument("integer" /* Integer */);
67
+ var number = createArgument("number" /* Number */);
68
+ var user = createArgument("user" /* User */);
69
+ var member = createArgument("member" /* Member */);
70
+ function describeArgumentExpectation(arg) {
71
+ const parts = [arg.type];
72
+ switch (arg.type) {
73
+ case "string" /* String */: {
74
+ if (arg.minLength && !arg.maxLength) {
75
+ parts.push(`\u2265 ${String(arg.minLength)}`);
85
76
  }
86
- case "user" /* User */:
87
- case "member" /* Member */: {
88
- break;
77
+ if (!arg.minLength && arg.maxLength) {
78
+ parts.push(`\u2264 ${String(arg.maxLength)}`);
79
+ }
80
+ if (arg.minLength && arg.maxLength) {
81
+ parts.push(`${String(arg.minLength)} - ${String(arg.maxLength)}`);
89
82
  }
83
+ break;
90
84
  }
91
- return parts.join(", ");
92
- }
93
- static createArgument(type) {
94
- return function(options) {
95
- const objOptions = typeof options === "string" ? { name: options } : options;
96
- const fullOptions = { ...objOptions, type };
97
- if (!fullOptions.description) {
98
- fullOptions.description = fullOptions.name;
85
+ case "number" /* Number */:
86
+ case "integer" /* Integer */: {
87
+ if (arg.minValue !== void 0 && arg.maxValue === void 0) {
88
+ parts.push(`\u2265 ${String(arg.minValue)}`);
99
89
  }
100
- if (!("required" in fullOptions)) {
101
- fullOptions.required = true;
90
+ if (arg.minValue === void 0 && arg.maxValue !== void 0) {
91
+ parts.push(`\u2264 ${String(arg.maxValue)}`);
102
92
  }
103
- return function(target, key, _index) {
104
- const method = Object.getOwnPropertyDescriptor(target, key)?.value;
105
- if (!method) {
106
- throw new Error("No method found");
107
- }
108
- const args = _Arg.getMethodArguments(method, true);
109
- args.unshift(fullOptions);
110
- };
111
- };
93
+ if (arg.minValue !== void 0 && arg.maxValue !== void 0) {
94
+ parts.push(`${String(arg.minValue)} - ${String(arg.maxValue)}`);
95
+ }
96
+ break;
97
+ }
98
+ case "user" /* User */:
99
+ case "member" /* Member */: {
100
+ break;
101
+ }
112
102
  }
103
+ return parts.join(", ");
104
+ }
105
+ function format(arg) {
106
+ const { name, required, tuple } = arg;
107
+ const opening = required ? "<" : "[";
108
+ const closing = required ? ">" : "]";
109
+ const prefix = tuple ? "..." : "";
110
+ return `${opening}${prefix}${name}: ${describeArgumentExpectation(arg)}${closing}`;
111
+ }
112
+ var Arg = {
113
+ getMethodArguments,
114
+ createArgument,
115
+ describeArgumentExpectation,
116
+ format,
117
+ string,
118
+ number,
119
+ integer,
120
+ user,
121
+ member
113
122
  };
114
123
 
115
124
  // src/command/CommandEntry.ts
116
- var HookExecutionState = /* @__PURE__ */ ((HookExecutionState2) => {
117
- HookExecutionState2["Main"] = "main";
118
- HookExecutionState2["Pre"] = "pre";
119
- HookExecutionState2["Post"] = "post";
120
- HookExecutionState2["Error"] = "error";
121
- return HookExecutionState2;
122
- })(HookExecutionState || {});
125
+ var CommandHookExecutionState = /* @__PURE__ */ ((CommandHookExecutionState2) => {
126
+ CommandHookExecutionState2["Main"] = "main";
127
+ CommandHookExecutionState2["Pre"] = "pre";
128
+ CommandHookExecutionState2["Post"] = "post";
129
+ CommandHookExecutionState2["Error"] = "error";
130
+ return CommandHookExecutionState2;
131
+ })(CommandHookExecutionState || {});
123
132
  var HOOKS_KEY = Symbol("hooks");
124
133
  var BaseCommandEntry = class _BaseCommandEntry {
125
134
  constructor(options) {
@@ -237,25 +246,27 @@ var SubcommandEntry = class extends BaseCommandEntry {
237
246
 
238
247
  // src/command/Command.ts
239
248
  var ROOT_KEY = Symbol("root");
240
- var Command = class {
241
- static create(options) {
242
- if (typeof options === "string") {
243
- options = { name: options };
244
- }
245
- if (!options.description) {
246
- options.description = options.name;
247
- }
248
- return new RootCommandEntry(options);
249
- }
250
- static use(command) {
251
- return (target) => {
252
- Reflect.defineMetadata(ROOT_KEY, command, target);
253
- };
249
+ function use(command) {
250
+ return (target) => {
251
+ Reflect.defineMetadata(ROOT_KEY, command, target);
252
+ };
253
+ }
254
+ function getRoot(constructor) {
255
+ return Reflect.getMetadata(ROOT_KEY, constructor);
256
+ }
257
+ function CommandFactory(options) {
258
+ if (typeof options === "string") {
259
+ options = { name: options };
254
260
  }
255
- static getRoot(constructor) {
256
- return Reflect.getMetadata(ROOT_KEY, constructor);
261
+ if (!options.description) {
262
+ options.description = options.name;
257
263
  }
258
- };
264
+ return new RootCommandEntry(options);
265
+ }
266
+ var Command = Object.assign(CommandFactory, {
267
+ use,
268
+ getRoot
269
+ });
259
270
 
260
271
  // src/command/CommandRegistry.ts
261
272
  var CommandRegistry = class _CommandRegistry {
@@ -553,13 +564,13 @@ var ArgumentResolver = class _ArgumentResolver {
553
564
  return this.options.message.client;
554
565
  }
555
566
  static create(message) {
556
- const client = message.client;
557
- const { enableMentionPrefix } = client.options;
567
+ const client2 = message.client;
568
+ const { enableMentionPrefix } = client2.options;
558
569
  const prefixes = [
559
570
  // Custom prefixes specified in options
560
- ...client.options.prefixes ?? [],
571
+ ...client2.options.prefixes ?? [],
561
572
  // Use bot mention as prefix if enabled
562
- ...enableMentionPrefix ? [client.user.toString()] : []
573
+ ...enableMentionPrefix ? [client2.user.toString()] : []
563
574
  ];
564
575
  const prefix = prefixes.find((p) => message.content.startsWith(p)) ?? null;
565
576
  if (!prefix) {
@@ -699,11 +710,11 @@ var ArgumentResolver = class _ArgumentResolver {
699
710
  if (!userId) {
700
711
  return null;
701
712
  }
702
- const user = await this.client.users.fetch(userId).catch(() => null);
703
- if (!user) {
713
+ const user2 = await this.client.users.fetch(userId).catch(() => null);
714
+ if (!user2) {
704
715
  return null;
705
716
  }
706
- return user;
717
+ return user2;
707
718
  }
708
719
  matchIntegerValue(arg, value) {
709
720
  const intVal = parseInt(value, 10);
@@ -801,6 +812,133 @@ var StateBox = class _StateBox {
801
812
  }
802
813
  };
803
814
 
815
+ // src/listener/ListenerEntry.ts
816
+ var HOOKS_KEY2 = Symbol("hooks");
817
+ var ListenerEntry = class _ListenerEntry {
818
+ constructor(options) {
819
+ this.options = options;
820
+ }
821
+ static cache = /* @__PURE__ */ new WeakMap();
822
+ main = _ListenerEntry.createMainHookDecorator("main" /* Main */, this);
823
+ pre = _ListenerEntry.createMainHookDecorator("pre" /* Pre */, this);
824
+ post = _ListenerEntry.createMainHookDecorator("post" /* Post */, this);
825
+ error = _ListenerEntry.createErrorHookDecorator("error" /* Error */, this);
826
+ static getHooks(constructor, init = false) {
827
+ let hooks = this.cache.get(constructor) ?? Reflect.getMetadata(HOOKS_KEY2, constructor);
828
+ if (!hooks) {
829
+ hooks = [];
830
+ if (init) {
831
+ Reflect.defineMetadata(HOOKS_KEY2, hooks, constructor);
832
+ this.cache.set(constructor, hooks);
833
+ }
834
+ }
835
+ return init ? hooks : Object.freeze([...hooks]);
836
+ }
837
+ static createMainHookDecorator(state, entry) {
838
+ return (target, _key, descriptor) => {
839
+ this.addHook(target, state, descriptor.value, entry);
840
+ };
841
+ }
842
+ static createErrorHookDecorator(state, entry) {
843
+ return (target, _key, descriptor) => {
844
+ this.addHook(target, state, descriptor.value, entry);
845
+ };
846
+ }
847
+ static addHook(target, state, method, entry) {
848
+ const { constructor } = target;
849
+ const hooks = this.getHooks(constructor, true);
850
+ if (typeof method !== "function") {
851
+ throw new Error("CommandEntry decorator must be used with a class method.");
852
+ }
853
+ if (hooks.some((hook2) => hook2.state === state && hook2.entry === entry)) {
854
+ throw new Error(
855
+ `Hook "${state}" is already defined for entry "${String(entry.options.name)}".`
856
+ );
857
+ }
858
+ const hook = {
859
+ state,
860
+ entry,
861
+ method
862
+ };
863
+ hooks.push(hook);
864
+ }
865
+ };
866
+
867
+ // src/listener/Listener.ts
868
+ function ListenerFactory(options) {
869
+ if (typeof options !== "object") {
870
+ options = {
871
+ name: options,
872
+ once: false
873
+ };
874
+ }
875
+ options.once = Boolean(options.once);
876
+ return new ListenerEntry(options);
877
+ }
878
+ var ENTRY_KEY = Symbol("entry");
879
+ function use2(listener) {
880
+ return (target) => {
881
+ Reflect.defineMetadata(ENTRY_KEY, listener, target);
882
+ };
883
+ }
884
+ function getEntry(constructor) {
885
+ return Reflect.getMetadata(ENTRY_KEY, constructor);
886
+ }
887
+ var Listener = Object.assign(ListenerFactory, {
888
+ use: use2,
889
+ getEntry
890
+ });
891
+
892
+ // src/listener/ListenerRegistry.ts
893
+ var client;
894
+ var constructors = /* @__PURE__ */ new Set();
895
+ var instances = /* @__PURE__ */ new WeakMap();
896
+ function add(constructor) {
897
+ const entry = Listener.getEntry(constructor);
898
+ if (!entry) {
899
+ throw new Error(`No entry found for "${constructor.name}"`);
900
+ }
901
+ const { options } = entry;
902
+ if (!options.emitter) {
903
+ if (!client) {
904
+ throw new Error("Client is not ready.");
905
+ }
906
+ options.emitter = client;
907
+ }
908
+ constructors.add(constructor);
909
+ instances.set(constructor, new constructor());
910
+ }
911
+ function remove(constructor) {
912
+ const entry = Listener.getEntry(constructor);
913
+ if (!entry) {
914
+ return;
915
+ }
916
+ constructors.delete(constructor);
917
+ instances.delete(constructor);
918
+ const hook = ListenerEntry.getHooks(constructor).find((hook2) => hook2.entry === entry);
919
+ if (!hook) {
920
+ return;
921
+ }
922
+ const { name, emitter } = entry.options;
923
+ emitter?.removeListener(name, hook.method);
924
+ }
925
+ function removeAll() {
926
+ for (const constructor of constructors) {
927
+ remove(constructor);
928
+ }
929
+ }
930
+ function setClient(newClient) {
931
+ client = newClient;
932
+ }
933
+ var ListenerRegistry = {
934
+ constructors,
935
+ instances,
936
+ add,
937
+ setClient,
938
+ remove,
939
+ removeAll
940
+ };
941
+
804
942
  // src/BakitClient.ts
805
943
  var BakitClient = class _BakitClient extends Client {
806
944
  constructor(options) {
@@ -808,9 +946,10 @@ var BakitClient = class _BakitClient extends Client {
808
946
  options.getSyntaxErrorMessage = _BakitClient.getSyntaxErrorMessage;
809
947
  }
810
948
  super(options);
949
+ ListenerRegistry.setClient(this);
811
950
  this.once(
812
951
  Events.ClientReady,
813
- (client) => void this.registerApplicationCommands(client)
952
+ (client2) => void this.registerApplicationCommands(client2)
814
953
  );
815
954
  this.on(Events.InteractionCreate, (interaction) => void this.handleInteraction(interaction));
816
955
  this.on(Events.MessageCreate, (message) => void this.handleMessage(message));
@@ -830,9 +969,9 @@ var BakitClient = class _BakitClient extends Client {
830
969
  content
831
970
  };
832
971
  };
833
- async registerApplicationCommands(client) {
972
+ async registerApplicationCommands(client2) {
834
973
  const commands = CommandRegistry.constructors.map((c) => CommandRegistry.buildSlashCommand(c));
835
- await client.application.commands.set(commands);
974
+ await client2.application.commands.set(commands);
836
975
  }
837
976
  async handleMessage(message) {
838
977
  if (message.author.bot) {
@@ -988,7 +1127,7 @@ var BakitClient = class _BakitClient extends Client {
988
1127
  return { root, group, subcommand: sub };
989
1128
  }
990
1129
  createHookRecord(hooks) {
991
- return Object.values(HookExecutionState).reduce(
1130
+ return Object.values(CommandHookExecutionState).reduce(
992
1131
  (acc, state) => {
993
1132
  acc[state] = hooks.find((h) => h.state === state);
994
1133
  return acc;
@@ -1006,15 +1145,18 @@ export {
1006
1145
  BaseContext,
1007
1146
  ChatInputContext,
1008
1147
  Command,
1148
+ CommandFactory,
1009
1149
  CommandGroupEntry,
1150
+ CommandHookExecutionState,
1010
1151
  CommandRegistry,
1011
1152
  CommandSyntaxError,
1012
1153
  CommandSyntaxErrorType,
1013
1154
  HOOKS_KEY,
1014
- HookExecutionState,
1015
1155
  MessageContext,
1016
1156
  RootCommandEntry,
1017
1157
  StateBox,
1018
1158
  SubcommandEntry,
1019
- extractId
1159
+ extractId,
1160
+ getRoot,
1161
+ use
1020
1162
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "A framework for discord.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -12,8 +12,7 @@
12
12
  "scripts": {
13
13
  "build": "tsup",
14
14
  "type-check": "tsc --noEmit",
15
- "test": "vitest run --pass-with-no-tests",
16
- "prepare": "husky"
15
+ "test": "vitest run --pass-with-no-tests"
17
16
  },
18
17
  "files": [
19
18
  "dist"
@@ -30,25 +29,6 @@
30
29
  "peerDependencies": {
31
30
  "discord.js": "^14.0.0"
32
31
  },
33
- "devDependencies": {
34
- "@eslint/js": "^9.34.0",
35
- "@types/node": "^24.3.0",
36
- "@vitest/ui": "^3.2.4",
37
- "discord.js": "^14.22.1",
38
- "dotenv": "^17.2.1",
39
- "eslint": "^9.34.0",
40
- "eslint-config-prettier": "^10.1.8",
41
- "eslint-plugin-prettier": "^5.5.4",
42
- "husky": "^9.1.7",
43
- "lint-staged": "^16.1.5",
44
- "prettier": "^3.6.2",
45
- "tsup": "^8.5.0",
46
- "tsx": "^4.20.5",
47
- "typescript": "^5.9.2",
48
- "typescript-eslint": "^8.40.0",
49
- "vitest": "^3.2.4",
50
- "bakit": "link:../../.local/share/pnpm/global/5/node_modules/bakit"
51
- },
52
32
  "dependencies": {
53
33
  "reflect-metadata": "^0.2.2",
54
34
  "tiny-glob": "^0.2.9",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Louis Johnson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,2 +0,0 @@
1
- # bakit
2
- A discord.js framework