@mostfeatured/dbi 0.1.29 → 0.1.30

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 (99) hide show
  1. package/.gitattributes +2 -2
  2. package/.hintrc +7 -7
  3. package/.vscode/settings.json +2 -2
  4. package/LICENSE +674 -674
  5. package/dist/DBI.js.map +1 -1
  6. package/dist/Events.js.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/methods/handleMessageCommands.js.map +1 -1
  9. package/dist/methods/hookEventListeners.js.map +1 -1
  10. package/dist/methods/hookInteractionListeners.js.map +1 -1
  11. package/dist/methods/publishInteractions.js.map +1 -1
  12. package/dist/types/ApplicationRoleConnectionMetadata.js.map +1 -1
  13. package/dist/types/Builders/ButtonBuilder.js.map +1 -1
  14. package/dist/types/Builders/ChannelSelectMenuBuilder.js.map +1 -1
  15. package/dist/types/Builders/MentionableSelectMenuBuilder.js.map +1 -1
  16. package/dist/types/Builders/ModalBuilder.js.map +1 -1
  17. package/dist/types/Builders/RoleSelectMenuBuilder.js.map +1 -1
  18. package/dist/types/Builders/StringSelectMenuBuilder.js.map +1 -1
  19. package/dist/types/Builders/UserSelectMenuBuilder.js.map +1 -1
  20. package/dist/types/ChatInput/ChatInput.js.map +1 -1
  21. package/dist/types/ChatInput/ChatInputOptions.d.ts +16 -16
  22. package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
  23. package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
  24. package/dist/types/Components/Button.js.map +1 -1
  25. package/dist/types/Components/ChannelSelectMenu.js.map +1 -1
  26. package/dist/types/Components/MentionableSelectMenu.js.map +1 -1
  27. package/dist/types/Components/Modal.js.map +1 -1
  28. package/dist/types/Components/RoleSelectMenu.js.map +1 -1
  29. package/dist/types/Components/StringSelectMenu.js.map +1 -1
  30. package/dist/types/Components/UserSelectMenu.js.map +1 -1
  31. package/dist/types/Event.js.map +1 -1
  32. package/dist/types/Interaction.js.map +1 -1
  33. package/dist/types/other/CustomEvent.js.map +1 -1
  34. package/dist/types/other/FakeMessageInteraction.js.map +1 -1
  35. package/dist/types/other/InteractionLocale.js.map +1 -1
  36. package/dist/types/other/Locale.js.map +1 -1
  37. package/dist/types/other/MessageContextMenu.js.map +1 -1
  38. package/dist/types/other/UserContextMenu.js.map +1 -1
  39. package/dist/utils/MemoryStore.js.map +1 -1
  40. package/dist/utils/UtilTypes.js.map +1 -1
  41. package/dist/utils/customId.js.map +1 -1
  42. package/dist/utils/permissions.js.map +1 -1
  43. package/dist/utils/recursiveImport.js.map +1 -1
  44. package/dist/utils/recursiveUnload.js.map +1 -1
  45. package/dist/utils/unloadModule.js.map +1 -1
  46. package/examples/modal/dbi.js +29 -29
  47. package/examples/modal/login.js +14 -14
  48. package/examples/modal/package.json +15 -15
  49. package/examples/modal/publish.js +12 -12
  50. package/examples/modal/src/chatInput.js +37 -37
  51. package/examples/modal/src/components.js +32 -32
  52. package/examples/modal/src/event.js +19 -19
  53. package/examples/modal/src/interactionlocales.js +23 -23
  54. package/examples/modal/src/locales.js +37 -37
  55. package/examples/modal/src/modal.js +27 -27
  56. package/generated/namespaceData.d.ts +14 -14
  57. package/package.json +6 -6
  58. package/readme.md +591 -591
  59. package/src/DBI.ts +1090 -1090
  60. package/src/Events.ts +189 -189
  61. package/src/data/eventMap.json +247 -247
  62. package/src/index.ts +23 -23
  63. package/src/methods/handleMessageCommands.ts +482 -482
  64. package/src/methods/hookEventListeners.ts +118 -118
  65. package/src/methods/hookInteractionListeners.ts +260 -260
  66. package/src/methods/publishInteractions.ts +255 -255
  67. package/src/types/ApplicationRoleConnectionMetadata.ts +19 -19
  68. package/src/types/Builders/ButtonBuilder.ts +52 -52
  69. package/src/types/Builders/ChannelSelectMenuBuilder.ts +52 -52
  70. package/src/types/Builders/MentionableSelectMenuBuilder.ts +52 -52
  71. package/src/types/Builders/ModalBuilder.ts +52 -52
  72. package/src/types/Builders/RoleSelectMenuBuilder.ts +52 -52
  73. package/src/types/Builders/StringSelectMenuBuilder.ts +52 -52
  74. package/src/types/Builders/UserSelectMenuBuilder.ts +52 -52
  75. package/src/types/ChatInput/ChatInput.ts +27 -27
  76. package/src/types/ChatInput/ChatInputOptions.ts +388 -388
  77. package/src/types/Components/Button.ts +38 -38
  78. package/src/types/Components/ChannelSelectMenu.ts +42 -42
  79. package/src/types/Components/MentionableSelectMenu.ts +42 -42
  80. package/src/types/Components/Modal.ts +45 -45
  81. package/src/types/Components/RoleSelectMenu.ts +42 -42
  82. package/src/types/Components/StringSelectMenu.ts +42 -42
  83. package/src/types/Components/UserSelectMenu.ts +42 -42
  84. package/src/types/Event.ts +144 -144
  85. package/src/types/Interaction.ts +96 -96
  86. package/src/types/other/CustomEvent.ts +18 -18
  87. package/src/types/other/FakeMessageInteraction.ts +407 -407
  88. package/src/types/other/InteractionLocale.ts +33 -33
  89. package/src/types/other/Locale.ts +69 -69
  90. package/src/types/other/MessageContextMenu.ts +26 -26
  91. package/src/types/other/UserContextMenu.ts +24 -24
  92. package/src/utils/MemoryStore.ts +27 -27
  93. package/src/utils/UtilTypes.ts +10 -10
  94. package/src/utils/customId.ts +44 -44
  95. package/src/utils/permissions.ts +4 -4
  96. package/src/utils/recursiveImport.ts +22 -22
  97. package/src/utils/recursiveUnload.ts +24 -24
  98. package/src/utils/unloadModule.ts +6 -6
  99. package/tsconfig.json +40 -40
package/readme.md CHANGED
@@ -1,592 +1,592 @@
1
- # DiscordBotInfrastructure - [English]
2
-
3
- The most advanced, up-to-date and simple to use Discord bot infrastructure you can find on the internet.
4
-
5
- # Usage Scenario
6
-
7
- The MostFeatured/DiscordBotInfrastructure project is not a stand-alone project like other infrastructures you are used to, it is an NPM module. In this context, before you start using it, you need to open a folder and download the infrastructure and discord.js by entering the `npm install @mostfeatured/dbi discord.js` command.
8
-
9
- # While Starting
10
-
11
- First we will need `3 files` and `1 folder`. This structure can be configured completely in accordance with your working order. However, the scenario we propose is as follows.
12
-
13
- Files and folders that need to be opened; Files `dbi.js`, `login.js`, `publish.js` and `src` folder.
14
-
15
- As the first step, we open our file named `dbi.js` and lay the foundations of the infrastructure in it.
16
- ```js
17
- const { createDBI } = require("@mostfeatured/dbi");
18
- let dbi = createDBI("xd", {
19
- strict: true,
20
- discord: {
21
- token: "<yourTokenHere>",
22
- options: {
23
- intents: [
24
- "Guilds"
25
- ]
26
- }
27
- },
28
- defaults: {
29
- locale: {
30
- name: "en"
31
- },
32
- defaultMemberPermissions: ["SendMessages"],
33
- directMessages: false
34
- },
35
- references: {
36
- autoClear: {
37
- ttl: 60 * 1000 * 60,
38
- check: 60 * 1000
39
- }
40
- },
41
- // Message Commands are optional. Message Commands work trough emulating the slash commands..
42
- messageCommands: {
43
- prefixes: ["!", "."],
44
- typeAliases: {
45
- booleans: {
46
- "true": true,
47
- "false": false,
48
- "yes": true,
49
- "no": false,
50
- }
51
- }
52
- }
53
- });
54
-
55
- dbi.events.on("messageCommandArgumentError", (data) => {
56
- data.message.reply(`‼️ Invalid argument \`${data.error.option.name}\` (Index: \`${data.error.index}\`). Error Kind: \`${data.error.type}\`. Expected: \`${ApplicationCommandOptionType[data.error.option.type]}\`${data.error.extra ? ` with any of \`${data.error.extra.map(i => i.name).join(", ")}\`` : ""}.`);
57
- return false;
58
- });
59
-
60
- module.exports = dbi;
61
- ```
62
-
63
- We start the infrastructure with the `createDBI()` function. The first parameter of the function is your bot's 'codeName' and the second parameter is your bot's configuration.
64
-
65
- As the second step, we open our `login.js` file and write the code group that we will use to open the bot.
66
- ```js
67
- const { Utils } = require("@mostfeatured/dbi");
68
- const dbi = require("./dbi");
69
- (async () => {
70
- await Utils.recursiveImport("./src");
71
- await dbi.load();
72
- await dbi.login();
73
- await dbi.client.user.setActivity({
74
- name: "MostFeatured ❤️ TheArmagan"
75
- });
76
- console.log(`Logged in! ${dbi.client.user.tag} (${dbi.client.user.id})`);
77
- })();
78
- ```
79
-
80
- We import the `Utils.recursiveImport()` function into it. With this function we can `import`/`require` all files in `x` folder endlessly. In this way, the infrastructure is aware of these files.
81
- We access our infrastructure from our main `dbi.js` file and create an `async` environment and first define all project files to the infrastructure. After the definition, we load all the features we have defined to the infrastructure with the `load()` function. Right after, we log in to Discord with the `login()` function.
82
-
83
- As the 3rd step, we open our `publish.js` file and repeat all the operations we did in the second step.
84
- ```js
85
- const { Utils } = require("@mostfeatured/dbi");
86
- const dbi = require("./dbi");
87
- (async () => {
88
- await Utils.recursiveImport("./src");
89
- await dbi.load();
90
- await dbi.publish("Guild", "<yourGuildId>");
91
- // await dbi.publish("Global");
92
- await dbi.unload();
93
- console.log("Published!");
94
- })();
95
- ```
96
-
97
- However, instead of calling the `login()` function, we call the `publish()` function and with this function we introduce the commands of our bot wherever we want.
98
-
99
- # Fantastic!
100
-
101
- We now have all the necessary files to use the infrastructure. (Information: If these steps that we have explained in detail are complex and difficult for you, we are sorry that this infrastructure is not suitable for you.)
102
-
103
- # Detailed Usage Scenario
104
-
105
- You can fully use all kinds of Discord's features with our specially developed infrastructure that fully supports v14. (`ChatInput`, `Event`, `Locale`, `Button`, `SelectMenu`, `MessageContextMenu`, `UserContextMenu`, `Modal`, `InteractionLocale`)
106
-
107
- Now we want to show you how to define properties in infrastructure. Example: (ChatInput/Button etc.)
108
-
109
- First, we include the relevant feature in our infrastructure.
110
- ```js
111
- const dbi = require("../dbi");
112
- ```
113
- And then we call the `register()` function on the infrastructure and put a `callback` function in it. This `callback` function presents as the first parameter everything you can define on the infrastructure as an object. You can perform the definition to the infrastructure by calling the feature function you want from this object.
114
- ```js
115
- dbi.register(({ ChatInput, Event }) => {
116
- ChatInput({ ... });
117
- Event({ ... });
118
- })
119
- ```
120
- Remember, you can summon as many features as you want at the same time!
121
-
122
- # ChatInput & ChatInputOptions
123
-
124
- `ChatInput` is defined as "Slash Command" as you can understand.
125
-
126
- <sub>`src/chatInput.js` file:</sub>
127
-
128
- ```js
129
- const dbi = require("../dbi");
130
- const Discord = require("discord.js");
131
-
132
- dbi.register(({ ChatInput, ChatInputOptions }) => {
133
- ChatInput({
134
- name: "cinsiyet seç",
135
- description: "Cinsiyet seçmenizi sağlar.",
136
- onExecute({ interaction, locale }) {
137
- let gender = interaction.options.get("cinsiyet").value;
138
- let genderNames = locale.user.data.genders;
139
- let genderText = locale.user.data.genderText(interaction.user, genderNames[gender]());
140
-
141
- interaction.reply({
142
- content: genderText,
143
- components: [
144
- {
145
- type: Discord.ComponentType.ActionRow,
146
- components: [
147
- dbi.interaction("viewGender").toJSON({ overrides: { label: locale.user.data.clickText() }, reference: { ttl: 1000 * 60 * 10, data: [gender] } }),
148
- ]
149
- }
150
- ]
151
- });
152
- },
153
- options: [
154
- ChatInputOptions.stringChoices({
155
- name: "cinsiyet",
156
- description: "Seçeceğiniz cinsiyet.",
157
- required: true,
158
- choices: [
159
- { name: "Erkek", value: "erkek" },
160
- { name: "Kadın", value: "kadın" },
161
- { name: "Diğer", value: "diğer" },
162
- ]
163
- })
164
- ],
165
- });
166
- });
167
- ```
168
- In general, the structure of `ChatInput` may seem familiar to you, except for `options`. When you try to fill something in options directly, you will not get autocomplete. Because options expect static functions in ChatInputOptions class. The functions are similar to: `stringChoices`, `user`, `numberAutocomplete` etc.
169
- You can also find more examples below for a sample demonstration of how the Locale and Component system we have shown above is used.
170
-
171
- # Event
172
-
173
- <sub>`src/event.js` file:</sub>
174
-
175
- ```js
176
- const dbi = require("../dbi");
177
- dbi.register(({ Event }) => {
178
- Event({
179
- name: "ready",
180
- id: "botIsReady",
181
- onExecute() {
182
- console.log(`Bot ready!`);
183
- }
184
- });
185
- });
186
- ```
187
- When defining an event, you can write the name of the event you want in the `name` field. However, if you want to open more than one of the same event, you need to define an 'id' for that event.
188
-
189
- # Locale
190
-
191
- <sub>`src/locales.js` file:</sub>
192
-
193
- ```js
194
- const dbi = require("../dbi");
195
- dbi.register(({ Locale }) => {
196
- Locale({
197
- name: "tr",
198
- data: {
199
- genders: {
200
- erkek: "Erkek",
201
- kadın: "Kadın",
202
- diğer: "Diğer"
203
- },
204
- genderText: "{0} adlı üye {1} cinsiyetini seçti."
205
- }
206
- });
207
- Locale({
208
- name: "en",
209
- data: {
210
- genders: {
211
- erkek: "Male",
212
- kadın: "Female",
213
- diğer: "Other"
214
- },
215
- genderText: "{0}, picked {1} gender."
216
- }
217
- });
218
- });
219
- ```
220
-
221
- Thanks to Locale, there is information in each interaction that will make it easier for you to respond according to the language of the user or the server. The `name` in Locale contains the values you want to keep, and the `data` part for which language you define. The `{0}` and `{1}` signs in the text are also our variables in the text. When using locale, we can take the value we want and call it like a function. And in it we give the parameters respectively. For example `locale.data.genderText(user, gender)`.
222
-
223
- # Button & SelectMenu & Modal
224
-
225
- In this section, we will look at three of our features. (Actually, it's all the same feature in the background.)
226
-
227
- <sub>`src/components.js` file:</sub>
228
-
229
- ```js
230
- const dbi = require("../dbi");
231
- const Discord = require("discord.js");
232
- dbi.register(({ Button, SelectMenu, Modal }) => {
233
- Button({
234
- name: "viewGender",
235
- onExecute({ interaction, data }) {
236
- interaction.reply(`\`${data[0]}\``);
237
- },
238
- options: {
239
- style: Discord.ButtonStyle.Primary,
240
- label: "View Gender"
241
- }
242
- });
243
- });
244
- ```
245
- We bring you a very cool and cool feature about Button & SelectMenu & Modal. Now you can move the value you want on them. (Like Reference/Object or text/number.) For example `dbi.interaction("viewGender").toJSON("male")` will provide us a valid component powered by Discord.js. And you can reach the value presented in the json both by turning the `options` part into a function and when the interaction itself is called. There is one thing you should not forget about this subject. If you are going to carry plain text or numbers, the total length of these texts or numbers should not exceed 100 characters. Because these values ​​are carried directly on the button and they work in such a way that they remain there even if you turn the bot off and on.
246
-
247
- # MessageContextMenu & UserContextMenu
248
-
249
- It has exactly the same properties as `ChatInput` but does not take `options` value.
250
-
251
- # InteractionLocale
252
-
253
- We offer you another unique feature. You can now define a custom script language for each user.
254
- For example, the command that appears as `/select gender` to a Turkish user may appear as `/select gender` to a foreign user. (You can configure it as you wish.)
255
-
256
- <sub>`src/interactionlocales.js` file:</sub>
257
-
258
- ```js
259
- const dbi = require("../dbi");
260
- dbi.register(({ InteractionLocale }) => {
261
- InteractionLocale({
262
- name: "cinsiyet seç",
263
- data: {
264
- en: {
265
- name: "select gender",
266
- description: "Allows you to select a gender.",
267
- options: {
268
- cinsiyet: {
269
- name: "gender",
270
- description: "Select your gender correctly.",
271
- choices: {
272
- "Erkek": "Male",
273
- "Kadın": "Female",
274
- "Diğer": "Other"
275
- }
276
- }
277
- }
278
- }
279
- }
280
- });
281
- });
282
- ```
283
-
284
- Final note: The value `name` for `InteractionLocale` will be the name of one of the other interactions you define. For example `select gender`. We tried to simplify Data's structure. First you select the language you want and then you fill in the content as in the example. You can add how it will appear in as many languages as you want at the same time.
285
-
286
- You can contact me via Discord for errors or similar issues. (Armagan#4869)
287
-
288
- Remember: "There will always be something free and valuable on earth."
289
-
290
- <sub>12.09.2022: Original text written by TheArmagan, edited by Maschera. </sub>
291
-
292
- # DiscordBotInfrastructure - [Turkish]
293
-
294
- İnternet üzerinde bulabileceğiniz en gelişmiş, güncel ve kullanımı basit Discord bot altyapısı.
295
-
296
- # Kullanım Senaryosu
297
-
298
- MostFeatured/DiscordBotInfrastructure projesi diğer alışık olduğunuz altyapılar gibi kendi halinde bir proje değil, bir NPM modülüdür. Bu bağlamda kullanmaya başlamadan önce bir klasör açmanız ve içerisine `npm install @mostfeatured/dbi discord.js` komutunu girerek altyapıyı ve discord.js'i indirmeniz gerekmektedir.
299
-
300
- # Başlarken
301
-
302
- İlk olarak `3 dosya` ve `1 klasöre` ihitiyacımız olacak. Bu yapı tamamen sizin çalışma düzeninize uygun olarak konfigüre edilebilmektedir. Lakin bizim önerdiğimiz senaryo aşağıdaki gibidir.
303
-
304
- Açılması gereken dosyalar ve klasörler; `dbi.js`, `login.js`, `publish.js` dosyaları ve `src` klasörü.
305
-
306
- 1. adım olarak `dbi.js` adındaki dosyamızı açıyoruz ve içerisine altyapının temellerini atıyoruz.
307
- ```js
308
- const { createDBI } = require("@mostfeatured/dbi");
309
-
310
- let dbi = createDBI("xd", {
311
- strict: true,
312
- discord: {
313
- token: "<yourTokenHere>",
314
- options: {
315
- intents: [
316
- "Guilds"
317
- ]
318
- }
319
- },
320
- defaults: {
321
- locale: "en",
322
- defaultMemberPermissions: ["SendMessages"],
323
- directMessages: false
324
- },
325
- references: {
326
- autoClear: {
327
- ttl: 60 * 1000 * 60,
328
- check: 60 * 1000
329
- }
330
- },
331
- // Mesaj Komutları isteğe bağlıdır. Mesaj Komutları slash komutlarını taklit ederek çalışır. Yani siz sadece slash komut kodlasanız bile uyumlu olarak çalışacaktır.
332
- messageCommands: {
333
- prefixes: ["!", "."],
334
- typeAliases: {
335
- booleans: {
336
- "true": true,
337
- "false": false,
338
- "yes": true,
339
- "no": false,
340
- }
341
- }
342
- }
343
- });
344
-
345
- dbi.events.on("messageCommandArgumentError", (data) => {
346
- data.message.reply(`‼️ Hatalı argument \`${data.error.option.name}\` (Konum: \`${data.error.index}\`). Hata Tipi: \`${data.error.type}\`. Beklenen: \`${ApplicationCommandOptionType[data.error.option.type]}\`${data.error.extra ? ` şunlardan herhangi biri \`${data.error.extra.map(i => i.name).join(", ")}\`` : ""}.`);
347
- return false;
348
- });
349
-
350
- module.exports = dbi;
351
- ```
352
-
353
- `createDBI()` fonksiyonu ile altyapıyı başlatıyoruz. Fonksiyonun ilk parametresi botunuzun `kodAdı`, ikinci parametresi ise botunuzun konfigürasyonudur.
354
-
355
- 2. adım olarak `login.js` dosyamızı açıyoruz ve içerisine botu açmak için kullanacağımız kod gurubunu yazıyoruz.
356
- ```js
357
- const { Utils } = require("@mostfeatured/dbi");
358
- const dbi = require("./dbi");
359
-
360
- (async () => {
361
- await Utils.recursiveImport("./src");
362
-
363
- await dbi.load();
364
- await dbi.login();
365
-
366
- await dbi.client.user.setActivity({
367
- name: "MostFeatured ❤️ TheArmagan"
368
- });
369
-
370
- console.log(`Logged in! ${dbi.client.user.tag} (${dbi.client.user.id})`);
371
- })();
372
- ```
373
-
374
- İçeriye `Utils.recursiveImport()` fonksiyonunu alıyoruz. Bu fonksiyon ile sonsuz bir şekilde `x` klasöründeki bütün dosyaları `import`/`require` edebiliyoruz. Bu sayede altyapı bu dosyalardan haberdar oluyor.
375
- Ana `dbi.js` dosyamızdan altyapımıza ulaşıyoruz ve `async` bir ortam oluşturup ilk önce tüm proje dosylarını altyapıya tanımlıyoruz. Tanımlamanın ardından tanımladığımız tüm özellikleri altyapıya `load()` fonksiyonunu ile yüklüyoruz. Hemen ardından `login()` fonksiyonu ile Discord'a giriş sağlıyoruz.
376
-
377
-
378
- 3. adım olarak `publish.js` dosyamızı açıyoruz ve ikinci aşamada yaptığımız tüm işlemleri tekrardan uyguluyoruz.
379
- ```js
380
- const { Utils } = require("@mostfeatured/dbi");
381
- const dbi = require("./dbi");
382
-
383
- (async () => {
384
- await Utils.recursiveImport("./src");
385
-
386
- await dbi.load();
387
- await dbi.publish("Guild", "<yourGuildId>");
388
- // await dbi.publish("Global");
389
- await dbi.unload();
390
-
391
- console.log("Published!");
392
- })();
393
- ```
394
-
395
- Ancak `login()` fonksiyonunu çağırmak yerine, `publish()` fonksiyonunu çağrıyoruz ve bu fonksiyon ile botumuzun komutlarını istediğimiz yere tanıtıyoruz.
396
-
397
- # Harika!
398
-
399
- Artık altyapıyı kullanabilmek için gerekli olan bütün dosyalara sahibiz. (Bilgilendirme: Detaylı bir şekilde anlattığımız bu adımlar size karmaşık ve zor geliyorsa üzgünüz ki bu altyapı size uygun değil.)
400
-
401
- # Detaylı Kullanım Senaryosu
402
-
403
- Özel olarak geliştirdiğimiz ve v14'ü eksiksiz bir şekilde destekleyen altyapımız ile Discord'un her türlü özelliğini tam anlamıyla kullanabiliyorsunuz. (`ChatInput`, `Event`, `Locale`, `Button`, `SelectMenu`, `MessageContextMenu`, `UserContextMenu`, `Modal`, `InteractionLocale`)
404
-
405
- Şimdi sizlere altyapıya özellik tanımlamayı göstermek istiyoruz. Örnek: (ChatInput/Button vb.)
406
-
407
- İlk olarak ilgili özelliği altyapımıza dahil ediyoruz.
408
- ```js
409
- const dbi = require("../dbi");
410
- ```
411
- Ve devamında altyapının üzerindeki `register()` fonksiyonunu çağırıp içerisine bir `callback` fonksiyonu koyuyoruz. Bu `callback` fonksiyonu ilk parametre olarak size altyapı üzerine tanımlayabilceğiniz tüm her şeyi bir obje olarak sunuyor. Bu obje içerisinden istediğiniz özellik fonksiyonunu çağırarak altyapıya tanımlama işlemini gerçekleştirebiliyorsunuz.
412
- ```js
413
- dbi.register(({ ChatInput, Event }) => {
414
- ChatInput({ ... });
415
- Event({ ... });
416
- })
417
- ```
418
- Unutmayın ki aynı anda istediğiniz kadar özelliği çağırabilirsiniz!
419
-
420
- # ChatInput & ChatInputOptions
421
-
422
- `ChatInput` sizin anlayacağınız şekilde "Slash Komut" olarak tanımlanmaktadır.
423
-
424
- <sub>`src/chatInput.js` dosyası:</sub>
425
-
426
- ```js
427
- const dbi = require("../dbi");
428
- const Discord = require("discord.js");
429
-
430
- dbi.register(({ ChatInput, ChatInputOptions }) => {
431
- ChatInput({
432
- name: "cinsiyet seç",
433
- description: "Cinsiyet seçmenizi sağlar.",
434
- onExecute({ interaction, locale }) {
435
- let gender = interaction.options.get("cinsiyet").value;
436
- let genderNames = locale.user.data.genders;
437
- let genderText = locale.user.data.genderText(interaction.user, genderNames[gender]());
438
- interaction.reply({
439
- content: genderText,
440
- components: [
441
- {
442
- type: Discord.ComponentType.ActionRow,
443
- components: [
444
- dbi.interaction("viewGender").toJSON({ overrides: { label: locale.user.data.clickText() }, reference: { ttl: 1000 * 60 * 10, data: [gender] } }),
445
- ]
446
- }
447
- ]
448
- });
449
- },
450
- options: [
451
- ChatInputOptions.stringChoices({
452
- name: "cinsiyet",
453
- description: "Seçeceğiniz cinsiyet.",
454
- required: true,
455
- choices: [
456
- { name: "Erkek", value: "erkek" },
457
- { name: "Kadın", value: "kadın" },
458
- { name: "Diğer", value: "diğer" },
459
- ]
460
- })
461
- ],
462
- });
463
- });
464
- ```
465
- Genel olarak `ChatInput`'un yapısı gözünüze `options` dışında tanıdık gelmiş olabilir. Direkt olarak options içerisine bir şey doldurmaya çalıştığınızda otomatik tamamlama alamayacaksınız. Çünkü options içerisinde ChatInputOptions class'ındaki statik fonksiyonlardan beklemekte. Fonksiyonlar ise şunlara benzemekte; `stringChoices`, `user`, `numberAutocomplete` vb.
466
- Ayrıca yukarıda göstermiş olduğumuz Locale ve Component sisteminin nasıl kullanıldığıyla ilgili örnek gösterim için aşağıdan daha fazla örneğe ulaşabilirsiniz.
467
-
468
- # Event
469
-
470
- <sub>`src/event.js` dosyası:</sub>
471
-
472
- ```js
473
- const dbi = require("../dbi");
474
-
475
- dbi.register(({ Event }) => {
476
- Event({
477
- name: "ready",
478
- id: "botIsReady",
479
- onExecute() {
480
- console.log(`Bot ready!`);
481
- }
482
- });
483
- });
484
- ```
485
- Event yani olay tanımlarken `name` kısmına istediğiniz olayın ismini yazabilirsiniz. Ancak eğer aynı olaydan birden fazla açmak istiyorsanız o olaya bir `id` tanımlamanız gerekmektedir.
486
-
487
- # Locale
488
-
489
- <sub>`src/locales.js` dosyası:</sub>
490
-
491
- ```js
492
- const dbi = require("../dbi");
493
-
494
- dbi.register(({ Locale }) => {
495
- Locale({
496
- name: "tr",
497
- data: {
498
- genders: {
499
- erkek: "Erkek",
500
- kadın: "Kadın",
501
- diğer: "Diğer"
502
- },
503
- genderText: "{0} adlı üye {1} cinsiyetini seçti."
504
- }
505
- });
506
-
507
- Locale({
508
- name: "en",
509
- data: {
510
- genders: {
511
- erkek: "Male",
512
- kadın: "Female",
513
- diğer: "Other"
514
- },
515
- genderText: "{0}, picked {1} gender."
516
- }
517
- });
518
- });
519
- ```
520
-
521
- Locale sayesinde her interaksiyon içerisinde kullanıcının veya sunucunun diline göre cevap vermenizi kolaylaştıracak bilgiler bulunmakta. Locale içerisindeki `name` hangi dil için tanımlama yaptığınız `data` kısmı ise tutmak istediğiniz değerleri içermekte. Yazı içerisindeki `{0}` ve `{1}` işaretleri aynı şekilde yazı içerisindeki değişkenlerimiz. Locale kullanırken istediğimiz değeri alıp onu bir fonksiyon gibi çağırabiliyoruz. Ve içerisine sırasıyla parametreleri veriyoruz. Örneğin `locale.data.genderText(user, gender)`.
522
-
523
- # Button & SelectMenu & Modal
524
-
525
- Bu bölümde ise üç adet özelliğimize bakacağız. (Aslında arka planda hepsi aynı özellik.)
526
-
527
- <sub>`src/components.js` dosyası:</sub>
528
-
529
- ```js
530
- const dbi = require("../dbi");
531
- const Discord = require("discord.js");
532
-
533
- dbi.register(({ Button, SelectMenu, Modal }) => {
534
- Button({
535
- name: "viewGender",
536
- onExecute({ interaction, data }) {
537
- interaction.reply(`\`${data[0]}\``);
538
- },
539
- options: {
540
- style: Discord.ButtonStyle.Primary,
541
- label: "View Gender"
542
- }
543
- });
544
- });
545
- ```
546
- Button & SelectMenu & Modal hakkında çok güzel ve havalı bir özelliği sizlerle buluşturuyoruz. Artık bunların üzerinde istediğiniz değeri taşıyabilirsiniz. (Referans/Obje veya yazı/sayı gibi.) Örneğin `dbi.interaction("viewGender").toJSON("male")` bize Discord.js tarafından desteklenen geçerli bir component sunacaktır. Ve to json içerisinde sunulan değere hem `options` kısmını bir fonksiyona çevirerek ulaşabilir hem de interaksiyonun kendisi çağırıldığında ulaşabilirsiniz. Bu konuyla ilgili unutmamanız gereken bir şey var. Eğer düz yazı veya sayı taşıyacaksanız bu yazı veya sayıların toplam uzunluğu 100 karakteri geçmemeli. Çünkü bu değerler direkt olarak düğmenin üzerinde taşınmakta ve siz botu kapatıp açsanız bile orada kalacak şekilde çalışmaktadırlar.
547
-
548
- # MessageContextMenu & UserContextMenu
549
-
550
- `ChatInput` ile birebir aynı özelliklere sahip ancak `options` değeri almamaktadır.
551
-
552
- # InteractionLocale
553
-
554
- Bir eşsiz özelliği daha sizlere sunuyoruz. Artık her kullanıcıya özel komut dili tanımlamanızı sağlayabilirsiniz.
555
- Örneğin Türk bir kullanıcıya `/cinsiyet seç` şeklinde gözüken komut yabancı bir kullanıcıya `/select gender` olarak gözükebilir. (Dilediğiniz gibi konfigüre edebilirsiniz.)
556
-
557
- <sub>`src/interactionlocales.js` dosyası:</sub>
558
-
559
- ```js
560
- const dbi = require("../dbi");
561
-
562
- dbi.register(({ InteractionLocale }) => {
563
- InteractionLocale({
564
- name: "cinsiyet seç",
565
- data: {
566
- en: {
567
- name: "select gender",
568
- description: "Allows you to select a gender.",
569
- options: {
570
- cinsiyet: {
571
- name: "gender",
572
- description: "Select your gender correctly.",
573
- choices: {
574
- "Erkek": "Male",
575
- "Kadın": "Female",
576
- "Diğer": "Other"
577
- }
578
- }
579
- }
580
- }
581
- }
582
- });
583
- });
584
- ```
585
-
586
- Son not: `InteractionLocale` için `name` değeri sizin tanımladığınız diğer interaksiyonlardan birinin ismi olacaktır. Örneğin `cinsiyet seç`. Data'nın yapısını en basit hale getirmeye çalıştık. ilk önce istediğiniz dili seçiyorsunuz ve sonrasında içerisini örnekteki gibi uygun bir şekilde dolduruyorsunuz. İçerisine aynı anda istediğin kadar dilde nasıl gözükeceğini ekleyebilirsiniz.
587
-
588
- Karşılacağınız hatalar ya da benzer konular için Discord üzerinden tarafıma ulaşabilirsiniz. (Armagan#4869)
589
-
590
- Unutmayın ki: "Yeryüzünde her zaman ücretsiz ve değerli bir şeyler olacaktır."
591
-
1
+ # DiscordBotInfrastructure - [English]
2
+
3
+ The most advanced, up-to-date and simple to use Discord bot infrastructure you can find on the internet.
4
+
5
+ # Usage Scenario
6
+
7
+ The MostFeatured/DiscordBotInfrastructure project is not a stand-alone project like other infrastructures you are used to, it is an NPM module. In this context, before you start using it, you need to open a folder and download the infrastructure and discord.js by entering the `npm install @mostfeatured/dbi discord.js` command.
8
+
9
+ # While Starting
10
+
11
+ First we will need `3 files` and `1 folder`. This structure can be configured completely in accordance with your working order. However, the scenario we propose is as follows.
12
+
13
+ Files and folders that need to be opened; Files `dbi.js`, `login.js`, `publish.js` and `src` folder.
14
+
15
+ As the first step, we open our file named `dbi.js` and lay the foundations of the infrastructure in it.
16
+ ```js
17
+ const { createDBI } = require("@mostfeatured/dbi");
18
+ let dbi = createDBI("xd", {
19
+ strict: true,
20
+ discord: {
21
+ token: "<yourTokenHere>",
22
+ options: {
23
+ intents: [
24
+ "Guilds"
25
+ ]
26
+ }
27
+ },
28
+ defaults: {
29
+ locale: {
30
+ name: "en"
31
+ },
32
+ defaultMemberPermissions: ["SendMessages"],
33
+ directMessages: false
34
+ },
35
+ references: {
36
+ autoClear: {
37
+ ttl: 60 * 1000 * 60,
38
+ check: 60 * 1000
39
+ }
40
+ },
41
+ // Message Commands are optional. Message Commands work trough emulating the slash commands..
42
+ messageCommands: {
43
+ prefixes: ["!", "."],
44
+ typeAliases: {
45
+ booleans: {
46
+ "true": true,
47
+ "false": false,
48
+ "yes": true,
49
+ "no": false,
50
+ }
51
+ }
52
+ }
53
+ });
54
+
55
+ dbi.events.on("messageCommandArgumentError", (data) => {
56
+ data.message.reply(`‼️ Invalid argument \`${data.error.option.name}\` (Index: \`${data.error.index}\`). Error Kind: \`${data.error.type}\`. Expected: \`${ApplicationCommandOptionType[data.error.option.type]}\`${data.error.extra ? ` with any of \`${data.error.extra.map(i => i.name).join(", ")}\`` : ""}.`);
57
+ return false;
58
+ });
59
+
60
+ module.exports = dbi;
61
+ ```
62
+
63
+ We start the infrastructure with the `createDBI()` function. The first parameter of the function is your bot's 'codeName' and the second parameter is your bot's configuration.
64
+
65
+ As the second step, we open our `login.js` file and write the code group that we will use to open the bot.
66
+ ```js
67
+ const { Utils } = require("@mostfeatured/dbi");
68
+ const dbi = require("./dbi");
69
+ (async () => {
70
+ await Utils.recursiveImport("./src");
71
+ await dbi.load();
72
+ await dbi.login();
73
+ await dbi.client.user.setActivity({
74
+ name: "MostFeatured ❤️ TheArmagan"
75
+ });
76
+ console.log(`Logged in! ${dbi.client.user.tag} (${dbi.client.user.id})`);
77
+ })();
78
+ ```
79
+
80
+ We import the `Utils.recursiveImport()` function into it. With this function we can `import`/`require` all files in `x` folder endlessly. In this way, the infrastructure is aware of these files.
81
+ We access our infrastructure from our main `dbi.js` file and create an `async` environment and first define all project files to the infrastructure. After the definition, we load all the features we have defined to the infrastructure with the `load()` function. Right after, we log in to Discord with the `login()` function.
82
+
83
+ As the 3rd step, we open our `publish.js` file and repeat all the operations we did in the second step.
84
+ ```js
85
+ const { Utils } = require("@mostfeatured/dbi");
86
+ const dbi = require("./dbi");
87
+ (async () => {
88
+ await Utils.recursiveImport("./src");
89
+ await dbi.load();
90
+ await dbi.publish("Guild", "<yourGuildId>");
91
+ // await dbi.publish("Global");
92
+ await dbi.unload();
93
+ console.log("Published!");
94
+ })();
95
+ ```
96
+
97
+ However, instead of calling the `login()` function, we call the `publish()` function and with this function we introduce the commands of our bot wherever we want.
98
+
99
+ # Fantastic!
100
+
101
+ We now have all the necessary files to use the infrastructure. (Information: If these steps that we have explained in detail are complex and difficult for you, we are sorry that this infrastructure is not suitable for you.)
102
+
103
+ # Detailed Usage Scenario
104
+
105
+ You can fully use all kinds of Discord's features with our specially developed infrastructure that fully supports v14. (`ChatInput`, `Event`, `Locale`, `Button`, `SelectMenu`, `MessageContextMenu`, `UserContextMenu`, `Modal`, `InteractionLocale`)
106
+
107
+ Now we want to show you how to define properties in infrastructure. Example: (ChatInput/Button etc.)
108
+
109
+ First, we include the relevant feature in our infrastructure.
110
+ ```js
111
+ const dbi = require("../dbi");
112
+ ```
113
+ And then we call the `register()` function on the infrastructure and put a `callback` function in it. This `callback` function presents as the first parameter everything you can define on the infrastructure as an object. You can perform the definition to the infrastructure by calling the feature function you want from this object.
114
+ ```js
115
+ dbi.register(({ ChatInput, Event }) => {
116
+ ChatInput({ ... });
117
+ Event({ ... });
118
+ })
119
+ ```
120
+ Remember, you can summon as many features as you want at the same time!
121
+
122
+ # ChatInput & ChatInputOptions
123
+
124
+ `ChatInput` is defined as "Slash Command" as you can understand.
125
+
126
+ <sub>`src/chatInput.js` file:</sub>
127
+
128
+ ```js
129
+ const dbi = require("../dbi");
130
+ const Discord = require("discord.js");
131
+
132
+ dbi.register(({ ChatInput, ChatInputOptions }) => {
133
+ ChatInput({
134
+ name: "cinsiyet seç",
135
+ description: "Cinsiyet seçmenizi sağlar.",
136
+ onExecute({ interaction, locale }) {
137
+ let gender = interaction.options.get("cinsiyet").value;
138
+ let genderNames = locale.user.data.genders;
139
+ let genderText = locale.user.data.genderText(interaction.user, genderNames[gender]());
140
+
141
+ interaction.reply({
142
+ content: genderText,
143
+ components: [
144
+ {
145
+ type: Discord.ComponentType.ActionRow,
146
+ components: [
147
+ dbi.interaction("viewGender").toJSON({ overrides: { label: locale.user.data.clickText() }, reference: { ttl: 1000 * 60 * 10, data: [gender] } }),
148
+ ]
149
+ }
150
+ ]
151
+ });
152
+ },
153
+ options: [
154
+ ChatInputOptions.stringChoices({
155
+ name: "cinsiyet",
156
+ description: "Seçeceğiniz cinsiyet.",
157
+ required: true,
158
+ choices: [
159
+ { name: "Erkek", value: "erkek" },
160
+ { name: "Kadın", value: "kadın" },
161
+ { name: "Diğer", value: "diğer" },
162
+ ]
163
+ })
164
+ ],
165
+ });
166
+ });
167
+ ```
168
+ In general, the structure of `ChatInput` may seem familiar to you, except for `options`. When you try to fill something in options directly, you will not get autocomplete. Because options expect static functions in ChatInputOptions class. The functions are similar to: `stringChoices`, `user`, `numberAutocomplete` etc.
169
+ You can also find more examples below for a sample demonstration of how the Locale and Component system we have shown above is used.
170
+
171
+ # Event
172
+
173
+ <sub>`src/event.js` file:</sub>
174
+
175
+ ```js
176
+ const dbi = require("../dbi");
177
+ dbi.register(({ Event }) => {
178
+ Event({
179
+ name: "ready",
180
+ id: "botIsReady",
181
+ onExecute() {
182
+ console.log(`Bot ready!`);
183
+ }
184
+ });
185
+ });
186
+ ```
187
+ When defining an event, you can write the name of the event you want in the `name` field. However, if you want to open more than one of the same event, you need to define an 'id' for that event.
188
+
189
+ # Locale
190
+
191
+ <sub>`src/locales.js` file:</sub>
192
+
193
+ ```js
194
+ const dbi = require("../dbi");
195
+ dbi.register(({ Locale }) => {
196
+ Locale({
197
+ name: "tr",
198
+ data: {
199
+ genders: {
200
+ erkek: "Erkek",
201
+ kadın: "Kadın",
202
+ diğer: "Diğer"
203
+ },
204
+ genderText: "{0} adlı üye {1} cinsiyetini seçti."
205
+ }
206
+ });
207
+ Locale({
208
+ name: "en",
209
+ data: {
210
+ genders: {
211
+ erkek: "Male",
212
+ kadın: "Female",
213
+ diğer: "Other"
214
+ },
215
+ genderText: "{0}, picked {1} gender."
216
+ }
217
+ });
218
+ });
219
+ ```
220
+
221
+ Thanks to Locale, there is information in each interaction that will make it easier for you to respond according to the language of the user or the server. The `name` in Locale contains the values you want to keep, and the `data` part for which language you define. The `{0}` and `{1}` signs in the text are also our variables in the text. When using locale, we can take the value we want and call it like a function. And in it we give the parameters respectively. For example `locale.data.genderText(user, gender)`.
222
+
223
+ # Button & SelectMenu & Modal
224
+
225
+ In this section, we will look at three of our features. (Actually, it's all the same feature in the background.)
226
+
227
+ <sub>`src/components.js` file:</sub>
228
+
229
+ ```js
230
+ const dbi = require("../dbi");
231
+ const Discord = require("discord.js");
232
+ dbi.register(({ Button, SelectMenu, Modal }) => {
233
+ Button({
234
+ name: "viewGender",
235
+ onExecute({ interaction, data }) {
236
+ interaction.reply(`\`${data[0]}\``);
237
+ },
238
+ options: {
239
+ style: Discord.ButtonStyle.Primary,
240
+ label: "View Gender"
241
+ }
242
+ });
243
+ });
244
+ ```
245
+ We bring you a very cool and cool feature about Button & SelectMenu & Modal. Now you can move the value you want on them. (Like Reference/Object or text/number.) For example `dbi.interaction("viewGender").toJSON("male")` will provide us a valid component powered by Discord.js. And you can reach the value presented in the json both by turning the `options` part into a function and when the interaction itself is called. There is one thing you should not forget about this subject. If you are going to carry plain text or numbers, the total length of these texts or numbers should not exceed 100 characters. Because these values ​​are carried directly on the button and they work in such a way that they remain there even if you turn the bot off and on.
246
+
247
+ # MessageContextMenu & UserContextMenu
248
+
249
+ It has exactly the same properties as `ChatInput` but does not take `options` value.
250
+
251
+ # InteractionLocale
252
+
253
+ We offer you another unique feature. You can now define a custom script language for each user.
254
+ For example, the command that appears as `/select gender` to a Turkish user may appear as `/select gender` to a foreign user. (You can configure it as you wish.)
255
+
256
+ <sub>`src/interactionlocales.js` file:</sub>
257
+
258
+ ```js
259
+ const dbi = require("../dbi");
260
+ dbi.register(({ InteractionLocale }) => {
261
+ InteractionLocale({
262
+ name: "cinsiyet seç",
263
+ data: {
264
+ en: {
265
+ name: "select gender",
266
+ description: "Allows you to select a gender.",
267
+ options: {
268
+ cinsiyet: {
269
+ name: "gender",
270
+ description: "Select your gender correctly.",
271
+ choices: {
272
+ "Erkek": "Male",
273
+ "Kadın": "Female",
274
+ "Diğer": "Other"
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+ });
281
+ });
282
+ ```
283
+
284
+ Final note: The value `name` for `InteractionLocale` will be the name of one of the other interactions you define. For example `select gender`. We tried to simplify Data's structure. First you select the language you want and then you fill in the content as in the example. You can add how it will appear in as many languages as you want at the same time.
285
+
286
+ You can contact me via Discord for errors or similar issues. (Armagan#4869)
287
+
288
+ Remember: "There will always be something free and valuable on earth."
289
+
290
+ <sub>12.09.2022: Original text written by TheArmagan, edited by Maschera. </sub>
291
+
292
+ # DiscordBotInfrastructure - [Turkish]
293
+
294
+ İnternet üzerinde bulabileceğiniz en gelişmiş, güncel ve kullanımı basit Discord bot altyapısı.
295
+
296
+ # Kullanım Senaryosu
297
+
298
+ MostFeatured/DiscordBotInfrastructure projesi diğer alışık olduğunuz altyapılar gibi kendi halinde bir proje değil, bir NPM modülüdür. Bu bağlamda kullanmaya başlamadan önce bir klasör açmanız ve içerisine `npm install @mostfeatured/dbi discord.js` komutunu girerek altyapıyı ve discord.js'i indirmeniz gerekmektedir.
299
+
300
+ # Başlarken
301
+
302
+ İlk olarak `3 dosya` ve `1 klasöre` ihitiyacımız olacak. Bu yapı tamamen sizin çalışma düzeninize uygun olarak konfigüre edilebilmektedir. Lakin bizim önerdiğimiz senaryo aşağıdaki gibidir.
303
+
304
+ Açılması gereken dosyalar ve klasörler; `dbi.js`, `login.js`, `publish.js` dosyaları ve `src` klasörü.
305
+
306
+ 1. adım olarak `dbi.js` adındaki dosyamızı açıyoruz ve içerisine altyapının temellerini atıyoruz.
307
+ ```js
308
+ const { createDBI } = require("@mostfeatured/dbi");
309
+
310
+ let dbi = createDBI("xd", {
311
+ strict: true,
312
+ discord: {
313
+ token: "<yourTokenHere>",
314
+ options: {
315
+ intents: [
316
+ "Guilds"
317
+ ]
318
+ }
319
+ },
320
+ defaults: {
321
+ locale: "en",
322
+ defaultMemberPermissions: ["SendMessages"],
323
+ directMessages: false
324
+ },
325
+ references: {
326
+ autoClear: {
327
+ ttl: 60 * 1000 * 60,
328
+ check: 60 * 1000
329
+ }
330
+ },
331
+ // Mesaj Komutları isteğe bağlıdır. Mesaj Komutları slash komutlarını taklit ederek çalışır. Yani siz sadece slash komut kodlasanız bile uyumlu olarak çalışacaktır.
332
+ messageCommands: {
333
+ prefixes: ["!", "."],
334
+ typeAliases: {
335
+ booleans: {
336
+ "true": true,
337
+ "false": false,
338
+ "yes": true,
339
+ "no": false,
340
+ }
341
+ }
342
+ }
343
+ });
344
+
345
+ dbi.events.on("messageCommandArgumentError", (data) => {
346
+ data.message.reply(`‼️ Hatalı argument \`${data.error.option.name}\` (Konum: \`${data.error.index}\`). Hata Tipi: \`${data.error.type}\`. Beklenen: \`${ApplicationCommandOptionType[data.error.option.type]}\`${data.error.extra ? ` şunlardan herhangi biri \`${data.error.extra.map(i => i.name).join(", ")}\`` : ""}.`);
347
+ return false;
348
+ });
349
+
350
+ module.exports = dbi;
351
+ ```
352
+
353
+ `createDBI()` fonksiyonu ile altyapıyı başlatıyoruz. Fonksiyonun ilk parametresi botunuzun `kodAdı`, ikinci parametresi ise botunuzun konfigürasyonudur.
354
+
355
+ 2. adım olarak `login.js` dosyamızı açıyoruz ve içerisine botu açmak için kullanacağımız kod gurubunu yazıyoruz.
356
+ ```js
357
+ const { Utils } = require("@mostfeatured/dbi");
358
+ const dbi = require("./dbi");
359
+
360
+ (async () => {
361
+ await Utils.recursiveImport("./src");
362
+
363
+ await dbi.load();
364
+ await dbi.login();
365
+
366
+ await dbi.client.user.setActivity({
367
+ name: "MostFeatured ❤️ TheArmagan"
368
+ });
369
+
370
+ console.log(`Logged in! ${dbi.client.user.tag} (${dbi.client.user.id})`);
371
+ })();
372
+ ```
373
+
374
+ İçeriye `Utils.recursiveImport()` fonksiyonunu alıyoruz. Bu fonksiyon ile sonsuz bir şekilde `x` klasöründeki bütün dosyaları `import`/`require` edebiliyoruz. Bu sayede altyapı bu dosyalardan haberdar oluyor.
375
+ Ana `dbi.js` dosyamızdan altyapımıza ulaşıyoruz ve `async` bir ortam oluşturup ilk önce tüm proje dosylarını altyapıya tanımlıyoruz. Tanımlamanın ardından tanımladığımız tüm özellikleri altyapıya `load()` fonksiyonunu ile yüklüyoruz. Hemen ardından `login()` fonksiyonu ile Discord'a giriş sağlıyoruz.
376
+
377
+
378
+ 3. adım olarak `publish.js` dosyamızı açıyoruz ve ikinci aşamada yaptığımız tüm işlemleri tekrardan uyguluyoruz.
379
+ ```js
380
+ const { Utils } = require("@mostfeatured/dbi");
381
+ const dbi = require("./dbi");
382
+
383
+ (async () => {
384
+ await Utils.recursiveImport("./src");
385
+
386
+ await dbi.load();
387
+ await dbi.publish("Guild", "<yourGuildId>");
388
+ // await dbi.publish("Global");
389
+ await dbi.unload();
390
+
391
+ console.log("Published!");
392
+ })();
393
+ ```
394
+
395
+ Ancak `login()` fonksiyonunu çağırmak yerine, `publish()` fonksiyonunu çağrıyoruz ve bu fonksiyon ile botumuzun komutlarını istediğimiz yere tanıtıyoruz.
396
+
397
+ # Harika!
398
+
399
+ Artık altyapıyı kullanabilmek için gerekli olan bütün dosyalara sahibiz. (Bilgilendirme: Detaylı bir şekilde anlattığımız bu adımlar size karmaşık ve zor geliyorsa üzgünüz ki bu altyapı size uygun değil.)
400
+
401
+ # Detaylı Kullanım Senaryosu
402
+
403
+ Özel olarak geliştirdiğimiz ve v14'ü eksiksiz bir şekilde destekleyen altyapımız ile Discord'un her türlü özelliğini tam anlamıyla kullanabiliyorsunuz. (`ChatInput`, `Event`, `Locale`, `Button`, `SelectMenu`, `MessageContextMenu`, `UserContextMenu`, `Modal`, `InteractionLocale`)
404
+
405
+ Şimdi sizlere altyapıya özellik tanımlamayı göstermek istiyoruz. Örnek: (ChatInput/Button vb.)
406
+
407
+ İlk olarak ilgili özelliği altyapımıza dahil ediyoruz.
408
+ ```js
409
+ const dbi = require("../dbi");
410
+ ```
411
+ Ve devamında altyapının üzerindeki `register()` fonksiyonunu çağırıp içerisine bir `callback` fonksiyonu koyuyoruz. Bu `callback` fonksiyonu ilk parametre olarak size altyapı üzerine tanımlayabilceğiniz tüm her şeyi bir obje olarak sunuyor. Bu obje içerisinden istediğiniz özellik fonksiyonunu çağırarak altyapıya tanımlama işlemini gerçekleştirebiliyorsunuz.
412
+ ```js
413
+ dbi.register(({ ChatInput, Event }) => {
414
+ ChatInput({ ... });
415
+ Event({ ... });
416
+ })
417
+ ```
418
+ Unutmayın ki aynı anda istediğiniz kadar özelliği çağırabilirsiniz!
419
+
420
+ # ChatInput & ChatInputOptions
421
+
422
+ `ChatInput` sizin anlayacağınız şekilde "Slash Komut" olarak tanımlanmaktadır.
423
+
424
+ <sub>`src/chatInput.js` dosyası:</sub>
425
+
426
+ ```js
427
+ const dbi = require("../dbi");
428
+ const Discord = require("discord.js");
429
+
430
+ dbi.register(({ ChatInput, ChatInputOptions }) => {
431
+ ChatInput({
432
+ name: "cinsiyet seç",
433
+ description: "Cinsiyet seçmenizi sağlar.",
434
+ onExecute({ interaction, locale }) {
435
+ let gender = interaction.options.get("cinsiyet").value;
436
+ let genderNames = locale.user.data.genders;
437
+ let genderText = locale.user.data.genderText(interaction.user, genderNames[gender]());
438
+ interaction.reply({
439
+ content: genderText,
440
+ components: [
441
+ {
442
+ type: Discord.ComponentType.ActionRow,
443
+ components: [
444
+ dbi.interaction("viewGender").toJSON({ overrides: { label: locale.user.data.clickText() }, reference: { ttl: 1000 * 60 * 10, data: [gender] } }),
445
+ ]
446
+ }
447
+ ]
448
+ });
449
+ },
450
+ options: [
451
+ ChatInputOptions.stringChoices({
452
+ name: "cinsiyet",
453
+ description: "Seçeceğiniz cinsiyet.",
454
+ required: true,
455
+ choices: [
456
+ { name: "Erkek", value: "erkek" },
457
+ { name: "Kadın", value: "kadın" },
458
+ { name: "Diğer", value: "diğer" },
459
+ ]
460
+ })
461
+ ],
462
+ });
463
+ });
464
+ ```
465
+ Genel olarak `ChatInput`'un yapısı gözünüze `options` dışında tanıdık gelmiş olabilir. Direkt olarak options içerisine bir şey doldurmaya çalıştığınızda otomatik tamamlama alamayacaksınız. Çünkü options içerisinde ChatInputOptions class'ındaki statik fonksiyonlardan beklemekte. Fonksiyonlar ise şunlara benzemekte; `stringChoices`, `user`, `numberAutocomplete` vb.
466
+ Ayrıca yukarıda göstermiş olduğumuz Locale ve Component sisteminin nasıl kullanıldığıyla ilgili örnek gösterim için aşağıdan daha fazla örneğe ulaşabilirsiniz.
467
+
468
+ # Event
469
+
470
+ <sub>`src/event.js` dosyası:</sub>
471
+
472
+ ```js
473
+ const dbi = require("../dbi");
474
+
475
+ dbi.register(({ Event }) => {
476
+ Event({
477
+ name: "ready",
478
+ id: "botIsReady",
479
+ onExecute() {
480
+ console.log(`Bot ready!`);
481
+ }
482
+ });
483
+ });
484
+ ```
485
+ Event yani olay tanımlarken `name` kısmına istediğiniz olayın ismini yazabilirsiniz. Ancak eğer aynı olaydan birden fazla açmak istiyorsanız o olaya bir `id` tanımlamanız gerekmektedir.
486
+
487
+ # Locale
488
+
489
+ <sub>`src/locales.js` dosyası:</sub>
490
+
491
+ ```js
492
+ const dbi = require("../dbi");
493
+
494
+ dbi.register(({ Locale }) => {
495
+ Locale({
496
+ name: "tr",
497
+ data: {
498
+ genders: {
499
+ erkek: "Erkek",
500
+ kadın: "Kadın",
501
+ diğer: "Diğer"
502
+ },
503
+ genderText: "{0} adlı üye {1} cinsiyetini seçti."
504
+ }
505
+ });
506
+
507
+ Locale({
508
+ name: "en",
509
+ data: {
510
+ genders: {
511
+ erkek: "Male",
512
+ kadın: "Female",
513
+ diğer: "Other"
514
+ },
515
+ genderText: "{0}, picked {1} gender."
516
+ }
517
+ });
518
+ });
519
+ ```
520
+
521
+ Locale sayesinde her interaksiyon içerisinde kullanıcının veya sunucunun diline göre cevap vermenizi kolaylaştıracak bilgiler bulunmakta. Locale içerisindeki `name` hangi dil için tanımlama yaptığınız `data` kısmı ise tutmak istediğiniz değerleri içermekte. Yazı içerisindeki `{0}` ve `{1}` işaretleri aynı şekilde yazı içerisindeki değişkenlerimiz. Locale kullanırken istediğimiz değeri alıp onu bir fonksiyon gibi çağırabiliyoruz. Ve içerisine sırasıyla parametreleri veriyoruz. Örneğin `locale.data.genderText(user, gender)`.
522
+
523
+ # Button & SelectMenu & Modal
524
+
525
+ Bu bölümde ise üç adet özelliğimize bakacağız. (Aslında arka planda hepsi aynı özellik.)
526
+
527
+ <sub>`src/components.js` dosyası:</sub>
528
+
529
+ ```js
530
+ const dbi = require("../dbi");
531
+ const Discord = require("discord.js");
532
+
533
+ dbi.register(({ Button, SelectMenu, Modal }) => {
534
+ Button({
535
+ name: "viewGender",
536
+ onExecute({ interaction, data }) {
537
+ interaction.reply(`\`${data[0]}\``);
538
+ },
539
+ options: {
540
+ style: Discord.ButtonStyle.Primary,
541
+ label: "View Gender"
542
+ }
543
+ });
544
+ });
545
+ ```
546
+ Button & SelectMenu & Modal hakkında çok güzel ve havalı bir özelliği sizlerle buluşturuyoruz. Artık bunların üzerinde istediğiniz değeri taşıyabilirsiniz. (Referans/Obje veya yazı/sayı gibi.) Örneğin `dbi.interaction("viewGender").toJSON("male")` bize Discord.js tarafından desteklenen geçerli bir component sunacaktır. Ve to json içerisinde sunulan değere hem `options` kısmını bir fonksiyona çevirerek ulaşabilir hem de interaksiyonun kendisi çağırıldığında ulaşabilirsiniz. Bu konuyla ilgili unutmamanız gereken bir şey var. Eğer düz yazı veya sayı taşıyacaksanız bu yazı veya sayıların toplam uzunluğu 100 karakteri geçmemeli. Çünkü bu değerler direkt olarak düğmenin üzerinde taşınmakta ve siz botu kapatıp açsanız bile orada kalacak şekilde çalışmaktadırlar.
547
+
548
+ # MessageContextMenu & UserContextMenu
549
+
550
+ `ChatInput` ile birebir aynı özelliklere sahip ancak `options` değeri almamaktadır.
551
+
552
+ # InteractionLocale
553
+
554
+ Bir eşsiz özelliği daha sizlere sunuyoruz. Artık her kullanıcıya özel komut dili tanımlamanızı sağlayabilirsiniz.
555
+ Örneğin Türk bir kullanıcıya `/cinsiyet seç` şeklinde gözüken komut yabancı bir kullanıcıya `/select gender` olarak gözükebilir. (Dilediğiniz gibi konfigüre edebilirsiniz.)
556
+
557
+ <sub>`src/interactionlocales.js` dosyası:</sub>
558
+
559
+ ```js
560
+ const dbi = require("../dbi");
561
+
562
+ dbi.register(({ InteractionLocale }) => {
563
+ InteractionLocale({
564
+ name: "cinsiyet seç",
565
+ data: {
566
+ en: {
567
+ name: "select gender",
568
+ description: "Allows you to select a gender.",
569
+ options: {
570
+ cinsiyet: {
571
+ name: "gender",
572
+ description: "Select your gender correctly.",
573
+ choices: {
574
+ "Erkek": "Male",
575
+ "Kadın": "Female",
576
+ "Diğer": "Other"
577
+ }
578
+ }
579
+ }
580
+ }
581
+ }
582
+ });
583
+ });
584
+ ```
585
+
586
+ Son not: `InteractionLocale` için `name` değeri sizin tanımladığınız diğer interaksiyonlardan birinin ismi olacaktır. Örneğin `cinsiyet seç`. Data'nın yapısını en basit hale getirmeye çalıştık. ilk önce istediğiniz dili seçiyorsunuz ve sonrasında içerisini örnekteki gibi uygun bir şekilde dolduruyorsunuz. İçerisine aynı anda istediğin kadar dilde nasıl gözükeceğini ekleyebilirsiniz.
587
+
588
+ Karşılacağınız hatalar ya da benzer konular için Discord üzerinden tarafıma ulaşabilirsiniz. (Armagan#4869)
589
+
590
+ Unutmayın ki: "Yeryüzünde her zaman ücretsiz ve değerli bir şeyler olacaktır."
591
+
592
592
  <sub>12.09.2022: Orjinal metin TheArmagan tarafından yazıldı, Maschera tarafından düzenlendi. </sub>