bakit 1.0.0-beta.11 → 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
@@ -1,9 +1,227 @@
1
- import { B as BaseEntry, C as ConstructorLike, a as BaseHook, b as BaseMainHookMethod, c as BaseErrorHookMethod, d as BakitClient } from './BakitClient-Dx4blRq3.js';
2
- export { A as Arg, h as ArgumentOptions, f as ArgumentType, e as BakitClientOptions, g as BaseArgumentOptions, m as BaseCommandEntry, k as BaseCommandEntryOptions, n as BaseCommandGroupEntry, x as BaseContext, y as ChatInputContext, u as ChatInputContextSendOptions, s as Command, q as CommandAPI, r as CommandFactory, o as CommandGroupEntry, j as CommandHook, t as CommandRegistry, J as CommandSyntaxError, H as CommandSyntaxErrorOptions, F as CommandSyntaxErrorType, D as Context, w as ContextSendOptions, l as CreateCommandOptions, E as ErrorCommandHookMethod, G as GetSyntaxErrorMessageFunction, I as IntegerArgumentOptions, i as MainCommandHookMethod, M as MemberArgumentOptions, z as MessageContext, v as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, p as SubcommandEntry, U as UserArgumentOptions } from './BakitClient-Dx4blRq3.js';
1
+ import * as discord_js from 'discord.js';
2
+ import { Awaitable, ChatInputCommandInteraction, CacheType, Message, InteractionReplyOptions, MessageCreateOptions, User, Collection, RESTPostAPIApplicationCommandsJSONBody, Client, ClientOptions, IntentsBitField, ClientEvents } from 'discord.js';
3
3
  import { AsyncLocalStorage } from 'node:async_hooks';
4
- import { ClientEvents } from 'discord.js';
5
- import EventEmitter from 'node:events';
6
4
  import { SetOptional } from 'type-fest';
5
+ import EventEmitter from 'node:events';
6
+
7
+ type ConstructorLike = new (...args: unknown[]) => object;
8
+ declare enum HookExecutionState {
9
+ Main = "MAIN",
10
+ Pre = "PRE",
11
+ Post = "POST",
12
+ Error = "ERROR"
13
+ }
14
+ type BaseMainHookMethod<Args extends unknown[]> = (...args: Args) => Awaitable<void>;
15
+ type BaseErrorHookMethod<Args extends unknown[]> = (error: unknown, ...args: Args) => Awaitable<void>;
16
+ interface BaseHook {
17
+ state: HookExecutionState;
18
+ method: BaseMainHookMethod<never> | BaseErrorHookMethod<never>;
19
+ entry: unknown;
20
+ }
21
+ declare class BaseEntry<Constructor extends ConstructorLike, Hook extends BaseHook, MainHookMethod extends BaseMainHookMethod<never>, ErrorHookMethod extends BaseErrorHookMethod<never>> {
22
+ protected target?: Constructor;
23
+ hooks: Record<HookExecutionState, Hook | undefined>;
24
+ main: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
25
+ pre: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
26
+ post: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
27
+ error: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
28
+ constructor();
29
+ setTarget(target: Constructor): void;
30
+ createMainHookDecorator(state: HookExecutionState): <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
31
+ createErrorHookDecorator(state: HookExecutionState): <T extends ErrorHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
32
+ protected addHook<T extends Hook["method"]>(state: HookExecutionState, target: object, descriptor: TypedPropertyDescriptor<T>): void;
33
+ }
34
+
35
+ type ChatInputContextSendOptions = string | InteractionReplyOptions;
36
+ type MessageContextSendOptions = string | MessageCreateOptions;
37
+ type ContextSendOptions = ChatInputContextSendOptions | MessageContextSendOptions;
38
+ declare abstract class BaseContext<Cached extends boolean, InGuild extends boolean> {
39
+ source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType> | Message<InGuild>;
40
+ constructor(source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType> | Message<InGuild>);
41
+ get client(): BakitClient<true>;
42
+ get channel(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.GuildTextBasedChannel | null, discord_js.GuildTextBasedChannel | null, discord_js.GuildTextBasedChannel | null, discord_js.TextBasedChannel | null> | discord_js.If<InGuild, discord_js.GuildTextBasedChannel, discord_js.TextBasedChannel>;
43
+ get channelId(): string;
44
+ get guild(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.Guild, null, discord_js.Guild | null, discord_js.Guild | null> | discord_js.If<InGuild, discord_js.Guild, null>;
45
+ get guildId(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, string, string, string, string | null> | discord_js.If<InGuild, string, null>;
46
+ inGuild(): this is Context<Cached, true>;
47
+ inCachedGuild(): this is Context<true, true>;
48
+ get author(): User;
49
+ isChatInput(): this is ChatInputContext;
50
+ isMessage(): this is MessageContext;
51
+ abstract send(options: ContextSendOptions): Promise<Message<InGuild>>;
52
+ }
53
+ declare class ChatInputContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> extends BaseContext<Cached, InGuild> {
54
+ source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType>;
55
+ send(options: ContextSendOptions): Promise<Message<InGuild>>;
56
+ }
57
+ declare class MessageContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> extends BaseContext<Cached, InGuild> {
58
+ source: Message<InGuild>;
59
+ send(options: string | MessageCreateOptions): Promise<Message<InGuild>>;
60
+ }
61
+ type Context<Cached extends boolean = boolean, InGuild extends boolean = boolean> = ChatInputContext<Cached, InGuild> | MessageContext<Cached, InGuild>;
62
+
63
+ type MainCommandHookMethod = BaseMainHookMethod<[context: Context, ...args: any[]]>;
64
+ type ErrorCommandHookMethod = BaseErrorHookMethod<[context: Context, ...args: any[]]>;
65
+ interface CommandHook extends BaseHook {
66
+ method: MainCommandHookMethod | ErrorCommandHookMethod;
67
+ }
68
+ interface BaseCommandEntryOptions {
69
+ name: string;
70
+ description: string;
71
+ nsfw?: boolean;
72
+ }
73
+ type CreateCommandOptions<T extends BaseCommandEntryOptions> = SetOptional<T, "description"> | string;
74
+ declare class BaseCommandEntry extends BaseEntry<ConstructorLike, CommandHook, MainCommandHookMethod, ErrorCommandHookMethod> {
75
+ options: BaseCommandEntryOptions;
76
+ constructor(options: BaseCommandEntryOptions);
77
+ }
78
+ declare class BaseCommandGroupEntry extends BaseCommandEntry {
79
+ children: Collection<string, CommandGroupEntry | SubcommandEntry>;
80
+ subcommand(options: CreateCommandOptions<BaseCommandEntryOptions>): SubcommandEntry;
81
+ }
82
+ declare class RootCommandEntry extends BaseCommandGroupEntry {
83
+ group(options: CreateCommandOptions<BaseCommandEntryOptions>): CommandGroupEntry;
84
+ }
85
+ declare class CommandGroupEntry extends BaseCommandGroupEntry {
86
+ parent: RootCommandEntry;
87
+ children: Collection<string, SubcommandEntry>;
88
+ constructor(options: BaseCommandEntryOptions, parent: RootCommandEntry);
89
+ }
90
+ declare class SubcommandEntry extends BaseCommandEntry {
91
+ parent: BaseCommandGroupEntry;
92
+ constructor(options: BaseCommandEntryOptions, parent: BaseCommandGroupEntry);
93
+ }
94
+
95
+ declare enum ArgumentType {
96
+ String = "string",
97
+ Integer = "integer",
98
+ Number = "number",
99
+ User = "user",
100
+ Member = "member"
101
+ }
102
+ interface BaseArgumentOptions {
103
+ type: ArgumentType;
104
+ name: string;
105
+ description?: string;
106
+ required?: boolean;
107
+ tuple?: boolean;
108
+ }
109
+ interface StringArgumentOptions extends BaseArgumentOptions {
110
+ type: ArgumentType.String;
111
+ maxLength?: number;
112
+ minLength?: number;
113
+ }
114
+ interface IntegerArgumentOptions extends BaseArgumentOptions {
115
+ type: ArgumentType.Integer;
116
+ maxValue?: number;
117
+ minValue?: number;
118
+ }
119
+ interface NumberArgumentOptions extends BaseArgumentOptions {
120
+ type: ArgumentType.Number;
121
+ maxValue?: number;
122
+ minValue?: number;
123
+ }
124
+ interface UserArgumentOptions extends BaseArgumentOptions {
125
+ type: ArgumentType.User;
126
+ }
127
+ interface MemberArgumentOptions extends BaseArgumentOptions {
128
+ type: ArgumentType.Member;
129
+ }
130
+ type ArgumentOptions = StringArgumentOptions | IntegerArgumentOptions | NumberArgumentOptions | UserArgumentOptions | MemberArgumentOptions;
131
+
132
+ declare function getMethodArguments(method: CommandHook["method"]): readonly ArgumentOptions[];
133
+ declare function getMethodArguments(method: CommandHook["method"], init: true): ArgumentOptions[];
134
+ declare function createArgument<Options extends ArgumentOptions>(type: Options["type"]): (options: Omit<Options, "type"> | string) => (target: object, key: string | symbol, _index: number) => void;
135
+ declare function describeArgumentExpectation(arg: ArgumentOptions): string;
136
+ declare function format(arg: ArgumentOptions): string;
137
+ declare const Arg: {
138
+ getMethodArguments: typeof getMethodArguments;
139
+ createArgument: typeof createArgument;
140
+ describeArgumentExpectation: typeof describeArgumentExpectation;
141
+ format: typeof format;
142
+ string: (options: string | Omit<StringArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
143
+ number: (options: string | Omit<NumberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
144
+ integer: (options: string | Omit<IntegerArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
145
+ user: (options: string | Omit<UserArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
146
+ member: (options: string | Omit<MemberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
147
+ };
148
+
149
+ declare namespace CommandAPI {
150
+ function use(root: RootCommandEntry): (target: ConstructorLike) => void;
151
+ function getRoot(constructor: ConstructorLike): RootCommandEntry | undefined;
152
+ }
153
+ declare function CommandFactory(options: CreateCommandOptions<BaseCommandEntryOptions> | string): RootCommandEntry;
154
+ declare const Command: typeof CommandFactory & typeof CommandAPI;
155
+
156
+ declare class CommandRegistry {
157
+ static constructors: Collection<string, ConstructorLike>;
158
+ static instances: Collection<string, object>;
159
+ /**
160
+ * Add a command to the registry.
161
+ * @param constructor The command class you want to add.
162
+ */
163
+ static add(constructor: ConstructorLike): void;
164
+ /**
165
+ * Load and add all commands which matched provided glob pattern to the registry.
166
+ * @param pattern glob pattern to load.
167
+ * @param parallel load all matched results in parallel, enabled by default.
168
+ * @returns All loaded command constructors.
169
+ */
170
+ static load(pattern: string, parallel?: boolean): Promise<ConstructorLike[]>;
171
+ /**
172
+ * Build a command into application command data.
173
+ * @param constructor The command class you want to build.
174
+ * @returns a REST JSON version of the application command data.
175
+ */
176
+ static buildSlashCommand(constructor: ConstructorLike): RESTPostAPIApplicationCommandsJSONBody;
177
+ private static getMainHookArguments;
178
+ private static buildSlashCommandSubcommands;
179
+ private static buildSlashCommandOptions;
180
+ private static attachSlashCommandOption;
181
+ }
182
+
183
+ declare enum CommandSyntaxErrorType {
184
+ MissingRequireArgument = "MISSING_REQUIRE_ARGUMENT",
185
+ InvalidArgument = "INVALID_ARGUMENT",
186
+ InvalidVariadicArgumentValue = "INVALID_VARIADIC_ARGUMENT_VALUE"
187
+ }
188
+ interface CommandSyntaxErrorOptions {
189
+ arg: ArgumentOptions;
190
+ type: CommandSyntaxErrorType;
191
+ received: unknown;
192
+ }
193
+ declare class CommandSyntaxError extends Error {
194
+ readonly arg: ArgumentOptions;
195
+ readonly type: CommandSyntaxErrorType;
196
+ readonly expected: unknown;
197
+ readonly received: unknown;
198
+ constructor(options: CommandSyntaxErrorOptions);
199
+ get name(): string;
200
+ }
201
+
202
+ type GetSyntaxErrorMessageFunction = (command: object, error: CommandSyntaxError, context: MessageContext, args: readonly ArgumentOptions[], prefix: string) => Awaitable<MessageCreateOptions | undefined>;
203
+ interface BakitClientOptions extends ClientOptions {
204
+ prefixes?: string[];
205
+ enableMentionPrefix?: boolean;
206
+ getSyntaxErrorMessage?: GetSyntaxErrorMessageFunction | null;
207
+ }
208
+ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready> {
209
+ options: Omit<BakitClientOptions, "intents"> & {
210
+ intents: IntentsBitField;
211
+ };
212
+ constructor(options: BakitClientOptions);
213
+ static getSyntaxErrorMessage: GetSyntaxErrorMessageFunction;
214
+ private registerApplicationCommands;
215
+ private handleMessage;
216
+ private handleInteraction;
217
+ private handleChatInputHooks;
218
+ private handleMessageHooks;
219
+ private handleChildMessageHooks;
220
+ private runMessageHooks;
221
+ private runChatInputHooks;
222
+ private runHooks;
223
+ private getChatInputTargetHooks;
224
+ }
7
225
 
8
226
  declare function extractId(value: string): string | null;
9
227
 
@@ -34,7 +252,6 @@ declare class ListenerEntry<E extends EventsLike, K extends keyof E> extends Bas
34
252
  }
35
253
 
36
254
  declare namespace ListenerAPI {
37
- const ENTRY_KEY: unique symbol;
38
255
  function use<E extends EventsLike, K extends keyof E>(entry: ListenerEntry<E, K>): (target: ConstructorLike) => void;
39
256
  function getEntry<E extends EventsLike, K extends keyof E>(target: ConstructorLike): ListenerEntry<E, K> | undefined;
40
257
  }
@@ -93,4 +310,4 @@ declare module "discord.js" {
93
310
  }
94
311
  }
95
312
 
96
- export { BakitClient, type ErrorListenerHookMethod, type EventsLike, Listener, ListenerAPI, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerRegistry, type MainListenerHookMethod, StateBox, type States, extractId };
313
+ export { Arg, type ArgumentOptions, ArgumentType, BakitClient, type BakitClientOptions, type BaseArgumentOptions, BaseCommandEntry, type BaseCommandEntryOptions, BaseCommandGroupEntry, BaseContext, ChatInputContext, type ChatInputContextSendOptions, Command, CommandAPI, CommandFactory, CommandGroupEntry, type CommandHook, CommandRegistry, CommandSyntaxError, type CommandSyntaxErrorOptions, CommandSyntaxErrorType, type Context, type ContextSendOptions, type CreateCommandOptions, type ErrorCommandHookMethod, type ErrorListenerHookMethod, type EventsLike, type GetSyntaxErrorMessageFunction, type IntegerArgumentOptions, Listener, ListenerAPI, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerRegistry, type MainCommandHookMethod, type MainListenerHookMethod, type MemberArgumentOptions, MessageContext, type MessageContextSendOptions, type NumberArgumentOptions, RootCommandEntry, StateBox, type States, type StringArgumentOptions, SubcommandEntry, type UserArgumentOptions, extractId };
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // src/index.ts
2
- import "reflect-metadata";
3
-
4
1
  // src/BakitClient.ts
5
2
  import {
6
3
  Client,
@@ -151,15 +148,13 @@ var ArgumentType = /* @__PURE__ */ ((ArgumentType2) => {
151
148
  })(ArgumentType || {});
152
149
 
153
150
  // src/command/argument/Arg.ts
154
- var ARGS_KEY = Symbol("args");
155
- var cache = /* @__PURE__ */ new WeakMap();
151
+ var store = /* @__PURE__ */ new WeakMap();
156
152
  function getMethodArguments(method, init = false) {
157
- let args = cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
153
+ let args = store.get(method);
158
154
  if (!args) {
159
155
  args = [];
160
156
  if (init) {
161
- Reflect.defineMetadata(ARGS_KEY, args, method);
162
- cache.set(method, args);
157
+ store.set(method, args);
163
158
  }
164
159
  }
165
160
  return init ? args : Object.freeze([...args]);
@@ -217,10 +212,6 @@ function describeArgumentExpectation(arg) {
217
212
  }
218
213
  break;
219
214
  }
220
- case "user" /* User */:
221
- case "member" /* Member */: {
222
- break;
223
- }
224
215
  }
225
216
  return parts.join(", ");
226
217
  }
@@ -780,8 +771,8 @@ var StateBox = class _StateBox {
780
771
  }
781
772
  return state;
782
773
  }
783
- static run(fn, store = {}) {
784
- return this.storage.run(store, fn);
774
+ static run(fn, store2 = {}) {
775
+ return this.storage.run(store2, fn);
785
776
  }
786
777
  static wrap(fn) {
787
778
  const currentStore = this.storage.getStore();
@@ -822,15 +813,15 @@ var ListenerEntry = class extends BaseEntry {
822
813
  // src/listener/Listener.ts
823
814
  var ListenerAPI;
824
815
  ((ListenerAPI2) => {
825
- ListenerAPI2.ENTRY_KEY = Symbol("entry");
816
+ const entries = /* @__PURE__ */ new WeakMap();
826
817
  function use(entry) {
827
818
  return (target) => {
828
- Reflect.defineMetadata(ListenerAPI2.ENTRY_KEY, entry, target);
819
+ entries.set(target, entry);
829
820
  };
830
821
  }
831
822
  ListenerAPI2.use = use;
832
823
  function getEntry(target) {
833
- return Reflect.getMetadata(ListenerAPI2.ENTRY_KEY, target);
824
+ return entries.get(target);
834
825
  }
835
826
  ListenerAPI2.getEntry = getEntry;
836
827
  })(ListenerAPI || (ListenerAPI = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.13",
4
4
  "description": "A framework for discord.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,8 +38,10 @@
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"
43
+ },
44
+ "devDependencies": {
45
+ "@swc/core": "^1.13.5"
44
46
  }
45
47
  }
@@ -1,224 +0,0 @@
1
- import * as discord_js from 'discord.js';
2
- import { Awaitable, ChatInputCommandInteraction, CacheType, Message, InteractionReplyOptions, MessageCreateOptions, User, Collection, RESTPostAPIApplicationCommandsJSONBody, Client, ClientOptions, IntentsBitField } from 'discord.js';
3
- import { SetOptional } from 'type-fest';
4
-
5
- type ConstructorLike = new (...args: unknown[]) => object;
6
- declare enum HookExecutionState {
7
- Main = "MAIN",
8
- Pre = "PRE",
9
- Post = "POST",
10
- Error = "ERROR"
11
- }
12
- type BaseMainHookMethod<Args extends unknown[]> = (...args: Args) => Awaitable<void>;
13
- type BaseErrorHookMethod<Args extends unknown[]> = (error: unknown, ...args: Args) => Awaitable<void>;
14
- interface BaseHook {
15
- state: HookExecutionState;
16
- method: BaseMainHookMethod<never> | BaseErrorHookMethod<never>;
17
- entry: unknown;
18
- }
19
- declare class BaseEntry<Constructor extends ConstructorLike, Hook extends BaseHook, MainHookMethod extends BaseMainHookMethod<never>, ErrorHookMethod extends BaseErrorHookMethod<never>> {
20
- protected target?: Constructor;
21
- hooks: Record<HookExecutionState, Hook | undefined>;
22
- main: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
23
- pre: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
24
- post: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
25
- error: <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
26
- constructor();
27
- setTarget(target: Constructor): void;
28
- createMainHookDecorator(state: HookExecutionState): <T extends MainHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
29
- createErrorHookDecorator(state: HookExecutionState): <T extends ErrorHookMethod>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
30
- protected addHook<T extends Hook["method"]>(state: HookExecutionState, target: object, descriptor: TypedPropertyDescriptor<T>): void;
31
- }
32
-
33
- type ChatInputContextSendOptions = string | InteractionReplyOptions;
34
- type MessageContextSendOptions = string | MessageCreateOptions;
35
- type ContextSendOptions = ChatInputContextSendOptions | MessageContextSendOptions;
36
- declare abstract class BaseContext<Cached extends boolean, InGuild extends boolean> {
37
- source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType> | Message<InGuild>;
38
- constructor(source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType> | Message<InGuild>);
39
- get client(): BakitClient<true>;
40
- get channel(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.GuildTextBasedChannel | null, discord_js.GuildTextBasedChannel | null, discord_js.GuildTextBasedChannel | null, discord_js.TextBasedChannel | null> | discord_js.If<InGuild, discord_js.GuildTextBasedChannel, discord_js.TextBasedChannel>;
41
- get channelId(): string;
42
- get guild(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, discord_js.Guild, null, discord_js.Guild | null, discord_js.Guild | null> | discord_js.If<InGuild, discord_js.Guild, null>;
43
- get guildId(): discord_js.CacheTypeReducer<Cached extends true ? "cached" : CacheType, string, string, string, string | null> | discord_js.If<InGuild, string, null>;
44
- inGuild(): this is Context<Cached, true>;
45
- inCachedGuild(): this is Context<true, true>;
46
- get author(): User;
47
- isChatInput(): this is ChatInputContext;
48
- isMessage(): this is MessageContext;
49
- abstract send(options: ContextSendOptions): Promise<Message<InGuild>>;
50
- }
51
- declare class ChatInputContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> extends BaseContext<Cached, InGuild> {
52
- source: ChatInputCommandInteraction<Cached extends true ? "cached" : CacheType>;
53
- send(options: ContextSendOptions): Promise<Message<InGuild>>;
54
- }
55
- declare class MessageContext<Cached extends boolean = boolean, InGuild extends boolean = boolean> extends BaseContext<Cached, InGuild> {
56
- source: Message<InGuild>;
57
- send(options: string | MessageCreateOptions): Promise<Message<InGuild>>;
58
- }
59
- type Context<Cached extends boolean = boolean, InGuild extends boolean = boolean> = ChatInputContext<Cached, InGuild> | MessageContext<Cached, InGuild>;
60
-
61
- type MainCommandHookMethod = BaseMainHookMethod<[context: Context, ...args: any[]]>;
62
- type ErrorCommandHookMethod = BaseErrorHookMethod<[context: Context, ...args: any[]]>;
63
- interface CommandHook extends BaseHook {
64
- method: MainCommandHookMethod | ErrorCommandHookMethod;
65
- }
66
- interface BaseCommandEntryOptions {
67
- name: string;
68
- description: string;
69
- nsfw?: boolean;
70
- }
71
- type CreateCommandOptions<T extends BaseCommandEntryOptions> = SetOptional<T, "description"> | string;
72
- declare class BaseCommandEntry extends BaseEntry<ConstructorLike, CommandHook, MainCommandHookMethod, ErrorCommandHookMethod> {
73
- options: BaseCommandEntryOptions;
74
- constructor(options: BaseCommandEntryOptions);
75
- }
76
- declare class BaseCommandGroupEntry extends BaseCommandEntry {
77
- children: Collection<string, CommandGroupEntry | SubcommandEntry>;
78
- subcommand(options: CreateCommandOptions<BaseCommandEntryOptions>): SubcommandEntry;
79
- }
80
- declare class RootCommandEntry extends BaseCommandGroupEntry {
81
- group(options: CreateCommandOptions<BaseCommandEntryOptions>): CommandGroupEntry;
82
- }
83
- declare class CommandGroupEntry extends BaseCommandGroupEntry {
84
- parent: RootCommandEntry;
85
- children: Collection<string, SubcommandEntry>;
86
- constructor(options: BaseCommandEntryOptions, parent: RootCommandEntry);
87
- }
88
- declare class SubcommandEntry extends BaseCommandEntry {
89
- parent: BaseCommandGroupEntry;
90
- constructor(options: BaseCommandEntryOptions, parent: BaseCommandGroupEntry);
91
- }
92
-
93
- declare enum ArgumentType {
94
- String = "string",
95
- Integer = "integer",
96
- Number = "number",
97
- User = "user",
98
- Member = "member"
99
- }
100
- interface BaseArgumentOptions {
101
- type: ArgumentType;
102
- name: string;
103
- description?: string;
104
- required?: boolean;
105
- tuple?: boolean;
106
- }
107
- interface StringArgumentOptions extends BaseArgumentOptions {
108
- type: ArgumentType.String;
109
- maxLength?: number;
110
- minLength?: number;
111
- }
112
- interface IntegerArgumentOptions extends BaseArgumentOptions {
113
- type: ArgumentType.Integer;
114
- maxValue?: number;
115
- minValue?: number;
116
- }
117
- interface NumberArgumentOptions extends BaseArgumentOptions {
118
- type: ArgumentType.Number;
119
- maxValue?: number;
120
- minValue?: number;
121
- }
122
- interface UserArgumentOptions extends BaseArgumentOptions {
123
- type: ArgumentType.User;
124
- }
125
- interface MemberArgumentOptions extends BaseArgumentOptions {
126
- type: ArgumentType.Member;
127
- }
128
- type ArgumentOptions = StringArgumentOptions | IntegerArgumentOptions | NumberArgumentOptions | UserArgumentOptions | MemberArgumentOptions;
129
-
130
- declare function getMethodArguments(method: CommandHook["method"]): readonly ArgumentOptions[];
131
- declare function getMethodArguments(method: CommandHook["method"], init: true): ArgumentOptions[];
132
- declare function createArgument<Options extends ArgumentOptions>(type: Options["type"]): (options: Omit<Options, "type"> | string) => (target: object, key: string | symbol, _index: number) => void;
133
- declare function describeArgumentExpectation(arg: ArgumentOptions): string;
134
- declare function format(arg: ArgumentOptions): string;
135
- declare const Arg: {
136
- getMethodArguments: typeof getMethodArguments;
137
- createArgument: typeof createArgument;
138
- describeArgumentExpectation: typeof describeArgumentExpectation;
139
- format: typeof format;
140
- string: (options: string | Omit<StringArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
141
- number: (options: string | Omit<NumberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
142
- integer: (options: string | Omit<IntegerArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
143
- user: (options: string | Omit<UserArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
144
- member: (options: string | Omit<MemberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
145
- };
146
-
147
- declare namespace CommandAPI {
148
- function use(root: RootCommandEntry): (target: ConstructorLike) => void;
149
- function getRoot(constructor: ConstructorLike): RootCommandEntry | undefined;
150
- }
151
- declare function CommandFactory(options: CreateCommandOptions<BaseCommandEntryOptions> | string): RootCommandEntry;
152
- declare const Command: typeof CommandFactory & typeof CommandAPI;
153
-
154
- declare class CommandRegistry {
155
- static constructors: Collection<string, ConstructorLike>;
156
- static instances: Collection<string, object>;
157
- /**
158
- * Add a command to the registry.
159
- * @param constructor The command class you want to add.
160
- */
161
- static add(constructor: ConstructorLike): void;
162
- /**
163
- * Load and add all commands which matched provided glob pattern to the registry.
164
- * @param pattern glob pattern to load.
165
- * @param parallel load all matched results in parallel, enabled by default.
166
- * @returns All loaded command constructors.
167
- */
168
- static load(pattern: string, parallel?: boolean): Promise<ConstructorLike[]>;
169
- /**
170
- * Build a command into application command data.
171
- * @param constructor The command class you want to build.
172
- * @returns a REST JSON version of the application command data.
173
- */
174
- static buildSlashCommand(constructor: ConstructorLike): RESTPostAPIApplicationCommandsJSONBody;
175
- private static getMainHookArguments;
176
- private static buildSlashCommandSubcommands;
177
- private static buildSlashCommandOptions;
178
- private static attachSlashCommandOption;
179
- }
180
-
181
- declare enum CommandSyntaxErrorType {
182
- MissingRequireArgument = "MISSING_REQUIRE_ARGUMENT",
183
- InvalidArgument = "INVALID_ARGUMENT",
184
- InvalidVariadicArgumentValue = "INVALID_VARIADIC_ARGUMENT_VALUE"
185
- }
186
- interface CommandSyntaxErrorOptions {
187
- arg: ArgumentOptions;
188
- type: CommandSyntaxErrorType;
189
- received: unknown;
190
- }
191
- declare class CommandSyntaxError extends Error {
192
- readonly arg: ArgumentOptions;
193
- readonly type: CommandSyntaxErrorType;
194
- readonly expected: unknown;
195
- readonly received: unknown;
196
- constructor(options: CommandSyntaxErrorOptions);
197
- get name(): string;
198
- }
199
-
200
- type GetSyntaxErrorMessageFunction = (command: object, error: CommandSyntaxError, context: MessageContext, args: readonly ArgumentOptions[], prefix: string) => Awaitable<MessageCreateOptions | undefined>;
201
- interface BakitClientOptions extends ClientOptions {
202
- prefixes?: string[];
203
- enableMentionPrefix?: boolean;
204
- getSyntaxErrorMessage?: GetSyntaxErrorMessageFunction | null;
205
- }
206
- declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready> {
207
- options: Omit<BakitClientOptions, "intents"> & {
208
- intents: IntentsBitField;
209
- };
210
- constructor(options: BakitClientOptions);
211
- static getSyntaxErrorMessage: GetSyntaxErrorMessageFunction;
212
- private registerApplicationCommands;
213
- private handleMessage;
214
- private handleInteraction;
215
- private handleChatInputHooks;
216
- private handleMessageHooks;
217
- private handleChildMessageHooks;
218
- private runMessageHooks;
219
- private runChatInputHooks;
220
- private runHooks;
221
- private getChatInputTargetHooks;
222
- }
223
-
224
- export { Arg as A, BaseEntry as B, type ConstructorLike as C, type Context as D, type ErrorCommandHookMethod as E, CommandSyntaxErrorType as F, type GetSyntaxErrorMessageFunction as G, type CommandSyntaxErrorOptions as H, type IntegerArgumentOptions as I, CommandSyntaxError as J, type MemberArgumentOptions as M, type NumberArgumentOptions as N, RootCommandEntry as R, type StringArgumentOptions as S, type UserArgumentOptions as U, type BaseHook as a, type BaseMainHookMethod as b, type BaseErrorHookMethod as c, BakitClient as d, type BakitClientOptions as e, ArgumentType as f, type BaseArgumentOptions as g, type ArgumentOptions as h, type MainCommandHookMethod as i, type CommandHook as j, type BaseCommandEntryOptions as k, type CreateCommandOptions as l, BaseCommandEntry as m, BaseCommandGroupEntry as n, CommandGroupEntry as o, SubcommandEntry as p, CommandAPI as q, CommandFactory as r, Command as s, CommandRegistry as t, type ChatInputContextSendOptions as u, type MessageContextSendOptions as v, type ContextSendOptions as w, BaseContext as x, ChatInputContext as y, MessageContext as z };
@@ -1,3 +0,0 @@
1
- export { A as Arg, h as ArgumentOptions, f as ArgumentType, g as BaseArgumentOptions, m as BaseCommandEntry, k as BaseCommandEntryOptions, n as BaseCommandGroupEntry, x as BaseContext, y as ChatInputContext, u as ChatInputContextSendOptions, s as Command, q as CommandAPI, r as CommandFactory, o as CommandGroupEntry, j as CommandHook, t as CommandRegistry, D as Context, w as ContextSendOptions, l as CreateCommandOptions, E as ErrorCommandHookMethod, I as IntegerArgumentOptions, i as MainCommandHookMethod, M as MemberArgumentOptions, z as MessageContext, v as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, p as SubcommandEntry, U as UserArgumentOptions } from '../BakitClient-Dx4blRq3.js';
2
- import 'discord.js';
3
- import 'type-fest';
@@ -1,473 +0,0 @@
1
- // src/command/argument/Argument.ts
2
- var ArgumentType = /* @__PURE__ */ ((ArgumentType2) => {
3
- ArgumentType2["String"] = "string";
4
- ArgumentType2["Integer"] = "integer";
5
- ArgumentType2["Number"] = "number";
6
- ArgumentType2["User"] = "user";
7
- ArgumentType2["Member"] = "member";
8
- return ArgumentType2;
9
- })(ArgumentType || {});
10
-
11
- // src/command/argument/Arg.ts
12
- var ARGS_KEY = Symbol("args");
13
- var cache = /* @__PURE__ */ new WeakMap();
14
- function getMethodArguments(method, init = false) {
15
- let args = cache.get(method) ?? Reflect.getMetadata(ARGS_KEY, method);
16
- if (!args) {
17
- args = [];
18
- if (init) {
19
- Reflect.defineMetadata(ARGS_KEY, args, method);
20
- cache.set(method, args);
21
- }
22
- }
23
- return init ? args : Object.freeze([...args]);
24
- }
25
- function createArgument(type) {
26
- return function(options) {
27
- const objOptions = typeof options === "string" ? { name: options } : options;
28
- const fullOptions = { ...objOptions, type };
29
- if (!fullOptions.description) {
30
- fullOptions.description = fullOptions.name;
31
- }
32
- if (!("required" in fullOptions)) {
33
- fullOptions.required = true;
34
- }
35
- return function(target, key, _index) {
36
- const method = Object.getOwnPropertyDescriptor(target, key)?.value;
37
- if (!method) {
38
- throw new Error("No method found");
39
- }
40
- const args = getMethodArguments(method, true);
41
- args.unshift(fullOptions);
42
- };
43
- };
44
- }
45
- var string = createArgument("string" /* String */);
46
- var integer = createArgument("integer" /* Integer */);
47
- var number = createArgument("number" /* Number */);
48
- var user = createArgument("user" /* User */);
49
- var member = createArgument("member" /* Member */);
50
- function describeArgumentExpectation(arg) {
51
- const parts = [arg.type];
52
- switch (arg.type) {
53
- case "string" /* String */: {
54
- if (arg.minLength && !arg.maxLength) {
55
- parts.push(`\u2265 ${String(arg.minLength)}`);
56
- }
57
- if (!arg.minLength && arg.maxLength) {
58
- parts.push(`\u2264 ${String(arg.maxLength)}`);
59
- }
60
- if (arg.minLength && arg.maxLength) {
61
- parts.push(`${String(arg.minLength)} - ${String(arg.maxLength)}`);
62
- }
63
- break;
64
- }
65
- case "number" /* Number */:
66
- case "integer" /* Integer */: {
67
- if (arg.minValue !== void 0 && arg.maxValue === void 0) {
68
- parts.push(`\u2265 ${String(arg.minValue)}`);
69
- }
70
- if (arg.minValue === void 0 && arg.maxValue !== void 0) {
71
- parts.push(`\u2264 ${String(arg.maxValue)}`);
72
- }
73
- if (arg.minValue !== void 0 && arg.maxValue !== void 0) {
74
- parts.push(`${String(arg.minValue)} - ${String(arg.maxValue)}`);
75
- }
76
- break;
77
- }
78
- case "user" /* User */:
79
- case "member" /* Member */: {
80
- break;
81
- }
82
- }
83
- return parts.join(", ");
84
- }
85
- function format(arg) {
86
- const { name, required, tuple } = arg;
87
- const opening = required ? "<" : "[";
88
- const closing = required ? ">" : "]";
89
- const prefix = tuple ? "..." : "";
90
- return `${opening}${prefix}${name}: ${describeArgumentExpectation(arg)}${closing}`;
91
- }
92
- var Arg = {
93
- getMethodArguments,
94
- createArgument,
95
- describeArgumentExpectation,
96
- format,
97
- string,
98
- number,
99
- integer,
100
- user,
101
- member
102
- };
103
-
104
- // src/command/CommandEntry.ts
105
- import { Collection } from "discord.js";
106
-
107
- // src/base/BaseEntry.ts
108
- var BaseEntry = class {
109
- target;
110
- hooks = {
111
- ["MAIN" /* Main */]: void 0,
112
- ["ERROR" /* Error */]: void 0,
113
- ["POST" /* Post */]: void 0,
114
- ["PRE" /* Pre */]: void 0
115
- };
116
- main;
117
- pre;
118
- post;
119
- error;
120
- constructor() {
121
- this.main = this.createMainHookDecorator("MAIN" /* Main */);
122
- this.pre = this.createMainHookDecorator("PRE" /* Pre */);
123
- this.post = this.createMainHookDecorator("POST" /* Post */);
124
- this.error = this.createMainHookDecorator("ERROR" /* Error */);
125
- }
126
- setTarget(target) {
127
- this.target = target;
128
- }
129
- createMainHookDecorator(state) {
130
- return (target, _key, descriptor) => {
131
- this.addHook(state, target, descriptor);
132
- };
133
- }
134
- createErrorHookDecorator(state) {
135
- return (target, _key, descriptor) => {
136
- this.addHook(state, target, descriptor);
137
- };
138
- }
139
- addHook(state, target, descriptor) {
140
- if (this.target && this.target !== target.constructor) {
141
- throw new Error("Hook is used at wrong constructor.");
142
- }
143
- const { value: method } = descriptor;
144
- if (typeof method !== "function") {
145
- throw new Error("Invalid target method for hook.");
146
- }
147
- const hook = {
148
- state,
149
- method,
150
- entry: this
151
- };
152
- this.hooks[state] = hook;
153
- }
154
- };
155
-
156
- // src/command/CommandEntry.ts
157
- var BaseCommandEntry = class extends BaseEntry {
158
- constructor(options) {
159
- super();
160
- this.options = options;
161
- }
162
- };
163
- var BaseCommandGroupEntry = class extends BaseCommandEntry {
164
- children = new Collection();
165
- subcommand(options) {
166
- const fullOptions = typeof options === "string" ? { name: options, description: `${options} command` } : { description: `${options.name} command`, ...options };
167
- if (this.children.has(fullOptions.name)) {
168
- throw new Error(`Entry "${fullOptions.name}" is already existed.`);
169
- }
170
- const subcommand = new SubcommandEntry(fullOptions, this);
171
- this.children.set(fullOptions.name, subcommand);
172
- return subcommand;
173
- }
174
- };
175
- var RootCommandEntry = class extends BaseCommandGroupEntry {
176
- group(options) {
177
- const fullOptions = typeof options === "string" ? { name: options, description: `${options} command` } : { description: `${options.name} command`, ...options };
178
- if (this.children.has(fullOptions.name)) {
179
- throw new Error(`Entry "${fullOptions.name}" is already existed.`);
180
- }
181
- const group = new CommandGroupEntry(fullOptions, this);
182
- this.children.set(fullOptions.name, group);
183
- return group;
184
- }
185
- };
186
- var CommandGroupEntry = class extends BaseCommandGroupEntry {
187
- constructor(options, parent) {
188
- super(options);
189
- this.parent = parent;
190
- }
191
- };
192
- var SubcommandEntry = class extends BaseCommandEntry {
193
- constructor(options, parent) {
194
- super(options);
195
- this.parent = parent;
196
- }
197
- };
198
-
199
- // src/command/Command.ts
200
- var CommandAPI;
201
- ((CommandAPI2) => {
202
- const rootEntries = /* @__PURE__ */ new WeakMap();
203
- function use(root) {
204
- return (target) => {
205
- root.setTarget(target);
206
- rootEntries.set(target, root);
207
- };
208
- }
209
- CommandAPI2.use = use;
210
- function getRoot(constructor) {
211
- return rootEntries.get(constructor);
212
- }
213
- CommandAPI2.getRoot = getRoot;
214
- })(CommandAPI || (CommandAPI = {}));
215
- function CommandFactory(options) {
216
- if (typeof options === "string") {
217
- options = { name: options };
218
- }
219
- if (!options.description) {
220
- options.description = options.name;
221
- }
222
- return new RootCommandEntry(options);
223
- }
224
- var Command = Object.assign(CommandFactory, CommandAPI);
225
-
226
- // src/command/CommandRegistry.ts
227
- import {
228
- Collection as Collection2,
229
- SlashCommandBuilder,
230
- SlashCommandSubcommandBuilder,
231
- SlashCommandSubcommandGroupBuilder
232
- } from "discord.js";
233
- import glob from "tiny-glob";
234
- import { pathToFileURL } from "url";
235
- var CommandRegistry = class _CommandRegistry {
236
- static constructors = new Collection2();
237
- static instances = new Collection2();
238
- /**
239
- * Add a command to the registry.
240
- * @param constructor The command class you want to add.
241
- */
242
- static add(constructor) {
243
- const root = Command.getRoot(constructor);
244
- if (!root) {
245
- throw new Error(`No root found for "${constructor.name}"`);
246
- }
247
- const { options } = root;
248
- this.constructors.set(options.name, constructor);
249
- this.instances.set(options.name, new constructor());
250
- }
251
- /**
252
- * Load and add all commands which matched provided glob pattern to the registry.
253
- * @param pattern glob pattern to load.
254
- * @param parallel load all matched results in parallel, enabled by default.
255
- * @returns All loaded command constructors.
256
- */
257
- static async load(pattern, parallel = true) {
258
- const files = await glob(pattern);
259
- const loaders = files.map(async (file) => {
260
- const fileURL = pathToFileURL(file).toString();
261
- const { default: constructor } = await import(fileURL);
262
- _CommandRegistry.add(constructor);
263
- return constructor;
264
- });
265
- if (parallel) {
266
- return await Promise.all(loaders);
267
- }
268
- const result = [];
269
- for (const loader of loaders) {
270
- result.push(await loader);
271
- }
272
- return result;
273
- }
274
- /**
275
- * Build a command into application command data.
276
- * @param constructor The command class you want to build.
277
- * @returns a REST JSON version of the application command data.
278
- */
279
- static buildSlashCommand(constructor) {
280
- const root = Command.getRoot(constructor);
281
- if (!root) {
282
- throw new Error(`No root found for "${constructor.name}"`);
283
- }
284
- const { options } = root;
285
- const builder = new SlashCommandBuilder().setName(options.name).setDescription(options.description).setNSFW(Boolean(options.nsfw));
286
- const args = this.getMainHookArguments(root);
287
- if (root.children.size) {
288
- this.buildSlashCommandSubcommands(builder, root, args);
289
- } else {
290
- this.buildSlashCommandOptions(builder, args);
291
- }
292
- return builder.toJSON();
293
- }
294
- static getMainHookArguments(entry) {
295
- const { hooks } = entry;
296
- const mainHook = hooks["MAIN" /* Main */];
297
- return mainHook ? Arg.getMethodArguments(mainHook.method) : [];
298
- }
299
- static buildSlashCommandSubcommands(parent, entry, inheritedArgs) {
300
- const { children } = entry;
301
- for (const child of children.values()) {
302
- if (child instanceof CommandGroupEntry && parent instanceof SlashCommandBuilder) {
303
- const { options } = child;
304
- const group = new SlashCommandSubcommandGroupBuilder().setName(options.name).setDescription(options.description);
305
- this.buildSlashCommandSubcommands(group, child, [
306
- ...inheritedArgs,
307
- ...this.getMainHookArguments(child)
308
- ]);
309
- parent.addSubcommandGroup(group);
310
- } else if (child instanceof SubcommandEntry) {
311
- const { options } = child;
312
- const subcommand = new SlashCommandSubcommandBuilder().setName(options.name).setDescription(options.description);
313
- this.buildSlashCommandOptions(subcommand, [
314
- ...inheritedArgs,
315
- ...this.getMainHookArguments(child)
316
- ]);
317
- parent.addSubcommand(subcommand);
318
- }
319
- }
320
- }
321
- static buildSlashCommandOptions(builder, args) {
322
- const argGroup = Object.groupBy(args, ({ required }) => required ? "required" : "optional");
323
- const orderedArgs = [...argGroup.required || [], ...argGroup.optional || []];
324
- for (const arg of orderedArgs) {
325
- this.attachSlashCommandOption(builder, arg);
326
- }
327
- }
328
- static attachSlashCommandOption(builder, arg) {
329
- const setupOption = (option) => {
330
- return option.setName(arg.name).setDescription(arg.description || arg.name).setRequired(Boolean(arg.required));
331
- };
332
- switch (arg.type) {
333
- case "string" /* String */: {
334
- builder.addStringOption((data) => {
335
- const option = setupOption(data);
336
- if (arg.maxLength) {
337
- option.setMaxLength(arg.maxLength);
338
- }
339
- if (arg.minLength) {
340
- option.setMinLength(arg.minLength);
341
- }
342
- return option;
343
- });
344
- break;
345
- }
346
- case "integer" /* Integer */: {
347
- builder.addIntegerOption((data) => {
348
- const option = setupOption(data);
349
- if (arg.maxValue) {
350
- option.setMaxValue(arg.maxValue);
351
- }
352
- if (arg.minValue) {
353
- option.setMinValue(arg.minValue);
354
- }
355
- return option;
356
- });
357
- break;
358
- }
359
- case "number" /* Number */: {
360
- builder.addNumberOption((data) => {
361
- const option = setupOption(data);
362
- if (arg.maxValue) {
363
- option.setMaxValue(arg.maxValue);
364
- }
365
- if (arg.minValue) {
366
- option.setMinValue(arg.minValue);
367
- }
368
- return option;
369
- });
370
- break;
371
- }
372
- case "user" /* User */:
373
- case "member" /* Member */: {
374
- builder.addUserOption((option) => setupOption(option));
375
- break;
376
- }
377
- }
378
- }
379
- };
380
-
381
- // src/command/Context.ts
382
- import {
383
- ChatInputCommandInteraction,
384
- Message
385
- } from "discord.js";
386
- var BaseContext = class {
387
- constructor(source) {
388
- this.source = source;
389
- }
390
- get client() {
391
- return this.source.client;
392
- }
393
- get channel() {
394
- return this.source.channel;
395
- }
396
- get channelId() {
397
- return this.source.channelId;
398
- }
399
- get guild() {
400
- return this.source.guild;
401
- }
402
- get guildId() {
403
- return this.source.guildId;
404
- }
405
- inGuild() {
406
- return Boolean(this.guildId);
407
- }
408
- inCachedGuild() {
409
- if (this.isChatInput()) {
410
- return this.source.inCachedGuild();
411
- } else if (this.isMessage()) {
412
- return this.source.inGuild();
413
- } else {
414
- throw new Error("Invalid source");
415
- }
416
- }
417
- get author() {
418
- if (this.isChatInput()) {
419
- return this.source.user;
420
- } else if (this.isMessage()) {
421
- return this.source.author;
422
- } else {
423
- throw new Error("Invalid source");
424
- }
425
- }
426
- isChatInput() {
427
- return this.source instanceof ChatInputCommandInteraction;
428
- }
429
- isMessage() {
430
- return this.source instanceof Message;
431
- }
432
- };
433
- var ChatInputContext = class extends BaseContext {
434
- async send(options) {
435
- if (typeof options === "string") {
436
- options = { content: options };
437
- }
438
- const sendOptions = {
439
- ...options,
440
- withResponse: true
441
- };
442
- if (this.source.deferred || this.source.replied) {
443
- return await this.source.followUp(sendOptions);
444
- }
445
- const response = await this.source.reply(sendOptions);
446
- return response.resource?.message;
447
- }
448
- };
449
- var MessageContext = class extends BaseContext {
450
- async send(options) {
451
- const { channel } = this;
452
- if (!channel?.isSendable()) {
453
- throw new Error("Invalid channel or channel is not sendable");
454
- }
455
- return await channel.send(options);
456
- }
457
- };
458
- export {
459
- Arg,
460
- ArgumentType,
461
- BaseCommandEntry,
462
- BaseCommandGroupEntry,
463
- BaseContext,
464
- ChatInputContext,
465
- Command,
466
- CommandAPI,
467
- CommandFactory,
468
- CommandGroupEntry,
469
- CommandRegistry,
470
- MessageContext,
471
- RootCommandEntry,
472
- SubcommandEntry
473
- };