stoatx 0.7.5 → 0.7.7
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 +335 -336
- package/dist/index.d.ts +335 -336
- package/dist/index.js +16 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,335 +1,43 @@
|
|
|
1
|
-
import { Client as Client$1,
|
|
1
|
+
import { Message, Client as Client$1, PermissionResolvable } from '@stoatx/client';
|
|
2
2
|
export * from '@stoatx/client';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Simple command options passed to @SimpleCommand decorator
|
|
6
|
-
* Used with @Stoat() decorated classes for method-based commands
|
|
7
|
-
*/
|
|
8
|
-
interface SimpleCommandOptions {
|
|
9
|
-
/** Command name (defaults to method name) */
|
|
10
|
-
name?: string;
|
|
11
|
-
/** Command description */
|
|
12
|
-
description?: string;
|
|
13
|
-
/** Command aliases */
|
|
14
|
-
aliases?: string[];
|
|
15
|
-
/** Required permissions to run the command */
|
|
16
|
-
permissions?: PermissionResolvable[];
|
|
17
|
-
/** Command category (auto-detected from directory if not provided) */
|
|
18
|
-
category?: string;
|
|
19
|
-
/** Cooldown in milliseconds */
|
|
20
|
-
cooldown?: number;
|
|
21
|
-
/** Storage strategy or identifier for cooldowns (e.g. "memory", "database") */
|
|
22
|
-
cooldownStorage?: string;
|
|
23
|
-
/** Whether the command is NSFW only */
|
|
24
|
-
nsfw?: boolean;
|
|
25
|
-
/** Whether the command is owner only */
|
|
26
|
-
ownerOnly?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Resolved command metadata with required fields
|
|
30
|
-
*/
|
|
31
|
-
interface CommandMetadata {
|
|
32
|
-
name: string;
|
|
33
|
-
description: string;
|
|
34
|
-
aliases: string[];
|
|
35
|
-
permissions: PermissionResolvable[];
|
|
36
|
-
category: string;
|
|
37
|
-
cooldown: number;
|
|
38
|
-
cooldownStorage?: string;
|
|
39
|
-
nsfw: boolean;
|
|
40
|
-
ownerOnly: boolean;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Command execution context
|
|
44
|
-
*/
|
|
45
|
-
interface CommandContext {
|
|
46
|
-
/** The client instance */
|
|
47
|
-
client: Client$1;
|
|
48
|
-
/** The raw message content */
|
|
49
|
-
content: string;
|
|
50
|
-
/** The author ID */
|
|
51
|
-
authorId: string;
|
|
52
|
-
/** The channel ID */
|
|
53
|
-
channelId: string;
|
|
54
|
-
/** The server/guild ID (if applicable) */
|
|
55
|
-
serverId?: string | undefined;
|
|
56
|
-
/** Parsed command arguments */
|
|
57
|
-
args: string[];
|
|
58
|
-
/** The prefix used */
|
|
59
|
-
prefix: string;
|
|
60
|
-
/** The command name used (could be an alias) */
|
|
61
|
-
commandName: string;
|
|
62
|
-
/** Reply to the message */
|
|
63
|
-
reply: (content: string) => Promise<Message>;
|
|
64
|
-
/** The original message object (platform-specific) */
|
|
65
|
-
message: Message;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Optional lifecycle hooks for @Stoat() class instances
|
|
69
|
-
*/
|
|
70
|
-
interface StoatLifecycle {
|
|
71
|
-
/** Optional: Called when an error occurs during command execution */
|
|
72
|
-
onError?(ctx: CommandContext, error: Error): Promise<void> | void;
|
|
73
|
-
/** Optional: Called when a cooldown is active */
|
|
74
|
-
onCooldown?(ctx: CommandContext, remaining: number): Promise<void> | void;
|
|
75
|
-
/** Optional: Called when user doesn't have the permissions needed */
|
|
76
|
-
onMissingPermissions?(ctx: CommandContext, missing: PermissionResolvable[]): Promise<void> | void;
|
|
77
|
-
/** Allows the class to contain other methods (such as your commands) */
|
|
78
|
-
[method: string]: any;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Cooldown manager interface for custom cooldown storage (e.g., database)
|
|
82
|
-
*/
|
|
83
|
-
interface CooldownManager {
|
|
84
|
-
check(ctx: CommandContext, metadata: CommandMetadata): boolean | Promise<boolean>;
|
|
85
|
-
getRemaining(ctx: CommandContext, metadata: CommandMetadata): number | Promise<number>;
|
|
86
|
-
set(ctx: CommandContext, metadata: CommandMetadata): void | Promise<void>;
|
|
87
|
-
clear?(): void | Promise<void>;
|
|
88
|
-
}
|
|
89
|
-
interface StoatxGuard {
|
|
90
|
-
run(ctx: CommandContext): Promise<boolean> | boolean;
|
|
91
|
-
guardFail?(ctx: CommandContext): Promise<void> | void;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Discovery options for automatic command module loading
|
|
95
|
-
*/
|
|
96
|
-
interface StoatxDiscoveryOptions {
|
|
97
|
-
/** Root directories to scan (default: [process.cwd()]) */
|
|
4
|
+
interface AutoDiscoveryOptions {
|
|
98
5
|
roots?: string[];
|
|
99
|
-
/** Glob patterns relative to each root */
|
|
100
6
|
include?: string[];
|
|
101
|
-
/** Additional ignore patterns */
|
|
102
7
|
ignore?: string[];
|
|
103
8
|
}
|
|
104
9
|
/**
|
|
105
|
-
*
|
|
106
|
-
*/
|
|
107
|
-
interface StoatxHandlerOptions {
|
|
108
|
-
/** The client instance */
|
|
109
|
-
client: Client$1;
|
|
110
|
-
/** Directory to scan for command modules (absolute path) */
|
|
111
|
-
commandsDir?: string;
|
|
112
|
-
/** Auto-discovery options used when commandsDir is not provided */
|
|
113
|
-
discovery?: StoatxDiscoveryOptions;
|
|
114
|
-
/** Command prefix or prefix resolver function */
|
|
115
|
-
prefix: string | ((ctx: {
|
|
116
|
-
serverId?: string | undefined;
|
|
117
|
-
}) => string | Promise<string>);
|
|
118
|
-
/** Owner IDs for owner-only commands */
|
|
119
|
-
owners?: string[];
|
|
120
|
-
/** File extensions to load (default: ['.js', '.mjs', '.cjs']) */
|
|
121
|
-
extensions?: string[];
|
|
122
|
-
/** Disable mention prefix support (default: false) */
|
|
123
|
-
disableMentionPrefix?: boolean;
|
|
124
|
-
/** Custom cooldown manager */
|
|
125
|
-
cooldownManager?: CooldownManager;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @Stoat
|
|
130
|
-
* Marks a class as a Stoat command container.
|
|
131
|
-
* Use this decorator on classes that contain @SimpleCommand methods.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```ts
|
|
135
|
-
* import { Stoat, SimpleCommand, CommandContext } from 'stoatx';
|
|
136
|
-
*
|
|
137
|
-
* @Stoat()
|
|
138
|
-
* class ModerationCommands {
|
|
139
|
-
* @SimpleCommand({ name: 'ban', description: 'Ban a user' })
|
|
140
|
-
* async ban(ctx: CommandContext) {
|
|
141
|
-
* await ctx.reply('User banned!');
|
|
142
|
-
* }
|
|
143
|
-
*
|
|
144
|
-
* @SimpleCommand({ name: 'kick', description: 'Kick a user' })
|
|
145
|
-
* async kick(ctx: CommandContext) {
|
|
146
|
-
* await ctx.reply('User kicked!');
|
|
147
|
-
* }
|
|
148
|
-
* }
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
declare function Stoat(): ClassDecorator;
|
|
152
|
-
/**
|
|
153
|
-
* Check if a class is decorated with @Stoat
|
|
154
|
-
*/
|
|
155
|
-
declare function isStoatClass(target: Function): boolean;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Stored simple command metadata from method decorator
|
|
10
|
+
* Stored command entry from @Stoat/@SimpleCommand registration.
|
|
159
11
|
*/
|
|
160
|
-
interface
|
|
12
|
+
interface RegisteredCommand {
|
|
13
|
+
/** Instance of the @Stoat class */
|
|
14
|
+
instance: object;
|
|
15
|
+
/** Command metadata */
|
|
16
|
+
metadata: CommandMetadata;
|
|
17
|
+
/** Method name to call */
|
|
161
18
|
methodName: string;
|
|
162
|
-
|
|
19
|
+
/** The original class constructor (for guard validation) */
|
|
20
|
+
classConstructor: Function;
|
|
163
21
|
}
|
|
164
22
|
/**
|
|
165
|
-
* @
|
|
166
|
-
* Marks a method as a simple command within a @Stoat() decorated class.
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```ts
|
|
170
|
-
* @Stoat()
|
|
171
|
-
* class Example {
|
|
172
|
-
* @SimpleCommand({ name: 'ping', description: 'Replies with Pong!' })
|
|
173
|
-
* async ping(ctx: CommandContext) {
|
|
174
|
-
* await ctx.reply('Pong!');
|
|
175
|
-
* }
|
|
176
|
-
*
|
|
177
|
-
* @SimpleCommand({ aliases: ['perm'], name: 'permission' })
|
|
178
|
-
* async permission(ctx: CommandContext) {
|
|
179
|
-
* await ctx.reply('Access granted');
|
|
180
|
-
* }
|
|
181
|
-
* }
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
declare function SimpleCommand(options?: SimpleCommandOptions): MethodDecorator;
|
|
185
|
-
/**
|
|
186
|
-
* Get all simple command definitions from a @Stoat class
|
|
187
|
-
*/
|
|
188
|
-
declare function getSimpleCommands(target: Function): SimpleCommandDefinition[];
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @Guard
|
|
192
|
-
* Runs before a command to check if it should execute.
|
|
193
|
-
* Should return true to allow execution, false to block.
|
|
194
|
-
* Applied on @Stoat classes to guard all contained @SimpleCommand methods.
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* import { Guard, Stoat, SimpleCommand, CommandContext } from 'stoatx';
|
|
199
|
-
*
|
|
200
|
-
* // Define a guard
|
|
201
|
-
* class NotBot implements StoatxGuard {
|
|
202
|
-
* run(ctx: CommandContext): boolean {
|
|
203
|
-
* return !ctx.message.author.bot;
|
|
204
|
-
* }
|
|
205
|
-
*
|
|
206
|
-
* guardFail(ctx: CommandContext): void {
|
|
207
|
-
* ctx.reply("Bots cannot use this command!");
|
|
208
|
-
* }
|
|
209
|
-
* }
|
|
210
|
-
*
|
|
211
|
-
* @Stoat()
|
|
212
|
-
* @Guard(NotBot)
|
|
213
|
-
* class AdminCommands {
|
|
214
|
-
* @SimpleCommand({ name: 'admin', description: 'Admin only command' })
|
|
215
|
-
* async admin(ctx: CommandContext) {
|
|
216
|
-
* ctx.reply("You passed the guard check!");
|
|
217
|
-
* }
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
declare function Guard(guardClass: Function): ClassDecorator;
|
|
222
|
-
/**
|
|
223
|
-
* Get all guards from a decorated class
|
|
23
|
+
* Stored event entry from @On/@Once registration.
|
|
224
24
|
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
interface EventDefinition {
|
|
25
|
+
interface RegisteredEvent {
|
|
26
|
+
instance: object;
|
|
228
27
|
methodName: string;
|
|
229
28
|
event: string;
|
|
230
29
|
type: "on" | "once";
|
|
231
30
|
}
|
|
232
31
|
/**
|
|
233
|
-
*
|
|
234
|
-
* Triggered on every occurrence of the event.
|
|
235
|
-
* Marks a method to be executed whenever the specified client event is emitted.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* import { Stoat, On } from 'stoatx';
|
|
240
|
-
* import { Message, Client } from 'stoat.js';
|
|
241
|
-
*
|
|
242
|
-
* @Stoat()
|
|
243
|
-
* class BotEvents {
|
|
244
|
-
* @On('messageCreate')
|
|
245
|
-
* async onMessage(message: Message, client: Client) {
|
|
246
|
-
* console.log('New message received:', message.content);
|
|
247
|
-
* }
|
|
248
|
-
* }
|
|
249
|
-
* ```
|
|
250
|
-
*
|
|
251
|
-
* @param event The name of the client event to listen to
|
|
252
|
-
*/
|
|
253
|
-
declare function On(event: string): MethodDecorator;
|
|
254
|
-
/**
|
|
255
|
-
* @Once
|
|
256
|
-
* Triggered only fully once.
|
|
257
|
-
* Marks a method to be executed only the FIRST time the specified client event is emitted.
|
|
32
|
+
* CommandRegistry - Scans directories and stores commands in a Map
|
|
258
33
|
*
|
|
259
34
|
* @example
|
|
260
35
|
* ```ts
|
|
261
|
-
*
|
|
262
|
-
*
|
|
36
|
+
* const registry = new CommandRegistry();
|
|
37
|
+
* await registry.loadFromDirectory('./src/commands');
|
|
263
38
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* @Once('ready')
|
|
267
|
-
* async onReady(client: Client) {
|
|
268
|
-
* console.log('Bot successfully started and logged in!');
|
|
269
|
-
* }
|
|
270
|
-
* }
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
* @param event The name of the client event to listen to
|
|
274
|
-
*/
|
|
275
|
-
declare function Once(event: string): MethodDecorator;
|
|
276
|
-
/**
|
|
277
|
-
* Get all event definitions from a @Stoat class
|
|
278
|
-
*/
|
|
279
|
-
declare function getEventsMetadata(target: Function): EventDefinition[];
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Build CommandMetadata from SimpleCommandOptions
|
|
283
|
-
*/
|
|
284
|
-
declare function buildSimpleCommandMetadata(options: SimpleCommandOptions, methodName: string, category?: string): CommandMetadata;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Metadata keys used by decorators
|
|
288
|
-
*/
|
|
289
|
-
declare const METADATA_KEYS: {
|
|
290
|
-
readonly IS_STOAT_CLASS: symbol;
|
|
291
|
-
readonly SIMPLE_COMMANDS: symbol;
|
|
292
|
-
readonly GUARDS: "stoatx:command:guards";
|
|
293
|
-
readonly EVENTS: symbol;
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
interface AutoDiscoveryOptions {
|
|
297
|
-
roots?: string[];
|
|
298
|
-
include?: string[];
|
|
299
|
-
ignore?: string[];
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Stored command entry from @Stoat/@SimpleCommand registration.
|
|
303
|
-
*/
|
|
304
|
-
interface RegisteredCommand {
|
|
305
|
-
/** Instance of the @Stoat class */
|
|
306
|
-
instance: object;
|
|
307
|
-
/** Command metadata */
|
|
308
|
-
metadata: CommandMetadata;
|
|
309
|
-
/** Method name to call */
|
|
310
|
-
methodName: string;
|
|
311
|
-
/** The original class constructor (for guard validation) */
|
|
312
|
-
classConstructor: Function;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Stored event entry from @On/@Once registration.
|
|
316
|
-
*/
|
|
317
|
-
interface RegisteredEvent {
|
|
318
|
-
instance: object;
|
|
319
|
-
methodName: string;
|
|
320
|
-
event: string;
|
|
321
|
-
type: "on" | "once";
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* CommandRegistry - Scans directories and stores commands in a Map
|
|
325
|
-
*
|
|
326
|
-
* @example
|
|
327
|
-
* ```ts
|
|
328
|
-
* const registry = new CommandRegistry();
|
|
329
|
-
* await registry.loadFromDirectory('./src/commands');
|
|
330
|
-
*
|
|
331
|
-
* const ping = registry.get('ping');
|
|
332
|
-
* const allCommands = registry.getAll();
|
|
39
|
+
* const ping = registry.get('ping');
|
|
40
|
+
* const allCommands = registry.getAll();
|
|
333
41
|
* ```
|
|
334
42
|
*/
|
|
335
43
|
declare class CommandRegistry {
|
|
@@ -426,29 +134,6 @@ declare class DefaultCooldownManager implements CooldownManager {
|
|
|
426
134
|
set(ctx: CommandContext, metadata: CommandMetadata): void;
|
|
427
135
|
clear(): void;
|
|
428
136
|
}
|
|
429
|
-
/**
|
|
430
|
-
* Client - An extended Client that integrates StoatxHandler directly
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* ```ts
|
|
434
|
-
* import { Client } from 'stoatx';
|
|
435
|
-
*
|
|
436
|
-
* const client = new Client({
|
|
437
|
-
* prefix: '!',
|
|
438
|
-
* owners: ['owner-user-id'],
|
|
439
|
-
* });
|
|
440
|
-
*
|
|
441
|
-
* await client.initCommands();
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
declare class Client extends Client$1 {
|
|
445
|
-
readonly handler: StoatxHandler;
|
|
446
|
-
constructor(options: Omit<StoatxHandlerOptions, "client">);
|
|
447
|
-
/**
|
|
448
|
-
* Initialize the StoatxHandler commands
|
|
449
|
-
*/
|
|
450
|
-
initCommands(): Promise<void>;
|
|
451
|
-
}
|
|
452
137
|
/**
|
|
453
138
|
* StoatxHandler - The execution engine for commands
|
|
454
139
|
*
|
|
@@ -482,7 +167,7 @@ declare class StoatxHandler {
|
|
|
482
167
|
channelId: string;
|
|
483
168
|
serverId?: string | undefined;
|
|
484
169
|
reply: (content: string) => Promise<Message>;
|
|
485
|
-
}): Promise<CommandContext | null>;
|
|
170
|
+
}): Promise<CommandContext<Client> | null>;
|
|
486
171
|
/**
|
|
487
172
|
* Handle a message object using the configured message adapter
|
|
488
173
|
*
|
|
@@ -520,7 +205,7 @@ declare class StoatxHandler {
|
|
|
520
205
|
/**
|
|
521
206
|
* Execute a command with the given context
|
|
522
207
|
*/
|
|
523
|
-
execute(ctx: CommandContext): Promise<boolean>;
|
|
208
|
+
execute(ctx: CommandContext<Client>): Promise<boolean>;
|
|
524
209
|
/**
|
|
525
210
|
* Get the command registry
|
|
526
211
|
*/
|
|
@@ -555,4 +240,318 @@ declare class StoatxHandler {
|
|
|
555
240
|
private resolvePrefix;
|
|
556
241
|
}
|
|
557
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Client - An extended Client that integrates StoatxHandler directly
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { Client } from 'stoatx';
|
|
249
|
+
*
|
|
250
|
+
* const client = new Client({
|
|
251
|
+
* prefix: '!',
|
|
252
|
+
* owners: ['owner-user-id'],
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
255
|
+
* await client.initCommands();
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare class Client extends Client$1 {
|
|
259
|
+
readonly handler: StoatxHandler;
|
|
260
|
+
constructor(options: Omit<StoatxHandlerOptions, "client">);
|
|
261
|
+
initCommands(): Promise<void>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Simple command options passed to @SimpleCommand decorator
|
|
266
|
+
* Used with @Stoat() decorated classes for method-based commands
|
|
267
|
+
*/
|
|
268
|
+
interface SimpleCommandOptions {
|
|
269
|
+
/** Command name (defaults to method name) */
|
|
270
|
+
name?: string;
|
|
271
|
+
/** Command description */
|
|
272
|
+
description?: string;
|
|
273
|
+
/** Command aliases */
|
|
274
|
+
aliases?: string[];
|
|
275
|
+
/** Required permissions to run the command */
|
|
276
|
+
permissions?: PermissionResolvable[];
|
|
277
|
+
/** Command category (auto-detected from directory if not provided) */
|
|
278
|
+
category?: string;
|
|
279
|
+
/** Cooldown in milliseconds */
|
|
280
|
+
cooldown?: number;
|
|
281
|
+
/** Storage strategy or identifier for cooldowns (e.g. "memory", "database") */
|
|
282
|
+
cooldownStorage?: string;
|
|
283
|
+
/** Whether the command is NSFW only */
|
|
284
|
+
nsfw?: boolean;
|
|
285
|
+
/** Whether the command is owner only */
|
|
286
|
+
ownerOnly?: boolean;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Resolved command metadata with required fields
|
|
290
|
+
*/
|
|
291
|
+
interface CommandMetadata {
|
|
292
|
+
name: string;
|
|
293
|
+
description: string;
|
|
294
|
+
aliases: string[];
|
|
295
|
+
permissions: PermissionResolvable[];
|
|
296
|
+
category: string;
|
|
297
|
+
cooldown: number;
|
|
298
|
+
cooldownStorage?: string;
|
|
299
|
+
nsfw: boolean;
|
|
300
|
+
ownerOnly: boolean;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Command execution context
|
|
304
|
+
*/
|
|
305
|
+
interface CommandContext<TClient extends Client$1 = Client> {
|
|
306
|
+
/** The client instance */
|
|
307
|
+
client: TClient;
|
|
308
|
+
/** The raw message content */
|
|
309
|
+
content: string;
|
|
310
|
+
/** The author ID */
|
|
311
|
+
authorId: string;
|
|
312
|
+
/** The channel ID */
|
|
313
|
+
channelId: string;
|
|
314
|
+
/** The server/guild ID (if applicable) */
|
|
315
|
+
serverId?: string | undefined;
|
|
316
|
+
/** Parsed command arguments */
|
|
317
|
+
args: string[];
|
|
318
|
+
/** The prefix used */
|
|
319
|
+
prefix: string;
|
|
320
|
+
/** The command name used (could be an alias) */
|
|
321
|
+
commandName: string;
|
|
322
|
+
/** Reply to the message */
|
|
323
|
+
reply: (content: string) => Promise<Message>;
|
|
324
|
+
/** The original message object (platform-specific) */
|
|
325
|
+
message: Message;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Optional lifecycle hooks for @Stoat() class instances
|
|
329
|
+
*/
|
|
330
|
+
interface StoatLifecycle {
|
|
331
|
+
/** Optional: Called when an error occurs during command execution */
|
|
332
|
+
onError?(ctx: CommandContext<Client>, error: Error): Promise<void> | void;
|
|
333
|
+
/** Optional: Called when a cooldown is active */
|
|
334
|
+
onCooldown?(ctx: CommandContext<Client>, remaining: number): Promise<void> | void;
|
|
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) */
|
|
338
|
+
[method: string]: any;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Cooldown manager interface for custom cooldown storage (e.g., database)
|
|
342
|
+
*/
|
|
343
|
+
interface CooldownManager {
|
|
344
|
+
check(ctx: CommandContext<any>, metadata: CommandMetadata): boolean | Promise<boolean>;
|
|
345
|
+
getRemaining(ctx: CommandContext<any>, metadata: CommandMetadata): number | Promise<number>;
|
|
346
|
+
set(ctx: CommandContext<any>, metadata: CommandMetadata): void | Promise<void>;
|
|
347
|
+
clear?(): void | Promise<void>;
|
|
348
|
+
}
|
|
349
|
+
interface StoatxGuard {
|
|
350
|
+
run(ctx: CommandContext<Client>): Promise<boolean> | boolean;
|
|
351
|
+
guardFail?(ctx: CommandContext<Client>): Promise<void> | void;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Discovery options for automatic command module loading
|
|
355
|
+
*/
|
|
356
|
+
interface StoatxDiscoveryOptions {
|
|
357
|
+
/** Root directories to scan (default: [process.cwd()]) */
|
|
358
|
+
roots?: string[];
|
|
359
|
+
/** Glob patterns relative to each root */
|
|
360
|
+
include?: string[];
|
|
361
|
+
/** Additional ignore patterns */
|
|
362
|
+
ignore?: string[];
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Handler options
|
|
366
|
+
*/
|
|
367
|
+
interface StoatxHandlerOptions {
|
|
368
|
+
/** The client instance */
|
|
369
|
+
client: Client;
|
|
370
|
+
/** Directory to scan for command modules (absolute path) */
|
|
371
|
+
commandsDir?: string;
|
|
372
|
+
/** Auto-discovery options used when commandsDir is not provided */
|
|
373
|
+
discovery?: StoatxDiscoveryOptions;
|
|
374
|
+
/** Command prefix or prefix resolver function */
|
|
375
|
+
prefix: string | ((ctx: {
|
|
376
|
+
serverId?: string | undefined;
|
|
377
|
+
}) => string | Promise<string>);
|
|
378
|
+
/** Owner IDs for owner-only commands */
|
|
379
|
+
owners?: string[];
|
|
380
|
+
/** File extensions to load (default: ['.js', '.mjs', '.cjs']) */
|
|
381
|
+
extensions?: string[];
|
|
382
|
+
/** Disable mention prefix support (default: false) */
|
|
383
|
+
disableMentionPrefix?: boolean;
|
|
384
|
+
/** Custom cooldown manager */
|
|
385
|
+
cooldownManager?: CooldownManager;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @Stoat
|
|
390
|
+
* Marks a class as a Stoat command container.
|
|
391
|
+
* Use this decorator on classes that contain @SimpleCommand methods.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* import { Stoat, SimpleCommand, CommandContext } from 'stoatx';
|
|
396
|
+
*
|
|
397
|
+
* @Stoat()
|
|
398
|
+
* class ModerationCommands {
|
|
399
|
+
* @SimpleCommand({ name: 'ban', description: 'Ban a user' })
|
|
400
|
+
* async ban(ctx: CommandContext) {
|
|
401
|
+
* await ctx.reply('User banned!');
|
|
402
|
+
* }
|
|
403
|
+
*
|
|
404
|
+
* @SimpleCommand({ name: 'kick', description: 'Kick a user' })
|
|
405
|
+
* async kick(ctx: CommandContext) {
|
|
406
|
+
* await ctx.reply('User kicked!');
|
|
407
|
+
* }
|
|
408
|
+
* }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
declare function Stoat(): ClassDecorator;
|
|
412
|
+
/**
|
|
413
|
+
* Check if a class is decorated with @Stoat
|
|
414
|
+
*/
|
|
415
|
+
declare function isStoatClass(target: Function): boolean;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Stored simple command metadata from method decorator
|
|
419
|
+
*/
|
|
420
|
+
interface SimpleCommandDefinition {
|
|
421
|
+
methodName: string;
|
|
422
|
+
options: SimpleCommandOptions;
|
|
423
|
+
}
|
|
424
|
+
type CommandMethod = (ctx: CommandContext<Client>) => Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* @SimpleCommand
|
|
427
|
+
* Marks a method as a simple command within a @Stoat() decorated class.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* @Stoat()
|
|
432
|
+
* class Example {
|
|
433
|
+
* @SimpleCommand({ name: 'ping', description: 'Replies with Pong!' })
|
|
434
|
+
* async ping(ctx: CommandContext) {
|
|
435
|
+
* await ctx.reply('Pong!');
|
|
436
|
+
* }
|
|
437
|
+
*
|
|
438
|
+
* @SimpleCommand({ aliases: ['perm'], name: 'permission' })
|
|
439
|
+
* async permission(ctx: CommandContext) {
|
|
440
|
+
* await ctx.reply('Access granted');
|
|
441
|
+
* }
|
|
442
|
+
* }
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
declare function SimpleCommand(options?: SimpleCommandOptions): <T extends CommandMethod>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
|
|
446
|
+
/**
|
|
447
|
+
* Get all simple command definitions from a @Stoat class
|
|
448
|
+
*/
|
|
449
|
+
declare function getSimpleCommands(target: Function): SimpleCommandDefinition[];
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @Guard
|
|
453
|
+
* Runs before a command to check if it should execute.
|
|
454
|
+
* Should return true to allow execution, false to block.
|
|
455
|
+
* Applied on @Stoat classes to guard all contained @SimpleCommand methods.
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* import { Guard, Stoat, SimpleCommand, CommandContext } from 'stoatx';
|
|
460
|
+
*
|
|
461
|
+
* // Define a guard
|
|
462
|
+
* class NotBot implements StoatxGuard {
|
|
463
|
+
* run(ctx: CommandContext): boolean {
|
|
464
|
+
* return !ctx.message.author.bot;
|
|
465
|
+
* }
|
|
466
|
+
*
|
|
467
|
+
* guardFail(ctx: CommandContext): void {
|
|
468
|
+
* ctx.reply("Bots cannot use this command!");
|
|
469
|
+
* }
|
|
470
|
+
* }
|
|
471
|
+
*
|
|
472
|
+
* @Stoat()
|
|
473
|
+
* @Guard(NotBot)
|
|
474
|
+
* class AdminCommands {
|
|
475
|
+
* @SimpleCommand({ name: 'admin', description: 'Admin only command' })
|
|
476
|
+
* async admin(ctx: CommandContext) {
|
|
477
|
+
* ctx.reply("You passed the guard check!");
|
|
478
|
+
* }
|
|
479
|
+
* }
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
declare function Guard(guardClass: Function): ClassDecorator;
|
|
483
|
+
/**
|
|
484
|
+
* Get all guards from a decorated class
|
|
485
|
+
*/
|
|
486
|
+
declare function getGuards(target: Function): Function[];
|
|
487
|
+
|
|
488
|
+
interface EventDefinition {
|
|
489
|
+
methodName: string;
|
|
490
|
+
event: string;
|
|
491
|
+
type: "on" | "once";
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* @On
|
|
495
|
+
* Triggered on every occurrence of the event.
|
|
496
|
+
* Marks a method to be executed whenever the specified client event is emitted.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* import { Stoat, On } from 'stoatx';
|
|
501
|
+
* import { Message, Client } from 'stoat.js';
|
|
502
|
+
*
|
|
503
|
+
* @Stoat()
|
|
504
|
+
* class BotEvents {
|
|
505
|
+
* @On('messageCreate')
|
|
506
|
+
* async onMessage(message: Message, client: Client) {
|
|
507
|
+
* console.log('New message received:', message.content);
|
|
508
|
+
* }
|
|
509
|
+
* }
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* @param event The name of the client event to listen to
|
|
513
|
+
*/
|
|
514
|
+
declare function On(event: string): MethodDecorator;
|
|
515
|
+
/**
|
|
516
|
+
* @Once
|
|
517
|
+
* Triggered only fully once.
|
|
518
|
+
* Marks a method to be executed only the FIRST time the specified client event is emitted.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* import { Stoat, Once } from 'stoatx';
|
|
523
|
+
* import { Client } from 'stoat.js';
|
|
524
|
+
*
|
|
525
|
+
* @Stoat()
|
|
526
|
+
* class BotEvents {
|
|
527
|
+
* @Once('ready')
|
|
528
|
+
* async onReady(client: Client) {
|
|
529
|
+
* console.log('Bot successfully started and logged in!');
|
|
530
|
+
* }
|
|
531
|
+
* }
|
|
532
|
+
* ```
|
|
533
|
+
*
|
|
534
|
+
* @param event The name of the client event to listen to
|
|
535
|
+
*/
|
|
536
|
+
declare function Once(event: string): MethodDecorator;
|
|
537
|
+
/**
|
|
538
|
+
* Get all event definitions from a @Stoat class
|
|
539
|
+
*/
|
|
540
|
+
declare function getEventsMetadata(target: Function): EventDefinition[];
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Build CommandMetadata from SimpleCommandOptions
|
|
544
|
+
*/
|
|
545
|
+
declare function buildSimpleCommandMetadata(options: SimpleCommandOptions, methodName: string, category?: string): CommandMetadata;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Metadata keys used by decorators
|
|
549
|
+
*/
|
|
550
|
+
declare const METADATA_KEYS: {
|
|
551
|
+
readonly IS_STOAT_CLASS: symbol;
|
|
552
|
+
readonly SIMPLE_COMMANDS: symbol;
|
|
553
|
+
readonly GUARDS: "stoatx:command:guards";
|
|
554
|
+
readonly EVENTS: symbol;
|
|
555
|
+
};
|
|
556
|
+
|
|
558
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 };
|