js-discord-modularcommand 2.0.2 → 2.1.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.
- package/dist/modularcommand.d.ts +15 -7
- package/dist/modularcommand.js +24 -5
- package/dist/registercommand.js +5 -2
- package/package.json +1 -1
package/dist/modularcommand.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @author vicentefelipechile
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
import { LocalizationMap, ButtonStyle
|
|
6
|
+
import { LocalizationMap, ButtonStyle } from 'discord.js';
|
|
7
7
|
import ModularModal from './modularmodal.js';
|
|
8
8
|
import ModularButton from './modularbutton.js';
|
|
9
9
|
import { ButtonExecuteFunction, CommandExecuteFunction, CommandOption, ComponentExecuteFunction, ModalExecuteFunction, PermissionCheckFunction } from './types.js';
|
|
@@ -37,7 +37,7 @@ export default class ModularCommand {
|
|
|
37
37
|
/** The options (arguments) that the command accepts. */
|
|
38
38
|
options: CommandOption[];
|
|
39
39
|
/** An object containing localizations for the names and descriptions of the options. */
|
|
40
|
-
optionsLocalizations:
|
|
40
|
+
optionsLocalizations: LocalizationMap;
|
|
41
41
|
/** The main function that executes when the command is invoked. */
|
|
42
42
|
execute: CommandExecuteFunction;
|
|
43
43
|
/** (Optional) The function to handle button interactions. */
|
|
@@ -53,7 +53,7 @@ export default class ModularCommand {
|
|
|
53
53
|
/** Whether the command is marked as Not Safe For Work (NSFW). */
|
|
54
54
|
isNSFW: boolean;
|
|
55
55
|
/** (Optional) An object with localized phrases to be used within the command's execution. */
|
|
56
|
-
localizationPhrases?:
|
|
56
|
+
localizationPhrases?: LocalizationMap;
|
|
57
57
|
/** (Optional) The function that checks if a user has permission to execute the command. */
|
|
58
58
|
permissionCheck?: PermissionCheckFunction;
|
|
59
59
|
/** (Optional) The base ID for components associated with this command. */
|
|
@@ -72,23 +72,31 @@ export default class ModularCommand {
|
|
|
72
72
|
*/
|
|
73
73
|
setDescription(description: string): this;
|
|
74
74
|
/**
|
|
75
|
+
* @deprecated Use setLocalizationDescription instead.
|
|
75
76
|
* Sets the description localizations for the command.
|
|
76
77
|
* @param {LocalizationMap} localizations The description localizations map.
|
|
77
78
|
* @returns {ModularCommand} The command instance for chaining.
|
|
78
79
|
*/
|
|
79
80
|
setLocalizationsDescription(localizations: LocalizationMap): this;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the description localizations for the command.
|
|
83
|
+
* @param {LocalizationMap} localizations The description localizations map.
|
|
84
|
+
* @returns {ModularCommand} The command instance for chaining.
|
|
85
|
+
*/
|
|
86
|
+
setLocalizationDescription(localizations: LocalizationMap): this;
|
|
80
87
|
/**
|
|
81
88
|
* Sets the localizations for the command's options.
|
|
82
|
-
* @param {
|
|
89
|
+
* @param {LocalizationMap} localizations An object with the localizations.
|
|
83
90
|
* @returns {ModularCommand} The command instance for chaining.
|
|
84
91
|
*/
|
|
85
|
-
setLocalizationOptions(localizations:
|
|
92
|
+
setLocalizationOptions(localizations: LocalizationMap): this;
|
|
86
93
|
/**
|
|
87
94
|
* Sets the localization phrases for the command.
|
|
88
|
-
*
|
|
95
|
+
* Accepts a partial record, so not all locales need to be provided.
|
|
96
|
+
* @param {LocalizationMap} localizationPhrases The localization phrases.
|
|
89
97
|
* @returns {ModularCommand} The command instance for chaining.
|
|
90
98
|
*/
|
|
91
|
-
setLocalizationPhrases(localizationPhrases:
|
|
99
|
+
setLocalizationPhrases(localizationPhrases: LocalizationMap): this;
|
|
92
100
|
/**
|
|
93
101
|
* Sets the execute function for the command.
|
|
94
102
|
* @param {CommandExecuteFunction} executeFunction The function to execute.
|
package/dist/modularcommand.js
CHANGED
|
@@ -63,31 +63,50 @@ class ModularCommand {
|
|
|
63
63
|
return this;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
+
* @deprecated Use setLocalizationDescription instead.
|
|
66
67
|
* Sets the description localizations for the command.
|
|
67
68
|
* @param {LocalizationMap} localizations The description localizations map.
|
|
68
69
|
* @returns {ModularCommand} The command instance for chaining.
|
|
69
70
|
*/
|
|
70
71
|
setLocalizationsDescription(localizations) {
|
|
72
|
+
return this.setLocalizationDescription(localizations);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sets the description localizations for the command.
|
|
76
|
+
* @param {LocalizationMap} localizations The description localizations map.
|
|
77
|
+
* @returns {ModularCommand} The command instance for chaining.
|
|
78
|
+
*/
|
|
79
|
+
setLocalizationDescription(localizations) {
|
|
71
80
|
this.description = localizations[discord_js_1.Locale.EnglishUS] || this.description;
|
|
72
|
-
this.descriptionLocalizations =
|
|
81
|
+
this.descriptionLocalizations = {
|
|
82
|
+
...this.descriptionLocalizations,
|
|
83
|
+
...localizations,
|
|
84
|
+
};
|
|
73
85
|
return this;
|
|
74
86
|
}
|
|
75
87
|
/**
|
|
76
88
|
* Sets the localizations for the command's options.
|
|
77
|
-
* @param {
|
|
89
|
+
* @param {LocalizationMap} localizations An object with the localizations.
|
|
78
90
|
* @returns {ModularCommand} The command instance for chaining.
|
|
79
91
|
*/
|
|
80
92
|
setLocalizationOptions(localizations) {
|
|
81
|
-
this.optionsLocalizations =
|
|
93
|
+
this.optionsLocalizations = {
|
|
94
|
+
...this.optionsLocalizations,
|
|
95
|
+
...localizations,
|
|
96
|
+
};
|
|
82
97
|
return this;
|
|
83
98
|
}
|
|
84
99
|
/**
|
|
85
100
|
* Sets the localization phrases for the command.
|
|
86
|
-
*
|
|
101
|
+
* Accepts a partial record, so not all locales need to be provided.
|
|
102
|
+
* @param {LocalizationMap} localizationPhrases The localization phrases.
|
|
87
103
|
* @returns {ModularCommand} The command instance for chaining.
|
|
88
104
|
*/
|
|
89
105
|
setLocalizationPhrases(localizationPhrases) {
|
|
90
|
-
this.localizationPhrases =
|
|
106
|
+
this.localizationPhrases = {
|
|
107
|
+
...this.localizationPhrases,
|
|
108
|
+
...localizationPhrases,
|
|
109
|
+
};
|
|
91
110
|
return this;
|
|
92
111
|
}
|
|
93
112
|
/**
|
package/dist/registercommand.js
CHANGED
|
@@ -48,11 +48,14 @@ const locales_1 = require("./locales");
|
|
|
48
48
|
* @param {ModularCommand} command The command instance.
|
|
49
49
|
* @param {Interaction} interaction The interaction object to get the locale from.
|
|
50
50
|
* @returns {CommandLocale} The resolved locale object.
|
|
51
|
-
* @throws {Error} If the EnglishUS localization is missing.
|
|
51
|
+
* @throws {Error} If the EnglishUS localization is missing when at least one localization is defined.
|
|
52
52
|
*/
|
|
53
53
|
function getCommandLocale(command, interaction) {
|
|
54
54
|
const localeTable = command.localizationPhrases;
|
|
55
|
-
if (!localeTable ||
|
|
55
|
+
if (!localeTable || Object.keys(localeTable).length === 0) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
if (!localeTable[discord_js_1.Locale.EnglishUS]) {
|
|
56
59
|
throw new Error(`Missing localization for EnglishUS in command ${command.name}`);
|
|
57
60
|
}
|
|
58
61
|
const targetLocale = localeTable[interaction.locale] ? interaction.locale : discord_js_1.Locale.EnglishUS;
|