@mostfeatured/dbi 0.2.13 → 0.2.15

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.
Files changed (45) hide show
  1. package/dist/src/types/Components/HTMLComponentsV2/index.d.ts +33 -1
  2. package/dist/src/types/Components/HTMLComponentsV2/index.d.ts.map +1 -1
  3. package/dist/src/types/Components/HTMLComponentsV2/index.js +408 -82
  4. package/dist/src/types/Components/HTMLComponentsV2/index.js.map +1 -1
  5. package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts +52 -0
  6. package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts.map +1 -1
  7. package/dist/src/types/Components/HTMLComponentsV2/parser.js +275 -0
  8. package/dist/src/types/Components/HTMLComponentsV2/parser.js.map +1 -1
  9. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts +26 -0
  10. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts.map +1 -1
  11. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js +509 -34
  12. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js.map +1 -1
  13. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts +10 -0
  14. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts.map +1 -1
  15. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js +76 -11
  16. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js.map +1 -1
  17. package/dist/test/index.js +76 -3
  18. package/dist/test/index.js.map +1 -1
  19. package/docs/ADVANCED_FEATURES.md +4 -0
  20. package/docs/API_REFERENCE.md +4 -0
  21. package/docs/CHAT_INPUT.md +4 -0
  22. package/docs/COMPONENTS.md +4 -0
  23. package/docs/EVENTS.md +4 -0
  24. package/docs/GETTING_STARTED.md +4 -0
  25. package/docs/LOCALIZATION.md +4 -0
  26. package/docs/README.md +4 -0
  27. package/docs/SVELTE_COMPONENTS.md +162 -6
  28. package/docs/llm/ADVANCED_FEATURES.txt +521 -0
  29. package/docs/llm/API_REFERENCE.txt +659 -0
  30. package/docs/llm/CHAT_INPUT.txt +514 -0
  31. package/docs/llm/COMPONENTS.txt +595 -0
  32. package/docs/llm/EVENTS.txt +449 -0
  33. package/docs/llm/GETTING_STARTED.txt +296 -0
  34. package/docs/llm/LOCALIZATION.txt +501 -0
  35. package/docs/llm/README.txt +193 -0
  36. package/docs/llm/SVELTE_COMPONENTS.txt +566 -0
  37. package/generated/svelte-dbi.d.ts +122 -0
  38. package/package.json +1 -1
  39. package/src/types/Components/HTMLComponentsV2/index.ts +466 -94
  40. package/src/types/Components/HTMLComponentsV2/parser.ts +317 -0
  41. package/src/types/Components/HTMLComponentsV2/svelteParser.ts +567 -35
  42. package/src/types/Components/HTMLComponentsV2/svelteRenderer.ts +91 -13
  43. package/test/index.ts +76 -3
  44. package/test/product-showcase.svelte +380 -24
  45. package/llm.txt +0 -1088
@@ -0,0 +1,521 @@
1
+ ================================================================================
2
+ DBI - ADVANCED FEATURES - LLM REFERENCE DOCUMENT
3
+ ================================================================================
4
+
5
+ DOCUMENT TYPE: Advanced Features Reference
6
+ PACKAGE: @mostfeatured/dbi
7
+
8
+ ================================================================================
9
+ SECTION 1: MESSAGE COMMANDS
10
+ ================================================================================
11
+
12
+ DBI can convert slash commands to message-based commands automatically.
13
+
14
+ ENABLING MESSAGE COMMANDS:
15
+ --------------------------
16
+ const dbi = createDBI("my-bot", {
17
+ discord: {
18
+ token: process.env.DISCORD_TOKEN,
19
+ options: {
20
+ intents: ["Guilds", "GuildMessages", "MessageContent"]
21
+ }
22
+ },
23
+
24
+ messageCommands: {
25
+ prefixes: ["!", ".", "?"],
26
+
27
+ // Or dynamic prefixes:
28
+ // prefixes: async ({ message }) => {
29
+ // const guildPrefix = await getGuildPrefix(message.guild?.id);
30
+ // return [guildPrefix, "!"];
31
+ // },
32
+
33
+ typeAliases: {
34
+ booleans: {
35
+ "yes": true, "no": false,
36
+ "true": true, "false": false,
37
+ "on": true, "off": false,
38
+ "1": true, "0": false
39
+ }
40
+ }
41
+ },
42
+
43
+ defaults: {
44
+ messageCommands: {
45
+ deferReplyContent: "Processing..."
46
+ }
47
+ }
48
+ });
49
+
50
+ HOW IT WORKS:
51
+ -------------
52
+ !ping → /ping
53
+ !user info @John → /user info user:@John
54
+ !ban @User spam → /ban user:@User reason:spam
55
+
56
+ MESSAGE COMMAND ALIASES:
57
+ ------------------------
58
+ ChatInput({
59
+ name: "help",
60
+ description: "Show help",
61
+ other: {
62
+ messageCommand: {
63
+ aliases: ["h", "?", "commands", "cmds"],
64
+ ignore: false // Set true to disable message command
65
+ }
66
+ },
67
+ onExecute({ interaction }) {
68
+ interaction.reply("Help information...");
69
+ }
70
+ });
71
+
72
+ // Now works with: !help, !h, !?, !commands, !cmds
73
+
74
+ REST STRING ARGUMENTS:
75
+ ----------------------
76
+ ChatInput({
77
+ name: "say",
78
+ description: "Make the bot say something",
79
+ options: [
80
+ ChatInputOptions.string({
81
+ name: "message",
82
+ description: "The message",
83
+ required: true,
84
+ messageCommands: {
85
+ rest: true // Capture all remaining text
86
+ }
87
+ })
88
+ ],
89
+ onExecute({ interaction }) {
90
+ const message = interaction.options.getString("message");
91
+ interaction.reply(message);
92
+ }
93
+ });
94
+
95
+ // !say Hello world, how are you?
96
+ // message = "Hello world, how are you?"
97
+
98
+ ================================================================================
99
+ SECTION 2: REFERENCE SYSTEM
100
+ ================================================================================
101
+
102
+ Pass data through Discord's component custom IDs.
103
+
104
+ CUSTOM ID ENCODING:
105
+ -------------------
106
+ TYPE | ENCODING | EXAMPLE
107
+ ----------|---------------|---------------------------
108
+ String | Raw | "hello" → hello
109
+ Number | π prefix | 42 → π42
110
+ BigInt | ᙖ prefix | 12345n → ᙖ12345
111
+ Boolean | 𝞫 prefix | true → 𝞫1
112
+ undefined | 🗶u | undefined → 🗶u
113
+ null | 🗶n | null → 🗶n
114
+ Object | ¤ + ref ID | {...} → ¤abc123
115
+
116
+ USING REFERENCES:
117
+ -----------------
118
+ Button({
119
+ name: "action",
120
+ options: { style: Discord.ButtonStyle.Primary, label: "Action" },
121
+ onExecute({ interaction, data }) {
122
+ const [userId, action, metadata] = data;
123
+
124
+ console.log(`User: ${userId}`); // string
125
+ console.log(`Action: ${action}`); // string
126
+ console.log(`Metadata:`, metadata); // object (if was object)
127
+
128
+ if (metadata?.$ref) {
129
+ console.log(`Ref ID: ${metadata.$ref}`);
130
+ metadata.$unRef(); // Clean up when done
131
+ }
132
+
133
+ interaction.reply("Done!");
134
+ }
135
+ });
136
+
137
+ // Creating the button:
138
+ const button = dbi.interaction("action").toJSON({
139
+ reference: {
140
+ data: [
141
+ "123456789", // String - in custom ID
142
+ "approve", // String - in custom ID
143
+ { complex: "object", nested: {} } // Object - stored in memory
144
+ ],
145
+ ttl: 300000 // Optional: auto-expire in 5 minutes
146
+ }
147
+ });
148
+
149
+ REFERENCE CONFIGURATION:
150
+ ------------------------
151
+ const dbi = createDBI("my-bot", {
152
+ references: {
153
+ autoClear: {
154
+ ttl: 3600000, // Default TTL: 1 hour
155
+ check: 60000 // Check every minute
156
+ }
157
+ }
158
+ });
159
+
160
+ MANUAL REFERENCE MANAGEMENT:
161
+ ----------------------------
162
+ const refs = dbi.data.refs;
163
+
164
+ const ref = refs.get("refId");
165
+ console.log(ref.value); // Stored object
166
+ console.log(ref.at); // Timestamp
167
+ console.log(ref.ttl); // Time-to-live
168
+
169
+ refs.delete("refId");
170
+ refs.has("refId");
171
+
172
+ ================================================================================
173
+ SECTION 3: RATE LIMITING
174
+ ================================================================================
175
+
176
+ DECLARATIVE RATE LIMITS:
177
+ ------------------------
178
+ ChatInput({
179
+ name: "daily",
180
+ description: "Claim daily reward",
181
+ rateLimits: [
182
+ {
183
+ type: "User",
184
+ duration: 86400000 // 24 hours in ms
185
+ }
186
+ ],
187
+ onExecute({ interaction }) {
188
+ interaction.reply("Here's your daily reward!");
189
+ }
190
+ });
191
+
192
+ RATE LIMIT TYPES:
193
+ -----------------
194
+ TYPE | DESCRIPTION
195
+ --------|----------------------------------
196
+ User | Per-user across all servers
197
+ Channel | Per-channel
198
+ Guild | Per-server
199
+ Member | Per-member (user+guild combination)
200
+ Message | Per-message
201
+
202
+ DYNAMIC RATE LIMITS:
203
+ --------------------
204
+ async onExecute({ interaction, setRateLimit }) {
205
+ const isPremium = await checkPremium(interaction.user.id);
206
+
207
+ if (isPremium) {
208
+ await setRateLimit("User", 30000); // 30 seconds
209
+ } else {
210
+ await setRateLimit("User", 300000); // 5 minutes
211
+ }
212
+
213
+ interaction.reply("Done!");
214
+ }
215
+
216
+ ================================================================================
217
+ SECTION 4: MULTI-CLIENT SUPPORT
218
+ ================================================================================
219
+
220
+ Run multiple Discord clients simultaneously.
221
+
222
+ CONFIGURATION:
223
+ --------------
224
+ const dbi = createDBI("my-bot", {
225
+ discord: [
226
+ {
227
+ namespace: "main",
228
+ token: process.env.MAIN_BOT_TOKEN,
229
+ options: { intents: ["Guilds", "GuildMessages"] }
230
+ },
231
+ {
232
+ namespace: "music",
233
+ token: process.env.MUSIC_BOT_TOKEN,
234
+ options: { intents: ["Guilds", "GuildVoiceStates"] }
235
+ },
236
+ {
237
+ namespace: "moderation",
238
+ token: process.env.MOD_BOT_TOKEN,
239
+ options: { intents: ["Guilds", "GuildMembers", "GuildBans"] }
240
+ }
241
+ ]
242
+ });
243
+
244
+ ACCESSING CLIENTS:
245
+ ------------------
246
+ const defaultClient = dbi.client();
247
+ const musicClient = dbi.client("music");
248
+ const modClient = dbi.client("moderation");
249
+
250
+ const discordClient = musicClient.client;
251
+ console.log(discordClient.user.tag);
252
+
253
+ const allClients = dbi.data.clients;
254
+ const nextClient = dbi.data.clients.next();
255
+ const randomClient = dbi.data.clients.random();
256
+
257
+ PUBLISHING TO SPECIFIC CLIENTS:
258
+ -------------------------------
259
+ ChatInput({
260
+ name: "play",
261
+ description: "Play music",
262
+ publish: "music", // Only publish to music bot
263
+ onExecute({ interaction, clientNamespace }) {
264
+ console.log(`Handled by: ${clientNamespace}`);
265
+ }
266
+ });
267
+
268
+ EVENTS WITH MULTIPLE CLIENTS:
269
+ -----------------------------
270
+ Event({
271
+ name: "guildCreate",
272
+ id: "guild-logger",
273
+ triggerType: "OneByOneGlobal", // Default
274
+ // triggerType: "Random",
275
+ // triggerType: "First",
276
+ onExecute({ guild, nextClient }) {
277
+ console.log(`${nextClient.namespace} joined: ${guild.name}`);
278
+ }
279
+ });
280
+
281
+ ================================================================================
282
+ SECTION 5: SHARDING
283
+ ================================================================================
284
+
285
+ DEFAULT SHARDING:
286
+ -----------------
287
+ const dbi = createDBI("my-bot", {
288
+ sharding: "default",
289
+ discord: {
290
+ token: process.env.DISCORD_TOKEN,
291
+ options: { intents: ["Guilds"] }
292
+ }
293
+ });
294
+
295
+ HYBRID SHARDING (for large bots):
296
+ ---------------------------------
297
+ const dbi = createDBI("my-bot", {
298
+ sharding: "hybrid",
299
+ discord: {
300
+ token: process.env.DISCORD_TOKEN,
301
+ options: { intents: ["Guilds"] }
302
+ }
303
+ });
304
+
305
+ if (dbi.cluster) {
306
+ console.log(`Cluster ID: ${dbi.cluster.id}`);
307
+ console.log(`Shard IDs: ${dbi.cluster.shards}`);
308
+ }
309
+
310
+ SHARD MANAGER (separate file):
311
+ ------------------------------
312
+ const { ClusterManager } = require("discord-hybrid-sharding");
313
+
314
+ const manager = new ClusterManager("./bot.js", {
315
+ totalShards: "auto",
316
+ shardsPerClusters: 2,
317
+ token: process.env.DISCORD_TOKEN
318
+ });
319
+
320
+ manager.on("clusterCreate", cluster => {
321
+ console.log(`Launched cluster ${cluster.id}`);
322
+ });
323
+
324
+ manager.spawn();
325
+
326
+ ================================================================================
327
+ SECTION 6: HOT RELOADING
328
+ ================================================================================
329
+
330
+ USING onUnload:
331
+ ---------------
332
+ dbi.register(({ ChatInput, Event, onUnload }) => {
333
+ let interval;
334
+
335
+ Event({
336
+ name: "clientReady",
337
+ id: "stats-updater",
338
+ onExecute({ client }) {
339
+ interval = setInterval(() => updateStats(client), 60000);
340
+ }
341
+ });
342
+
343
+ onUnload(() => {
344
+ if (interval) clearInterval(interval);
345
+ console.log("Stats updater cleaned up");
346
+ });
347
+
348
+ ChatInput({
349
+ name: "reload-safe",
350
+ description: "Safe command",
351
+ onExecute({ interaction }) {
352
+ interaction.reply("Hello!");
353
+ }
354
+ });
355
+ });
356
+
357
+ RELOAD FLOW:
358
+ ------------
359
+ await dbi.unload();
360
+ Utils.recursiveUnload("./src");
361
+ await Utils.recursiveImport("./src");
362
+ await dbi.load();
363
+ console.log("Bot reloaded!");
364
+
365
+ UTILS FOR HOT RELOADING:
366
+ ------------------------
367
+ const { Utils } = require("@mostfeatured/dbi");
368
+
369
+ await Utils.recursiveImport("./src");
370
+ Utils.recursiveUnload("./src");
371
+ Utils.unloadModule("./src/commands/ping.js");
372
+
373
+ ================================================================================
374
+ SECTION 7: PERSISTENT STORE
375
+ ================================================================================
376
+
377
+ DEFAULT MEMORYSTORE:
378
+ --------------------
379
+ const { MemoryStore } = require("@mostfeatured/dbi");
380
+
381
+ const dbi = createDBI("my-bot", {
382
+ store: new MemoryStore() // Default - not persistent
383
+ });
384
+
385
+ CUSTOM STORE IMPLEMENTATION:
386
+ ----------------------------
387
+ class RedisStore {
388
+ constructor(redis) {
389
+ this.redis = redis;
390
+ }
391
+
392
+ async get(key, defaultValue) {
393
+ const value = await this.redis.get(key);
394
+ return value ? JSON.parse(value) : defaultValue;
395
+ }
396
+
397
+ async set(key, value) {
398
+ await this.redis.set(key, JSON.stringify(value));
399
+ }
400
+
401
+ async delete(key) {
402
+ await this.redis.del(key);
403
+ }
404
+
405
+ async has(key) {
406
+ return (await this.redis.exists(key)) === 1;
407
+ }
408
+ }
409
+
410
+ const dbi = createDBI("my-bot", {
411
+ store: new RedisStore(redisClient)
412
+ });
413
+
414
+ await dbi.config.store.set("key", { data: "value" });
415
+ const data = await dbi.config.store.get("key");
416
+
417
+ ================================================================================
418
+ SECTION 8: FLAG-BASED LOADING
419
+ ================================================================================
420
+
421
+ DEFINING FLAGS:
422
+ ---------------
423
+ dbi.register(({ ChatInput }) => {
424
+ // Always loaded
425
+ ChatInput({
426
+ name: "ping",
427
+ description: "Ping",
428
+ onExecute({ interaction }) {
429
+ interaction.reply("Pong!");
430
+ }
431
+ });
432
+
433
+ // Only loaded with 'debug' flag
434
+ ChatInput({
435
+ name: "debug-info",
436
+ description: "Debug information",
437
+ flag: "debug",
438
+ onExecute({ interaction }) {
439
+ interaction.reply("Debug info...");
440
+ }
441
+ });
442
+
443
+ // Only loaded with 'admin' flag
444
+ ChatInput({
445
+ name: "eval",
446
+ description: "Evaluate code",
447
+ flag: "admin",
448
+ onExecute({ interaction }) { /* Dangerous! */ }
449
+ });
450
+ });
451
+
452
+ LOADING WITH FLAGS:
453
+ -------------------
454
+ await dbi.load(); // Only non-flagged
455
+ await dbi.load("debug"); // With debug flag
456
+ await dbi.load("debug", "admin"); // With both flags
457
+ await dbi.load("all"); // Everything
458
+
459
+ ================================================================================
460
+ SECTION 9: DATA MANAGEMENT
461
+ ================================================================================
462
+
463
+ USING dbi.data.other:
464
+ ---------------------
465
+ dbi.set("config", { prefix: "!", language: "en" });
466
+ dbi.set("cache.users", new Map());
467
+
468
+ const config = dbi.get("config");
469
+ const cache = dbi.get("cache.users");
470
+
471
+ const settings = dbi.get("settings", { theme: "dark" }); // With default
472
+
473
+ if (dbi.has("config")) { /* ... */ }
474
+ dbi.delete("cache");
475
+
476
+ CONSTRUCTOR DATA:
477
+ -----------------
478
+ const dbi = createDBI("my-bot", {
479
+ data: {
480
+ other: {
481
+ startTime: Date.now(),
482
+ version: "1.0.0",
483
+ customData: {}
484
+ },
485
+ refs: new Map()
486
+ }
487
+ });
488
+
489
+ ACCESSING REGISTERED FEATURES:
490
+ ------------------------------
491
+ const ping = dbi.interaction("ping");
492
+ const button = dbi.interaction("my-button");
493
+ const readyEvent = dbi.event("ready-handler");
494
+ const enLocale = dbi.locale("en");
495
+
496
+ const allInteractions = dbi.data.interactions; // Discord.Collection
497
+ const allEvents = dbi.data.events;
498
+ const allLocales = dbi.data.locales;
499
+
500
+ ================================================================================
501
+ SECTION 10: STRICT MODE
502
+ ================================================================================
503
+
504
+ const dbi = createDBI("my-bot", {
505
+ strict: true // Default is true
506
+ });
507
+
508
+ WITH STRICT MODE:
509
+ - Duplicate interaction names throw errors
510
+ - Duplicate event IDs throw errors
511
+ - Duplicate locale names throw errors
512
+ - Custom IDs over 100 characters throw errors
513
+ - Missing event IDs throw errors
514
+
515
+ WITHOUT STRICT MODE:
516
+ - Duplicates silently ignored/overwritten
517
+ - Long custom IDs truncated
518
+
519
+ ================================================================================
520
+ END OF DOCUMENT
521
+ ================================================================================