js-discord-modularcommand 2.0.3 → 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.
@@ -3,7 +3,7 @@
3
3
  * @author vicentefelipechile
4
4
  * @license MIT
5
5
  */
6
- import { LocalizationMap, ButtonStyle, Locale } from 'discord.js';
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: Record<string, Record<Locale, string>>;
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?: Record<Locale, string>;
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 {Record<string, Record<Locale, string>>} localizations An object with the localizations.
89
+ * @param {LocalizationMap} localizations An object with the localizations.
83
90
  * @returns {ModularCommand} The command instance for chaining.
84
91
  */
85
- setLocalizationOptions(localizations: Record<string, Record<Locale, string>>): this;
92
+ setLocalizationOptions(localizations: LocalizationMap): this;
86
93
  /**
87
94
  * Sets the localization phrases for the command.
88
- * @param {Record<Locale, string>} localizationPhrases The localization phrases.
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: Record<Locale, string>): this;
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.
@@ -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 = localizations;
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 {Record<string, Record<Locale, string>>} localizations An object with the localizations.
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 = localizations;
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
- * @param {Record<Locale, string>} localizationPhrases The localization phrases.
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 = localizationPhrases;
106
+ this.localizationPhrases = {
107
+ ...this.localizationPhrases,
108
+ ...localizationPhrases,
109
+ };
91
110
  return this;
92
111
  }
93
112
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-discord-modularcommand",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "discord",