@stonyx/discord 0.1.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/src/main.js ADDED
@@ -0,0 +1,20 @@
1
+ export { default as DiscordBot } from './bot.js';
2
+ export { default as Command } from './command.js';
3
+ export { default as EventHandler } from './event-handler.js';
4
+ export { chunkMessage } from './message.js';
5
+
6
+ export default class Discord {
7
+ constructor() {
8
+ if (Discord.instance) return Discord.instance;
9
+ Discord.instance = this;
10
+ }
11
+
12
+ async init() {
13
+ // Bot initialization is deferred to DiscordBot.init()
14
+ // This entry point satisfies Stonyx module auto-initialization
15
+ }
16
+
17
+ reset() {
18
+ Discord.instance = null;
19
+ }
20
+ }
package/src/message.js ADDED
@@ -0,0 +1,30 @@
1
+ const MAX_LENGTH = 2000;
2
+
3
+ function splitAtBoundary(text, max) {
4
+ if (text.length <= max) return [text, ''];
5
+
6
+ const region = text.slice(0, max);
7
+ const newlineIdx = region.lastIndexOf('\n');
8
+ if (newlineIdx > 0) return [text.slice(0, newlineIdx + 1), text.slice(newlineIdx + 1)];
9
+
10
+ const spaceIdx = region.lastIndexOf(' ');
11
+ if (spaceIdx > 0) return [text.slice(0, spaceIdx + 1), text.slice(spaceIdx + 1)];
12
+
13
+ return [text.slice(0, max), text.slice(max)];
14
+ }
15
+
16
+ export function chunkMessage(header, body) {
17
+ const chunks = [];
18
+ const firstChunkMax = MAX_LENGTH - header.length;
19
+
20
+ let [first, remaining] = splitAtBoundary(body, firstChunkMax);
21
+ chunks.push(header + first);
22
+
23
+ while (remaining.length > 0) {
24
+ let chunk;
25
+ [chunk, remaining] = splitAtBoundary(remaining, MAX_LENGTH);
26
+ chunks.push(chunk);
27
+ }
28
+
29
+ return chunks;
30
+ }