bakit 1.0.0-beta.13 → 1.0.0-beta.15

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +69 -32
  2. package/dist/index.js +595 -976
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
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
- import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { Awaitable, ChatInputCommandInteraction, CacheType, Message, InteractionReplyOptions, MessageCreateOptions, User, Collection, RESTPostAPIApplicationCommandsJSONBody, ClientOptions, Client, IntentsBitField, ClientEvents } from 'discord.js';
4
3
  import { SetOptional } from 'type-fest';
4
+ import { AsyncLocalStorage } from 'node:async_hooks';
5
5
  import EventEmitter from 'node:events';
6
6
 
7
7
  type ConstructorLike = new (...args: unknown[]) => object;
@@ -91,13 +91,15 @@ declare class SubcommandEntry extends BaseCommandEntry {
91
91
  parent: BaseCommandGroupEntry;
92
92
  constructor(options: BaseCommandEntryOptions, parent: BaseCommandGroupEntry);
93
93
  }
94
+ type CommandEntry = RootCommandEntry | CommandGroupEntry | SubcommandEntry;
94
95
 
95
96
  declare enum ArgumentType {
96
97
  String = "string",
97
98
  Integer = "integer",
98
99
  Number = "number",
99
100
  User = "user",
100
- Member = "member"
101
+ Member = "member",
102
+ Literal = "literal"
101
103
  }
102
104
  interface BaseArgumentOptions {
103
105
  type: ArgumentType;
@@ -127,13 +129,17 @@ interface UserArgumentOptions extends BaseArgumentOptions {
127
129
  interface MemberArgumentOptions extends BaseArgumentOptions {
128
130
  type: ArgumentType.Member;
129
131
  }
132
+ interface LiteralArgumentOptions extends Omit<BaseArgumentOptions, "name"> {
133
+ type: ArgumentType.Literal;
134
+ value: string;
135
+ }
130
136
  type ArgumentOptions = StringArgumentOptions | IntegerArgumentOptions | NumberArgumentOptions | UserArgumentOptions | MemberArgumentOptions;
131
137
 
132
138
  declare function getMethodArguments(method: CommandHook["method"]): readonly ArgumentOptions[];
133
139
  declare function getMethodArguments(method: CommandHook["method"], init: true): ArgumentOptions[];
134
140
  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;
141
+ declare function describeArgumentExpectation(arg: ArgumentOptions | LiteralArgumentOptions): string;
142
+ declare function format(arg: ArgumentOptions | LiteralArgumentOptions): string;
137
143
  declare const Arg: {
138
144
  getMethodArguments: typeof getMethodArguments;
139
145
  createArgument: typeof createArgument;
@@ -146,6 +152,36 @@ declare const Arg: {
146
152
  member: (options: string | Omit<MemberArgumentOptions, "type">) => (target: object, key: string | symbol, _index: number) => void;
147
153
  };
148
154
 
155
+ interface ArgumentResolverOptions {
156
+ message: Message;
157
+ values: string[];
158
+ prefix: string;
159
+ }
160
+ declare class ArgumentResolver {
161
+ private _values;
162
+ prefix: string;
163
+ message: Message;
164
+ private _parsedValues;
165
+ private _args;
166
+ constructor(_values: string[], prefix: string, message: Message);
167
+ get commandName(): string;
168
+ get values(): readonly string[];
169
+ get parsedValues(): readonly unknown[];
170
+ get args(): readonly (ArgumentOptions | LiteralArgumentOptions)[];
171
+ get client(): BakitClient<true>;
172
+ static initialize(message: Message): Promise<ArgumentResolver | undefined>;
173
+ resolve(entry: CommandEntry, at?: number): Promise<void>;
174
+ protected parseExact(args: ArgumentOptions[], values: string[]): Promise<unknown[]>;
175
+ protected parseFlexible(args: ArgumentOptions[], values: string[]): Promise<unknown[]>;
176
+ private matchValue;
177
+ private matchUserValue;
178
+ private matchMemberValue;
179
+ private matchIntegerValue;
180
+ private matchNumberValue;
181
+ private matchStringValue;
182
+ static resolveChatInputOption(interaction: ChatInputCommandInteraction, arg: ArgumentOptions): string | number | discord_js.GuildMember | discord_js.User | discord_js.APIInteractionDataResolvedGuildMember | null;
183
+ }
184
+
149
185
  declare namespace CommandAPI {
150
186
  function use(root: RootCommandEntry): (target: ConstructorLike) => void;
151
187
  function getRoot(constructor: ConstructorLike): RootCommandEntry | undefined;
@@ -199,9 +235,31 @@ declare class CommandSyntaxError extends Error {
199
235
  get name(): string;
200
236
  }
201
237
 
202
- type GetSyntaxErrorMessageFunction = (command: object, error: CommandSyntaxError, context: MessageContext, args: readonly ArgumentOptions[], prefix: string) => Awaitable<MessageCreateOptions | undefined>;
238
+ type GetSyntaxErrorMessageFunction = (command: object, error: CommandSyntaxError, context: MessageContext, resolver: ArgumentResolver) => Awaitable<MessageCreateOptions | undefined>;
239
+ declare const defaultGetSyntaxErrorMessage: GetSyntaxErrorMessageFunction;
240
+
241
+ declare class CommandDispatcher {
242
+ client: BakitClient;
243
+ constructor(client: BakitClient);
244
+ getPrefixes(message: Message): Promise<string[]>;
245
+ handleChatInput(interaction: ChatInputCommandInteraction): Promise<void>;
246
+ private getChatInputTriggerChain;
247
+ private resolveChatInputEntry;
248
+ handleMessage(message: Message): Promise<void>;
249
+ private resolveCommandEntryChain;
250
+ private executeChain;
251
+ private executeHooks;
252
+ }
253
+
254
+ declare class DispatcherManager {
255
+ client: BakitClient;
256
+ command: CommandDispatcher;
257
+ constructor(client: BakitClient);
258
+ }
259
+
260
+ type GetPrefixFunction = (message: Message) => Awaitable<string[] | string>;
203
261
  interface BakitClientOptions extends ClientOptions {
204
- prefixes?: string[];
262
+ prefixes?: (string | GetPrefixFunction)[];
205
263
  enableMentionPrefix?: boolean;
206
264
  getSyntaxErrorMessage?: GetSyntaxErrorMessageFunction | null;
207
265
  }
@@ -209,25 +267,16 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
209
267
  options: Omit<BakitClientOptions, "intents"> & {
210
268
  intents: IntentsBitField;
211
269
  };
270
+ dispatchers: DispatcherManager;
212
271
  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;
272
+ isReady(): this is BakitClient<true>;
273
+ private initializeHandlers;
224
274
  }
225
275
 
226
276
  declare function extractId(value: string): string | null;
227
277
 
228
278
  type States = Record<string | symbol, unknown>;
229
279
  declare class StateBox {
230
- private static readonly STATES_KEY;
231
280
  static storage: AsyncLocalStorage<States>;
232
281
  private static getState;
233
282
  static run<R>(fn: () => R, store?: {}): R;
@@ -298,16 +347,4 @@ declare abstract class ListenerRegistry {
298
347
  static load(pattern: string, parallel?: boolean): Promise<ConstructorLike[]>;
299
348
  }
300
349
 
301
- /**
302
- * This file is used to redeclare original client to the custom one
303
- * Most of the structure is from Base, but some might be not
304
- */
305
-
306
-
307
- declare module "discord.js" {
308
- interface Base {
309
- client: BakitClient<true>;
310
- }
311
- }
312
-
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 };
350
+ export { Arg, type ArgumentOptions, ArgumentResolver, type ArgumentResolverOptions, ArgumentType, BakitClient, type BakitClientOptions, type BaseArgumentOptions, BaseCommandEntry, type BaseCommandEntryOptions, BaseCommandGroupEntry, BaseContext, ChatInputContext, type ChatInputContextSendOptions, Command, CommandAPI, type CommandEntry, CommandFactory, CommandGroupEntry, type CommandHook, CommandRegistry, CommandSyntaxError, type CommandSyntaxErrorOptions, CommandSyntaxErrorType, type Context, type ContextSendOptions, type CreateCommandOptions, type ErrorCommandHookMethod, type ErrorListenerHookMethod, type EventsLike, type GetPrefixFunction, type GetSyntaxErrorMessageFunction, type IntegerArgumentOptions, Listener, ListenerAPI, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerRegistry, type LiteralArgumentOptions, type MainCommandHookMethod, type MainListenerHookMethod, type MemberArgumentOptions, MessageContext, type MessageContextSendOptions, type NumberArgumentOptions, RootCommandEntry, StateBox, type States, type StringArgumentOptions, SubcommandEntry, type UserArgumentOptions, defaultGetSyntaxErrorMessage, extractId };