bakit 1.0.0-beta.11 → 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.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
 
@@ -93,4 +311,4 @@ declare module "discord.js" {
93
311
  }
94
312
  }
95
313
 
96
- export { BakitClient, type ErrorListenerHookMethod, type EventsLike, Listener, ListenerAPI, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerRegistry, type MainListenerHookMethod, StateBox, type States, extractId };
314
+ 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 };