@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.
- package/dist/src/types/Components/HTMLComponentsV2/index.d.ts +33 -1
- package/dist/src/types/Components/HTMLComponentsV2/index.d.ts.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/index.js +408 -82
- package/dist/src/types/Components/HTMLComponentsV2/index.js.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts +52 -0
- package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/parser.js +275 -0
- package/dist/src/types/Components/HTMLComponentsV2/parser.js.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts +26 -0
- package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js +509 -34
- package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts +10 -0
- package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts.map +1 -1
- package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js +76 -11
- package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js.map +1 -1
- package/dist/test/index.js +76 -3
- package/dist/test/index.js.map +1 -1
- package/docs/ADVANCED_FEATURES.md +4 -0
- package/docs/API_REFERENCE.md +4 -0
- package/docs/CHAT_INPUT.md +4 -0
- package/docs/COMPONENTS.md +4 -0
- package/docs/EVENTS.md +4 -0
- package/docs/GETTING_STARTED.md +4 -0
- package/docs/LOCALIZATION.md +4 -0
- package/docs/README.md +4 -0
- package/docs/SVELTE_COMPONENTS.md +162 -6
- package/docs/llm/ADVANCED_FEATURES.txt +521 -0
- package/docs/llm/API_REFERENCE.txt +659 -0
- package/docs/llm/CHAT_INPUT.txt +514 -0
- package/docs/llm/COMPONENTS.txt +595 -0
- package/docs/llm/EVENTS.txt +449 -0
- package/docs/llm/GETTING_STARTED.txt +296 -0
- package/docs/llm/LOCALIZATION.txt +501 -0
- package/docs/llm/README.txt +193 -0
- package/docs/llm/SVELTE_COMPONENTS.txt +566 -0
- package/generated/svelte-dbi.d.ts +122 -0
- package/package.json +1 -1
- package/src/types/Components/HTMLComponentsV2/index.ts +466 -94
- package/src/types/Components/HTMLComponentsV2/parser.ts +317 -0
- package/src/types/Components/HTMLComponentsV2/svelteParser.ts +567 -35
- package/src/types/Components/HTMLComponentsV2/svelteRenderer.ts +91 -13
- package/test/index.ts +76 -3
- package/test/product-showcase.svelte +380 -24
- package/llm.txt +0 -1088
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
DBI - LOCALIZATION GUIDE - LLM REFERENCE DOCUMENT
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
DOCUMENT TYPE: Multi-Language Support Reference
|
|
6
|
+
PACKAGE: @mostfeatured/dbi
|
|
7
|
+
|
|
8
|
+
================================================================================
|
|
9
|
+
SECTION 1: CONTENT LOCALIZATION
|
|
10
|
+
================================================================================
|
|
11
|
+
|
|
12
|
+
BASIC LOCALE DEFINITION:
|
|
13
|
+
------------------------
|
|
14
|
+
dbi.register(({ Locale }) => {
|
|
15
|
+
// English locale
|
|
16
|
+
Locale({
|
|
17
|
+
name: "en",
|
|
18
|
+
data: {
|
|
19
|
+
greeting: "Hello!",
|
|
20
|
+
goodbye: "Goodbye!",
|
|
21
|
+
welcome: "Welcome to our server!",
|
|
22
|
+
help: {
|
|
23
|
+
title: "Help Menu",
|
|
24
|
+
description: "Here are the available commands:"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Turkish locale
|
|
30
|
+
Locale({
|
|
31
|
+
name: "tr",
|
|
32
|
+
data: {
|
|
33
|
+
greeting: "Merhaba!",
|
|
34
|
+
goodbye: "Hoşça kal!",
|
|
35
|
+
welcome: "Sunucumuza hoş geldiniz!",
|
|
36
|
+
help: {
|
|
37
|
+
title: "Yardım Menüsü",
|
|
38
|
+
description: "İşte mevcut komutlar:"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Spanish locale
|
|
44
|
+
Locale({
|
|
45
|
+
name: "es",
|
|
46
|
+
data: {
|
|
47
|
+
greeting: "¡Hola!",
|
|
48
|
+
goodbye: "¡Adiós!",
|
|
49
|
+
welcome: "¡Bienvenido a nuestro servidor!",
|
|
50
|
+
help: {
|
|
51
|
+
title: "Menú de Ayuda",
|
|
52
|
+
description: "Aquí están los comandos disponibles:"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
================================================================================
|
|
59
|
+
SECTION 2: USING VARIABLES IN TRANSLATIONS
|
|
60
|
+
================================================================================
|
|
61
|
+
|
|
62
|
+
Use {0}, {1}, etc. as placeholders:
|
|
63
|
+
|
|
64
|
+
Locale({
|
|
65
|
+
name: "en",
|
|
66
|
+
data: {
|
|
67
|
+
// Simple variable
|
|
68
|
+
welcomeUser: "Welcome, {0}!",
|
|
69
|
+
|
|
70
|
+
// Multiple variables
|
|
71
|
+
levelUp: "{0} reached level {1}!",
|
|
72
|
+
|
|
73
|
+
// Complex message
|
|
74
|
+
orderConfirm: "Order #{0} confirmed. Total: ${1}. Ships to: {2}",
|
|
75
|
+
|
|
76
|
+
// Nested with variables
|
|
77
|
+
messages: {
|
|
78
|
+
ban: "{0} has been banned by {1}. Reason: {2}",
|
|
79
|
+
kick: "{0} has been kicked by {1}."
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
Locale({
|
|
85
|
+
name: "tr",
|
|
86
|
+
data: {
|
|
87
|
+
welcomeUser: "Hoş geldin, {0}!",
|
|
88
|
+
levelUp: "{0} seviye {1}'e ulaştı!",
|
|
89
|
+
orderConfirm: "Sipariş #{0} onaylandı. Toplam: {1}₺. Teslimat: {2}",
|
|
90
|
+
messages: {
|
|
91
|
+
ban: "{0}, {1} tarafından yasaklandı. Sebep: {2}",
|
|
92
|
+
kick: "{0}, {1} tarafından atıldı."
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
================================================================================
|
|
98
|
+
SECTION 3: NESTED LOCALE STRUCTURE
|
|
99
|
+
================================================================================
|
|
100
|
+
|
|
101
|
+
Locale({
|
|
102
|
+
name: "en",
|
|
103
|
+
data: {
|
|
104
|
+
commands: {
|
|
105
|
+
help: {
|
|
106
|
+
title: "Help",
|
|
107
|
+
description: "List of commands",
|
|
108
|
+
noCommands: "No commands available"
|
|
109
|
+
},
|
|
110
|
+
settings: {
|
|
111
|
+
title: "Settings",
|
|
112
|
+
language: "Language",
|
|
113
|
+
notifications: "Notifications"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
errors: {
|
|
117
|
+
notFound: "Item not found",
|
|
118
|
+
noPermission: "You don't have permission",
|
|
119
|
+
cooldown: "Please wait {0} seconds"
|
|
120
|
+
},
|
|
121
|
+
success: {
|
|
122
|
+
saved: "Settings saved!",
|
|
123
|
+
deleted: "Item deleted!"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
================================================================================
|
|
129
|
+
SECTION 4: INTERACTION LOCALIZATION
|
|
130
|
+
================================================================================
|
|
131
|
+
|
|
132
|
+
Translates command names, descriptions, options as they appear in Discord UI:
|
|
133
|
+
|
|
134
|
+
dbi.register(({ ChatInput, ChatInputOptions, InteractionLocale }) => {
|
|
135
|
+
// Define command with primary language
|
|
136
|
+
ChatInput({
|
|
137
|
+
name: "ayarlar",
|
|
138
|
+
description: "Bot ayarlarını değiştir",
|
|
139
|
+
options: [
|
|
140
|
+
ChatInputOptions.string({
|
|
141
|
+
name: "dil",
|
|
142
|
+
description: "Tercih ettiğiniz dil",
|
|
143
|
+
required: true,
|
|
144
|
+
choices: [
|
|
145
|
+
{ name: "Türkçe", value: "tr" },
|
|
146
|
+
{ name: "İngilizce", value: "en" }
|
|
147
|
+
]
|
|
148
|
+
})
|
|
149
|
+
],
|
|
150
|
+
onExecute({ interaction }) {
|
|
151
|
+
const lang = interaction.options.getString("dil");
|
|
152
|
+
interaction.reply(`Dil: ${lang}`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Add translations for other languages
|
|
157
|
+
InteractionLocale({
|
|
158
|
+
name: "ayarlar", // Must match command name
|
|
159
|
+
data: {
|
|
160
|
+
en: {
|
|
161
|
+
name: "settings",
|
|
162
|
+
description: "Change bot settings",
|
|
163
|
+
options: {
|
|
164
|
+
dil: {
|
|
165
|
+
name: "language",
|
|
166
|
+
description: "Your preferred language",
|
|
167
|
+
choices: {
|
|
168
|
+
"Türkçe": "Turkish",
|
|
169
|
+
"İngilizce": "English"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
es: {
|
|
175
|
+
name: "ajustes",
|
|
176
|
+
description: "Cambiar configuración del bot",
|
|
177
|
+
options: {
|
|
178
|
+
dil: {
|
|
179
|
+
name: "idioma",
|
|
180
|
+
description: "Tu idioma preferido",
|
|
181
|
+
choices: {
|
|
182
|
+
"Türkçe": "Turco",
|
|
183
|
+
"İngilizce": "Inglés"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
INTERACTION LOCALE STRUCTURE:
|
|
193
|
+
-----------------------------
|
|
194
|
+
InteractionLocale({
|
|
195
|
+
name: "command-name",
|
|
196
|
+
data: {
|
|
197
|
+
"locale-code": {
|
|
198
|
+
name: "translated-name",
|
|
199
|
+
description: "translated-desc",
|
|
200
|
+
options: {
|
|
201
|
+
"original-option-name": {
|
|
202
|
+
name: "translated-option",
|
|
203
|
+
description: "translated-desc",
|
|
204
|
+
choices: {
|
|
205
|
+
"Original Choice": "Translated Choice"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
================================================================================
|
|
214
|
+
SECTION 5: SUPPORTED LOCALE CODES
|
|
215
|
+
================================================================================
|
|
216
|
+
|
|
217
|
+
CODE | LANGUAGE CODE | LANGUAGE
|
|
218
|
+
-----|------------- -----|-------------
|
|
219
|
+
en | English ja | Japanese
|
|
220
|
+
bg | Bulgarian ko | Korean
|
|
221
|
+
zh | Chinese no | Norwegian
|
|
222
|
+
hr | Croatian pl | Polish
|
|
223
|
+
cs | Czech pt | Portuguese
|
|
224
|
+
da | Danish ro | Romanian
|
|
225
|
+
nl | Dutch ru | Russian
|
|
226
|
+
fi | Finnish es | Spanish
|
|
227
|
+
fr | French sv | Swedish
|
|
228
|
+
de | German th | Thai
|
|
229
|
+
el | Greek tr | Turkish
|
|
230
|
+
hi | Hindi uk | Ukrainian
|
|
231
|
+
hu | Hungarian vi | Vietnamese
|
|
232
|
+
it | Italian
|
|
233
|
+
|
|
234
|
+
================================================================================
|
|
235
|
+
SECTION 6: USING LOCALES IN INTERACTIONS
|
|
236
|
+
================================================================================
|
|
237
|
+
|
|
238
|
+
ACCESS THROUGH LOCALE OBJECT:
|
|
239
|
+
-----------------------------
|
|
240
|
+
dbi.register(({ ChatInput }) => {
|
|
241
|
+
ChatInput({
|
|
242
|
+
name: "greet",
|
|
243
|
+
description: "Greet the user",
|
|
244
|
+
onExecute({ interaction, locale }) {
|
|
245
|
+
// User's locale (based on Discord client language)
|
|
246
|
+
const userGreeting = locale.user.data.greeting();
|
|
247
|
+
|
|
248
|
+
// Guild's locale (based on guild's preferred locale)
|
|
249
|
+
const guildGreeting = locale.guild?.data.greeting?.();
|
|
250
|
+
|
|
251
|
+
interaction.reply(userGreeting);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
FUNCTION-STYLE ACCESS WITH VARIABLES:
|
|
257
|
+
-------------------------------------
|
|
258
|
+
Locale({
|
|
259
|
+
name: "en",
|
|
260
|
+
data: {
|
|
261
|
+
welcome: "Welcome, {0}!",
|
|
262
|
+
levelUp: "{0} reached level {1}!"
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
ChatInput({
|
|
267
|
+
name: "welcome",
|
|
268
|
+
description: "Welcome someone",
|
|
269
|
+
onExecute({ interaction, locale }) {
|
|
270
|
+
const user = interaction.options.getUser("user");
|
|
271
|
+
|
|
272
|
+
// Pass variables to the locale function
|
|
273
|
+
const message = locale.user.data.welcome(user.username);
|
|
274
|
+
|
|
275
|
+
interaction.reply(message);
|
|
276
|
+
// Output: "Welcome, John!"
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
PATH-BASED ACCESS:
|
|
281
|
+
------------------
|
|
282
|
+
Locale({
|
|
283
|
+
name: "en",
|
|
284
|
+
data: {
|
|
285
|
+
commands: {
|
|
286
|
+
help: {
|
|
287
|
+
title: "Help Menu",
|
|
288
|
+
footer: "Page {0} of {1}"
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
ChatInput({
|
|
295
|
+
name: "help",
|
|
296
|
+
description: "Show help",
|
|
297
|
+
onExecute({ interaction, locale }) {
|
|
298
|
+
// Chain to access nested values
|
|
299
|
+
const title = locale.user.data.commands.help.title();
|
|
300
|
+
const footer = locale.user.data.commands.help.footer(1, 5);
|
|
301
|
+
|
|
302
|
+
interaction.reply({
|
|
303
|
+
embeds: [{
|
|
304
|
+
title: title,
|
|
305
|
+
footer: { text: footer }
|
|
306
|
+
}]
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
ALTERNATIVE ACCESS METHODS:
|
|
312
|
+
---------------------------
|
|
313
|
+
// Using get() for dynamic paths
|
|
314
|
+
const path = "commands.help.title";
|
|
315
|
+
const value = locale.user.get(path); // Returns raw string or null
|
|
316
|
+
|
|
317
|
+
// Using format() for dynamic paths with variables
|
|
318
|
+
const formatted = locale.user.format("commands.help.footer", 1, 5);
|
|
319
|
+
|
|
320
|
+
ACCESSING LOCALE BY NAME:
|
|
321
|
+
-------------------------
|
|
322
|
+
ChatInput({
|
|
323
|
+
name: "translate",
|
|
324
|
+
description: "Show translation",
|
|
325
|
+
onExecute({ interaction, dbi }) {
|
|
326
|
+
const enLocale = dbi.locale("en");
|
|
327
|
+
const trLocale = dbi.locale("tr");
|
|
328
|
+
|
|
329
|
+
const enGreeting = enLocale.data.greeting();
|
|
330
|
+
const trGreeting = trLocale.data.greeting();
|
|
331
|
+
|
|
332
|
+
interaction.reply(`EN: ${enGreeting}\nTR: ${trGreeting}`);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
================================================================================
|
|
337
|
+
SECTION 7: DYNAMIC LOCALE SELECTION
|
|
338
|
+
================================================================================
|
|
339
|
+
|
|
340
|
+
BASED ON USER SETTINGS:
|
|
341
|
+
-----------------------
|
|
342
|
+
ChatInput({
|
|
343
|
+
name: "message",
|
|
344
|
+
description: "Send a message",
|
|
345
|
+
async onExecute({ interaction, dbi }) {
|
|
346
|
+
const userLang = await getUserLanguage(interaction.user.id);
|
|
347
|
+
const locale = dbi.locale(userLang) || dbi.locale("en");
|
|
348
|
+
const message = locale.data.welcomeMessage();
|
|
349
|
+
interaction.reply(message);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
BASED ON GUILD SETTINGS:
|
|
354
|
+
------------------------
|
|
355
|
+
Event({
|
|
356
|
+
name: "guildMemberAdd",
|
|
357
|
+
id: "welcome-message",
|
|
358
|
+
async onExecute({ member, locale }) {
|
|
359
|
+
const guildLocale = locale?.guild || dbi.locale("en");
|
|
360
|
+
const message = guildLocale.data.welcome(member.user.username);
|
|
361
|
+
|
|
362
|
+
const channel = member.guild.systemChannel;
|
|
363
|
+
if (channel) await channel.send(message);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
================================================================================
|
|
368
|
+
SECTION 8: MERGING LOCALES
|
|
369
|
+
================================================================================
|
|
370
|
+
|
|
371
|
+
Locales with the same name are automatically merged:
|
|
372
|
+
|
|
373
|
+
// File 1: Base translations
|
|
374
|
+
dbi.register(({ Locale }) => {
|
|
375
|
+
Locale({
|
|
376
|
+
name: "en",
|
|
377
|
+
data: {
|
|
378
|
+
common: { yes: "Yes", no: "No", cancel: "Cancel" }
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// File 2: Feature-specific translations
|
|
384
|
+
dbi.register(({ Locale }) => {
|
|
385
|
+
Locale({
|
|
386
|
+
name: "en",
|
|
387
|
+
data: {
|
|
388
|
+
shop: { buy: "Buy", sell: "Sell", cart: "Cart" }
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Result: Both 'common' and 'shop' available in 'en' locale
|
|
394
|
+
|
|
395
|
+
================================================================================
|
|
396
|
+
SECTION 9: HANDLING MISSING TRANSLATIONS
|
|
397
|
+
================================================================================
|
|
398
|
+
|
|
399
|
+
DEFAULT INVALID PATH HANDLER:
|
|
400
|
+
-----------------------------
|
|
401
|
+
const dbi = createDBI("my-bot", {
|
|
402
|
+
defaults: {
|
|
403
|
+
locale: {
|
|
404
|
+
name: "en",
|
|
405
|
+
invalidPath: ({ path, locale }) => {
|
|
406
|
+
console.warn(`Missing translation: ${path} in ${locale.name}`);
|
|
407
|
+
return `[Missing: ${path}]`;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
FALLBACK TO DEFAULT LOCALE:
|
|
414
|
+
---------------------------
|
|
415
|
+
DBI automatically falls back to default locale when a path is missing:
|
|
416
|
+
|
|
417
|
+
Locale({
|
|
418
|
+
name: "en",
|
|
419
|
+
data: { greeting: "Hello!", special: "Special message" }
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
Locale({
|
|
423
|
+
name: "tr",
|
|
424
|
+
data: { greeting: "Merhaba!" }
|
|
425
|
+
// 'special' is missing - will fall back to English
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// In Turkish context:
|
|
429
|
+
const message = locale.user.data.special();
|
|
430
|
+
// Returns "Special message" (fallback to English)
|
|
431
|
+
|
|
432
|
+
================================================================================
|
|
433
|
+
SECTION 10: BEST PRACTICES
|
|
434
|
+
================================================================================
|
|
435
|
+
|
|
436
|
+
1. ORGANIZE BY FEATURE:
|
|
437
|
+
src/locales/
|
|
438
|
+
├── en/
|
|
439
|
+
│ ├── common.js
|
|
440
|
+
│ ├── commands.js
|
|
441
|
+
│ └── errors.js
|
|
442
|
+
└── tr/
|
|
443
|
+
├── common.js
|
|
444
|
+
├── commands.js
|
|
445
|
+
└── errors.js
|
|
446
|
+
|
|
447
|
+
2. USE CONSISTENT KEYS:
|
|
448
|
+
// GOOD
|
|
449
|
+
data: {
|
|
450
|
+
commands: {
|
|
451
|
+
help: { title: "...", description: "..." },
|
|
452
|
+
settings: { title: "...", description: "..." }
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// BAD
|
|
457
|
+
data: {
|
|
458
|
+
helpTitle: "...",
|
|
459
|
+
help_description: "...",
|
|
460
|
+
settingsHeader: "..."
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
3. INCLUDE CONTEXT FOR TRANSLATORS:
|
|
464
|
+
Locale({
|
|
465
|
+
name: "en",
|
|
466
|
+
data: {
|
|
467
|
+
// {0} = username, {1} = level number
|
|
468
|
+
levelUp: "{0} reached level {1}!",
|
|
469
|
+
// {0} = item name, {1} = price in dollars
|
|
470
|
+
itemPurchased: "Purchased {0} for ${1}!"
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
4. HANDLE PLURALIZATION:
|
|
475
|
+
Locale({
|
|
476
|
+
name: "en",
|
|
477
|
+
data: {
|
|
478
|
+
items: {
|
|
479
|
+
one: "1 item",
|
|
480
|
+
many: "{0} items"
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
function formatItems(count, locale) {
|
|
486
|
+
if (count === 1) return locale.data.items.one();
|
|
487
|
+
return locale.data.items.many(count);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
5. USE CONDITIONAL REGISTRATION:
|
|
491
|
+
Locale({
|
|
492
|
+
name: "de",
|
|
493
|
+
flag: "german",
|
|
494
|
+
data: { greeting: "Hallo!" }
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
await dbi.load("german"); // Load with German locale
|
|
498
|
+
|
|
499
|
+
================================================================================
|
|
500
|
+
END OF DOCUMENT
|
|
501
|
+
================================================================================
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
DBI (DISCORD BOT INFRASTRUCTURE) - LLM REFERENCE DOCUMENT
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
DOCUMENT TYPE: Overview & Quick Start Guide
|
|
6
|
+
PACKAGE: @mostfeatured/dbi
|
|
7
|
+
VERSION COMPATIBILITY: discord.js v14
|
|
8
|
+
LANGUAGE: TypeScript/JavaScript
|
|
9
|
+
|
|
10
|
+
================================================================================
|
|
11
|
+
SECTION 1: WHAT IS DBI?
|
|
12
|
+
================================================================================
|
|
13
|
+
|
|
14
|
+
DBI is an NPM module that provides complete infrastructure for building
|
|
15
|
+
production-ready Discord bots. It is NOT a template - it's a framework.
|
|
16
|
+
|
|
17
|
+
PRIMARY PURPOSE:
|
|
18
|
+
- Simplify Discord bot development
|
|
19
|
+
- Provide type-safe APIs
|
|
20
|
+
- Handle boilerplate automatically
|
|
21
|
+
- Enable reactive UI patterns
|
|
22
|
+
|
|
23
|
+
================================================================================
|
|
24
|
+
SECTION 2: CORE FEATURES
|
|
25
|
+
================================================================================
|
|
26
|
+
|
|
27
|
+
FEATURE | DESCRIPTION
|
|
28
|
+
-------------------------|--------------------------------------------------
|
|
29
|
+
Slash Commands | Full Discord application commands with type-safe options
|
|
30
|
+
Components V2 | Buttons, Select Menus, Modals with state management
|
|
31
|
+
Svelte Integration | Reactive Discord UIs with Svelte 5 components
|
|
32
|
+
Localization | Multi-language support for content and interactions
|
|
33
|
+
Message Commands | Automatic slash-to-message command conversion
|
|
34
|
+
Reference System | Pass complex data through components without database
|
|
35
|
+
Rate Limiting | Built-in per-user, channel, guild rate limiting
|
|
36
|
+
Multi-Client | Support for multiple bot clients simultaneously
|
|
37
|
+
Hybrid Sharding | Built-in support for discord-hybrid-sharding
|
|
38
|
+
Type Safety | Full TypeScript support with intelligent autocomplete
|
|
39
|
+
|
|
40
|
+
================================================================================
|
|
41
|
+
SECTION 3: INSTALLATION
|
|
42
|
+
================================================================================
|
|
43
|
+
|
|
44
|
+
COMMAND (npm):
|
|
45
|
+
npm install @mostfeatured/dbi discord.js
|
|
46
|
+
|
|
47
|
+
COMMAND (pnpm):
|
|
48
|
+
pnpm add @mostfeatured/dbi discord.js
|
|
49
|
+
|
|
50
|
+
COMMAND (yarn):
|
|
51
|
+
yarn add @mostfeatured/dbi discord.js
|
|
52
|
+
|
|
53
|
+
REQUIREMENTS:
|
|
54
|
+
- Node.js 16.9.0 or higher
|
|
55
|
+
- Discord Application with bot token
|
|
56
|
+
|
|
57
|
+
================================================================================
|
|
58
|
+
SECTION 4: PROJECT STRUCTURE (RECOMMENDED)
|
|
59
|
+
================================================================================
|
|
60
|
+
|
|
61
|
+
my-bot/
|
|
62
|
+
├── dbi.js # DBI configuration (createDBI call)
|
|
63
|
+
├── login.js # Bot startup script
|
|
64
|
+
├── publish.js # Command publishing script
|
|
65
|
+
└── src/
|
|
66
|
+
├── commands/ # Slash commands
|
|
67
|
+
├── events/ # Discord event handlers
|
|
68
|
+
├── components/ # Buttons, Select Menus, Modals
|
|
69
|
+
└── locales/ # Language files
|
|
70
|
+
|
|
71
|
+
================================================================================
|
|
72
|
+
SECTION 5: BASIC SETUP PATTERN
|
|
73
|
+
================================================================================
|
|
74
|
+
|
|
75
|
+
STEP 1 - Create DBI Instance (dbi.js):
|
|
76
|
+
----------------------------------------
|
|
77
|
+
const { createDBI } = require("@mostfeatured/dbi");
|
|
78
|
+
|
|
79
|
+
const dbi = createDBI("my-bot", {
|
|
80
|
+
strict: true,
|
|
81
|
+
discord: {
|
|
82
|
+
token: process.env.DISCORD_TOKEN,
|
|
83
|
+
options: {
|
|
84
|
+
intents: ["Guilds", "GuildMessages"]
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
defaults: {
|
|
88
|
+
locale: { name: "en" },
|
|
89
|
+
defaultMemberPermissions: ["SendMessages"],
|
|
90
|
+
directMessages: false
|
|
91
|
+
},
|
|
92
|
+
references: {
|
|
93
|
+
autoClear: {
|
|
94
|
+
ttl: 60 * 60 * 1000,
|
|
95
|
+
check: 60 * 1000
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
module.exports = dbi;
|
|
101
|
+
|
|
102
|
+
STEP 2 - Create Command (src/commands/ping.js):
|
|
103
|
+
------------------------------------------------
|
|
104
|
+
const dbi = require("../dbi");
|
|
105
|
+
|
|
106
|
+
dbi.register(({ ChatInput }) => {
|
|
107
|
+
ChatInput({
|
|
108
|
+
name: "ping",
|
|
109
|
+
description: "Check the bot's latency",
|
|
110
|
+
async onExecute({ interaction, dbi }) {
|
|
111
|
+
const latency = dbi.client().client.ws.ping;
|
|
112
|
+
await interaction.reply(`Pong! Latency: ${latency}ms`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
STEP 3 - Start Bot (login.js):
|
|
118
|
+
-------------------------------
|
|
119
|
+
const { Utils } = require("@mostfeatured/dbi");
|
|
120
|
+
const dbi = require("./dbi");
|
|
121
|
+
|
|
122
|
+
(async () => {
|
|
123
|
+
await Utils.recursiveImport("./src");
|
|
124
|
+
await dbi.load();
|
|
125
|
+
await dbi.login();
|
|
126
|
+
console.log(`Logged in as ${dbi.client().client.user.tag}`);
|
|
127
|
+
})();
|
|
128
|
+
|
|
129
|
+
STEP 4 - Publish Commands (publish.js):
|
|
130
|
+
----------------------------------------
|
|
131
|
+
const { Utils } = require("@mostfeatured/dbi");
|
|
132
|
+
const dbi = require("./dbi");
|
|
133
|
+
|
|
134
|
+
(async () => {
|
|
135
|
+
await Utils.recursiveImport("./src");
|
|
136
|
+
await dbi.load();
|
|
137
|
+
await dbi.publish("Guild", "YOUR_GUILD_ID"); // Development
|
|
138
|
+
// await dbi.publish("Global"); // Production
|
|
139
|
+
await dbi.unload();
|
|
140
|
+
console.log("Commands published!");
|
|
141
|
+
})();
|
|
142
|
+
|
|
143
|
+
================================================================================
|
|
144
|
+
SECTION 6: REGISTER PATTERN
|
|
145
|
+
================================================================================
|
|
146
|
+
|
|
147
|
+
All DBI features are defined using the register pattern:
|
|
148
|
+
|
|
149
|
+
dbi.register(({ ChatInput, Button, Event, Locale }) => {
|
|
150
|
+
// Define features here
|
|
151
|
+
ChatInput({ /* ... */ });
|
|
152
|
+
Button({ /* ... */ });
|
|
153
|
+
Event({ /* ... */ });
|
|
154
|
+
Locale({ /* ... */ });
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
AVAILABLE REGISTER FUNCTIONS:
|
|
158
|
+
- ChatInput : Slash commands
|
|
159
|
+
- Button : Button components
|
|
160
|
+
- StringSelectMenu : String select menus
|
|
161
|
+
- UserSelectMenu : User select menus
|
|
162
|
+
- RoleSelectMenu : Role select menus
|
|
163
|
+
- ChannelSelectMenu : Channel select menus
|
|
164
|
+
- MentionableSelectMenu : Mentionable select menus
|
|
165
|
+
- Modal : Modal dialogs
|
|
166
|
+
- MessageContextMenu : Message context menu commands
|
|
167
|
+
- UserContextMenu : User context menu commands
|
|
168
|
+
- Event : Discord events
|
|
169
|
+
- Locale : Content localization
|
|
170
|
+
- InteractionLocale : Interaction name localization
|
|
171
|
+
- CustomEvent : Custom event definitions
|
|
172
|
+
- HTMLComponentsV2 : Svelte/Eta template components
|
|
173
|
+
- ChatInputOptions : Command option builders
|
|
174
|
+
- onUnload : Cleanup callback for hot reloading
|
|
175
|
+
|
|
176
|
+
================================================================================
|
|
177
|
+
SECTION 7: DOCUMENTATION FILES
|
|
178
|
+
================================================================================
|
|
179
|
+
|
|
180
|
+
FILE | CONTENT
|
|
181
|
+
------------------------|--------------------------------------------------
|
|
182
|
+
GETTING_STARTED.md | Installation and basic setup
|
|
183
|
+
CHAT_INPUT.md | Slash commands and options
|
|
184
|
+
COMPONENTS.md | Buttons, Select Menus, Modals
|
|
185
|
+
EVENTS.md | Discord events and Custom Events
|
|
186
|
+
LOCALIZATION.md | Multi-language support
|
|
187
|
+
SVELTE_COMPONENTS.md | Reactive UI with Svelte 5
|
|
188
|
+
ADVANCED_FEATURES.md | References, Rate Limiting, Message Commands
|
|
189
|
+
API_REFERENCE.md | Complete API documentation
|
|
190
|
+
|
|
191
|
+
================================================================================
|
|
192
|
+
END OF DOCUMENT
|
|
193
|
+
================================================================================
|