@manybot/manybot 5.2.5 → 5.2.6

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.
@@ -64,15 +64,19 @@ async function startBot() {
64
64
  });
65
65
  // Incoming messages
66
66
  sock.ev.on("messages.upsert", async ({ messages, type }) => {
67
- if (type !== "notify" || state !== "READY")
67
+ if (state !== "READY")
68
+ return;
69
+ if (type !== "notify" && type !== "append")
68
70
  return;
69
71
  for (const msg of messages) {
70
- // Skip empty messages (e.g. presence updates)
71
- const body = getBodyQuick(msg);
72
- if (!body && !msgHasMediaQuick(msg))
72
+ const m = msg;
73
+ if (type === "append" && !m.key.fromMe)
74
+ continue;
75
+ const body = getBodyQuick(m);
76
+ if (!body && !msgHasMediaQuick(m))
73
77
  continue;
74
78
  try {
75
- await handleMessage(msg, sock, store);
79
+ await handleMessage(m, sock, store);
76
80
  }
77
81
  catch (e) {
78
82
  const err = e instanceof Error ? e : new Error(String(e));
@@ -85,9 +85,16 @@ function getConfiguredLang() {
85
85
  return lang;
86
86
  }
87
87
  // Load languages
88
- const currentLang = getConfiguredLang();
89
- const currentTranslations = loadLocale(currentLang) || {};
90
- const fallbackTranslations = loadLocale(DEFAULT_LANG) || {};
88
+ let currentLang = null;
89
+ let currentTranslations = {};
90
+ let fallbackTranslations = {};
91
+ function ensureLoaded() {
92
+ if (currentLang !== null)
93
+ return;
94
+ currentLang = getConfiguredLang();
95
+ currentTranslations = loadLocale(currentLang) || {};
96
+ fallbackTranslations = loadLocale(DEFAULT_LANG) || {};
97
+ }
91
98
  /**
92
99
  * Gets a nested value from an object using dot path
93
100
  * @param {object} obj
@@ -123,6 +130,7 @@ function interpolate(str, context = {}) {
123
130
  * @returns {string}
124
131
  */
125
132
  export function t(key, context = {}) {
133
+ ensureLoaded();
126
134
  // Try current language first
127
135
  let value = getNestedValue(currentTranslations, key);
128
136
  // Fallback to English if not found
@@ -162,6 +170,7 @@ export function t(key, context = {}) {
162
170
  export function createPluginT(pluginMetaUrl) {
163
171
  const pluginDir = path.dirname(fileURLToPath(pluginMetaUrl));
164
172
  const pluginLocaleDir = path.join(pluginDir, "locale");
173
+ ensureLoaded();
165
174
  // Get bot's configured language
166
175
  const targetLang = currentLang;
167
176
  // Load plugin translations
@@ -211,19 +220,16 @@ export function createPluginT(pluginMetaUrl) {
211
220
  */
212
221
  export function reloadTranslations() {
213
222
  translations.clear();
214
- const lang = getConfiguredLang();
215
- const newTranslations = loadLocale(lang) || {};
216
- const newFallback = loadLocale(DEFAULT_LANG) || {};
217
- // Update references
218
- Object.assign(currentTranslations, newTranslations);
219
- Object.assign(fallbackTranslations, newFallback);
220
- console.log(`[i18n] Translations reloaded for language: ${lang}`);
223
+ currentLang = null;
224
+ ensureLoaded();
225
+ console.log(`[i18n] Translations reloaded for language: ${currentLang}`);
221
226
  }
222
227
  /**
223
228
  * Returns current language
224
229
  * @returns {string}
225
230
  */
226
231
  export function getCurrentLang() {
232
+ ensureLoaded();
227
233
  return currentLang;
228
234
  }
229
235
  export default { t, createPluginT, reloadTranslations, getCurrentLang };
package/dist/main.js CHANGED
File without changes
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "SyntaxError!",
6
6
  "email": "me@stxerr.dev"
7
7
  },
8
- "version": "5.2.5",
8
+ "version": "5.2.6",
9
9
  "license": "GPL-3.0-only",
10
10
  "private": false,
11
11
  "engines": {