js-discord-modularcommand 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,179 +4,22 @@
4
4
  * @description A module for creating and managing modular commands in a easy way for me.
5
5
  * @license MIT
6
6
  */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
7
10
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.LOCALE_ERROR = exports.LOCALE_NSFW = exports.LOCALE_DELAY = exports.LOCALE_FORBIDDEN = exports.ModularModal = exports.ModularButton = exports.ModularCommand = exports.RegisterCommand = void 0;
9
11
  /**
10
12
  * Imports
11
13
  */
12
14
  const discord_js_1 = require("discord.js");
15
+ const modularmodal_js_1 = __importDefault(require("./modularmodal.js"));
16
+ const modularbutton_js_1 = __importDefault(require("./modularbutton.js"));
13
17
  /**
14
- * Localization Phrases
15
- */
16
- /**
17
- * @description Localization phrases for various commands.
18
- * @example
19
- * const example = LOCALE_FORBIDDEN[Locale.EnglishUS];
20
- * console.log(example); // 'You do not have permission to use this command.'
21
- */
22
- const LOCALE_FORBIDDEN = {
23
- [discord_js_1.Locale.SpanishLATAM]: 'No tienes permiso para usar este comando.',
24
- [discord_js_1.Locale.EnglishUS]: 'You do not have permission to use this command.',
25
- [discord_js_1.Locale.EnglishGB]: 'I say, it appears you lack the proper authorisation to utilise this command, old bean.',
26
- [discord_js_1.Locale.SpanishES]: 'Ostias chaval, tio parece que no vais a poder usar este comando madre mia willy, que barbaridad.',
27
- [discord_js_1.Locale.PortugueseBR]: 'Você não tem permissão para usar este comando.',
28
- [discord_js_1.Locale.French]: 'Vous n\'avez pas la permission d\'utiliser cette commande.',
29
- [discord_js_1.Locale.German]: 'Du hast keine Berechtigung, diesen Befehl zu verwenden.',
30
- [discord_js_1.Locale.Italian]: 'Non hai il permesso di usare questo comando.',
31
- [discord_js_1.Locale.Russian]: 'У вас нет разрешения на использование этой команды.',
32
- [discord_js_1.Locale.ChineseCN]: '您没有权限使用此命令。',
33
- [discord_js_1.Locale.ChineseTW]: '您沒有權限使用此命令。',
34
- [discord_js_1.Locale.Japanese]: 'このコマンドを使用する権限がありません。',
35
- [discord_js_1.Locale.Korean]: '이 명령을 사용할 권한이 없습니다.',
36
- [discord_js_1.Locale.Bulgarian]: 'Нямате разрешение да използвате тази команда.',
37
- [discord_js_1.Locale.Czech]: 'Nemáte oprávnění k použití tohoto příkazu.',
38
- [discord_js_1.Locale.Danish]: 'Du har ikke tilladelse til at bruge denne kommando.',
39
- [discord_js_1.Locale.Dutch]: 'Je hebt geen toestemming om deze opdracht te gebruiken.',
40
- [discord_js_1.Locale.Finnish]: 'Sinulla ei ole lupaa käyttää tätä komentoa.',
41
- [discord_js_1.Locale.Hungarian]: 'Nincs jogosultságod ehhez a parancshoz.',
42
- [discord_js_1.Locale.Norwegian]: 'Du har ikke tillatelse til å bruke denne kommandoen.',
43
- [discord_js_1.Locale.Polish]: 'Nie masz uprawnień do używania tej komendy.',
44
- [discord_js_1.Locale.Romanian]: 'Nu ai permisiunea de a folosi acest comandă.',
45
- [discord_js_1.Locale.Swedish]: 'Du har inte behörighet att använda det här kommandot.',
46
- [discord_js_1.Locale.Turkish]: 'Bu komutu kullanma izniniz yok.',
47
- [discord_js_1.Locale.Ukrainian]: 'У вас немає дозволу на використання цієї команди.',
48
- [discord_js_1.Locale.Hindi]: 'आपको इस कमांड का उपयोग करने की अनुमति नहीं है।',
49
- [discord_js_1.Locale.Indonesian]: 'Anda tidak memiliki izin untuk menggunakan perintah ini.',
50
- [discord_js_1.Locale.Greek]: 'Δεν έχετε άδεια να χρησιμοποιήσετε αυτήν την εντολή.',
51
- [discord_js_1.Locale.Croatian]: 'Nemate dopuštenje za korištenje ove naredbe.',
52
- [discord_js_1.Locale.Lithuanian]: 'Jūs neturite teisės naudoti šio komandos.',
53
- [discord_js_1.Locale.Thai]: 'คุณไม่มีสิทธิ์ใช้คำสั่งนี้.',
54
- [discord_js_1.Locale.Vietnamese]: 'Bạn không có quyền sử dụng lệnh này.'
55
- };
56
- exports.LOCALE_FORBIDDEN = LOCALE_FORBIDDEN;
57
- /**
58
- * @description Localization phrases for NSFW commands.
59
- * @example
60
- * const example = LOCALE_NSFW[Locale.EnglishUS];
61
- * console.log(example); // 'This command can only be used in NSFW channels.'
18
+ * Interface
62
19
  */
63
- const LOCALE_NSFW = {
64
- [discord_js_1.Locale.SpanishLATAM]: 'Este comando solo puede ser usado en canales NSFW.',
65
- [discord_js_1.Locale.EnglishUS]: 'This command can only be used in NSFW channels.',
66
- [discord_js_1.Locale.EnglishGB]: 'I do declare, this command is exclusively for channels of a... risqué nature. little bit of cheeky fun, eh?',
67
- [discord_js_1.Locale.SpanishES]: '¡Ostias, chaval! Que este comando es solo para los canales más guarros, ¿vale? No me seas meapilas.',
68
- [discord_js_1.Locale.PortugueseBR]: 'Este comando só pode ser usado em canais NSFW.',
69
- [discord_js_1.Locale.French]: 'Cette commande ne peut être utilisée que dans les salons NSFW.',
70
- [discord_js_1.Locale.German]: 'Dieser Befehl kann nur in NSFW-Kanälen verwendet werden.',
71
- [discord_js_1.Locale.Italian]: 'Questo comando può essere utilizzato solo nei canali NSFW.',
72
- [discord_js_1.Locale.Russian]: 'Эту команду можно использовать только в каналах NSFW.',
73
- [discord_js_1.Locale.ChineseCN]: '此命令只能在NSFW频道中使用。',
74
- [discord_js_1.Locale.ChineseTW]: '此命令只能在 NSFW 頻道中使用。',
75
- [discord_js_1.Locale.Japanese]: 'このコマンドはNSFWチャンネルでのみ使用できます。',
76
- [discord_js_1.Locale.Korean]: '이 명령어는 NSFW 채널에서만 사용할 수 있습니다.',
77
- [discord_js_1.Locale.Bulgarian]: 'Тази команда може да се използва само в NSFW канали.',
78
- [discord_js_1.Locale.Czech]: 'Tento příkaz lze použít pouze v kanálech NSFW.',
79
- [discord_js_1.Locale.Danish]: 'Denne kommando kan kun bruges i NSFW-kanaler.',
80
- [discord_js_1.Locale.Dutch]: 'Deze opdracht kan alleen worden gebruikt in NSFW-kanalen.',
81
- [discord_js_1.Locale.Finnish]: 'Tätä komentoa voi käyttää vain NSFW-kanavilla.',
82
- [discord_js_1.Locale.Hungarian]: 'Ez a parancs csak NSFW csatornákon használható.',
83
- [discord_js_1.Locale.Norwegian]: 'Denne kommandoen kan bare brukes i NSFW-kanaler.',
84
- [discord_js_1.Locale.Polish]: 'Ta komenda może być używana tylko na kanałach NSFW.',
85
- [discord_js_1.Locale.Romanian]: 'Această comandă poate fi utilizată numai în canalele NSFW.',
86
- [discord_js_1.Locale.Swedish]: 'Det här kommandot kan endast användas i NSFW-kanaler.',
87
- [discord_js_1.Locale.Turkish]: 'Bu komut yalnızca NSFW kanallarında kullanılabilir.',
88
- [discord_js_1.Locale.Ukrainian]: 'Цю команду можна використовувати лише в каналах NSFW.',
89
- [discord_js_1.Locale.Hindi]: 'यह कमांड केवल NSFW चैनलों में ही उपयोग की जा सकती है।',
90
- [discord_js_1.Locale.Indonesian]: 'Perintah ini hanya dapat digunakan di saluran NSFW.',
91
- [discord_js_1.Locale.Greek]: 'Αυτή η εντολή μπορεί να χρησιμοποιηθεί μόνο σε κανάλια NSFW.',
92
- [discord_js_1.Locale.Croatian]: 'Ova se naredba može koristiti samo u NSFW kanalima.',
93
- [discord_js_1.Locale.Lithuanian]: 'Ši komanda gali būti naudojama tik NSFW kanaluose.',
94
- [discord_js_1.Locale.Thai]: 'คำสั่งนี้สามารถใช้ได้เฉพาะในช่องทาง NSFW เท่านั้น.',
95
- [discord_js_1.Locale.Vietnamese]: 'Lệnh này chỉ có thể được sử dụng trong các kênh NSFW.'
96
- };
97
- exports.LOCALE_NSFW = LOCALE_NSFW;
98
20
  /**
99
- * @description Localization phrases for delay commands.
100
- * @example
101
- * const example = LOCALE_DELAY[Locale.EnglishUS];
102
- * const secondsPluralRegEx = new RegExp('{plural\\|([^}]+)}', 'g');
103
- * const seconds = 5;
104
- * const formattedPhrase = example
105
- * .replace('{seconds}', seconds.toString())
106
- * .replace(secondsPluralRegEx, seconds === 1 ? '' : '$1');
107
- *
108
- * console.log(formattedPhrase); // 'You must wait 5 seconds before using this command again.'
21
+ * @description Represents a command option for a modular command.
109
22
  */
110
- const LOCALE_DELAY = {
111
- [discord_js_1.Locale.SpanishLATAM]: 'Debes esperar {seconds} segundo{plural|s} antes de utilizar este comando denuevo.',
112
- [discord_js_1.Locale.EnglishUS]: 'You must wait {seconds} second{plural|s} before using this command again.',
113
- [discord_js_1.Locale.EnglishGB]: 'I do declare, you must wait {seconds} second{plural|s} before using this command again.',
114
- [discord_js_1.Locale.SpanishES]: '¡Ostias, chaval! Debes esperar {seconds} segundo{plural|s} antes de utilizar este comando denuevo.',
115
- [discord_js_1.Locale.PortugueseBR]: 'Você deve esperar {seconds} segundo{plural|s} antes de usar este comando novamente.',
116
- [discord_js_1.Locale.French]: 'Vous devez attendre {seconds} seconde{plural|s} avant d\'utiliser cette commande à nouveau.',
117
- [discord_js_1.Locale.German]: 'Sie müssen {seconds} Sekunde{plural|n} warten, bevor Sie diesen Befehl erneut verwenden können.',
118
- [discord_js_1.Locale.Italian]: 'Devi aspettare {seconds} secondo{plural|i} prima di utilizzare di nuovo questo comando.',
119
- [discord_js_1.Locale.Russian]: 'Вы должны подождать {seconds} секунду{plural|ы} перед повторным использованием этой команды.',
120
- [discord_js_1.Locale.ChineseCN]: '您必须等待 {seconds} 秒钟{plural|s}才能再次使用此命令。',
121
- [discord_js_1.Locale.ChineseTW]: '您必須等待 {seconds} 秒鐘{plural|s}才能再次使用此命令。',
122
- [discord_js_1.Locale.Japanese]: 'このコマンドを再度使用するには、{seconds} 秒待つ必要があります。',
123
- [discord_js_1.Locale.Korean]: '이 명령어를 다시 사용하려면 {seconds} 초 기다려야 합니다.',
124
- [discord_js_1.Locale.Bulgarian]: 'Трябва да изчакате {seconds} секунда{plural|и}, преди да използвате тази команда отново.',
125
- [discord_js_1.Locale.Czech]: 'Musíte počkat {seconds} sekundu{plural|y}, než znovu použijete tento příkaz.',
126
- [discord_js_1.Locale.Danish]: 'Du skal vente {seconds} sekund{plural|er} før du kan bruge denne kommando igen.',
127
- [discord_js_1.Locale.Dutch]: 'Je moet {seconds} seconde{plural|n} wachten voordat je dit commando opnieuw kunt gebruiken.',
128
- [discord_js_1.Locale.Finnish]: 'Sinun on odotettava {seconds} sekuntia ennen kuin voit käyttää tätä komentoa uudelleen.',
129
- [discord_js_1.Locale.Hungarian]: 'Várnod kell {seconds} másodpercet, mielőtt újra használhatod ezt a parancsot.',
130
- [discord_js_1.Locale.Norwegian]: 'Du må vente {seconds} sekund{plural|er} før du kan bruke denne kommandoen igjen.',
131
- [discord_js_1.Locale.Polish]: 'Musisz poczekać {seconds} sekund{plural|y}, zanim ponownie użyjesz tego polecenia.',
132
- [discord_js_1.Locale.Romanian]: 'Trebuie să aștepți {seconds} secundă{plural|e} înainte de a folosi din nou acest comandă.',
133
- [discord_js_1.Locale.Swedish]: 'Du måste vänta {seconds} sekund{plural|er} innan du kan använda det här kommandot igen.',
134
- [discord_js_1.Locale.Turkish]: 'Bu komutu tekrar kullanmadan önce {seconds} saniye beklemelisiniz.',
135
- [discord_js_1.Locale.Ukrainian]: 'Вам потрібно почекати {seconds} секунду{plural|и}, перш ніж знову використовувати цю команду.',
136
- [discord_js_1.Locale.Hindi]: 'आपको इस कमांड का उपयोग करने से पहले {seconds} सेकंड{plural|s} इंतजार करना होगा।',
137
- [discord_js_1.Locale.Indonesian]: 'Anda harus menunggu {seconds} detik{plural|s} sebelum menggunakan perintah ini lagi.',
138
- [discord_js_1.Locale.Greek]: 'Πρέπει να περιμένετε {seconds} δευτερόλεπτο{plural|α} πριν χρησιμοποιήσετε ξανά αυτήν την εντολή.',
139
- [discord_js_1.Locale.Croatian]: 'Morate pričekati {seconds} sekundu{plural|e} prije nego što ponovno upotrijebite ovu naredbu.',
140
- [discord_js_1.Locale.Lithuanian]: 'Prieš vėl naudodamiesi šiuo komandu, turite palaukti {seconds} sekundę{plural|es}.',
141
- [discord_js_1.Locale.Thai]: 'คุณต้องรอ {seconds} วินาที{plural|s} ก่อนที่จะใช้คำสั่งนี้อีกครั้ง',
142
- [discord_js_1.Locale.Vietnamese]: 'Bạn phải đợi {seconds} giây{plural|s} trước khi sử dụng lại lệnh này.'
143
- };
144
- exports.LOCALE_DELAY = LOCALE_DELAY;
145
- const LOCALE_ERROR = {
146
- [discord_js_1.Locale.SpanishLATAM]: 'Ocurrió un error al procesar tu solicitud.',
147
- [discord_js_1.Locale.EnglishUS]: 'An error occurred while processing your request.',
148
- [discord_js_1.Locale.EnglishGB]: 'I do declare, an error occurred while processing your request.',
149
- [discord_js_1.Locale.SpanishES]: 'Pero que me estás contando, willy, ocurrió un error al procesar tu solicitud.',
150
- [discord_js_1.Locale.PortugueseBR]: 'Ocorreu um erro ao processar sua solicitação.',
151
- [discord_js_1.Locale.French]: 'Une erreur est survenue lors du traitement de votre demande.',
152
- [discord_js_1.Locale.German]: 'Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten.',
153
- [discord_js_1.Locale.Italian]: 'Si è verificato un errore durante l\'elaborazione della tua richiesta.',
154
- [discord_js_1.Locale.Russian]: 'Произошла ошибка при обработке вашего запроса.',
155
- [discord_js_1.Locale.ChineseCN]: '处理您的请求时发生错误。',
156
- [discord_js_1.Locale.ChineseTW]: '處理您的請求時發生錯誤。',
157
- [discord_js_1.Locale.Japanese]: 'リクエストの処理中にエラーが発生しました。',
158
- [discord_js_1.Locale.Korean]: '요청을 처리하는 동안 오류가 발생했습니다.',
159
- [discord_js_1.Locale.Bulgarian]: 'При обработката на заявката ви възникна грешка.',
160
- [discord_js_1.Locale.Czech]: 'Při zpracování vaší žádosti došlo k chybě.',
161
- [discord_js_1.Locale.Danish]: 'Der opstod en fejl under behandlingen af din anmodning.',
162
- [discord_js_1.Locale.Dutch]: 'Er is een fout opgetreden bij het verwerken van uw verzoek.',
163
- [discord_js_1.Locale.Finnish]: 'Pyyntösi käsittelyssä tapahtui virhe.',
164
- [discord_js_1.Locale.Hungarian]: 'A kérésed feldolgozása során hiba lépett fel.',
165
- [discord_js_1.Locale.Norwegian]: 'Det oppstod en feil under behandling av forespørselen din.',
166
- [discord_js_1.Locale.Polish]: 'Wystąpił błąd podczas przetwarzania twojej prośby.',
167
- [discord_js_1.Locale.Romanian]: 'A apărut o eroare în timpul procesării cererii tale.',
168
- [discord_js_1.Locale.Swedish]: 'Ett fel inträffade vid behandling av din begäran.',
169
- [discord_js_1.Locale.Turkish]: 'Talebiniz işlenirken bir hata oluştu.',
170
- [discord_js_1.Locale.Ukrainian]: 'Під час обробки вашого запиту сталася помилка.',
171
- [discord_js_1.Locale.Hindi]: 'आपके अनुरोध को संसाधित करते समय एक त्रुटि हुई।',
172
- [discord_js_1.Locale.Indonesian]: 'Terjadi kesalahan saat memproses permintaan Anda.',
173
- [discord_js_1.Locale.Greek]: 'Συνέβη σφάλμα κατά την επεξεργασία του αιτήματός σας.',
174
- [discord_js_1.Locale.Croatian]: 'Došlo je do pogreške prilikom obrade vašeg zahtjeva.',
175
- [discord_js_1.Locale.Lithuanian]: 'Apdorojant jūsų užklausą įvyko klaida.',
176
- [discord_js_1.Locale.Thai]: 'เกิดข้อผิดพลาดระหว่างการประมวลผลคำขอของคุณ',
177
- [discord_js_1.Locale.Vietnamese]: 'Đã xảy ra lỗi trong quá trình xử lý yêu cầu của bạn.'
178
- };
179
- exports.LOCALE_ERROR = LOCALE_ERROR;
180
23
  /**
181
24
  * Variables
182
25
  */
@@ -189,106 +32,32 @@ const ALLOWED_OPTION_TYPE = [
189
32
  discord_js_1.ApplicationCommandOptionType.Channel,
190
33
  ];
191
34
  /**
192
- * @class ModularButton
193
- * @description Represents a modular button that can be registered with Discord.js.
194
- * It allows for dynamic button creation and execution.
195
- */
196
- class ModularButton {
197
- /**
198
- * Creates a new button for the command.
199
- * @param {string} customId The custom ID for the button.
200
- * @param {ButtonStyle} style The style of the button.
201
- */
202
- constructor(customId, style) {
203
- this.execute = async () => { };
204
- this.buttonObject = new discord_js_1.ButtonBuilder();
205
- this.buttonObject.setCustomId(customId);
206
- this.buttonObject.setStyle(style);
207
- this.customId = customId;
208
- this.style = style;
209
- }
210
- /**
211
- * Sets the execute function for the button.
212
- * @param {ButtonExecuteFunction} executeFunction The function to execute.
213
- * @return {ModularButton} The button instance for chaining.
214
- */
215
- setExecute(executeFunction) {
216
- this.execute = executeFunction;
217
- return this;
218
- }
219
- }
220
- exports.ModularButton = ModularButton;
221
- /**
222
- * @class ModularModal
223
- * @description Represents a modular modal that can be registered with Discord.js.
224
- * It allows for dynamic modal creation and execution.
225
- */
226
- class ModularModal {
227
- /**
228
- * Creates a new modal for the command.
229
- * @param {string} modalId The ID for the modal.
230
- * @param {ModularCommand} command The command that this modal belongs to.
231
- */
232
- constructor(modalId, command) {
233
- this.execute = async () => { };
234
- this.modalObject = new discord_js_1.ModalBuilder();
235
- this.modalObject.setCustomId(modalId);
236
- this.modalId = modalId;
237
- this.modalInputs = new Map();
238
- this.command = command;
239
- }
240
- /**
241
- * Sets the execute function for the modal.
242
- * @param {ModalExecuteFunction} executeFunction The function to execute.
243
- * @returns {ModularModal} The modal instance for chaining.
244
- */
245
- setExecute(executeFunction) {
246
- this.execute = executeFunction;
247
- return this;
248
- }
249
- /**
250
- * Creates a new text input for the modal.
251
- * @param {string} id The ID for the text input.
252
- * @param {TextInputStyle} style The style of the text input.
253
- * @returns {TextInputBuilder} The created text input instance.
254
- */
255
- newTextInput(id, style) {
256
- const textInput = new discord_js_1.TextInputBuilder();
257
- textInput.setCustomId(id);
258
- textInput.setStyle(style);
259
- this.modalInputs.set(id, textInput);
260
- this.modalObject.addComponents(new discord_js_1.ActionRowBuilder().addComponents(textInput));
261
- return textInput;
262
- }
263
- /**
264
- * Builds the modal object.
265
- * @param {Record<string, any>} locale The localization object for the modal.
266
- * @return {ModalBuilder} The built modal object.
267
- */
268
- build(locale) {
269
- const selfModal = this.modalObject;
270
- const commandName = this.command.name;
271
- selfModal.setTitle(locale[`${commandName}.${this.modalId}.title`]);
272
- this.modalInputs.forEach((input, id) => {
273
- input.setLabel(locale[`${commandName}.${id}.label`]);
274
- input.setPlaceholder(locale[`${commandName}.${id}.placeholder`]);
275
- });
276
- return selfModal;
277
- }
278
- }
279
- exports.ModularModal = ModularModal;
280
- /**
281
- * @class ModularCommand
282
35
  * @description Represents a modular command that can be registered with Discord.js.
283
36
  * It allows for dynamic command creation and execution.
37
+ * @example
38
+ * const { ModularCommand, RegisterCommand } = require('js-discord-modularcommand');
39
+ *
40
+ * const PingCommand = new ModularCommand('ping');
41
+ * PingCommand.setDescription('Sends a ping message.');
42
+ * PingCommand.setExecute(async ({interaction}) => {
43
+ * await interaction.reply('Pong!');
44
+ * });
45
+ *
46
+ * PingCommand.setPermissionCheck(({ interaction }) => {
47
+ * return interaction.member.permissions.has(PermissionFlagsBits.Administrator);
48
+ * });
49
+ *
50
+ * module.exports = RegisterCommand([
51
+ * PingCommand
52
+ * ]);
284
53
  */
285
54
  class ModularCommand {
286
- constructor({ name, description, execute, componentExecute, modalExecute }) {
55
+ constructor(name) {
287
56
  this.name = name;
288
- this.description = description || '';
289
- this.execute = execute || (async () => { });
290
- this.componentExecute = componentExecute;
291
- this.modalExecute = modalExecute;
57
+ this.description = '';
58
+ this.execute = async () => { };
59
+ this.componentExecute = undefined;
60
+ this.modalExecute = undefined;
292
61
  this.options = [];
293
62
  this.optionsLocalizations = {};
294
63
  this.customIdHandlers = {};
@@ -323,7 +92,7 @@ class ModularCommand {
323
92
  }
324
93
  /**
325
94
  * Sets the localization phrases for the command.
326
- * @param {Record<Locale, any>} localizationPhrases The localization phrases.
95
+ * @param {Record<Locale, string>} localizationPhrases The localization phrases.
327
96
  * @returns {ModularCommand} The command instance for chaining.
328
97
  */
329
98
  setLocalizationPhrases(localizationPhrases) {
@@ -332,7 +101,7 @@ class ModularCommand {
332
101
  }
333
102
  /**
334
103
  * Sets the execute function for the command.
335
- * @param {ExecuteFunction<CommandInteraction>} executeFunction The function to execute.
104
+ * @param {CommandExecuteFunction} executeFunction The function to execute.
336
105
  * @returns {ModularCommand} The command instance for chaining.
337
106
  */
338
107
  setExecute(executeFunction) {
@@ -342,7 +111,7 @@ class ModularCommand {
342
111
  /**
343
112
  * Sets the component execute function for the command.
344
113
  * @param {string} componentId The base ID for the components.
345
- * @param {ExecuteFunction<MessageComponentInteraction>} executeFunction The function to execute for component interactions.
114
+ * @param {ComponentExecuteFunction} executeFunction The function to execute for component interactions.
346
115
  * @returns {ModularCommand} The command instance for chaining.
347
116
  */
348
117
  setComponentExecute(componentId, executeFunction) {
@@ -350,28 +119,6 @@ class ModularCommand {
350
119
  this.componentExecute = executeFunction;
351
120
  return this;
352
121
  }
353
- /**
354
- * Creates a new modal for the command.
355
- * @param {string} modalId The ID for the modal.
356
- * @returns {ModularModal} The created modal instance.
357
- */
358
- newModal(modalId) {
359
- const modal = new ModularModal(modalId, this);
360
- this.modals.set(modalId, modal);
361
- return modal;
362
- }
363
- /**
364
- * Creates a new button for the command.
365
- * @param {string} customId The custom ID for the button.
366
- * @param {ButtonStyle} style The style of the button.
367
- * @return {ModularButton} The created button instance.
368
- */
369
- newButton(customId, style) {
370
- const button = new ModularButton(customId, style);
371
- this.buttons.set(customId, button);
372
- this.buttonsArray.push(button);
373
- return button;
374
- }
375
122
  /**
376
123
  * Set the minimun permissions required to execute the command.
377
124
  * @param {PermissionCheckFunction} permissionCheckFunction The function to check permissions.
@@ -412,191 +159,34 @@ class ModularCommand {
412
159
  /**
413
160
  * Adds a custom ID handler for the command.
414
161
  * @param {string} customId The custom ID to match.
415
- * @param {ExecuteFunction<CommandInteraction<CacheType>>} handlerFunction The function to execute when the custom ID matches.
162
+ * @param {CommandInteraction<CacheType>} handlerFunction The function to execute when the custom ID matches.
416
163
  * @returns {ModularCommand} The command instance for chaining.
417
164
  */
418
165
  addCustomIDHandler(customId, handlerFunction) {
419
166
  this.customIdHandlers[customId] = handlerFunction;
420
167
  return this;
421
168
  }
169
+ /**
170
+ * Creates a new modal for the command.
171
+ * @param {string} modalId The ID for the modal.
172
+ * @returns {ModularModal} The created modal instance.
173
+ */
174
+ addModal(modalId) {
175
+ const modal = new modularmodal_js_1.default(modalId, this);
176
+ this.modals.set(modalId, modal);
177
+ return modal;
178
+ }
179
+ /**
180
+ * Creates a new button for the command.
181
+ * @param {string} customId The custom ID for the button.
182
+ * @param {ButtonStyle} style The style of the button.
183
+ * @return {ModularButton} The created button instance.
184
+ */
185
+ addButton(customId, style) {
186
+ const button = new modularbutton_js_1.default(customId, style);
187
+ this.buttons.set(customId, button);
188
+ this.buttonsArray.push(button);
189
+ return button;
190
+ }
422
191
  }
423
- exports.ModularCommand = ModularCommand;
424
- /**
425
- * Registers an array of modular commands.
426
- * @param {ModularCommand[]} commands An array of ModularCommand instances.
427
- * @returns {RegisteredCommand[]} An array of command data objects ready for Discord.js client.
428
- */
429
- const RegisterCommand = (commands) => {
430
- return commands.map(command => {
431
- const commandBuilder = new discord_js_1.SlashCommandBuilder()
432
- .setName(command.name)
433
- .setDescription(command.description)
434
- .setDescriptionLocalizations(command.descriptionLocalizations || null);
435
- const options = {};
436
- command.options.forEach(opt => {
437
- const description = typeof opt.description === 'string' ?
438
- opt.description :
439
- (opt.description[discord_js_1.Locale.EnglishUS] || `The description for ${opt.name} in English.`);
440
- const descriptionsLocalizations = typeof opt.description === 'object' ? opt.description : {};
441
- if (!description) {
442
- throw new Error(`Option '${opt.name}' is missing a description.`);
443
- }
444
- options[opt.name] = opt.type;
445
- const optionBuilder = (option) => {
446
- option.setName(opt.name)
447
- .setDescription(description)
448
- .setRequired(opt.required || false)
449
- .setDescriptionLocalizations(descriptionsLocalizations);
450
- if (opt.choices && opt.choices.length > 0) {
451
- option.addChoices(...opt.choices);
452
- }
453
- return option;
454
- };
455
- switch (opt.type) {
456
- case discord_js_1.ApplicationCommandOptionType.String:
457
- commandBuilder.addStringOption(optionBuilder);
458
- break;
459
- case discord_js_1.ApplicationCommandOptionType.Boolean:
460
- commandBuilder.addBooleanOption(optionBuilder);
461
- break;
462
- case discord_js_1.ApplicationCommandOptionType.Integer:
463
- commandBuilder.addIntegerOption(optionBuilder);
464
- break;
465
- case discord_js_1.ApplicationCommandOptionType.Number:
466
- commandBuilder.addNumberOption(optionBuilder);
467
- break;
468
- case discord_js_1.ApplicationCommandOptionType.User:
469
- commandBuilder.addUserOption(optionBuilder);
470
- break;
471
- case discord_js_1.ApplicationCommandOptionType.Channel:
472
- commandBuilder.addChannelOption(optionBuilder);
473
- break;
474
- default:
475
- throw new Error(`Unsupported option type: ${opt.type}`);
476
- }
477
- });
478
- const executeBuilder = async (interaction) => {
479
- if (command.permissionCheck && !command.permissionCheck(interaction)) {
480
- await interaction.reply({
481
- content: LOCALE_FORBIDDEN[interaction.locale] || LOCALE_FORBIDDEN[discord_js_1.Locale.EnglishUS],
482
- flags: discord_js_1.MessageFlags.Ephemeral,
483
- });
484
- return;
485
- }
486
- if (command.isNSFW && (!interaction.channel || !('nsfw' in interaction.channel) || !interaction.channel.nsfw)) {
487
- await interaction.reply({
488
- content: LOCALE_NSFW[interaction.locale] || LOCALE_NSFW[discord_js_1.Locale.EnglishUS],
489
- flags: discord_js_1.MessageFlags.Ephemeral,
490
- });
491
- return;
492
- }
493
- const args = {};
494
- for (const option of Object.keys(options)) {
495
- switch (options[option]) {
496
- case discord_js_1.ApplicationCommandOptionType.String:
497
- args[option] = interaction.options.getString(option, false);
498
- break;
499
- case discord_js_1.ApplicationCommandOptionType.Boolean:
500
- args[option] = interaction.options.getBoolean(option, false);
501
- break;
502
- case discord_js_1.ApplicationCommandOptionType.Integer:
503
- args[option] = interaction.options.getInteger(option, false);
504
- break;
505
- case discord_js_1.ApplicationCommandOptionType.Number:
506
- args[option] = interaction.options.getNumber(option, false);
507
- break;
508
- case discord_js_1.ApplicationCommandOptionType.User:
509
- args[option] = interaction.options.getUser(option, false);
510
- break;
511
- case discord_js_1.ApplicationCommandOptionType.Channel:
512
- args[option] = interaction.options.getChannel(option, false);
513
- break;
514
- default:
515
- throw new Error(`Unsupported option type: ${options[option]}`);
516
- }
517
- }
518
- const localeTarget = (command.localizationPhrases && command.localizationPhrases[interaction.locale])
519
- ? interaction.locale
520
- : discord_js_1.Locale.EnglishUS;
521
- const localeTable = command.localizationPhrases;
522
- const customId = interaction.customId;
523
- if (customId && command.customIdHandlers[customId]) {
524
- await command.customIdHandlers[customId]({
525
- interaction,
526
- args,
527
- command,
528
- locale: localeTable ? localeTable[localeTarget] : {},
529
- });
530
- }
531
- else {
532
- await command.execute({
533
- interaction,
534
- args,
535
- command,
536
- locale: localeTable ? localeTable[localeTarget] : {},
537
- });
538
- }
539
- };
540
- const componentExecuteBuilder = async (interaction) => {
541
- if (!command.componentExecute)
542
- return;
543
- if (!interaction.customId.startsWith(command.getComponentId()))
544
- return;
545
- const localeTarget = (command.localizationPhrases && command.localizationPhrases[interaction.locale])
546
- ? interaction.locale
547
- : discord_js_1.Locale.EnglishUS;
548
- const localeTable = command.localizationPhrases;
549
- await command.componentExecute({
550
- interaction,
551
- command,
552
- locale: localeTable ? localeTable[localeTarget] : {},
553
- });
554
- };
555
- const modalExecuteBuilder = async (interaction) => {
556
- const modalId = interaction.customId;
557
- const modalObject = command.modals.get(modalId);
558
- if (!modalObject)
559
- return;
560
- const args = {};
561
- for (const [id] of modalObject.modalInputs.entries()) {
562
- args[id] = interaction.fields.getTextInputValue(id);
563
- }
564
- const localeTarget = (command.localizationPhrases && command.localizationPhrases[interaction.locale])
565
- ? interaction.locale
566
- : discord_js_1.Locale.EnglishUS;
567
- const localeTable = command.localizationPhrases;
568
- await modalObject.execute({
569
- interaction,
570
- args,
571
- command,
572
- locale: localeTable ? localeTable[localeTarget] : {},
573
- });
574
- };
575
- const buttonExecuteBuilder = async (interaction) => {
576
- const buttonId = interaction.customId;
577
- const buttonObject = command.buttons.get(buttonId);
578
- if (!buttonObject)
579
- return;
580
- const localeTarget = (command.localizationPhrases && command.localizationPhrases[interaction.locale])
581
- ? interaction.locale
582
- : discord_js_1.Locale.EnglishUS;
583
- const localeTable = command.localizationPhrases;
584
- await buttonObject.execute({
585
- interaction,
586
- command,
587
- locale: localeTable ? localeTable[localeTarget] : {},
588
- message: interaction.message,
589
- });
590
- };
591
- return {
592
- data: commandBuilder,
593
- execute: executeBuilder,
594
- componentExecute: command.componentExecute ? componentExecuteBuilder : undefined,
595
- modalExecute: command.modals.size > 0 ? modalExecuteBuilder : undefined,
596
- buttonExecute: command.buttons.size > 0 ? buttonExecuteBuilder : undefined,
597
- cooldown: command.cooldown,
598
- };
599
- });
600
- };
601
- exports.RegisterCommand = RegisterCommand;
602
192
  exports.default = ModularCommand;