stonyx 0.2.3-alpha.3 → 0.2.3-alpha.5

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.
@@ -0,0 +1,62 @@
1
+ # Discord Conventions
2
+
3
+ Conventions for projects using `@stonyx/discord`.
4
+
5
+ ## Command Files
6
+
7
+ - One class per file in the configured command directory (default: `discord-commands/`)
8
+ - Each file default-exports a class extending `Command` from `@stonyx/discord`
9
+ - Class must define a `data` property (a `SlashCommandBuilder` instance) and an `async execute(interaction)` method
10
+ - Class ordering: static properties → `data` → `execute()`
11
+ - Filenames use kebab-case; `forEachFileImport` converts to camelCase for internal registration
12
+ - Permission checks belong in the consuming application, not in the module
13
+
14
+ ```js
15
+ import { Command } from '@stonyx/discord';
16
+ import { SlashCommandBuilder } from 'discord.js';
17
+
18
+ export default class PingCommand extends Command {
19
+ data = new SlashCommandBuilder()
20
+ .setName('ping')
21
+ .setDescription('Replies with Pong!');
22
+
23
+ async execute(interaction) {
24
+ await interaction.reply('Pong!');
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## Event Handler Files
30
+
31
+ - One class per file in the configured event directory (default: `discord-events/`)
32
+ - Each file default-exports a class extending `EventHandler` from `@stonyx/discord`
33
+ - Class must set `static event` to a valid Discord.js event name (e.g., `'messageCreate'`, `'voiceStateUpdate'`)
34
+ - Class must implement a `handle(...args)` method matching the Discord.js event signature
35
+ - Class ordering: static properties → `handle()`
36
+
37
+ ```js
38
+ import { EventHandler } from '@stonyx/discord';
39
+
40
+ export default class WelcomeHandler extends EventHandler {
41
+ static event = 'guildMemberAdd';
42
+
43
+ handle(member) {
44
+ // Welcome new member
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ - Config namespace: `config.discord`
52
+ - Environment variables prefixed with `DISCORD_`
53
+ - Logging: `log.discord()` — configured via `logColor: '#7289da'` and `logMethod: 'discord'`
54
+ - Intent auto-derivation: the module computes required gateway intents from discovered event handlers; use `additionalIntents` in config for edge cases
55
+
56
+ ## Module Keywords
57
+
58
+ ```json
59
+ "keywords": ["stonyx-async", "stonyx-module"]
60
+ ```
61
+
62
+ `stonyx-async` indicates the module's `init()` is async and must be awaited by the framework.
@@ -103,6 +103,12 @@ WebSocket handlers. Class ordering: static properties → `server()` method →
103
103
 
104
104
  Exports: `SocketServer`, `SocketClient`, `Handler`, `Sockets`
105
105
 
106
+ ## `@stonyx/discord`
107
+
108
+ Discord bot with command and event handler auto-discovery. Class ordering: static properties → `data` / `static event` → `execute()` / `handle()`.
109
+
110
+ Exports: `DiscordBot`, `Command`, `EventHandler`, `Discord`, `chunkMessage`
111
+
106
112
  ## `@stonyx/oauth`
107
113
 
108
114
  OAuth providers. Class ordering: constructor with `super()` → async methods → transform methods.
@@ -20,4 +20,5 @@ Universal rules that apply to every Stonyx project. Section-specific conventions
20
20
  - [Framework Modules](./framework-modules.md) — when to use which `@stonyx/*` module
21
21
  - [ORM Conventions](./orm-conventions.md) — models, serializers, access control, transforms, hooks
22
22
  - [REST Conventions](./rest-conventions.md) — REST server request classes and handlers
23
+ - [Discord Conventions](./discord-conventions.md) — Discord bot commands and event handlers
23
24
  - [Testing Conventions](./testing-conventions.md) — test organization, patterns, and tooling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stonyx",
3
- "version": "0.2.3-alpha.3",
3
+ "version": "0.2.3-alpha.5",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "main.js",
6
6
  "type": "module",
@@ -1,4 +1,8 @@
1
- import { copyFile, createDirectory } from '@stonyx/utils/file';
1
+ // Skip postinstall for global installations
2
+ const isGlobal = !process.env.INIT_CWD || process.env.npm_config_global === 'true';
3
+ if (isGlobal) process.exit(0);
4
+
5
+ const { copyFile, createDirectory } = await import('@stonyx/utils/file');
2
6
 
3
7
  const projectDir = process.env.INIT_CWD;
4
8
  const configDir = `${projectDir}/config`;
package/src/cli/new.js CHANGED
@@ -33,6 +33,11 @@ const MODULE_OPTIONS = [
33
33
  {
34
34
  question: 'Will this project need pub/sub events?',
35
35
  package: '@stonyx/events'
36
+ },
37
+ {
38
+ question: 'Will this project need a Discord bot?',
39
+ package: '@stonyx/discord',
40
+ dirs: ['discord-commands', 'discord-events']
36
41
  }
37
42
  ];
38
43