spacecommands 3.5.2 → 3.5.4

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.
@@ -31,13 +31,14 @@ module.exports = {
31
31
  }
32
32
  const lang = text.toLowerCase();
33
33
  if (!instance.messageHandler.languages().includes(lang)) {
34
- return interaction.reply({
34
+ await interaction.reply({
35
35
  content: instance.messageHandler.get(guild, 'LANGUAGE_NOT_SUPPORTED', { LANGUAGE: lang }),
36
36
  flags: discord_js_1.MessageFlags.Ephemeral,
37
37
  });
38
+ return;
38
39
  }
39
40
  await instance.messageHandler.setUserLanguage(user, lang);
40
- return interaction.reply({
41
+ await interaction.reply({
41
42
  content: instance.messageHandler.get(guild, 'NEW_LANGUAGE', { LANGUAGE: lang }, user),
42
43
  flags: discord_js_1.MessageFlags.Ephemeral,
43
44
  });
@@ -49,11 +49,24 @@ class MessageHandler {
49
49
  this._instance = instance;
50
50
  (async () => {
51
51
  this._messages = messagePath ? await Promise.resolve(`${messagePath}`).then(s => __importStar(require(s))) : defualtMessages;
52
- for (const messageId of Object.keys(this._messages)) {
53
- for (const language of Object.keys(this._messages[messageId])) {
52
+ const languages = this._messages['LANGUAGE_NOT_SUPPORTED'] || this._messages['NEW_LANGUAGE'];
53
+ if (languages) {
54
+ for (const language of Object.keys(languages)) {
54
55
  this._languages.push(language.toLowerCase());
55
56
  }
56
57
  }
58
+ else {
59
+ // Fallback: Use the first message found if standard ones are missing (unlikely)
60
+ for (const messageId of Object.keys(this._messages)) {
61
+ for (const language of Object.keys(this._messages[messageId])) {
62
+ const lowerCaseLanguage = language.toLowerCase();
63
+ if (!this._languages.includes(lowerCaseLanguage)) {
64
+ this._languages.push(lowerCaseLanguage);
65
+ }
66
+ }
67
+ break; // Only check the first message to avoid iterating config objects
68
+ }
69
+ }
57
70
  if (!this._languages.includes(instance.defaultLanguage)) {
58
71
  throw new Error(`The current default language defined is not supported.`);
59
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spacecommands",
3
- "version": "3.5.2",
3
+ "version": "3.5.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "./typings.d.ts",
6
6
  "typings": "./typings.d.ts",