stoatx 0.7.7 → 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/README.md +3 -264
- package/dist/index.d.mts +204 -183
- package/dist/index.d.ts +204 -183
- package/dist/index.js +635 -236
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +621 -234
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,31 @@
|
|
|
1
|
-
import { Message, Client as Client$1, 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;
|
|
@@ -150,93 +85,46 @@ declare class StoatxHandler {
|
|
|
150
85
|
private readonly cooldownManager;
|
|
151
86
|
private readonly disableMentionPrefix;
|
|
152
87
|
private readonly client;
|
|
88
|
+
private readonly flagPrefix;
|
|
89
|
+
private readonly globalGuards;
|
|
90
|
+
readonly container: StoatxContainer;
|
|
153
91
|
constructor(options: StoatxHandlerOptions);
|
|
154
|
-
/**
|
|
155
|
-
* Initialize the handler - load all commands
|
|
156
|
-
*/
|
|
157
92
|
init(): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Attach registered events to the client
|
|
160
|
-
*/
|
|
161
93
|
private attachEvents;
|
|
162
|
-
|
|
163
|
-
* Parse a raw message into command context
|
|
164
|
-
*/
|
|
94
|
+
private parseRawInput;
|
|
165
95
|
parseMessage(rawContent: string, message: Message, meta: {
|
|
166
96
|
authorId: string;
|
|
167
97
|
channelId: string;
|
|
168
98
|
serverId?: string | undefined;
|
|
169
99
|
reply: (content: string) => Promise<Message>;
|
|
170
|
-
}): Promise<CommandContext
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* // With message adapter configured
|
|
177
|
-
* client.on('messageCreate', (message) => {
|
|
178
|
-
* handler.handle(message);
|
|
179
|
-
* });
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
100
|
+
}): Promise<(CommandContext & {
|
|
101
|
+
_rawArgs: string[];
|
|
102
|
+
_rawFlags: Record<string, string | boolean>;
|
|
103
|
+
}) | null>;
|
|
182
104
|
handle(message: Message): Promise<boolean>;
|
|
183
|
-
/**
|
|
184
|
-
* Handle a raw message string with metadata
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```ts
|
|
188
|
-
* // Manual usage without message adapter
|
|
189
|
-
* client.on('messageCreate', (message) => {
|
|
190
|
-
* handler.handleMessage(message.content, message, {
|
|
191
|
-
* authorId: message.author.id,
|
|
192
|
-
* channelId: message.channel.id,
|
|
193
|
-
* serverId: message.server?.id,
|
|
194
|
-
* reply: (content) => message.channel.sendMessage(content),
|
|
195
|
-
* });
|
|
196
|
-
* });
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
105
|
handleMessage(rawContent: string, message: Message, meta: {
|
|
200
106
|
authorId: string;
|
|
201
107
|
channelId: string;
|
|
202
108
|
serverId?: string | undefined;
|
|
203
109
|
reply: (content: string) => Promise<Message>;
|
|
204
110
|
}): Promise<void>;
|
|
111
|
+
execute(ctx: CommandContext & {
|
|
112
|
+
_rawArgs: string[];
|
|
113
|
+
_rawFlags: Record<string, string | boolean>;
|
|
114
|
+
}): Promise<boolean>;
|
|
205
115
|
/**
|
|
206
|
-
*
|
|
207
|
-
*/
|
|
208
|
-
execute(ctx: CommandContext<Client>): Promise<boolean>;
|
|
209
|
-
/**
|
|
210
|
-
* Get the command registry
|
|
116
|
+
* Report a validation error to the instance via onValidationError → onError → default reply
|
|
211
117
|
*/
|
|
118
|
+
private reportValidationError;
|
|
119
|
+
private resolveParams;
|
|
120
|
+
private resolveValue;
|
|
212
121
|
getRegistry(): CommandRegistry;
|
|
213
|
-
/**
|
|
214
|
-
* Get a command by name or alias
|
|
215
|
-
*/
|
|
216
122
|
getCommand(name: string): RegisteredCommand | undefined;
|
|
217
|
-
/**
|
|
218
|
-
* Get all commands
|
|
219
|
-
*/
|
|
220
123
|
getCommands(): RegisteredCommand[];
|
|
221
|
-
/**
|
|
222
|
-
* Reload all commands
|
|
223
|
-
*/
|
|
224
124
|
reload(): Promise<void>;
|
|
225
|
-
/**
|
|
226
|
-
* Check if a user is an owner
|
|
227
|
-
*/
|
|
228
125
|
isOwner(userId: string): boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Add an owner
|
|
231
|
-
*/
|
|
232
126
|
addOwner(userId: string): void;
|
|
233
|
-
/**
|
|
234
|
-
* Remove an owner
|
|
235
|
-
*/
|
|
236
127
|
removeOwner(userId: string): void;
|
|
237
|
-
/**
|
|
238
|
-
* Resolve the prefix for a context
|
|
239
|
-
*/
|
|
240
128
|
private resolvePrefix;
|
|
241
129
|
}
|
|
242
130
|
|
|
@@ -257,13 +145,86 @@ declare class StoatxHandler {
|
|
|
257
145
|
*/
|
|
258
146
|
declare class Client extends Client$1 {
|
|
259
147
|
readonly handler: StoatxHandler;
|
|
260
|
-
constructor(options: Omit<StoatxHandlerOptions, "client">);
|
|
261
|
-
|
|
148
|
+
constructor(options: Omit<StoatxHandlerOptions, "client"> & ClientOptions);
|
|
149
|
+
login(token: string): Promise<string>;
|
|
150
|
+
executeCommand(message: Message): Promise<void>;
|
|
262
151
|
}
|
|
263
152
|
|
|
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;
|
|
225
|
+
}
|
|
264
226
|
/**
|
|
265
227
|
* Simple command options passed to @SimpleCommand decorator
|
|
266
|
-
* Used with @Stoat() decorated classes for method-based commands
|
|
267
228
|
*/
|
|
268
229
|
interface SimpleCommandOptions {
|
|
269
230
|
/** Command name (defaults to method name) */
|
|
@@ -285,6 +246,14 @@ interface SimpleCommandOptions {
|
|
|
285
246
|
/** Whether the command is owner only */
|
|
286
247
|
ownerOnly?: boolean;
|
|
287
248
|
}
|
|
249
|
+
interface GroupOptions {
|
|
250
|
+
name: string;
|
|
251
|
+
description?: string;
|
|
252
|
+
permissions?: PermissionResolvable[];
|
|
253
|
+
ownerOnly?: boolean;
|
|
254
|
+
cooldown?: number;
|
|
255
|
+
nsfw?: boolean;
|
|
256
|
+
}
|
|
288
257
|
/**
|
|
289
258
|
* Resolved command metadata with required fields
|
|
290
259
|
*/
|
|
@@ -298,9 +267,12 @@ interface CommandMetadata {
|
|
|
298
267
|
cooldownStorage?: string;
|
|
299
268
|
nsfw: boolean;
|
|
300
269
|
ownerOnly: boolean;
|
|
270
|
+
/** Parameter schema built at scan time from @Arg/@Option decorators */
|
|
271
|
+
params: ParamSchema[];
|
|
301
272
|
}
|
|
302
273
|
/**
|
|
303
|
-
* Command execution context
|
|
274
|
+
* Command execution context — carries message context only.
|
|
275
|
+
* Args and options are injected directly as typed method parameters.
|
|
304
276
|
*/
|
|
305
277
|
interface CommandContext<TClient extends Client$1 = Client> {
|
|
306
278
|
/** The client instance */
|
|
@@ -313,77 +285,71 @@ interface CommandContext<TClient extends Client$1 = Client> {
|
|
|
313
285
|
channelId: string;
|
|
314
286
|
/** The server/guild ID (if applicable) */
|
|
315
287
|
serverId?: string | undefined;
|
|
316
|
-
/** Parsed command arguments */
|
|
317
|
-
args: string[];
|
|
318
288
|
/** The prefix used */
|
|
319
289
|
prefix: string;
|
|
320
290
|
/** The command name used (could be an alias) */
|
|
321
291
|
commandName: string;
|
|
322
292
|
/** Reply to the message */
|
|
323
293
|
reply: (content: string) => Promise<Message>;
|
|
324
|
-
/** The original message object
|
|
294
|
+
/** The original message object */
|
|
325
295
|
message: Message;
|
|
326
296
|
}
|
|
327
297
|
/**
|
|
328
298
|
* Optional lifecycle hooks for @Stoat() class instances
|
|
329
299
|
*/
|
|
330
300
|
interface StoatLifecycle {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
/** Optional: Called when user doesn't have the permissions needed */
|
|
336
|
-
onMissingPermissions?(ctx: CommandContext<Client>, missing: PermissionResolvable[]): Promise<void> | void;
|
|
337
|
-
/** 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;
|
|
338
305
|
[method: string]: any;
|
|
339
306
|
}
|
|
307
|
+
interface GuardInterface {
|
|
308
|
+
run(ctx: CommandContext): Promise<boolean> | boolean;
|
|
309
|
+
guardFail?(ctx: CommandContext): Promise<void> | void;
|
|
310
|
+
}
|
|
340
311
|
/**
|
|
341
|
-
* Cooldown manager interface for custom cooldown storage
|
|
312
|
+
* Cooldown manager interface for custom cooldown storage
|
|
342
313
|
*/
|
|
343
314
|
interface CooldownManager {
|
|
344
|
-
check(ctx: CommandContext
|
|
345
|
-
getRemaining(ctx: CommandContext
|
|
346
|
-
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>;
|
|
347
318
|
clear?(): void | Promise<void>;
|
|
348
319
|
}
|
|
349
320
|
interface StoatxGuard {
|
|
350
|
-
run(ctx: CommandContext
|
|
351
|
-
guardFail?(ctx: CommandContext
|
|
321
|
+
run(ctx: CommandContext): Promise<boolean> | boolean;
|
|
322
|
+
guardFail?(ctx: CommandContext): Promise<void> | void;
|
|
352
323
|
}
|
|
353
324
|
/**
|
|
354
325
|
* Discovery options for automatic command module loading
|
|
355
326
|
*/
|
|
356
327
|
interface StoatxDiscoveryOptions {
|
|
357
|
-
/** Root directories to scan (default: [process.cwd()]) */
|
|
358
328
|
roots?: string[];
|
|
359
|
-
/** Glob patterns relative to each root */
|
|
360
329
|
include?: string[];
|
|
361
|
-
/** Additional ignore patterns */
|
|
362
330
|
ignore?: string[];
|
|
363
331
|
}
|
|
364
332
|
/**
|
|
365
333
|
* Handler options
|
|
366
334
|
*/
|
|
367
335
|
interface StoatxHandlerOptions {
|
|
368
|
-
/** The client instance */
|
|
369
336
|
client: Client;
|
|
370
|
-
/** Directory to scan for command modules (absolute path) */
|
|
371
337
|
commandsDir?: string;
|
|
372
|
-
/** Auto-discovery options used when commandsDir is not provided */
|
|
373
338
|
discovery?: StoatxDiscoveryOptions;
|
|
374
|
-
|
|
375
|
-
prefix: string | ((ctx: {
|
|
339
|
+
prefix: string | string[] | ((ctx: {
|
|
376
340
|
serverId?: string | undefined;
|
|
377
|
-
}) => string | Promise<string>);
|
|
378
|
-
/** Owner IDs for owner-only commands */
|
|
341
|
+
}) => string | string[] | Promise<string | string[]>);
|
|
379
342
|
owners?: string[];
|
|
380
|
-
/** File extensions to load (default: ['.js', '.mjs', '.cjs']) */
|
|
381
343
|
extensions?: string[];
|
|
382
|
-
/** Disable mention prefix support (default: false) */
|
|
383
344
|
disableMentionPrefix?: boolean;
|
|
384
|
-
/** Custom cooldown manager */
|
|
385
345
|
cooldownManager?: CooldownManager;
|
|
346
|
+
flagPrefix?: string;
|
|
347
|
+
globalGuards?: Function[];
|
|
386
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Map from reflect-metadata design:paramtypes constructor to resolved param type
|
|
351
|
+
*/
|
|
352
|
+
declare const PARAM_TYPE_MAP: Map<Function, ResolvedParamType>;
|
|
387
353
|
|
|
388
354
|
/**
|
|
389
355
|
* @Stoat
|
|
@@ -421,7 +387,7 @@ interface SimpleCommandDefinition {
|
|
|
421
387
|
methodName: string;
|
|
422
388
|
options: SimpleCommandOptions;
|
|
423
389
|
}
|
|
424
|
-
type CommandMethod = (
|
|
390
|
+
type CommandMethod = (...args: any[]) => Promise<void>;
|
|
425
391
|
/**
|
|
426
392
|
* @SimpleCommand
|
|
427
393
|
* Marks a method as a simple command within a @Stoat() decorated class.
|
|
@@ -479,11 +445,11 @@ declare function getSimpleCommands(target: Function): SimpleCommandDefinition[];
|
|
|
479
445
|
* }
|
|
480
446
|
* ```
|
|
481
447
|
*/
|
|
482
|
-
declare function Guard(guardClass: Function):
|
|
448
|
+
declare function Guard(guardClass: Function): (target: any, propertyKey?: string | symbol) => void;
|
|
483
449
|
/**
|
|
484
450
|
* Get all guards from a decorated class
|
|
485
451
|
*/
|
|
486
|
-
declare function getGuards(target: Function): Function[];
|
|
452
|
+
declare function getGuards(target: Function, propertyKey?: string | symbol): Function[];
|
|
487
453
|
|
|
488
454
|
interface EventDefinition {
|
|
489
455
|
methodName: string;
|
|
@@ -511,7 +477,7 @@ interface EventDefinition {
|
|
|
511
477
|
*
|
|
512
478
|
* @param event The name of the client event to listen to
|
|
513
479
|
*/
|
|
514
|
-
declare function On(event:
|
|
480
|
+
declare function On(event: keyof ClientEvents): MethodDecorator;
|
|
515
481
|
/**
|
|
516
482
|
* @Once
|
|
517
483
|
* Triggered only fully once.
|
|
@@ -533,16 +499,66 @@ declare function On(event: string): MethodDecorator;
|
|
|
533
499
|
*
|
|
534
500
|
* @param event The name of the client event to listen to
|
|
535
501
|
*/
|
|
536
|
-
declare function Once(event:
|
|
502
|
+
declare function Once(event: keyof ClientEvents): MethodDecorator;
|
|
537
503
|
/**
|
|
538
504
|
* Get all event definitions from a @Stoat class
|
|
539
505
|
*/
|
|
540
506
|
declare function getEventsMetadata(target: Function): EventDefinition[];
|
|
541
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
|
+
|
|
542
558
|
/**
|
|
543
559
|
* Build CommandMetadata from SimpleCommandOptions
|
|
544
560
|
*/
|
|
545
|
-
declare function buildSimpleCommandMetadata(options: SimpleCommandOptions, methodName: string, category
|
|
561
|
+
declare function buildSimpleCommandMetadata(options: SimpleCommandOptions, methodName: string, category: string | undefined, params: ParamSchema[]): CommandMetadata;
|
|
546
562
|
|
|
547
563
|
/**
|
|
548
564
|
* Metadata keys used by decorators
|
|
@@ -552,6 +568,11 @@ declare const METADATA_KEYS: {
|
|
|
552
568
|
readonly SIMPLE_COMMANDS: symbol;
|
|
553
569
|
readonly GUARDS: "stoatx:command:guards";
|
|
554
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;
|
|
555
576
|
};
|
|
556
577
|
|
|
557
|
-
export { Client, type CommandContext, type CommandMetadata, CommandRegistry, type CooldownManager, DefaultCooldownManager, type EventDefinition, Guard, METADATA_KEYS, On, Once, 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 };
|