@stonyx/discord 0.1.1-alpha.10 → 0.1.1-alpha.12
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 +2 -9
- package/dist/bot.js +13 -12
- package/dist/main.js +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -68,20 +68,13 @@ export default class MessageCreateHandler extends EventHandler {
|
|
|
68
68
|
|
|
69
69
|
### 4. Start the bot
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Stonyx auto-initializes the bot when your app boots — no manual wiring needed:
|
|
72
72
|
|
|
73
73
|
```bash
|
|
74
74
|
stonyx serve
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```javascript
|
|
80
|
-
import { DiscordBot } from '@stonyx/discord';
|
|
81
|
-
|
|
82
|
-
const bot = new DiscordBot();
|
|
83
|
-
await bot.init();
|
|
84
|
-
```
|
|
77
|
+
`Discord.init()` (called by the Stonyx module loader) awaits `new DiscordBot().init()`, which discovers commands/events, derives intents, and connects to the gateway. The lazy-init guards still apply: if `DISCORD_TOKEN` is unset or no commands/events exist, the bot skips login.
|
|
85
78
|
|
|
86
79
|
## Command Architecture
|
|
87
80
|
|
package/dist/bot.js
CHANGED
|
@@ -17,20 +17,21 @@ export default class DiscordBot {
|
|
|
17
17
|
DiscordBot.instance = this;
|
|
18
18
|
}
|
|
19
19
|
async init() {
|
|
20
|
+
if (this.client) {
|
|
21
|
+
// Already initialized — singleton reuse via Discord.init() or a direct
|
|
22
|
+
// new DiscordBot().init() call. Wait for the existing ready promise
|
|
23
|
+
// rather than re-running discovery + login.
|
|
24
|
+
await this.ready;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
20
27
|
const { token } = config.discord;
|
|
21
28
|
if (!token) {
|
|
22
|
-
log.discord('No DISCORD_TOKEN configured — bot will not start');
|
|
29
|
+
log.discord?.('No DISCORD_TOKEN configured — bot will not start');
|
|
23
30
|
this.resolveReady();
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
26
33
|
await this.discoverCommands();
|
|
27
34
|
await this.discoverEvents();
|
|
28
|
-
const hasWork = Object.keys(this.commands).length > 0 || this.eventHandlers.length > 0;
|
|
29
|
-
if (!hasWork) {
|
|
30
|
-
log.discord('No discord commands or event handlers found — skipping bot initialization');
|
|
31
|
-
this.resolveReady();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
35
|
const intents = deriveIntents(this.eventHandlers, config.discord.additionalIntents);
|
|
35
36
|
const partials = derivePartials(intents, config.discord.additionalPartials);
|
|
36
37
|
if (Object.keys(this.commands).length > 0) {
|
|
@@ -47,7 +48,7 @@ export default class DiscordBot {
|
|
|
47
48
|
return;
|
|
48
49
|
client.on('ready', () => {
|
|
49
50
|
this.resolveReady();
|
|
50
|
-
log.discord('Discord Bot is Ready!');
|
|
51
|
+
log.discord?.('Discord Bot is Ready!');
|
|
51
52
|
});
|
|
52
53
|
client.on('interactionCreate', async (interaction) => {
|
|
53
54
|
if (!interaction.isChatInputCommand())
|
|
@@ -87,12 +88,12 @@ export default class DiscordBot {
|
|
|
87
88
|
const CommandClass = CommandClassUntyped;
|
|
88
89
|
const instance = new CommandClass();
|
|
89
90
|
if (!instance.data || typeof instance.execute !== 'function') {
|
|
90
|
-
log.discord(`Command "${name}" is missing data or execute — skipping`);
|
|
91
|
+
log.discord?.(`Command "${name}" is missing data or execute — skipping`);
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
94
|
instance._bot = this;
|
|
94
95
|
this.commands[instance.data.name] = instance;
|
|
95
|
-
log.discord(`Loaded command: /${instance.data.name}`);
|
|
96
|
+
log.discord?.(`Loaded command: /${instance.data.name}`);
|
|
96
97
|
}, { ignoreAccessFailure: true });
|
|
97
98
|
}
|
|
98
99
|
async discoverEvents() {
|
|
@@ -102,13 +103,13 @@ export default class DiscordBot {
|
|
|
102
103
|
await forEachFileImport(eventDir, (EventHandlerClassUntyped, { name }) => {
|
|
103
104
|
const EventHandlerClass = EventHandlerClassUntyped;
|
|
104
105
|
if (!EventHandlerClass.event) {
|
|
105
|
-
log.discord(`Event handler "${name}" is missing static event property — skipping`);
|
|
106
|
+
log.discord?.(`Event handler "${name}" is missing static event property — skipping`);
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
const instance = new EventHandlerClass();
|
|
109
110
|
instance._bot = this;
|
|
110
111
|
this.eventHandlers.push(instance);
|
|
111
|
-
log.discord(`Loaded event handler: ${EventHandlerClass.event} (${name})`);
|
|
112
|
+
log.discord?.(`Loaded event handler: ${EventHandlerClass.event} (${name})`);
|
|
112
113
|
}, { ignoreAccessFailure: true });
|
|
113
114
|
}
|
|
114
115
|
async sendMessage(content, channelId, imagePath = null) {
|
package/dist/main.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import DiscordBot from './bot.js';
|
|
1
2
|
export default class Discord {
|
|
2
3
|
static instance;
|
|
3
4
|
constructor() {
|
|
@@ -6,8 +7,7 @@ export default class Discord {
|
|
|
6
7
|
Discord.instance = this;
|
|
7
8
|
}
|
|
8
9
|
async init() {
|
|
9
|
-
|
|
10
|
-
// This entry point satisfies Stonyx module auto-initialization
|
|
10
|
+
await new DiscordBot().init();
|
|
11
11
|
}
|
|
12
12
|
reset() {
|
|
13
13
|
Discord.instance = null;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"stonyx-async",
|
|
5
5
|
"stonyx-module"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.1.1-alpha.
|
|
7
|
+
"version": "0.1.1-alpha.12",
|
|
8
8
|
"description": "Discord bot module for the Stonyx framework",
|
|
9
9
|
"main": "dist/main.js",
|
|
10
10
|
"types": "dist/main.d.ts",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"stonyx": ">=0.2.3-beta.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@stonyx/utils": "0.2.3-beta.
|
|
67
|
+
"@stonyx/utils": "0.2.3-beta.23",
|
|
68
68
|
"@types/node": "^25.5.2",
|
|
69
69
|
"@types/qunit": "^2.19.13",
|
|
70
70
|
"@types/sinon": "^21.0.1",
|
|
71
71
|
"qunit": "^2.24.1",
|
|
72
72
|
"sinon": "^21.0.0",
|
|
73
|
-
"stonyx": "0.2.3-beta.
|
|
73
|
+
"stonyx": "0.2.3-beta.62",
|
|
74
74
|
"tsx": "^4.21.0",
|
|
75
75
|
"typescript": "^5.8.3"
|
|
76
76
|
},
|