js-discord-modularcommand 3.2.2 → 3.3.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.
@@ -6,20 +6,13 @@
6
6
  */
7
7
  import { BaseInteraction, CommandInteraction, MessageComponentInteraction, ModalSubmitInteraction } from "discord.js";
8
8
  import { ClientWithCommands } from "./types";
9
- /**
10
- * @interface InteractionHandlerArgs
11
- * @description Defines the arguments for the custom interaction handler function.
12
- */
13
- interface InteractionHandlerArgs {
14
- /** The interaction received from Discord. */
15
- interaction: CommandInteraction | MessageComponentInteraction | ModalSubmitInteraction;
16
- }
17
9
  /**
18
10
  * @type InteractionHandler
19
11
  * @description A function signature for a custom interaction handler.
12
+ * @param interaction The interaction received from Discord.
20
13
  * @returns {Promise<boolean | undefined>} A promise that resolves to `false` to stop the default handler, or `true`/`undefined` to continue.
21
14
  */
22
- type InteractionHandler = (args: InteractionHandlerArgs) => Promise<boolean | undefined>;
15
+ type InteractionHandler = (interaction: CommandInteraction | MessageComponentInteraction | ModalSubmitInteraction) => Promise<boolean | undefined>;
23
16
  /**
24
17
  * @description Creates a modular command handler function for the Discord client.
25
18
  * @param {ClientWithCommands} client The Discord client instance with a commands collection.
@@ -33,7 +33,7 @@ function ModularCommandHandler(client, customHandler) {
33
33
  return;
34
34
  }
35
35
  if (typeof customHandler === "function") {
36
- const response = await customHandler({ interaction });
36
+ const response = await customHandler(interaction);
37
37
  if (response === false)
38
38
  return;
39
39
  }
package/dist/locales.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @description Localization phrases for various command responses in a Discord bot using Discord.js.
6
6
  */
7
7
  import { Locale } from "discord.js";
8
- import LOCALE_DELAY from "./modularlocale";
8
+ import LOCALE_DELAY from "./localesdelay";
9
9
  /**
10
10
  * @description Localization phrases for various commands, specifically for permission errors.
11
11
  */
package/dist/locales.js CHANGED
@@ -14,8 +14,8 @@ exports.LOCALE_NSFW = exports.LOCALE_FORBIDDEN = exports.LOCALE_ERROR = exports.
14
14
  // Imports
15
15
  // =================================================================================================
16
16
  const discord_js_1 = require("discord.js");
17
- const modularlocale_1 = __importDefault(require("./modularlocale"));
18
- exports.LOCALE_DELAY = modularlocale_1.default;
17
+ const localesdelay_1 = __importDefault(require("./localesdelay"));
18
+ exports.LOCALE_DELAY = localesdelay_1.default;
19
19
  // =================================================================================================
20
20
  // Localization Phrases
21
21
  // =================================================================================================
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @license MIT
3
+ * @file src/localesdelay.ts
4
+ * @author vicentefelipechile
5
+ * @description Generic localization phrases used throughout the application.
6
+ */
7
+ import { Locale } from "discord.js";
8
+ /**
9
+ * @description Class to handle localization in a modular way.
10
+ */
11
+ declare class ModularLocale {
12
+ locale: Locale;
13
+ phrases: Record<string, string>;
14
+ seconds: Record<string, string>;
15
+ minutes: Record<string, string>;
16
+ constructor(locale: Locale);
17
+ /**
18
+ * Set the singular and plural forms for seconds.
19
+ * @param {string} singular The singular form (e.g., '{s} segundo').
20
+ * @param {string} plural The plural form (e.g., '{s} segundos').
21
+ * @returns {ModularLocale}
22
+ */
23
+ setSeconds(singular: string, plural: string): this;
24
+ /**
25
+ * Set the singular and plural forms for minutes.
26
+ * @param {string} singular The singular form (e.g., '{m} minuto').
27
+ * @param {string} plural The plural form (e.g., '{m} minutos').
28
+ * @returns {ModularLocale}
29
+ */
30
+ setMinutes(singular: string, plural: string): this;
31
+ /**
32
+ * Set the main phrase for the command delay.
33
+ * @param {string} phrase The phrase when only seconds or minutes are present.
34
+ * @returns {ModularLocale}
35
+ */
36
+ setPhrase(phrase: string): this;
37
+ /**
38
+ * Set the phrase when both seconds and minutes are present.
39
+ * @param {string} phrase The phrase for combined time.
40
+ * @returns {ModularLocale}
41
+ */
42
+ setPhrasePlural(phrase: string): this;
43
+ /**
44
+ * Set the phrase when only minutes are present.
45
+ * @param {string} phrase The phrase for when only minutes are present.
46
+ * @returns {ModularLocale}
47
+ */
48
+ setPhraseOnlyMinutes(phrase: string): this;
49
+ getPhrase: () => Record<string, string>;
50
+ getSeconds: () => Record<string, string>;
51
+ getMinutes: () => Record<string, string>;
52
+ /**
53
+ * Get the formatted phrase based on the time.
54
+ * @param {number} time The time in seconds.
55
+ * @returns {string} The formatted string.
56
+ */
57
+ formatTime(time: number): string;
58
+ }
59
+ /**
60
+ * @description Localization phrases for delay commands in ModularLocale structure.
61
+ * @example ```js
62
+ * const phrase = LOCALE_DELAY[Locale.EnglishUS];
63
+ * console.log( phrase.formatTime(64) ); // 'You must wait 4 seconds and 1 minute.'
64
+ * console.log( phrase.formatTime(390) ); // 'You must wait 30 seconds and 6 minutes.'
65
+ * console.log( phrase.formatTime(1) ); // 'You must wait 1 second.'
66
+ * console.log( phrase.formatTime(120) ); // 'You must wait 2 minutes.'
67
+ * ```
68
+ */
69
+ declare const LOCALE_DELAY: {
70
+ "es-419": ModularLocale;
71
+ "en-US": ModularLocale;
72
+ "en-GB": ModularLocale;
73
+ "es-ES": ModularLocale;
74
+ "pt-BR": ModularLocale;
75
+ fr: ModularLocale;
76
+ de: ModularLocale;
77
+ it: ModularLocale;
78
+ ru: ModularLocale;
79
+ "zh-CN": ModularLocale;
80
+ "zh-TW": ModularLocale;
81
+ ja: ModularLocale;
82
+ ko: ModularLocale;
83
+ bg: ModularLocale;
84
+ cs: ModularLocale;
85
+ da: ModularLocale;
86
+ nl: ModularLocale;
87
+ fi: ModularLocale;
88
+ hu: ModularLocale;
89
+ no: ModularLocale;
90
+ pl: ModularLocale;
91
+ ro: ModularLocale;
92
+ "sv-SE": ModularLocale;
93
+ tr: ModularLocale;
94
+ uk: ModularLocale;
95
+ hi: ModularLocale;
96
+ id: ModularLocale;
97
+ el: ModularLocale;
98
+ hr: ModularLocale;
99
+ lt: ModularLocale;
100
+ th: ModularLocale;
101
+ vi: ModularLocale;
102
+ };
103
+ export default LOCALE_DELAY;
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ /**
3
+ * @license MIT
4
+ * @file src/localesdelay.ts
5
+ * @author vicentefelipechile
6
+ * @description Generic localization phrases used throughout the application.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ // =================================================================================================
10
+ // Imports
11
+ // =================================================================================================
12
+ const discord_js_1 = require("discord.js");
13
+ // =================================================================================================
14
+ // Helper Functions
15
+ // =================================================================================================
16
+ /**
17
+ * Format a time unit (seconds or minutes) for localization.
18
+ * @param unit The time unit ('s' for seconds, 'm' for minutes).
19
+ * @param unitCount The count of the time unit.
20
+ * @param unitData The localization data for the time unit.
21
+ * @returns The formatted string for the time unit.
22
+ */
23
+ function formatUnit(unit, unitCount, unitData) {
24
+ if (unitCount === 1) {
25
+ return unitData.singular.replace(`{${unit}}`, unitCount.toString());
26
+ }
27
+ else {
28
+ return unitData.plural.replace(`{${unit}}`, unitCount.toString());
29
+ }
30
+ }
31
+ ;
32
+ // =================================================================================================
33
+ // ModularLocale Class
34
+ // =================================================================================================
35
+ /**
36
+ * @description Class to handle localization in a modular way.
37
+ */
38
+ class ModularLocale {
39
+ constructor(locale) {
40
+ this.getPhrase = () => this.phrases;
41
+ this.getSeconds = () => this.seconds;
42
+ this.getMinutes = () => this.minutes;
43
+ this.locale = locale;
44
+ this.phrases = {};
45
+ this.seconds = {};
46
+ this.minutes = {};
47
+ }
48
+ /**
49
+ * Set the singular and plural forms for seconds.
50
+ * @param {string} singular The singular form (e.g., '{s} segundo').
51
+ * @param {string} plural The plural form (e.g., '{s} segundos').
52
+ * @returns {ModularLocale}
53
+ */
54
+ setSeconds(singular, plural) {
55
+ this.seconds = { singular, plural };
56
+ return this;
57
+ }
58
+ /**
59
+ * Set the singular and plural forms for minutes.
60
+ * @param {string} singular The singular form (e.g., '{m} minuto').
61
+ * @param {string} plural The plural form (e.g., '{m} minutos').
62
+ * @returns {ModularLocale}
63
+ */
64
+ setMinutes(singular, plural) {
65
+ this.minutes = { singular, plural };
66
+ return this;
67
+ }
68
+ /**
69
+ * Set the main phrase for the command delay.
70
+ * @param {string} phrase The phrase when only seconds or minutes are present.
71
+ * @returns {ModularLocale}
72
+ */
73
+ setPhrase(phrase) {
74
+ this.phrases.singular = phrase;
75
+ return this;
76
+ }
77
+ /**
78
+ * Set the phrase when both seconds and minutes are present.
79
+ * @param {string} phrase The phrase for combined time.
80
+ * @returns {ModularLocale}
81
+ */
82
+ setPhrasePlural(phrase) {
83
+ this.phrases.plural = phrase;
84
+ return this;
85
+ }
86
+ /**
87
+ * Set the phrase when only minutes are present.
88
+ * @param {string} phrase The phrase for when only minutes are present.
89
+ * @returns {ModularLocale}
90
+ */
91
+ setPhraseOnlyMinutes(phrase) {
92
+ this.phrases.onlyMinutes = phrase;
93
+ return this;
94
+ }
95
+ /**
96
+ * Get the formatted phrase based on the time.
97
+ * @param {number} time The time in seconds.
98
+ * @returns {string} The formatted string.
99
+ */
100
+ formatTime(time) {
101
+ const minutes = Math.floor(time / 60);
102
+ const seconds = time % 60;
103
+ let formattedPhrase = '';
104
+ if (minutes > 0 && seconds > 0) {
105
+ formattedPhrase = this.phrases.plural
106
+ .replace('{seconds}', formatUnit('s', seconds, this.seconds))
107
+ .replace('{minutes}', formatUnit('m', minutes, this.minutes));
108
+ }
109
+ else if (minutes > 0 && seconds === 0) {
110
+ // Handle case where only minutes are present
111
+ formattedPhrase = this.phrases.onlyMinutes
112
+ .replace('{minutes}', formatUnit('m', minutes, this.minutes));
113
+ }
114
+ else {
115
+ formattedPhrase = this.phrases.singular
116
+ .replace('{seconds}', formatUnit('s', seconds, this.seconds))
117
+ .replace('{minutes}', '')
118
+ .trim();
119
+ }
120
+ return formattedPhrase.replace(/\s+/g, ' ').trim();
121
+ }
122
+ }
123
+ // =================================================================================================
124
+ // Localization Phrases
125
+ // =================================================================================================
126
+ /**
127
+ * @description Localization phrases for delay commands in ModularLocale structure.
128
+ * @example ```js
129
+ * const phrase = LOCALE_DELAY[Locale.EnglishUS];
130
+ * console.log( phrase.formatTime(64) ); // 'You must wait 4 seconds and 1 minute.'
131
+ * console.log( phrase.formatTime(390) ); // 'You must wait 30 seconds and 6 minutes.'
132
+ * console.log( phrase.formatTime(1) ); // 'You must wait 1 second.'
133
+ * console.log( phrase.formatTime(120) ); // 'You must wait 2 minutes.'
134
+ * ```
135
+ */
136
+ const LOCALE_DELAY = {
137
+ [discord_js_1.Locale.SpanishLATAM]: new ModularLocale(discord_js_1.Locale.SpanishLATAM)
138
+ .setSeconds('{s} segundo', '{s} segundos')
139
+ .setMinutes('{m} minuto', '{m} minutos')
140
+ .setPhrase('Debes esperar {seconds} antes de utilizar este comando denuevo.')
141
+ .setPhrasePlural('Debes esperar {seconds} y {minutes} antes de utilizar este comando denuevo.')
142
+ .setPhraseOnlyMinutes('Debes esperar {minutes} antes de utilizar este comando denuevo.'),
143
+ [discord_js_1.Locale.EnglishUS]: new ModularLocale(discord_js_1.Locale.EnglishUS)
144
+ .setSeconds('{s} second', '{s} seconds')
145
+ .setMinutes('{m} minute', '{m} minutes')
146
+ .setPhrase('You must wait {seconds} before using this command again.')
147
+ .setPhrasePlural('You must wait {seconds} and {minutes} before using this command again.')
148
+ .setPhraseOnlyMinutes('You must wait {minutes} before using this command again.'),
149
+ [discord_js_1.Locale.EnglishGB]: new ModularLocale(discord_js_1.Locale.EnglishGB)
150
+ .setSeconds('{s} second', '{s} seconds')
151
+ .setMinutes('{m} minute', '{m} minutes')
152
+ .setPhrase('One must exhibit a spot of patience, you see. A brief pause of {seconds} is required before another attempt, what?')
153
+ .setPhrasePlural('One must exhibit a spot of patience, you see. A brief pause of {seconds} and {minutes} is required before another attempt, what?')
154
+ .setPhraseOnlyMinutes('One must exhibit a spot of patience, you see. A brief pause of {minutes} is required before another attempt, what?'),
155
+ [discord_js_1.Locale.SpanishES]: new ModularLocale(discord_js_1.Locale.SpanishES)
156
+ .setSeconds('{s} segundo', '{s} segundos')
157
+ .setMinutes('{m} minuto', '{m} minutos')
158
+ .setPhrase('¡Joder, tío! ¡Que te esperes {seconds} antes de utilizar este comando, coño!')
159
+ .setPhrasePlural('¡Joder, tío! ¡Que te esperes {seconds} y {minutes}, coño!')
160
+ .setPhraseOnlyMinutes('¡Joder, tío! ¡Que te esperes {minutes} antes de utilizar este comando, coño!'),
161
+ [discord_js_1.Locale.PortugueseBR]: new ModularLocale(discord_js_1.Locale.PortugueseBR)
162
+ .setSeconds('{s} segundo', '{s} segundos')
163
+ .setMinutes('{m} minuto', '{m} minutos')
164
+ .setPhrase('Você deve esperar {seconds} antes de usar este comando novamente.')
165
+ .setPhrasePlural('Você deve esperar {seconds} e {minutes} antes de usar este comando novamente.')
166
+ .setPhraseOnlyMinutes('Você deve esperar {minutes} antes de usar este comando novamente.'),
167
+ [discord_js_1.Locale.French]: new ModularLocale(discord_js_1.Locale.French)
168
+ .setSeconds('{s} seconde', '{s} secondes')
169
+ .setMinutes('{m} minute', '{m} minutes')
170
+ .setPhrase('Vous devez attendre {seconds} avant d\'utiliser cette commande à nouveau.')
171
+ .setPhrasePlural('Vous devez attendre {seconds} et {minutes} avant d\'utiliser cette commande à nouveau.')
172
+ .setPhraseOnlyMinutes('Vous devez attendre {minutes} avant d\'utiliser cette commande à nouveau.'),
173
+ [discord_js_1.Locale.German]: new ModularLocale(discord_js_1.Locale.German)
174
+ .setSeconds('{s} Sekunde', '{s} Sekunden')
175
+ .setMinutes('{m} Minute', '{m} Minuten')
176
+ .setPhrase('Sie müssen {seconds} warten, bevor Sie diesen Befehl erneut verwenden können.')
177
+ .setPhrasePlural('Sie müssen {seconds} und {minutes} warten, bevor Sie diesen Befehl erneut verwenden können.')
178
+ .setPhraseOnlyMinutes('Sie müssen {minutes} warten, bevor Sie diesen Befehl erneut verwenden können.'),
179
+ [discord_js_1.Locale.Italian]: new ModularLocale(discord_js_1.Locale.Italian)
180
+ .setSeconds('{s} secondo', '{s} secondi')
181
+ .setMinutes('{m} minuto', '{m} minuti')
182
+ .setPhrase('Devi aspettare {seconds} prima di utilizzare di nuovo questo comando.')
183
+ .setPhrasePlural('Devi aspettare {seconds} e {minutes} prima di utilizzare di nuovo questo comando.')
184
+ .setPhraseOnlyMinutes('Devi aspettare {minutes} prima di utilizzare di nuovo questo comando.'),
185
+ [discord_js_1.Locale.Russian]: new ModularLocale(discord_js_1.Locale.Russian)
186
+ .setSeconds('{s} секунду', '{s} секунд')
187
+ .setMinutes('{m} минуту', '{m} минут')
188
+ .setPhrase('Вы должны подождать {seconds} перед повторным использованием этой команды.')
189
+ .setPhrasePlural('Вы должны подождать {seconds} и {minutes} перед повторным использованием этой команды.')
190
+ .setPhraseOnlyMinutes('Вы должны подождать {minutes} перед повторным использованием этой команды.'),
191
+ [discord_js_1.Locale.ChineseCN]: new ModularLocale(discord_js_1.Locale.ChineseCN)
192
+ .setSeconds('{s} 秒', '{s} 秒')
193
+ .setMinutes('{m} 分钟', '{m} 分钟')
194
+ .setPhrase('您必须等待 {seconds} 才能再次使用此命令.')
195
+ .setPhrasePlural('您必须等待 {seconds} 和 {minutes} 才能再次使用此命令.')
196
+ .setPhraseOnlyMinutes('您必须等待 {minutes} 才能再次使用此命令.'),
197
+ [discord_js_1.Locale.ChineseTW]: new ModularLocale(discord_js_1.Locale.ChineseTW)
198
+ .setSeconds('{s} 秒', '{s} 秒')
199
+ .setMinutes('{m} 分鐘', '{m} 分鐘')
200
+ .setPhrase('您必須等待 {seconds} 才能再次使用此命令.')
201
+ .setPhrasePlural('您必須等待 {seconds} 和 {minutes} 才能再次使用此命令.')
202
+ .setPhraseOnlyMinutes('您必須等待 {minutes} 才能再次使用此命令.'),
203
+ [discord_js_1.Locale.Japanese]: new ModularLocale(discord_js_1.Locale.Japanese)
204
+ .setSeconds('{s} 秒', '{s} 秒')
205
+ .setMinutes('{m} 分', '{m} 分')
206
+ .setPhrase('このコマンドを再度使用するには、{seconds} 待つ必要があります.')
207
+ .setPhrasePlural('このコマンドを再度使用するには、{seconds} と {minutes} 待つ必要があります.')
208
+ .setPhraseOnlyMinutes('このコマンドを再度使用するには、{minutes} 待つ必要があります.'),
209
+ [discord_js_1.Locale.Korean]: new ModularLocale(discord_js_1.Locale.Korean)
210
+ .setSeconds('{s} 초', '{s} 초')
211
+ .setMinutes('{m} 분', '{m} 분')
212
+ .setPhrase('이 명령어를 다시 사용하려면 {seconds} 기다려야 합니다.')
213
+ .setPhrasePlural('이 명령어를 다시 사용하려면 {seconds} 하고 {minutes} 기다려야 합니다.')
214
+ .setPhraseOnlyMinutes('이 명령어를 다시 사용하려면 {minutes} 기다려야 합니다.'),
215
+ [discord_js_1.Locale.Bulgarian]: new ModularLocale(discord_js_1.Locale.Bulgarian)
216
+ .setSeconds('{s} секунд', '{s} секунди')
217
+ .setMinutes('{m} минут', '{m} минути')
218
+ .setPhrase('Трябва да изчакате {seconds} преди да използвате тази команда отново.')
219
+ .setPhrasePlural('Трябва да изчакате {seconds} и {minutes} преди да използвате тази команда отново.')
220
+ .setPhraseOnlyMinutes('Трябва да изчакате {minutes} преди да използвате тази команда отново.'),
221
+ [discord_js_1.Locale.Czech]: new ModularLocale(discord_js_1.Locale.Czech)
222
+ .setSeconds('{s} sekundu', '{s} sekund')
223
+ .setMinutes('{m} minutu', '{m} minut')
224
+ .setPhrase('Musíte počkat {seconds} než znovu použijete tento příkaz.')
225
+ .setPhrasePlural('Musíte počkat {seconds} a {minutes} než znovu použijete tento příkaz.')
226
+ .setPhraseOnlyMinutes('Musíte počkat {minutes} než znovu použijete tento příkaz.'),
227
+ [discord_js_1.Locale.Danish]: new ModularLocale(discord_js_1.Locale.Danish)
228
+ .setSeconds('{s} sekund', '{s} sekunder')
229
+ .setMinutes('{m} minut', '{m} minutter')
230
+ .setPhrase('Du skal vente {seconds} før du kan bruge denne kommando igen.')
231
+ .setPhrasePlural('Du skal vente {seconds} og {minutes} før du kan bruge denne kommando igen.')
232
+ .setPhraseOnlyMinutes('Du skal vente {minutes} før du kan bruge denne kommando igen.'),
233
+ [discord_js_1.Locale.Dutch]: new ModularLocale(discord_js_1.Locale.Dutch)
234
+ .setSeconds('{s} seconde', '{s} seconden')
235
+ .setMinutes('{m} minuut', '{m} minuten')
236
+ .setPhrase('Je moet {seconds} wachten voordat je dit commando opnieuw kunt gebruiken.')
237
+ .setPhrasePlural('Je moet {seconds} en {minutes} wachten voordat je dit commando opnieuw kunt gebruiken.')
238
+ .setPhraseOnlyMinutes('Je moet {minutes} wachten voordat je dit commando opnieuw kunt gebruiken.'),
239
+ [discord_js_1.Locale.Finnish]: new ModularLocale(discord_js_1.Locale.Finnish)
240
+ .setSeconds('{s} sekunti', '{s} sekuntia')
241
+ .setMinutes('{m} minuutti', '{m} minuuttia')
242
+ .setPhrase('Sinun on odotettava {seconds} ennen kuin voit käyttää tätä komentoa uudelleen.')
243
+ .setPhrasePlural('Sinun on odotettava {seconds} ja {minutes} ennen kuin voit käyttää tätä komentoa uudelleen.')
244
+ .setPhraseOnlyMinutes('Sinun on odotettava {minutes} ennen kuin voit käyttää tätä komentoa uudelleen.'),
245
+ [discord_js_1.Locale.Hungarian]: new ModularLocale(discord_js_1.Locale.Hungarian)
246
+ .setSeconds('{s} másodperc', '{s} másodpercet')
247
+ .setMinutes('{m} perc', '{m} percet')
248
+ .setPhrase('Várnod kell {seconds} mielőtt újra használhatod ezt a parancsot.')
249
+ .setPhrasePlural('Várnod kell {seconds} és {minutes} mielőtt újra használhatod ezt a parancsot.')
250
+ .setPhraseOnlyMinutes('Várnod kell {minutes} mielőtt újra használhatod ezt a parancsot.'),
251
+ [discord_js_1.Locale.Norwegian]: new ModularLocale(discord_js_1.Locale.Norwegian)
252
+ .setSeconds('{s} sekund', '{s} sekunder')
253
+ .setMinutes('{m} minutt', '{m} minutter')
254
+ .setPhrase('Du må vente {seconds} før du kan bruke denne kommandoen igjen.')
255
+ .setPhrasePlural('Du må vente {seconds} og {minutes} før du kan bruke denne kommandoen igjen.')
256
+ .setPhraseOnlyMinutes('Du må vente {minutes} før du kan bruke denne kommandoen igjen.'),
257
+ [discord_js_1.Locale.Polish]: new ModularLocale(discord_js_1.Locale.Polish)
258
+ .setSeconds('{s} sekundę', '{s} sekundy')
259
+ .setMinutes('{m} minutę', '{m} minuty')
260
+ .setPhrase('Musisz poczekać {seconds} zanim ponownie użyjesz tego polecenia.')
261
+ .setPhrasePlural('Musisz poczekać {seconds} i {minutes} zanim ponownie użyjesz tego polecenia.')
262
+ .setPhraseOnlyMinutes('Musisz poczekać {minutes} zanim ponownie użyjesz tego polecenia.'),
263
+ [discord_js_1.Locale.Romanian]: new ModularLocale(discord_js_1.Locale.Romanian)
264
+ .setSeconds('{s} secundă', '{s} secunde')
265
+ .setMinutes('{m} minut', '{m} minute')
266
+ .setPhrase('Trebuie să aștepți {seconds} înainte de a folosi din nou acest comandă.')
267
+ .setPhrasePlural('Trebuie să aștepți {seconds} și {minutes} înainte de a folosi din nou acest comandă.')
268
+ .setPhraseOnlyMinutes('Trebuie să aștepți {minutes} înainte de a folosi din nou acest comandă.'),
269
+ [discord_js_1.Locale.Swedish]: new ModularLocale(discord_js_1.Locale.Swedish)
270
+ .setSeconds('{s} sekund', '{s} sekunder')
271
+ .setMinutes('{m} minut', '{m} minuter')
272
+ .setPhrase('Du måste vänta {seconds} innan du kan använda det här kommandot igen.')
273
+ .setPhrasePlural('Du måste vänta {seconds} och {minutes} innan du kan använda det här kommandot igen.')
274
+ .setPhraseOnlyMinutes('Du måste vänta {minutes} innan du kan använda det här kommandot igen.'),
275
+ [discord_js_1.Locale.Turkish]: new ModularLocale(discord_js_1.Locale.Turkish)
276
+ .setSeconds('{s} saniye', '{s} saniye')
277
+ .setMinutes('{m} dakika', '{m} dakika')
278
+ .setPhrase('Bu komutu tekrar kullanmadan önce {seconds} beklemeniz gerekir.')
279
+ .setPhrasePlural('Bu komutu tekrar kullanmadan önce {seconds} ve {minutes} beklemeniz gerekir.')
280
+ .setPhraseOnlyMinutes('Bu komutu tekrar kullanmadan önce {minutes} beklemeniz gerekir.'),
281
+ [discord_js_1.Locale.Ukrainian]: new ModularLocale(discord_js_1.Locale.Ukrainian)
282
+ .setSeconds('{s} секунду', '{s} секунди')
283
+ .setMinutes('{m} хвилину', '{m} хвилини')
284
+ .setPhrase('Вам потрібно почекати {seconds} перш ніж знову використовувати цю команду.')
285
+ .setPhrasePlural('Вам потрібно почекати {seconds} і {minutes} перш ніж знову використовувати цю команду.')
286
+ .setPhraseOnlyMinutes('Вам потрібно почекати {minutes} перш ніж знову використовувати цю команду.'),
287
+ [discord_js_1.Locale.Hindi]: new ModularLocale(discord_js_1.Locale.Hindi)
288
+ .setSeconds('{s} सेकंड', '{s} सेकंड')
289
+ .setMinutes('{m} मिनट', '{m} मिनट')
290
+ .setPhrase('आपको इस कमांड का उपयोग करने से पहले {seconds} इंतजार करना होगा.')
291
+ .setPhrasePlural('आपको इस कमांड का उपयोग करने से पहले {seconds} और {minutes} इंतजार करना होगा.')
292
+ .setPhraseOnlyMinutes('आपको इस कमांड का उपयोग करने से पहले {minutes} इंतजार करना होगा.'),
293
+ [discord_js_1.Locale.Indonesian]: new ModularLocale(discord_js_1.Locale.Indonesian)
294
+ .setSeconds('{s} detik', '{s} detik')
295
+ .setMinutes('{m} menit', '{m} menit')
296
+ .setPhrase('Anda harus menunggu {seconds} sebelum menggunakan perintah ini lagi.')
297
+ .setPhrasePlural('Anda harus menunggu {seconds} dan {minutes} sebelum menggunakan perintah ini lagi.')
298
+ .setPhraseOnlyMinutes('Anda harus menunggu {minutes} sebelum menggunakan perintah ini lagi.'),
299
+ [discord_js_1.Locale.Greek]: new ModularLocale(discord_js_1.Locale.Greek)
300
+ .setSeconds('{s} δευτερόλεπτο', '{s} δευτερόλεπτα')
301
+ .setMinutes('{m} λεπτό', '{m} λεπτά')
302
+ .setPhrase('Πρέπει να περιμένετε {seconds} πριν χρησιμοποιήσετε ξανά αυτήν την εντολή.')
303
+ .setPhrasePlural('Πρέπει να περιμένετε {seconds} και {minutes} πριν χρησιμοποιήσετε ξανά αυτήν την εντολή.')
304
+ .setPhraseOnlyMinutes('Πρέπει να περιμένετε {minutes} πριν χρησιμοποιήσετε ξανά αυτήν την εντολή.'),
305
+ [discord_js_1.Locale.Croatian]: new ModularLocale(discord_js_1.Locale.Croatian)
306
+ .setSeconds('{s} sekundu', '{s} sekunde')
307
+ .setMinutes('{m} minutu', '{m} minute')
308
+ .setPhrase('Morate pričekati {seconds} prije nego što ponovno upotrijebite ovu naredbu.')
309
+ .setPhrasePlural('Morate pričekati {seconds} i {minutes} prije nego što ponovno upotrijebite ovu naredbu.')
310
+ .setPhraseOnlyMinutes('Morate pričekati {minutes} prije nego što ponovno upotrijebite ovu naredbu.'),
311
+ [discord_js_1.Locale.Lithuanian]: new ModularLocale(discord_js_1.Locale.Lithuanian)
312
+ .setSeconds('{s} sekundę', '{s} sekundes')
313
+ .setMinutes('{m} minutę', '{m} minutes')
314
+ .setPhrase('Prieš vėl naudodamiesi šiuo komandu, turite palaukti {seconds}.')
315
+ .setPhrasePlural('Prieš vėl naudodamiesi šiuo komandu, turite palaukti {seconds} ir {minutes}.')
316
+ .setPhraseOnlyMinutes('Prieš vėl naudodamiesi šiuo komandu, turite palaukti {minutes}.'),
317
+ [discord_js_1.Locale.Thai]: new ModularLocale(discord_js_1.Locale.Thai)
318
+ .setSeconds('{s} วินาที', '{s} วินาที')
319
+ .setMinutes('{m} นาที', '{m} นาที')
320
+ .setPhrase('คุณต้องรอ {seconds} ก่อนที่จะใช้คำสั่งนี้อีกครั้ง')
321
+ .setPhrasePlural('คุณต้องรอ {seconds} และ {minutes} ก่อนที่จะใช้คำสั่งนี้อีกครั้ง')
322
+ .setPhraseOnlyMinutes('คุณต้องรอ {minutes} ก่อนที่จะใช้คำสั่งนี้อีกครั้ง'),
323
+ [discord_js_1.Locale.Vietnamese]: new ModularLocale(discord_js_1.Locale.Vietnamese)
324
+ .setSeconds('{s} giây', '{s} giây')
325
+ .setMinutes('{m} phút', '{m} phút')
326
+ .setPhrase('Bạn phải đợi {seconds} trước khi sử dụng lại lệnh này.')
327
+ .setPhrasePlural('Bạn phải đợi {seconds} và {minutes} trước khi sử dụng lại lệnh này.')
328
+ .setPhraseOnlyMinutes('Bạn phải đợi {minutes} trước khi sử dụng lại lệnh này.')
329
+ };
330
+ Object.freeze(LOCALE_DELAY);
331
+ // =================================================================================================
332
+ // Export
333
+ // =================================================================================================
334
+ exports.default = LOCALE_DELAY;
@@ -49,19 +49,24 @@ const discord_js_1 = require("discord.js");
49
49
  const cooldown_1 = __importStar(require("./cooldown"));
50
50
  const locales_1 = require("./locales");
51
51
  /**
52
- * @description Gets localized description for a subcommand.
52
+ * @description Gets localized value for a subcommand or its option.
53
53
  * Supports multiple languages and falls back to default description if not found.
54
+ * This consolidated function handles both subcommand descriptions and option descriptions.
54
55
  * @param {ModularCommand} command The command instance.
55
56
  * @param {string} subCommandName The name of the subcommand.
56
- * @param {string} defaultDescription The default description.
57
+ * @param {string | null} optionName The name of the option, or null for the subcommand description itself.
58
+ * @param {string} defaultValue The default value to use if no localization is found.
57
59
  * @param {string} locale The locale to use (defaults to EnglishUS).
58
- * @returns {string} The localized description.
60
+ * @returns {string} The localized value.
59
61
  */
60
- function getLocalizedSubCommandDescription(command, subCommandName, defaultDescription, locale = discord_js_1.Locale.EnglishUS) {
62
+ function getLocalizedSubCommandValue(command, subCommandName, optionName, defaultValue, locale = discord_js_1.Locale.EnglishUS) {
61
63
  if (!command.subCommandLocalizations)
62
- return defaultDescription;
64
+ return defaultValue;
63
65
  const localizations = command.subCommandLocalizations;
64
- const key = `${subCommandName}.description`;
66
+ // Build the key based on whether we're looking for subcommand or option description
67
+ const key = optionName
68
+ ? `${subCommandName}.${optionName}.description`
69
+ : `${subCommandName}.description`;
65
70
  // Try to get the localization for the requested locale
66
71
  const targetLocalizations = localizations[locale];
67
72
  if (targetLocalizations?.[key]) {
@@ -73,36 +78,11 @@ function getLocalizedSubCommandDescription(command, subCommandName, defaultDescr
73
78
  return enLocalizations[key];
74
79
  }
75
80
  else {
76
- throw new Error(`Missing localization for subcommand '${subCommandName}' in command '${command.name}'`);
77
- }
78
- }
79
- /**
80
- * @description Gets localized description for a subcommand option.
81
- * Supports multiple languages and falls back to default description if not found.
82
- * @param {ModularCommand} command The command instance.
83
- * @param {string} subCommandName The name of the subcommand.
84
- * @param {string} optionName The name of the option.
85
- * @param {string} defaultDescription The default description.
86
- * @param {string} locale The locale to use (defaults to EnglishUS).
87
- * @returns {string} The localized description.
88
- */
89
- function getLocalizedOptionDescription(command, subCommandName, optionName, defaultDescription, locale = discord_js_1.Locale.EnglishUS) {
90
- if (!command.subCommandLocalizations)
91
- return defaultDescription;
92
- const localizations = command.subCommandLocalizations;
93
- const key = `${subCommandName}.${optionName}.description`;
94
- // Try to get the localization for the requested locale
95
- const targetLocalizations = localizations[locale];
96
- if (targetLocalizations?.[key]) {
97
- return targetLocalizations[key];
98
- }
99
- // Fall back to English if the requested locale is not found
100
- const enLocalizations = localizations[discord_js_1.Locale.EnglishUS];
101
- if (enLocalizations?.[key]) {
102
- return enLocalizations[key];
103
- }
104
- else {
105
- throw new Error(`Missing localization for option '${optionName}' in subcommand '${subCommandName}' for command '${command.name}'`);
81
+ // Build appropriate error message
82
+ const context = optionName
83
+ ? `option '${optionName}' in subcommand '${subCommandName}' for command '${command.name}'`
84
+ : `subcommand '${subCommandName}' in command '${command.name}'`;
85
+ throw new Error(`Missing localization for ${context}`);
106
86
  }
107
87
  }
108
88
  /**
@@ -125,6 +105,31 @@ function createOptionBuilder(opt, description) {
125
105
  return option;
126
106
  };
127
107
  }
108
+ /**
109
+ * @description Processes and adds a single option to a subcommand builder.
110
+ * This helper function encapsulates the logic for retrieving localized descriptions
111
+ * and adding options to subcommands, improving code maintainability.
112
+ * @param {SlashCommandSubcommandBuilder} subcommand The subcommand builder to add the option to.
113
+ * @param {CommandOption} opt The option to add.
114
+ * @param {string} subCommandName The name of the subcommand (used for localization).
115
+ * @param {ModularCommand} command The command instance (used for localization).
116
+ * @param {Record<string, OptionType>} options The options record to populate.
117
+ */
118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
+ function addSubCommandOption(subcommand, opt, subCommandName, command, options) {
120
+ // Get base description
121
+ let description = typeof opt.description === 'string'
122
+ ? opt.description
123
+ : (opt.description[discord_js_1.Locale.EnglishUS] || `The description for ${opt.name} in English.`);
124
+ // Apply subcommand-specific localization
125
+ description = getLocalizedSubCommandValue(command, subCommandName, opt.name, description);
126
+ if (!description) {
127
+ throw new Error(`Option '${opt.name}' in subcommand '${subCommandName}' is missing a description.`);
128
+ }
129
+ options[opt.name] = opt.type;
130
+ const optionBuilder = createOptionBuilder(opt, description);
131
+ addOptionToBuilder(subcommand, opt, optionBuilder);
132
+ }
128
133
  /**
129
134
  * @description Adds an option to a command or subcommand builder based on its type.
130
135
  * @param {any} builder The command or subcommand builder.
@@ -172,29 +177,18 @@ function processSubCommands(commandBuilder, command, options) {
172
177
  if (typeof subCmd.name !== 'string' || subCmd.name.trim() === '') {
173
178
  throw new Error("A subcommand is missing a name.");
174
179
  }
175
- // Get localized description for subcommand
176
- const subCmdDescription = getLocalizedSubCommandDescription(command, subCmd.name, subCmd.description);
180
+ // Get localized description for subcommand (pass null for optionName to get subcommand description)
181
+ const subCmdDescription = getLocalizedSubCommandValue(command, subCmd.name, null, subCmd.description);
177
182
  if (typeof subCmdDescription !== 'string' || subCmdDescription.trim() === '') {
178
183
  throw new Error(`Subcommand '${subCmd.name}' is missing a description.`);
179
184
  }
180
185
  subcommand
181
186
  .setName(subCmd.name)
182
187
  .setDescription(subCmdDescription);
183
- // Add options to the subcommand
188
+ // Add options to the subcommand using the helper function
184
189
  if (subCmd.options) {
185
190
  subCmd.options.forEach(opt => {
186
- // Get base description
187
- let description = typeof opt.description === 'string'
188
- ? opt.description
189
- : (opt.description[discord_js_1.Locale.EnglishUS] || `The description for ${opt.name} in English.`);
190
- // Apply subcommand-specific localization
191
- description = getLocalizedOptionDescription(command, subCmd.name, opt.name, description);
192
- if (!description) {
193
- throw new Error(`Option '${opt.name}' in subcommand '${subCmd.name}' is missing a description.`);
194
- }
195
- options[opt.name] = opt.type;
196
- const optionBuilder = createOptionBuilder(opt, description);
197
- addOptionToBuilder(subcommand, opt, optionBuilder);
191
+ addSubCommandOption(subcommand, opt, subCmd.name, command, options);
198
192
  });
199
193
  }
200
194
  return subcommand;
@@ -313,6 +307,9 @@ function createChatInputExecutor(command, options) {
313
307
  }
314
308
  // Add the current subcommand to args if it exists
315
309
  if (currentSubcommand) {
310
+ if ('subcommand' in args) {
311
+ console.warn(`Warning: 'subcommand' key already exists in args for command ${command.name}. Overwriting.`);
312
+ }
316
313
  args['subcommand'] = currentSubcommand;
317
314
  }
318
315
  const locale = getCommandLocale(command, interaction);
@@ -375,9 +372,13 @@ function createButtonExecutor(command) {
375
372
  const buttonObject = command.buttons.get(interaction.customId.split('_')[1]);
376
373
  if (!buttonObject)
377
374
  return;
378
- if (!buttonObject.allowOthers && interaction.user.id !== interaction.message.author.id) {
379
- await interaction.reply({ content: locales_1.LOCALE_FORBIDDEN[interaction.locale], flags: discord_js_1.MessageFlags.Ephemeral });
380
- return;
375
+ // Check if the button is allowed to be used by others
376
+ if (buttonObject.allowOthers === false) {
377
+ const interactionData = interaction.message.interactionMetadata;
378
+ if (interactionData !== null && interactionData.user.id !== interaction.user.id) {
379
+ await interaction.reply({ content: locales_1.LOCALE_FORBIDDEN[interaction.locale], flags: discord_js_1.MessageFlags.Ephemeral });
380
+ return;
381
+ }
381
382
  }
382
383
  await buttonObject.execute({
383
384
  interaction,
@@ -429,7 +430,7 @@ function RegisterCommand(commands) {
429
430
  throw new Error("A command is missing a name.");
430
431
  }
431
432
  if (typeof command.description !== 'string' || command.description.trim() === '') {
432
- throw new Error(`Command "${command.name}" is missing a description.`);
433
+ throw new Error(`Command "${command.name}" doesn't have a description.`);
433
434
  }
434
435
  // Build SlashCommand Data
435
436
  const commandBuilder = new discord_js_1.SlashCommandBuilder()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-discord-modularcommand",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "discord",