stoatx 0.8.0 → 1.0.1
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.mts +199 -211
- package/dist/index.d.ts +199 -211
- package/dist/index.js +513 -395
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +497 -392
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,45 +1,31 @@
|
|
|
1
|
-
import { Message, Client as Client$1, ClientOptions, PermissionResolvable } from '@stoatx/client';
|
|
1
|
+
import { Message, Client as Client$1, ClientOptions, PermissionResolvable, ClientEvents } from '@stoatx/client';
|
|
2
2
|
export * from '@stoatx/client';
|
|
3
3
|
|
|
4
|
+
declare class StoatxContainer {
|
|
5
|
+
private instances;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves a class instance, injecting any required dependencies.
|
|
8
|
+
*/
|
|
9
|
+
resolve<T>(target: any): T;
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
interface AutoDiscoveryOptions {
|
|
5
13
|
roots?: string[];
|
|
6
14
|
include?: string[];
|
|
7
15
|
ignore?: string[];
|
|
8
16
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Stored command entry from @Stoat/@SimpleCommand registration.
|
|
11
|
-
*/
|
|
12
17
|
interface RegisteredCommand {
|
|
13
|
-
/** Instance of the @Stoat class */
|
|
14
18
|
instance: object;
|
|
15
|
-
/** Command metadata */
|
|
16
19
|
metadata: CommandMetadata;
|
|
17
|
-
/** Method name to call */
|
|
18
20
|
methodName: string;
|
|
19
|
-
/** The original class constructor (for guard validation) */
|
|
20
21
|
classConstructor: Function;
|
|
21
22
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Stored event entry from @On/@Once registration.
|
|
24
|
-
*/
|
|
25
23
|
interface RegisteredEvent {
|
|
26
24
|
instance: object;
|
|
27
25
|
methodName: string;
|
|
28
26
|
event: string;
|
|
29
27
|
type: "on" | "once";
|
|
30
28
|
}
|
|
31
|
-
/**
|
|
32
|
-
* CommandRegistry - Scans directories and stores commands in a Map
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* const registry = new CommandRegistry();
|
|
37
|
-
* await registry.loadFromDirectory('./src/commands');
|
|
38
|
-
*
|
|
39
|
-
* const ping = registry.get('ping');
|
|
40
|
-
* const allCommands = registry.getAll();
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
29
|
declare class CommandRegistry {
|
|
44
30
|
private static readonly DEFAULT_AUTO_DISCOVERY_IGNORES;
|
|
45
31
|
private readonly commands;
|
|
@@ -47,80 +33,32 @@ declare class CommandRegistry {
|
|
|
47
33
|
private readonly registeredEvents;
|
|
48
34
|
private readonly extensions;
|
|
49
35
|
private readonly processedStoatClasses;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* Get the number of registered commands
|
|
53
|
-
*/
|
|
36
|
+
private readonly container;
|
|
37
|
+
constructor(container: StoatxContainer, extensions?: string[]);
|
|
54
38
|
get size(): number;
|
|
55
|
-
/**
|
|
56
|
-
* Load commands from a directory using glob pattern matching
|
|
57
|
-
*/
|
|
58
39
|
loadFromDirectory(directory: string): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Auto-discover command files across one or more roots.
|
|
61
|
-
*/
|
|
62
40
|
autoDiscover(options?: AutoDiscoveryOptions): Promise<void>;
|
|
63
41
|
private getDefaultAutoDiscoveryPatterns;
|
|
64
42
|
private isLikelyCommandModule;
|
|
65
|
-
/**
|
|
66
|
-
* Register a command instance
|
|
67
|
-
*/
|
|
68
43
|
register(instance: object, metadata: CommandMetadata, classConstructor: Function, methodName: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Get a command by name or alias
|
|
71
|
-
*/
|
|
72
44
|
get(name: string): RegisteredCommand | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Check if a command exists
|
|
75
|
-
*/
|
|
76
45
|
has(name: string): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Get all registered commands
|
|
79
|
-
*/
|
|
80
46
|
getAll(): RegisteredCommand[];
|
|
81
|
-
/**
|
|
82
|
-
* Get all command metadata
|
|
83
|
-
*/
|
|
84
47
|
getAllMetadata(): CommandMetadata[];
|
|
85
|
-
/**
|
|
86
|
-
* Get all registered events
|
|
87
|
-
*/
|
|
88
48
|
getEvents(): RegisteredEvent[];
|
|
89
|
-
/**
|
|
90
|
-
* Get commands grouped by category
|
|
91
|
-
*/
|
|
92
49
|
getByCategory(): Map<string, RegisteredCommand[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Clear all commands
|
|
95
|
-
*/
|
|
96
50
|
clear(): void;
|
|
97
|
-
/**
|
|
98
|
-
* Iterate over commands
|
|
99
|
-
*/
|
|
100
51
|
[Symbol.iterator](): IterableIterator<[string, RegisteredCommand]>;
|
|
101
|
-
/**
|
|
102
|
-
* Iterate over command values
|
|
103
|
-
*/
|
|
104
52
|
values(): IterableIterator<RegisteredCommand>;
|
|
105
|
-
/**
|
|
106
|
-
* Iterate over command names
|
|
107
|
-
*/
|
|
108
53
|
keys(): IterableIterator<string>;
|
|
109
|
-
/**
|
|
110
|
-
* Validate that all guards on a command implement the required methods
|
|
111
|
-
* @param commandClass
|
|
112
|
-
* @param commandName
|
|
113
|
-
* @private
|
|
114
|
-
*/
|
|
115
54
|
private validateGuards;
|
|
116
|
-
/**
|
|
117
|
-
* Load commands from a single file
|
|
118
|
-
*/
|
|
119
55
|
private loadFile;
|
|
120
56
|
private registerStoatClassCommands;
|
|
121
57
|
/**
|
|
122
|
-
*
|
|
58
|
+
* Build the parameter schema for a command method by combining
|
|
59
|
+
* reflect-metadata param types with @Arg/@Option decorator metadata.
|
|
123
60
|
*/
|
|
61
|
+
private buildParamSchema;
|
|
124
62
|
private getCategoryFromPath;
|
|
125
63
|
}
|
|
126
64
|
|
|
@@ -136,10 +74,7 @@ declare class DefaultCooldownManager implements CooldownManager {
|
|
|
136
74
|
}
|
|
137
75
|
/**
|
|
138
76
|
* StoatxHandler - The execution engine for commands
|
|
139
|
-
*
|
|
140
|
-
* Handles message parsing, middleware execution, and command dispatching
|
|
141
|
-
*
|
|
142
|
-
* @internal This class is not intended to be instantiated directly. Use the `Client` from `stoatx` instead.
|
|
77
|
+
* @internal
|
|
143
78
|
*/
|
|
144
79
|
declare class StoatxHandler {
|
|
145
80
|
private readonly commandsDir;
|
|
@@ -151,97 +86,45 @@ declare class StoatxHandler {
|
|
|
151
86
|
private readonly disableMentionPrefix;
|
|
152
87
|
private readonly client;
|
|
153
88
|
private readonly flagPrefix;
|
|
89
|
+
private readonly globalGuards;
|
|
90
|
+
readonly container: StoatxContainer;
|
|
154
91
|
constructor(options: StoatxHandlerOptions);
|
|
155
|
-
/**
|
|
156
|
-
* Initialize the handler - load all commands
|
|
157
|
-
*/
|
|
158
92
|
init(): Promise<void>;
|
|
159
|
-
/**
|
|
160
|
-
* Attach registered events to the client
|
|
161
|
-
*/
|
|
162
93
|
private attachEvents;
|
|
163
|
-
|
|
164
|
-
* Parses raw string arguments into positional args and key-value options
|
|
165
|
-
*/
|
|
166
|
-
private parseCommandOptions;
|
|
167
|
-
/**
|
|
168
|
-
* Parse a raw message into command context
|
|
169
|
-
*/
|
|
94
|
+
private parseRawInput;
|
|
170
95
|
parseMessage(rawContent: string, message: Message, meta: {
|
|
171
96
|
authorId: string;
|
|
172
97
|
channelId: string;
|
|
173
98
|
serverId?: string | undefined;
|
|
174
99
|
reply: (content: string) => Promise<Message>;
|
|
175
|
-
}): Promise<CommandContext
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* // With message adapter configured
|
|
182
|
-
* client.on('messageCreate', (message) => {
|
|
183
|
-
* handler.handle(message);
|
|
184
|
-
* });
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
100
|
+
}): Promise<(CommandContext & {
|
|
101
|
+
_rawArgs: string[];
|
|
102
|
+
_rawFlags: Record<string, string | boolean>;
|
|
103
|
+
}) | null>;
|
|
187
104
|
handle(message: Message): Promise<boolean>;
|
|
188
|
-
/**
|
|
189
|
-
* Handle a raw message string with metadata
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* ```ts
|
|
193
|
-
* // Manual usage without message adapter
|
|
194
|
-
* client.on('messageCreate', (message) => {
|
|
195
|
-
* handler.handleMessage(message.content, message, {
|
|
196
|
-
* authorId: message.author.id,
|
|
197
|
-
* channelId: message.channel.id,
|
|
198
|
-
* serverId: message.server?.id,
|
|
199
|
-
* reply: (content) => message.channel.sendMessage(content),
|
|
200
|
-
* });
|
|
201
|
-
* });
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
105
|
handleMessage(rawContent: string, message: Message, meta: {
|
|
205
106
|
authorId: string;
|
|
206
107
|
channelId: string;
|
|
207
108
|
serverId?: string | undefined;
|
|
208
109
|
reply: (content: string) => Promise<Message>;
|
|
209
110
|
}): Promise<void>;
|
|
111
|
+
execute(ctx: CommandContext & {
|
|
112
|
+
_rawArgs: string[];
|
|
113
|
+
_rawFlags: Record<string, string | boolean>;
|
|
114
|
+
}): Promise<boolean>;
|
|
210
115
|
/**
|
|
211
|
-
*
|
|
212
|
-
*/
|
|
213
|
-
execute(ctx: CommandContext): Promise<boolean>;
|
|
214
|
-
/**
|
|
215
|
-
* Get the command registry
|
|
116
|
+
* Report a validation error to the instance via onValidationError → onError → default reply
|
|
216
117
|
*/
|
|
118
|
+
private reportValidationError;
|
|
119
|
+
private resolveParams;
|
|
120
|
+
private resolveValue;
|
|
217
121
|
getRegistry(): CommandRegistry;
|
|
218
|
-
/**
|
|
219
|
-
* Get a command by name or alias
|
|
220
|
-
*/
|
|
221
122
|
getCommand(name: string): RegisteredCommand | undefined;
|
|
222
|
-
/**
|
|
223
|
-
* Get all commands
|
|
224
|
-
*/
|
|
225
123
|
getCommands(): RegisteredCommand[];
|
|
226
|
-
/**
|
|
227
|
-
* Reload all commands
|
|
228
|
-
*/
|
|
229
124
|
reload(): Promise<void>;
|
|
230
|
-
/**
|
|
231
|
-
* Check if a user is an owner
|
|
232
|
-
*/
|
|
233
125
|
isOwner(userId: string): boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Add an owner
|
|
236
|
-
*/
|
|
237
126
|
addOwner(userId: string): void;
|
|
238
|
-
/**
|
|
239
|
-
* Remove an owner
|
|
240
|
-
*/
|
|
241
127
|
removeOwner(userId: string): void;
|
|
242
|
-
/**
|
|
243
|
-
* Resolve the prefix for a context
|
|
244
|
-
*/
|
|
245
128
|
private resolvePrefix;
|
|
246
129
|
}
|
|
247
130
|
|
|
@@ -267,20 +150,81 @@ declare class Client extends Client$1 {
|
|
|
267
150
|
executeCommand(message: Message): Promise<void>;
|
|
268
151
|
}
|
|
269
152
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Base error class for all Stoatx errors
|
|
155
|
+
*/
|
|
156
|
+
declare class StoatxError extends Error {
|
|
157
|
+
constructor(message: string);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Base class for all command validation errors.
|
|
161
|
+
* Thrown before the command body runs when user input fails validation.
|
|
162
|
+
*/
|
|
163
|
+
declare class CommandValidationError extends StoatxError {
|
|
164
|
+
readonly paramName: string;
|
|
165
|
+
readonly paramKind: "arg" | "option";
|
|
166
|
+
constructor(paramName: string, paramKind: "arg" | "option", message: string);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Thrown when a required positional argument is missing
|
|
170
|
+
*/
|
|
171
|
+
declare class MissingArgumentError extends CommandValidationError {
|
|
172
|
+
constructor(paramName: string);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Thrown when a required named option is missing
|
|
176
|
+
*/
|
|
177
|
+
declare class MissingOptionError extends CommandValidationError {
|
|
178
|
+
constructor(paramName: string, flagPrefix: string);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Thrown when a value cannot be cast to the expected type
|
|
182
|
+
*/
|
|
183
|
+
declare class InvalidTypeError extends CommandValidationError {
|
|
184
|
+
readonly expected: string;
|
|
185
|
+
readonly received: string;
|
|
186
|
+
constructor(paramName: string, paramKind: "arg" | "option", expected: string, received: string);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Thrown when a mention string cannot be parsed as a valid ULID
|
|
190
|
+
*/
|
|
191
|
+
declare class InvalidMentionError extends CommandValidationError {
|
|
192
|
+
readonly mentionKind: "user" | "channel" | "role";
|
|
193
|
+
readonly rawValue: string;
|
|
194
|
+
constructor(paramName: string, paramKind: "arg" | "option", mentionKind: "user" | "channel" | "role", rawValue: string);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Thrown when fetch: true is set but the API call fails
|
|
198
|
+
*/
|
|
199
|
+
declare class FetchFailedError extends CommandValidationError {
|
|
200
|
+
readonly mentionKind: "user" | "channel" | "role";
|
|
201
|
+
readonly resolvedId: string;
|
|
202
|
+
constructor(paramName: string, paramKind: "arg" | "option", mentionKind: "user" | "channel" | "role", resolvedId: string);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Thrown when a role fetch is attempted outside a server context
|
|
206
|
+
*/
|
|
207
|
+
declare class NoServerContextError extends CommandValidationError {
|
|
208
|
+
constructor(paramName: string, paramKind: "arg" | "option");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Resolved parameter type from reflect-metadata or explicit decorator config
|
|
213
|
+
*/
|
|
214
|
+
type ResolvedParamType = "string" | "number" | "boolean" | "user" | "channel" | "role" | "ctx";
|
|
215
|
+
/**
|
|
216
|
+
* Schema for a single method parameter decorated with @Arg, @Option, or inferred as ctx
|
|
217
|
+
*/
|
|
218
|
+
interface ParamSchema {
|
|
219
|
+
index: number;
|
|
220
|
+
kind: "arg" | "option" | "ctx";
|
|
221
|
+
resolvedType: ResolvedParamType;
|
|
222
|
+
name?: string;
|
|
223
|
+
required?: boolean | undefined;
|
|
224
|
+
fetch?: boolean | undefined;
|
|
280
225
|
}
|
|
281
226
|
/**
|
|
282
227
|
* Simple command options passed to @SimpleCommand decorator
|
|
283
|
-
* Used with @Stoat() decorated classes for method-based commands
|
|
284
228
|
*/
|
|
285
229
|
interface SimpleCommandOptions {
|
|
286
230
|
/** Command name (defaults to method name) */
|
|
@@ -301,10 +245,14 @@ interface SimpleCommandOptions {
|
|
|
301
245
|
nsfw?: boolean;
|
|
302
246
|
/** Whether the command is owner only */
|
|
303
247
|
ownerOnly?: boolean;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
248
|
+
}
|
|
249
|
+
interface GroupOptions {
|
|
250
|
+
name: string;
|
|
251
|
+
description?: string;
|
|
252
|
+
permissions?: PermissionResolvable[];
|
|
253
|
+
ownerOnly?: boolean;
|
|
254
|
+
cooldown?: number;
|
|
255
|
+
nsfw?: boolean;
|
|
308
256
|
}
|
|
309
257
|
/**
|
|
310
258
|
* Resolved command metadata with required fields
|
|
@@ -319,13 +267,14 @@ interface CommandMetadata {
|
|
|
319
267
|
cooldownStorage?: string;
|
|
320
268
|
nsfw: boolean;
|
|
321
269
|
ownerOnly: boolean;
|
|
322
|
-
|
|
323
|
-
|
|
270
|
+
/** Parameter schema built at scan time from @Arg/@Option decorators */
|
|
271
|
+
params: ParamSchema[];
|
|
324
272
|
}
|
|
325
273
|
/**
|
|
326
|
-
* Command execution context
|
|
274
|
+
* Command execution context — carries message context only.
|
|
275
|
+
* Args and options are injected directly as typed method parameters.
|
|
327
276
|
*/
|
|
328
|
-
interface CommandContext<
|
|
277
|
+
interface CommandContext<TClient extends Client$1 = Client> {
|
|
329
278
|
/** The client instance */
|
|
330
279
|
client: TClient;
|
|
331
280
|
/** The raw message content */
|
|
@@ -336,82 +285,71 @@ interface CommandContext<TOptions = Record<string, string | number | boolean>, T
|
|
|
336
285
|
channelId: string;
|
|
337
286
|
/** The server/guild ID (if applicable) */
|
|
338
287
|
serverId?: string | undefined;
|
|
339
|
-
/** Parsed command arguments */
|
|
340
|
-
args: TArgs;
|
|
341
|
-
options?: TOptions;
|
|
342
288
|
/** The prefix used */
|
|
343
289
|
prefix: string;
|
|
344
290
|
/** The command name used (could be an alias) */
|
|
345
291
|
commandName: string;
|
|
346
292
|
/** Reply to the message */
|
|
347
293
|
reply: (content: string) => Promise<Message>;
|
|
348
|
-
/** The original message object
|
|
294
|
+
/** The original message object */
|
|
349
295
|
message: Message;
|
|
350
296
|
}
|
|
351
297
|
/**
|
|
352
298
|
* Optional lifecycle hooks for @Stoat() class instances
|
|
353
299
|
*/
|
|
354
300
|
interface StoatLifecycle {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
/** Optional: Called when user doesn't have the permissions needed */
|
|
360
|
-
onMissingPermissions?(ctx: CommandContext<Client>, missing: PermissionResolvable[]): Promise<void> | void;
|
|
361
|
-
/** Allows the class to contain other methods (such as your commands) */
|
|
301
|
+
onError?(ctx: CommandContext, error: Error): Promise<void> | void;
|
|
302
|
+
onValidationError?(ctx: CommandContext, error: CommandValidationError): Promise<void> | void;
|
|
303
|
+
onCooldown?(ctx: CommandContext, remaining: number): Promise<void> | void;
|
|
304
|
+
onMissingPermissions?(ctx: CommandContext, missing: PermissionResolvable[]): Promise<void> | void;
|
|
362
305
|
[method: string]: any;
|
|
363
306
|
}
|
|
307
|
+
interface GuardInterface {
|
|
308
|
+
run(ctx: CommandContext): Promise<boolean> | boolean;
|
|
309
|
+
guardFail?(ctx: CommandContext): Promise<void> | void;
|
|
310
|
+
}
|
|
364
311
|
/**
|
|
365
|
-
* Cooldown manager interface for custom cooldown storage
|
|
312
|
+
* Cooldown manager interface for custom cooldown storage
|
|
366
313
|
*/
|
|
367
314
|
interface CooldownManager {
|
|
368
|
-
check(ctx: CommandContext
|
|
369
|
-
getRemaining(ctx: CommandContext
|
|
370
|
-
set(ctx: CommandContext
|
|
315
|
+
check(ctx: CommandContext, metadata: CommandMetadata): boolean | Promise<boolean>;
|
|
316
|
+
getRemaining(ctx: CommandContext, metadata: CommandMetadata): number | Promise<number>;
|
|
317
|
+
set(ctx: CommandContext, metadata: CommandMetadata): void | Promise<void>;
|
|
371
318
|
clear?(): void | Promise<void>;
|
|
372
319
|
}
|
|
373
320
|
interface StoatxGuard {
|
|
374
|
-
run(ctx: CommandContext
|
|
375
|
-
guardFail?(ctx: CommandContext
|
|
321
|
+
run(ctx: CommandContext): Promise<boolean> | boolean;
|
|
322
|
+
guardFail?(ctx: CommandContext): Promise<void> | void;
|
|
376
323
|
}
|
|
377
324
|
/**
|
|
378
325
|
* Discovery options for automatic command module loading
|
|
379
326
|
*/
|
|
380
327
|
interface StoatxDiscoveryOptions {
|
|
381
|
-
/** Root directories to scan (default: [process.cwd()]) */
|
|
382
328
|
roots?: string[];
|
|
383
|
-
/** Glob patterns relative to each root */
|
|
384
329
|
include?: string[];
|
|
385
|
-
/** Additional ignore patterns */
|
|
386
330
|
ignore?: string[];
|
|
387
331
|
}
|
|
388
332
|
/**
|
|
389
333
|
* Handler options
|
|
390
334
|
*/
|
|
391
335
|
interface StoatxHandlerOptions {
|
|
392
|
-
/** The client instance */
|
|
393
336
|
client: Client;
|
|
394
|
-
/** Directory to scan for command modules (absolute path) */
|
|
395
337
|
commandsDir?: string;
|
|
396
|
-
/** Auto-discovery options used when commandsDir is not provided */
|
|
397
338
|
discovery?: StoatxDiscoveryOptions;
|
|
398
|
-
|
|
399
|
-
prefix: string | ((ctx: {
|
|
339
|
+
prefix: string | string[] | ((ctx: {
|
|
400
340
|
serverId?: string | undefined;
|
|
401
|
-
}) => string | Promise<string>);
|
|
402
|
-
/** Owner IDs for owner-only commands */
|
|
341
|
+
}) => string | string[] | Promise<string | string[]>);
|
|
403
342
|
owners?: string[];
|
|
404
|
-
/** File extensions to load (default: ['.js', '.mjs', '.cjs']) */
|
|
405
343
|
extensions?: string[];
|
|
406
|
-
/** Disable mention prefix support (default: false) */
|
|
407
344
|
disableMentionPrefix?: boolean;
|
|
408
|
-
/** Custom cooldown manager */
|
|
409
345
|
cooldownManager?: CooldownManager;
|
|
410
|
-
/** * The prefix used to identify flags/options (defaults to "-")
|
|
411
|
-
* @example "+" for +force, "/" for /force
|
|
412
|
-
*/
|
|
413
346
|
flagPrefix?: string;
|
|
347
|
+
globalGuards?: Function[];
|
|
414
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Map from reflect-metadata design:paramtypes constructor to resolved param type
|
|
351
|
+
*/
|
|
352
|
+
declare const PARAM_TYPE_MAP: Map<Function, ResolvedParamType>;
|
|
415
353
|
|
|
416
354
|
/**
|
|
417
355
|
* @Stoat
|
|
@@ -449,7 +387,7 @@ interface SimpleCommandDefinition {
|
|
|
449
387
|
methodName: string;
|
|
450
388
|
options: SimpleCommandOptions;
|
|
451
389
|
}
|
|
452
|
-
type CommandMethod = (
|
|
390
|
+
type CommandMethod = (...args: any[]) => Promise<void>;
|
|
453
391
|
/**
|
|
454
392
|
* @SimpleCommand
|
|
455
393
|
* Marks a method as a simple command within a @Stoat() decorated class.
|
|
@@ -507,11 +445,11 @@ declare function getSimpleCommands(target: Function): SimpleCommandDefinition[];
|
|
|
507
445
|
* }
|
|
508
446
|
* ```
|
|
509
447
|
*/
|
|
510
|
-
declare function Guard(guardClass: Function):
|
|
448
|
+
declare function Guard(guardClass: Function): (target: any, propertyKey?: string | symbol) => void;
|
|
511
449
|
/**
|
|
512
450
|
* Get all guards from a decorated class
|
|
513
451
|
*/
|
|
514
|
-
declare function getGuards(target: Function): Function[];
|
|
452
|
+
declare function getGuards(target: Function, propertyKey?: string | symbol): Function[];
|
|
515
453
|
|
|
516
454
|
interface EventDefinition {
|
|
517
455
|
methodName: string;
|
|
@@ -539,7 +477,7 @@ interface EventDefinition {
|
|
|
539
477
|
*
|
|
540
478
|
* @param event The name of the client event to listen to
|
|
541
479
|
*/
|
|
542
|
-
declare function On(event:
|
|
480
|
+
declare function On(event: keyof ClientEvents): MethodDecorator;
|
|
543
481
|
/**
|
|
544
482
|
* @Once
|
|
545
483
|
* Triggered only fully once.
|
|
@@ -561,16 +499,66 @@ declare function On(event: string): MethodDecorator;
|
|
|
561
499
|
*
|
|
562
500
|
* @param event The name of the client event to listen to
|
|
563
501
|
*/
|
|
564
|
-
declare function Once(event:
|
|
502
|
+
declare function Once(event: keyof ClientEvents): MethodDecorator;
|
|
565
503
|
/**
|
|
566
504
|
* Get all event definitions from a @Stoat class
|
|
567
505
|
*/
|
|
568
506
|
declare function getEventsMetadata(target: Function): EventDefinition[];
|
|
569
507
|
|
|
508
|
+
interface ArgDefinition {
|
|
509
|
+
index: number;
|
|
510
|
+
name?: string;
|
|
511
|
+
required?: boolean;
|
|
512
|
+
fetch?: boolean;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Marks a method parameter as a positional command argument.
|
|
516
|
+
* Type is inferred from the TypeScript parameter type via reflect-metadata.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* @SimpleCommand({ name: "ban" })
|
|
521
|
+
* async ban(
|
|
522
|
+
* @Arg({ required: true }) target: User,
|
|
523
|
+
* @Arg() reason: string | undefined,
|
|
524
|
+
* ctx: CommandContext
|
|
525
|
+
* ) {}
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
declare function Arg(options?: Omit<ArgDefinition, "index">): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
529
|
+
|
|
530
|
+
interface OptionDefinition {
|
|
531
|
+
index: number;
|
|
532
|
+
name: string;
|
|
533
|
+
required?: boolean;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* @Option
|
|
537
|
+
* Marks a method parameter as a named flag option (e.g. --reason value).
|
|
538
|
+
* Type is inferred from the TypeScript parameter type via reflect-metadata.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```ts
|
|
542
|
+
* @SimpleCommand({ name: "ban" })
|
|
543
|
+
* async ban(
|
|
544
|
+
* @Option({ name: "reason" }) reason: string | undefined,
|
|
545
|
+
* @Option({ name: "days" }) days: number | undefined,
|
|
546
|
+
* ctx: CommandContext
|
|
547
|
+
* ) {}
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare function Option(options: Omit<OptionDefinition, "index">): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
551
|
+
|
|
552
|
+
declare function Injectable(): ClassDecorator;
|
|
553
|
+
|
|
554
|
+
declare function CommandGroup(name: GroupOptions): ClassDecorator;
|
|
555
|
+
|
|
556
|
+
declare function SubCommand(options: SimpleCommandOptions | string): MethodDecorator;
|
|
557
|
+
|
|
570
558
|
/**
|
|
571
559
|
* Build CommandMetadata from SimpleCommandOptions
|
|
572
560
|
*/
|
|
573
|
-
declare function buildSimpleCommandMetadata(options: SimpleCommandOptions, methodName: string, category
|
|
561
|
+
declare function buildSimpleCommandMetadata(options: SimpleCommandOptions, methodName: string, category: string | undefined, params: ParamSchema[]): CommandMetadata;
|
|
574
562
|
|
|
575
563
|
/**
|
|
576
564
|
* Metadata keys used by decorators
|
|
@@ -580,11 +568,11 @@ declare const METADATA_KEYS: {
|
|
|
580
568
|
readonly SIMPLE_COMMANDS: symbol;
|
|
581
569
|
readonly GUARDS: "stoatx:command:guards";
|
|
582
570
|
readonly EVENTS: symbol;
|
|
571
|
+
readonly ARGS: symbol;
|
|
572
|
+
readonly OPTIONS: symbol;
|
|
573
|
+
readonly INJECTABLE: symbol;
|
|
574
|
+
readonly SUBCOMMAND: symbol;
|
|
575
|
+
readonly COMMAND_GROUP: symbol;
|
|
583
576
|
};
|
|
584
577
|
|
|
585
|
-
|
|
586
|
-
readonly optionName: string;
|
|
587
|
-
constructor(optionName: string, message: string);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
export { Client, type CommandContext, type CommandMetadata, type CommandOptionDefinition, CommandRegistry, CommandValidationError, type CooldownManager, DefaultCooldownManager, type EventDefinition, Guard, METADATA_KEYS, On, Once, type OptionType, type RegisteredCommand, type RegisteredEvent, SimpleCommand, type SimpleCommandDefinition, type SimpleCommandOptions, Stoat, type StoatLifecycle, type StoatxDiscoveryOptions, type StoatxGuard, StoatxHandler, type StoatxHandlerOptions, buildSimpleCommandMetadata, getEventsMetadata, getGuards, getSimpleCommands, isStoatClass };
|
|
578
|
+
export { Arg, Client, type CommandContext, CommandGroup, type CommandMetadata, CommandRegistry, CommandValidationError, type CooldownManager, DefaultCooldownManager, type EventDefinition, FetchFailedError, type GroupOptions, Guard, type GuardInterface, Injectable, InvalidMentionError, InvalidTypeError, METADATA_KEYS, MissingArgumentError, MissingOptionError, NoServerContextError, On, Once, Option, PARAM_TYPE_MAP, type ParamSchema, type RegisteredCommand, type RegisteredEvent, type ResolvedParamType, SimpleCommand, type SimpleCommandDefinition, type SimpleCommandOptions, Stoat, type StoatLifecycle, type StoatxDiscoveryOptions, StoatxError, type StoatxGuard, StoatxHandler, type StoatxHandlerOptions, SubCommand, buildSimpleCommandMetadata, getEventsMetadata, getGuards, getSimpleCommands, isStoatClass };
|