stoatx 0.2.0 → 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stoatx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -35,41 +35,33 @@ Make sure to enable decorators in your `tsconfig.json`:
35
35
 
36
36
  ```typescript
37
37
  // index.ts
38
- import 'reflect-metadata';
39
- import { Client } from 'stoat.js';
40
- import { MallyHandler } from 'stoatx';
38
+ import "reflect-metadata";
39
+ import { Client } from "stoatx";
41
40
 
42
- const client = new Client();
43
-
44
- const handler = new MallyHandler({
45
- client,
46
- prefix: '!',
47
- owners: ['your-user-id']
41
+ const client = new Client({
42
+ prefix: "!",
43
+ owners: ["your-user-id"],
48
44
  });
49
45
 
50
- await handler.init();
51
-
52
- client.on('messageCreate', (message) => {
53
- handler.handleMessage(message);
54
- });
46
+ await client.initCommands();
55
47
 
56
- client.login('your-token');
48
+ client.login("your-token");
57
49
  ```
58
50
 
59
51
  ### 2. Create commands
60
52
 
61
53
  ```typescript
62
54
  // commands/general.ts
63
- import { Stoat, SimpleCommand, Context } from 'stoatx';
55
+ import { Stoat, SimpleCommand, Context } from "stoatx";
64
56
 
65
57
  @Stoat()
66
58
  export class GeneralCommands {
67
- @SimpleCommand({ name: 'ping', description: 'Check bot latency' })
59
+ @SimpleCommand({ name: "ping", description: "Check bot latency" })
68
60
  async ping(ctx: Context) {
69
61
  await ctx.reply(`Pong! 🏓`);
70
62
  }
71
63
 
72
- @SimpleCommand({ name: 'hello', aliases: ['hi', 'hey'] })
64
+ @SimpleCommand({ name: "hello", aliases: ["hi", "hey"] })
73
65
  async hello(ctx: Context) {
74
66
  await ctx.reply(`Hello, <@${ctx.authorId}>!`);
75
67
  }
@@ -115,25 +107,25 @@ async ban(ctx: Context) {
115
107
  Adds a guard check before command execution.
116
108
 
117
109
  ```typescript
118
- import { Stoat, SimpleCommand, Guard, MallyGuard, Context } from 'stoatx';
110
+ import { Stoat, SimpleCommand, Guard, MallyGuard, Context } from "stoatx";
119
111
 
120
112
  // Define a guard
121
113
  class IsAdmin implements MallyGuard {
122
114
  run(ctx: Context): boolean {
123
- return ctx.message.member?.hasPermission('Administrator') ?? false;
115
+ return ctx.message.member?.hasPermission("Administrator") ?? false;
124
116
  }
125
117
 
126
118
  guardFail(ctx: Context): void {
127
- ctx.reply('You need Administrator permission!');
119
+ ctx.reply("You need Administrator permission!");
128
120
  }
129
121
  }
130
122
 
131
123
  @Stoat()
132
124
  @Guard(IsAdmin)
133
125
  export class AdminCommands {
134
- @SimpleCommand({ name: 'shutdown' })
126
+ @SimpleCommand({ name: "shutdown" })
135
127
  async shutdown(ctx: Context) {
136
- await ctx.reply('Shutting down...');
128
+ await ctx.reply("Shutting down...");
137
129
  }
138
130
  }
139
131
  ```
@@ -144,16 +136,16 @@ The `Context` object provides:
144
136
 
145
137
  ```typescript
146
138
  interface Context {
147
- client: Client; // Stoat client instance
148
- message: Message; // Original message
149
- content: string; // Raw message content
150
- authorId: string; // Author's user ID
151
- channelId: string; // Channel ID
152
- serverId?: string; // Server/Guild ID
153
- args: string[]; // Parsed arguments
154
- prefix: string; // Prefix used
155
- commandName: string; // Command name used
156
-
139
+ client: Client; // Stoat client instance
140
+ message: Message; // Original message
141
+ content: string; // Raw message content
142
+ authorId: string; // Author's user ID
143
+ channelId: string; // Channel ID
144
+ serverId?: string; // Server/Guild ID
145
+ args: string[]; // Parsed arguments
146
+ prefix: string; // Prefix used
147
+ commandName: string; // Command name used
148
+
157
149
  reply(content: string): Promise<void>;
158
150
  }
159
151
  ```
@@ -161,17 +153,17 @@ interface Context {
161
153
  ## Handler Options
162
154
 
163
155
  ```typescript
164
- interface MallyHandlerOptions {
156
+ interface StoatxHandlerOptions {
165
157
  client: Client;
166
- commandsDir?: string; // Legacy mode: explicitly scan this directory
158
+ commandsDir?: string; // Legacy mode: explicitly scan this directory
167
159
  discovery?: {
168
- roots?: string[]; // Default: [process.cwd()]
169
- include?: string[]; // Glob patterns per root
170
- ignore?: string[]; // Additional ignore globs
160
+ roots?: string[]; // Default: [process.cwd()]
161
+ include?: string[]; // Glob patterns per root
162
+ ignore?: string[]; // Additional ignore globs
171
163
  };
172
- prefix: string | ((ctx: { serverId?: string }) => string | Promise<string>);
173
- owners?: string[]; // Owner user IDs
174
- extensions?: string[]; // File extensions (default: ['.js', '.mjs', '.cjs'])
164
+ prefix: string ((ctx: { serverId?: string }) => string Promise<string>);
165
+ owners?: string[]; // Owner user IDs
166
+ extensions?: string[]; // File extensions (default: ['.js', '.mjs', '.cjs'])
175
167
  disableMentionPrefix?: boolean; // Disable @bot prefix
176
168
  }
177
169
 
@@ -182,31 +174,28 @@ interface MallyHandlerOptions {
182
174
  ## Dynamic Prefix
183
175
 
184
176
  ```typescript
185
- const handler = new MallyHandler({
186
- client,
177
+ const client = new Client({
187
178
  prefix: async ({ serverId }) => {
188
179
  // Fetch from database, etc.
189
- return serverId ? await getServerPrefix(serverId) : '!';
180
+ return serverId ? await getServerPrefix(serverId) : "!";
190
181
  },
191
182
  });
192
183
 
193
184
  // Optional: constrain auto-discovery to specific roots/patterns
194
- const scopedHandler = new MallyHandler({
195
- client,
196
- prefix: '!',
185
+ const scopedClient = new Client({
186
+ prefix: "!",
197
187
  discovery: {
198
188
  roots: [process.cwd()],
199
- include: ['apps/bot/dist/commands/**/*.js'],
189
+ include: ["apps/bot/dist/commands/**/*.js"],
200
190
  },
201
191
  });
202
192
 
203
193
  // TypeScript source discovery is opt-in and requires a TS runtime loader (tsx/ts-node)
204
- const tsRuntimeHandler = new MallyHandler({
205
- client,
206
- prefix: '!',
207
- extensions: ['.ts'],
194
+ const tsRuntimeClient = new Client({
195
+ prefix: "!",
196
+ extensions: [".ts"],
208
197
  discovery: {
209
- include: ['apps/bot/src/commands/**/*.ts'],
198
+ include: ["apps/bot/src/commands/**/*.ts"],
210
199
  },
211
200
  });
212
201
  ```
@@ -216,6 +205,3 @@ All commands are defined through `@Stoat()` classes and `@SimpleCommand()` metho
216
205
  ## License
217
206
 
218
207
  AGPL-3.0-or-later
219
-
220
-
221
-