@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.
- package/dist/drivers/whatsapp/index.js +9 -5
- package/dist/i18n/index.js +16 -10
- package/dist/main.js +0 -0
- package/package.json +1 -1
|
@@ -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 (
|
|
67
|
+
if (state !== "READY")
|
|
68
|
+
return;
|
|
69
|
+
if (type !== "notify" && type !== "append")
|
|
68
70
|
return;
|
|
69
71
|
for (const msg of messages) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
79
|
+
await handleMessage(m, sock, store);
|
|
76
80
|
}
|
|
77
81
|
catch (e) {
|
|
78
82
|
const err = e instanceof Error ? e : new Error(String(e));
|
package/dist/i18n/index.js
CHANGED
|
@@ -85,9 +85,16 @@ function getConfiguredLang() {
|
|
|
85
85
|
return lang;
|
|
86
86
|
}
|
|
87
87
|
// Load languages
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|