levix-bot 4.5.0 → 4.7.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.
Files changed (40) hide show
  1. package/app.cjs +32 -7
  2. package/package.json +2 -2
  3. package/public/dashboard/assets/index-RnT7DAde.js +540 -0
  4. package/public/dashboard/assets/index-UcqCdCvG.css +2 -0
  5. package/public/dashboard/index.html +4 -3
  6. package/public/dashboard.css +123 -53
  7. package/public/gateway-i18n.js +295 -0
  8. package/public/gateway.js +30 -1
  9. package/public/ui-boot.js +71 -0
  10. package/src/bootstrap/core.js +9 -0
  11. package/src/commands/autodelete.cjs +213 -0
  12. package/src/commands/pack.cjs +46 -25
  13. package/src/commands/packs.cjs +4 -1
  14. package/src/commands/shortlink.cjs +273 -66
  15. package/src/commands/stickers.cjs +26 -8
  16. package/src/config/defaults.cjs +1 -0
  17. package/src/config/settings.cjs +10 -0
  18. package/src/core/session.js +9 -1
  19. package/src/db/db.cjs +57 -0
  20. package/src/db/store.cjs +250 -0
  21. package/src/diagnostics/crashReports.cjs +491 -0
  22. package/src/diagnostics/device.cjs +119 -0
  23. package/src/diagnostics/sanitize.cjs +90 -0
  24. package/src/handlers/command.handler.js +1 -0
  25. package/src/handlers/message.handler.js +15 -0
  26. package/src/index.js +9 -1
  27. package/src/panel/feedback.cjs +13 -1
  28. package/src/routes/dashboard.api.esm.js +188 -4
  29. package/src/services/autoDelete.cjs +578 -0
  30. package/src/stickers/errors.cjs +7 -6
  31. package/src/stickers/library.cjs +118 -13
  32. package/src/utils/bidi.cjs +21 -0
  33. package/src/utils/storage.cjs +14 -0
  34. package/src/utils/storage.esm.js +15 -0
  35. package/views/dashboard.ejs +2 -1
  36. package/views/login.ejs +102 -71
  37. package/views/qr.ejs +59 -30
  38. package/views/setup.ejs +34 -30
  39. package/public/dashboard/assets/index-COI8zgqa.css +0 -2
  40. package/public/dashboard/assets/index-IZMBuNAZ.js +0 -505
@@ -0,0 +1,295 @@
1
+ // The gateway pages' bilingual text (login · setup · QR).
2
+ //
3
+ // The English copy is the markup's own default; this file carries both
4
+ // languages and rewrites the marked nodes as the DOM is parsed, so a page
5
+ // follows the shared <html lang> that ui-boot.js set — no client framework and
6
+ // no second render. It is the same idea as views/dashboard.ejs + dashboard.js,
7
+ // kept in its own file because the QR page loads neither.
8
+ //
9
+ // Markup contract:
10
+ // data-i18n="key" -> textContent
11
+ // data-i18n-html="key" -> innerHTML (the string may carry <strong>)
12
+ // data-i18n-placeholder="key" -> placeholder
13
+ // data-i18n-aria-label="key" -> aria-label
14
+ // data-i18n-title="key" -> title attribute
15
+ // data-i18n-error="code" -> the server-rendered error, translated by code
16
+ // data-i18n-n="8" -> the {n} in the string
17
+ // <html data-brand> -> the {brand} in the string
18
+
19
+ (function () {
20
+ var DICT = {
21
+ en: {
22
+ // Titles
23
+ titleLogin: "{brand} · Sign in",
24
+ titleSetup: "{brand} · First run",
25
+ titleQr: "{brand} · Link WhatsApp",
26
+
27
+ // Shared
28
+ tagline: "Personal WhatsApp Bot",
29
+ storyAbout: "About {brand}",
30
+ by: "by",
31
+ backToApp: "Back to app",
32
+ showPassword: "Show password",
33
+ hidePassword: "Hide password",
34
+
35
+ // Login
36
+ selfHosted: "Self-hosted by design",
37
+ loginHeadline: "The quiet control room behind every chat.",
38
+ loginLede:
39
+ "Connection, commands, memory, and moderation stay together—on your server and within reach.",
40
+ loginTrust: "<span></span> Private workspace · direct control",
41
+ secureAccess: "Secure access",
42
+ welcomeBack: "Welcome back",
43
+ loginSub: "Sign in to manage your {brand} workspace.",
44
+ passwordLabel: "Control panel password",
45
+ passwordPlaceholder: "Enter your password",
46
+ openWorkspace: "Open workspace",
47
+ forgotPassword: "Forgot password?",
48
+
49
+ // Password reset
50
+ backToSignIn: "Back to sign in",
51
+ resetEyebrow: "Password reset",
52
+ resetTitle: "Reset your password",
53
+ resetSubtitle:
54
+ "{brand} sends a one-time code to your WhatsApp — the linked account's own chat. The code works for 10 minutes.",
55
+ resetSend: "Send code to WhatsApp",
56
+ resetCodeLabel: "Reset code",
57
+ resetCodePlaceholder: "6 digits",
58
+ newPassword: "New password",
59
+ minLengthPlaceholder: "At least {n} characters",
60
+ repeatPassword: "Repeat password",
61
+ repeatPlaceholder: "Type it again",
62
+ resetSubmit: "Set new password",
63
+ resetErrThrottled: "Too many requests. Try again in {n} seconds.",
64
+ resetErrNoSession:
65
+ "WhatsApp isn't connected, so the code can't be sent. Sign in on the server and run `levix reset-password`, or start the WhatsApp session first.",
66
+ resetErrSendFailed: "Couldn't send the WhatsApp message. Try again in a minute.",
67
+ resetErrStart: "Couldn't start the reset. Try again.",
68
+ resetErrServer: "Couldn't reach the server. Try again.",
69
+ resetDone: "Password updated. Taking you to sign in…",
70
+ resetErrWrongCode: "Wrong code.",
71
+ resetErrAttemptsLeft: "{n} attempts left.",
72
+ resetErrExpired: "That code is no longer valid. Send a new one.",
73
+ resetErrMismatch: "The two passwords don't match.",
74
+ resetErrInvalidPassword: "That password isn't allowed.",
75
+ resetErrFailed: "Couldn't reset the password. Try again.",
76
+
77
+ // Setup
78
+ firstMinute: "Your first minute",
79
+ setupHeadline: "Make the workspace yours.",
80
+ setupLede:
81
+ "Choose one strong password, then manage the assistant from a single private control room.",
82
+ setupTrust: "<span></span> One setup · no configuration files",
83
+ createWorkspace: "Create your workspace",
84
+ setupWelcome: "Welcome to {brand}",
85
+ setupSub: "Protect the linked WhatsApp account with at least {n} characters.",
86
+ setupCodeLabel: "Setup code",
87
+ setupCodePlaceholder: "Printed in the bot's terminal",
88
+ setupCodeHint: "Confirms you can access the server running {brand}.",
89
+ setupPasswordLabel: "Password",
90
+ createWorkspaceBtn: "Create workspace",
91
+
92
+ // QR pairing
93
+ directLine: "A direct line",
94
+ qrHeadline: "Bring your assistant online.",
95
+ qrLede: "One scan securely links {brand} to the WhatsApp account you choose.",
96
+ qrTrust: "<span></span> Live pairing status",
97
+ linkDevice: "Link device",
98
+ qrScanTitle: "Scan with WhatsApp",
99
+ qrWaiting: "Waiting…",
100
+ qrStep1: "<span>Open</span> WhatsApp on the phone the bot should use.",
101
+ qrStep2: "<span>Choose</span> Settings → Linked devices → Link a device.",
102
+ qrStep3: "<span>Scan</span> the code shown above.",
103
+ qrCallout:
104
+ "No code yet? Press <strong>Start session</strong> on the dashboard's Connection screen.",
105
+ backToDashboard: "Back to dashboard",
106
+ qrScanMe: "Scan me",
107
+ qrWaitingCode: "Waiting for a code…",
108
+ qrConnected: "Connected",
109
+ qrLinked: "Linked ✓",
110
+ qrNotStarted: "Not started — start it from the dashboard",
111
+ qrConnecting: "Connecting…",
112
+
113
+ // Server-rendered errors, keyed by the code app.cjs passes beside them
114
+ tooManyAttempts: "Too many attempts. Try again later.",
115
+ incorrectPassword: "Incorrect Password",
116
+ wrongSetupCode: "Wrong setup code.",
117
+ passwordMismatch: "The two passwords don't match.",
118
+ invalidPassword: "Password must be at least {n} characters",
119
+ },
120
+ ar: {
121
+ // Titles
122
+ titleLogin: "{brand} · تسجيل الدخول",
123
+ titleSetup: "{brand} · التشغيل الأول",
124
+ titleQr: "{brand} · ربط واتساب",
125
+
126
+ // Shared
127
+ tagline: "بوت واتساب شخصي",
128
+ storyAbout: "عن {brand}",
129
+ by: "من",
130
+ backToApp: "العودة للتطبيق",
131
+ showPassword: "إظهار كلمة المرور",
132
+ hidePassword: "إخفاء كلمة المرور",
133
+
134
+ // Login
135
+ selfHosted: "استضافة ذاتية بالتصميم",
136
+ loginHeadline: "غرفة التحكم الهادئة خلف كل محادثة.",
137
+ loginLede: "الاتصال والأوامر والذاكرة والإشراف في مكان واحد — على خادمك وفي متناول يدك.",
138
+ loginTrust: "<span></span> مساحة عمل خاصة · تحكم مباشر",
139
+ secureAccess: "وصول آمن",
140
+ welcomeBack: "أهلاً بعودتك",
141
+ loginSub: "سجّل الدخول لإدارة مساحة عمل {brand}.",
142
+ passwordLabel: "كلمة مرور لوحة التحكم",
143
+ passwordPlaceholder: "أدخل كلمة المرور",
144
+ openWorkspace: "افتح مساحة العمل",
145
+ forgotPassword: "نسيت كلمة المرور؟",
146
+
147
+ // Password reset
148
+ backToSignIn: "العودة لتسجيل الدخول",
149
+ resetEyebrow: "إعادة تعيين كلمة المرور",
150
+ resetTitle: "أعِد تعيين كلمة المرور",
151
+ resetSubtitle:
152
+ "يرسل {brand} كوداً لمرة واحدة إلى واتساب الخاص بك — محادثة الحساب المرتبط نفسه. يصلح الكود لمدة 10 دقائق.",
153
+ resetSend: "أرسل الكود إلى واتساب",
154
+ resetCodeLabel: "كود إعادة التعيين",
155
+ resetCodePlaceholder: "6 أرقام",
156
+ newPassword: "كلمة المرور الجديدة",
157
+ minLengthPlaceholder: "لا تقل عن {n} خانات",
158
+ repeatPassword: "أعِد كتابة كلمة المرور",
159
+ repeatPlaceholder: "اكتبها مرة أخرى",
160
+ resetSubmit: "تعيين كلمة المرور الجديدة",
161
+ resetErrThrottled: "طلبات كثيرة جداً. حاول مرة أخرى خلال {n} ثانية.",
162
+ resetErrNoSession:
163
+ "واتساب غير متصل، لذا لا يمكن إرسال الكود. سجّل الدخول على الخادم ونفّذ `levix reset-password`، أو ابدأ جلسة واتساب أولاً.",
164
+ resetErrSendFailed: "تعذّر إرسال رسالة واتساب. حاول مرة أخرى خلال دقيقة.",
165
+ resetErrStart: "تعذّر بدء إعادة التعيين. حاول مرة أخرى.",
166
+ resetErrServer: "تعذّر الوصول إلى الخادم. حاول مرة أخرى.",
167
+ resetDone: "تم تحديث كلمة المرور. جارٍ تحويلك لتسجيل الدخول…",
168
+ resetErrWrongCode: "كود غير صحيح.",
169
+ resetErrAttemptsLeft: "{n} محاولات متبقية.",
170
+ resetErrExpired: "هذا الكود لم يعد صالحاً. أرسل كوداً جديداً.",
171
+ resetErrMismatch: "كلمتا المرور غير متطابقتين.",
172
+ resetErrInvalidPassword: "كلمة المرور غير مقبولة.",
173
+ resetErrFailed: "تعذّر إعادة تعيين كلمة المرور. حاول مرة أخرى.",
174
+
175
+ // Setup
176
+ firstMinute: "دقيقتك الأولى",
177
+ setupHeadline: "اجعل مساحة العمل ملكك.",
178
+ setupLede: "اختر كلمة مرور قوية واحدة، ثم أدِر المساعد من غرفة تحكم خاصة واحدة.",
179
+ setupTrust: "<span></span> إعداد واحد · بلا ملفات إعداد",
180
+ createWorkspace: "أنشئ مساحة عملك",
181
+ setupWelcome: "مرحباً بك في {brand}",
182
+ setupSub: "احمِ حساب واتساب المرتبط بكلمة مرور لا تقل عن {n} خانات.",
183
+ setupCodeLabel: "رمز الإعداد",
184
+ setupCodePlaceholder: "يُطبع في طرفية البوت",
185
+ setupCodeHint: "يتأكد من إمكانية وصولك إلى الخادم الذي يعمل عليه {brand}.",
186
+ setupPasswordLabel: "كلمة المرور",
187
+ createWorkspaceBtn: "إنشاء مساحة العمل",
188
+
189
+ // QR pairing
190
+ directLine: "خط مباشر",
191
+ qrHeadline: "اجعل مساعدك متصلاً.",
192
+ qrLede: "مسحة واحدة تربط {brand} بأمان بحساب واتساب الذي تختاره.",
193
+ qrTrust: "<span></span> حالة الربط المباشرة",
194
+ linkDevice: "ربط جهاز",
195
+ qrScanTitle: "امسح باستخدام واتساب",
196
+ qrWaiting: "بانتظار…",
197
+ qrStep1: "<span>افتح</span> واتساب على الهاتف الذي سيعمل عليه البوت.",
198
+ qrStep2: "<span>اختر</span> الإعدادات ← الأجهزة المرتبطة ← ربط جهاز.",
199
+ qrStep3: "<span>امسح</span> الرمز الظاهر بالأعلى.",
200
+ qrCallout: "لا يوجد رمز بعد؟ اضغط <strong>بدء الاتصال</strong> في شاشة الاتصال بلوحة التحكم.",
201
+ backToDashboard: "العودة إلى لوحة التحكم",
202
+ qrScanMe: "امسحني",
203
+ qrWaitingCode: "بانتظار رمز…",
204
+ qrConnected: "متصل",
205
+ qrLinked: "تم الربط ✓",
206
+ qrNotStarted: "لم تبدأ — ابدأها من لوحة التحكم",
207
+ qrConnecting: "جارٍ الاتصال…",
208
+
209
+ // Server-rendered errors, keyed by the code app.cjs passes beside them
210
+ tooManyAttempts: "محاولات كثيرة جداً. حاول مرة أخرى لاحقاً.",
211
+ incorrectPassword: "كلمة المرور غير صحيحة",
212
+ wrongSetupCode: "رمز الإعداد غير صحيح.",
213
+ passwordMismatch: "كلمتا المرور غير متطابقتين.",
214
+ invalidPassword: "يجب ألا تقل كلمة المرور عن {n} خانات",
215
+ },
216
+ };
217
+
218
+ var root = document.documentElement;
219
+ var lang = root.lang === "ar" ? "ar" : "en";
220
+
221
+ function t(key, vars) {
222
+ var value = (DICT[lang] && DICT[lang][key]) || DICT.en[key] || key;
223
+ if (vars) {
224
+ Object.keys(vars).forEach(function (name) {
225
+ value = value.split("{" + name + "}").join(vars[name] == null ? "" : String(vars[name]));
226
+ });
227
+ }
228
+ return value;
229
+ }
230
+
231
+ function varsFor(el) {
232
+ return {
233
+ n: el.getAttribute("data-i18n-n"),
234
+ brand: root.getAttribute("data-brand") || "",
235
+ };
236
+ }
237
+
238
+ function paint(el) {
239
+ var key = el.getAttribute("data-i18n");
240
+ if (key) el.textContent = t(key, varsFor(el));
241
+ var htmlKey = el.getAttribute("data-i18n-html");
242
+ if (htmlKey) el.innerHTML = t(htmlKey, varsFor(el));
243
+ var placeholder = el.getAttribute("data-i18n-placeholder");
244
+ if (placeholder) el.setAttribute("placeholder", t(placeholder, varsFor(el)));
245
+ var ariaLabel = el.getAttribute("data-i18n-aria-label");
246
+ if (ariaLabel) el.setAttribute("aria-label", t(ariaLabel, varsFor(el)));
247
+ var title = el.getAttribute("data-i18n-title");
248
+ if (title) el.setAttribute("title", t(title, varsFor(el)));
249
+ var errorCode = el.getAttribute("data-i18n-error");
250
+ if (errorCode && DICT[lang] && DICT[lang][errorCode]) {
251
+ el.textContent = t(errorCode, varsFor(el));
252
+ }
253
+ }
254
+
255
+ function apply(scope) {
256
+ var nodes = (scope || document).querySelectorAll(
257
+ "[data-i18n],[data-i18n-html],[data-i18n-placeholder],[data-i18n-aria-label],[data-i18n-title],[data-i18n-error]",
258
+ );
259
+ for (var i = 0; i < nodes.length; i += 1) paint(nodes[i]);
260
+ }
261
+
262
+ function setLanguage(nextLang) {
263
+ if (nextLang !== "ar" && nextLang !== "en") return;
264
+ lang = nextLang;
265
+ root.lang = lang;
266
+ root.dir = lang === "ar" ? "rtl" : "ltr";
267
+ window.LevixGatewayI18n.lang = lang;
268
+ apply();
269
+ window.dispatchEvent(new CustomEvent("levix-gateway-lang", { detail: { lang: lang } }));
270
+ }
271
+
272
+ function setTheme(nextTheme) {
273
+ if (nextTheme === "dark" || nextTheme === "light") {
274
+ root.setAttribute("data-theme", nextTheme);
275
+ }
276
+ }
277
+
278
+ window.addEventListener("levix-ui-prefs", function (event) {
279
+ var detail = event.detail || {};
280
+ if (detail.theme) setTheme(detail.theme);
281
+ if (detail.language) setLanguage(detail.language);
282
+ });
283
+
284
+ window.addEventListener("storage", function (event) {
285
+ if (event.key === "levix_theme" && (event.newValue === "dark" || event.newValue === "light")) {
286
+ setTheme(event.newValue);
287
+ }
288
+ if (event.key === "levix_lang" && (event.newValue === "ar" || event.newValue === "en")) {
289
+ setLanguage(event.newValue);
290
+ }
291
+ });
292
+
293
+ window.LevixGatewayI18n = { lang: lang, t: t, apply: apply };
294
+ apply();
295
+ })();
package/public/gateway.js CHANGED
@@ -4,6 +4,27 @@
4
4
  // itself fails to load: the page works without either one.
5
5
 
6
6
  (function () {
7
+ function updateEyeLabels() {
8
+ var i18n = window.LevixGatewayI18n;
9
+ var showLabel = i18n ? i18n.t("showPassword") : "Show password";
10
+ var hideLabel = i18n ? i18n.t("hidePassword") : "Hide password";
11
+ document.querySelectorAll(".eye-btn").forEach(function (btn) {
12
+ var isPressed = btn.getAttribute("aria-pressed") === "true";
13
+ btn.setAttribute("aria-label", isPressed ? hideLabel : showLabel);
14
+ });
15
+ }
16
+
17
+ document.querySelectorAll(".eye-btn").forEach(function (btn) {
18
+ btn.setAttribute("aria-pressed", "false");
19
+ });
20
+ updateEyeLabels();
21
+
22
+ window.addEventListener("levix-gateway-lang", updateEyeLabels);
23
+ window.addEventListener("levix-ui-prefs", updateEyeLabels);
24
+ window.addEventListener("storage", function (e) {
25
+ if (e.key === "levix_lang") updateEyeLabels();
26
+ });
27
+
7
28
  // Eye toggles. One delegated listener covers every password field on the
8
29
  // page — the button carries two icons and swaps which one is visible.
9
30
  document.addEventListener("click", function (event) {
@@ -13,12 +34,20 @@
13
34
  var input = btn.parentElement ? btn.parentElement.querySelector("input") : null;
14
35
  if (!input) return;
15
36
  var show = input.type === "password";
37
+ var start = input.selectionStart;
38
+ var end = input.selectionEnd;
16
39
  input.type = show ? "text" : "password";
40
+ input.focus({ preventScroll: true });
41
+ if (start !== null && end !== null) input.setSelectionRange(start, end);
17
42
  var on = btn.querySelector(".eye-on");
18
43
  var off = btn.querySelector(".eye-off");
19
44
  if (on) on.style.display = show ? "none" : "";
20
45
  if (off) off.style.display = show ? "" : "none";
21
- btn.setAttribute("aria-label", show ? "Hide password" : "Show password");
46
+ var i18n = window.LevixGatewayI18n;
47
+ var showLabel = i18n ? i18n.t("showPassword") : "Show password";
48
+ var hideLabel = i18n ? i18n.t("hidePassword") : "Hide password";
49
+ btn.setAttribute("aria-label", show ? hideLabel : showLabel);
50
+ btn.setAttribute("aria-pressed", String(show));
22
51
  });
23
52
 
24
53
  // Blur the password screens whenever the page can't be watched: another
@@ -0,0 +1,71 @@
1
+ // Decides lang, dir and data-theme before first paint, for the panel and
2
+ // every gateway page. Order: the Android host's preference, then what this
3
+ // browser saved, then the OS. Every gateway page is bilingual now, so none
4
+ // passes data-page-lang; the attribute remains an escape hatch for a future
5
+ // page whose text exists in one language only.
6
+ (function () {
7
+ var root = document.documentElement;
8
+ var host = window.LevixHost;
9
+ var script = document.currentScript;
10
+ var pageLang = script && script.getAttribute("data-page-lang");
11
+ var savedLang, savedTheme, prefs;
12
+ try {
13
+ savedLang = localStorage.getItem("levix_lang");
14
+ savedTheme = localStorage.getItem("levix_theme");
15
+ } catch (_) {}
16
+ if (host && typeof host.getUiPrefs === "function") {
17
+ try { prefs = JSON.parse(host.getUiPrefs()); } catch (_) {}
18
+ }
19
+ var language = prefs && (prefs.language === "ar" || prefs.language === "en")
20
+ ? prefs.language : (savedLang === "ar" || savedLang === "en" ? savedLang
21
+ : /^ar\b/i.test((navigator.languages && navigator.languages[0]) || navigator.language || "") ? "ar" : "en");
22
+ var dark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)");
23
+ var theme = prefs && (prefs.theme === "dark" || prefs.theme === "light")
24
+ ? prefs.theme : (savedTheme === "dark" || savedTheme === "light" ? savedTheme
25
+ : dark && dark.matches ? "dark" : "light");
26
+ function apply(next) {
27
+ var lang = pageLang || next.language;
28
+ if (lang === "ar" || lang === "en") {
29
+ root.lang = lang;
30
+ root.dir = lang === "ar" ? "rtl" : "ltr";
31
+ }
32
+ if (next.theme === "dark" || next.theme === "light") root.setAttribute("data-theme", next.theme);
33
+ }
34
+ apply({ language: language, theme: theme });
35
+ if (prefs) {
36
+ try {
37
+ localStorage.setItem("levix_lang", language);
38
+ localStorage.setItem("levix_theme", theme);
39
+ } catch (_) {}
40
+ }
41
+ window.addEventListener("levix-ui-prefs", function (event) {
42
+ var next = event.detail || {};
43
+ apply(next);
44
+ if (host) {
45
+ try {
46
+ if (next.language === "ar" || next.language === "en") localStorage.setItem("levix_lang", next.language);
47
+ if (next.theme === "dark" || next.theme === "light") localStorage.setItem("levix_theme", next.theme);
48
+ } catch (_) {}
49
+ }
50
+ });
51
+ window.addEventListener("storage", function (event) {
52
+ var next = {};
53
+ if (event.key === "levix_theme" && (event.newValue === "dark" || event.newValue === "light")) {
54
+ next.theme = event.newValue;
55
+ }
56
+ if (event.key === "levix_lang" && (event.newValue === "ar" || event.newValue === "en")) {
57
+ next.language = event.newValue;
58
+ }
59
+ if (next.theme || next.language) {
60
+ apply(next);
61
+ }
62
+ });
63
+ if (!host && savedTheme !== "dark" && savedTheme !== "light" && dark) {
64
+ dark.addEventListener("change", function (event) {
65
+ try { if (localStorage.getItem("levix_theme")) return; } catch (_) {}
66
+ var next = { theme: event.matches ? "dark" : "light" };
67
+ apply(next);
68
+ window.dispatchEvent(new CustomEvent("levix-ui-prefs", { detail: next }));
69
+ });
70
+ }
71
+ })();
@@ -45,6 +45,15 @@ export async function bootstrapCore({ autoStart = false } = {}) {
45
45
  // bot's state, not next to the code.
46
46
  ensureDataDir("media");
47
47
 
48
+ // Crash reports are local until the operator sends one. Sweep expired and
49
+ // over-cap files on boot so a device that crashed repeatedly does not keep
50
+ // them forever.
51
+ try {
52
+ require("../diagnostics/crashReports.cjs").sweep();
53
+ } catch (error) {
54
+ logger.warn({ err: error }, "[crash-reports] boot sweep failed");
55
+ }
56
+
48
57
  // A `creds` row alone is not enough: Baileys creates one before pairing.
49
58
  // `me.id` is the durable proof that this install was actually linked.
50
59
  const wasPaired = hasPairedCredentials(store.authRead("creds"));
@@ -0,0 +1,213 @@
1
+ const { tr } = require("../utils/i18n.cjs");
2
+ const logger = require("../utils/logger.cjs");
3
+ const autoDelete = require("../services/autoDelete.cjs");
4
+
5
+ const LIST_WORDS = new Set(["list", "ls", "show", "قائمة", "عرض"]);
6
+ const ADD_WORDS = new Set(["add", "اضف", "أضف", "ضيف"]);
7
+ const REMOVE_WORDS = new Set(["remove", "del", "delete", "rm", "احذف", "شيل", "امسح"]);
8
+ const ON_WORDS = new Set(["on", "enable", "تشغيل", "تفعيل"]);
9
+ const OFF_WORDS = new Set(["off", "disable", "ايقاف", "إيقاف", "تعطيل"]);
10
+ const STATS_WORDS = new Set(["stats", "stat", "counter", "احصائيات", "إحصائيات", "عداد"]);
11
+ const RESET_WORDS = new Set(["reset", "صفر", "صفّر", "اعادة", "إعادة"]);
12
+
13
+ function parseKeywords(args) {
14
+ return args
15
+ .join(" ")
16
+ .split("|")
17
+ .map((part) => part.trim())
18
+ .filter(Boolean);
19
+ }
20
+
21
+ function parseIdArg(value) {
22
+ const raw = String(value ?? "")
23
+ .trim()
24
+ .replace(/^#/, "");
25
+ const id = Number(raw);
26
+ if (!Number.isInteger(id) || id <= 0) return null;
27
+ return id;
28
+ }
29
+
30
+ function formatRule(rule) {
31
+ const state = rule.enabled ? tr("on", "تشغيل") : tr("off", "إيقاف");
32
+ const label = rule.name ? ` "${rule.name}"` : "";
33
+ const keywords = rule.keywords.join(", ");
34
+ return tr(
35
+ `#${rule.id}${label} · ${state} · ${rule.match} · ${rule.keywords.length} keyword(s) · deleted ${rule.deletedCount}\n ${keywords}`,
36
+ `#${rule.id}${label} · ${state} · ${rule.match} · ${rule.keywords.length} كلمة · حُذف ${rule.deletedCount}\n ${keywords}`,
37
+ );
38
+ }
39
+
40
+ function formatWhen(ts) {
41
+ if (!ts) return tr("never", "أبداً");
42
+ return new Date(ts).toISOString();
43
+ }
44
+
45
+ module.exports = {
46
+ name: "autodelete",
47
+ aliases: [...autoDelete.DECLARED_ALIASES],
48
+ description: {
49
+ en: "Manages keyword auto-delete rules: add, remove, enable, disable, and counters.",
50
+ ar: "يدير قواعد الحذف التلقائي حسب الكلمات: إضافة وإزالة وتشغيل وإيقاف والعداد.",
51
+ },
52
+ usage: {
53
+ en: "autodelete list\nautodelete add <word> [| <word> ...]\nautodelete remove <id>\nautodelete on <id>\nautodelete off <id>\nautodelete stats [id]\nautodelete reset <id>",
54
+ ar: "autodelete list\nautodelete add <كلمة> [| <كلمة> ...]\nautodelete remove <id>\nautodelete on <id>\nautodelete off <id>\nautodelete stats [id]\nautodelete reset <id>",
55
+ },
56
+ chat: "all",
57
+ keywords: [
58
+ ...LIST_WORDS,
59
+ ...ADD_WORDS,
60
+ ...REMOVE_WORDS,
61
+ ...ON_WORDS,
62
+ ...OFF_WORDS,
63
+ ...STATS_WORDS,
64
+ ...RESET_WORDS,
65
+ ],
66
+
67
+ async execute(sock, msg, args) {
68
+ const jid = msg.key.remoteJid;
69
+ const action = String(args[0] || "").toLowerCase();
70
+
71
+ try {
72
+ if (!action || LIST_WORDS.has(action)) {
73
+ const rules = autoDelete.listRules();
74
+ if (!rules.length) {
75
+ return sock.sendMessage(jid, {
76
+ text: tr("No auto-delete rules yet.", "لا توجد قواعد حذف تلقائي بعد."),
77
+ });
78
+ }
79
+ const header = tr(
80
+ `*Auto-delete rules (${rules.length}):*\n\n`,
81
+ `*قواعد الحذف التلقائي (${rules.length}):*\n\n`,
82
+ );
83
+ return sock.sendMessage(jid, {
84
+ text: header + rules.map(formatRule).join("\n"),
85
+ });
86
+ }
87
+
88
+ if (ADD_WORDS.has(action)) {
89
+ const keywords = parseKeywords(args.slice(1));
90
+ if (!keywords.length) {
91
+ return sock.sendMessage(jid, {
92
+ text: tr(
93
+ "Write one or more words to auto-delete, separated by |.",
94
+ "اكتب كلمة أو أكثر للحذف التلقائي، مفصولة بـ |.",
95
+ ),
96
+ });
97
+ }
98
+ const rule = autoDelete.createRule({
99
+ keywords,
100
+ match: "contains",
101
+ chatScope: "all",
102
+ senders: { mode: "everyone", list: [] },
103
+ includeOwn: false,
104
+ forEveryone: true,
105
+ keepCopy: false,
106
+ enabled: true,
107
+ });
108
+ return sock.sendMessage(jid, {
109
+ text: tr(
110
+ `Added auto-delete rule #${rule.id} (${rule.keywords.join(", ")}).`,
111
+ `تمت إضافة قاعدة الحذف التلقائي #${rule.id} (${rule.keywords.join(", ")}).`,
112
+ ),
113
+ });
114
+ }
115
+
116
+ if (REMOVE_WORDS.has(action)) {
117
+ const id = parseIdArg(args[1]);
118
+ if (!id) {
119
+ return sock.sendMessage(jid, {
120
+ text: tr("Give a rule id to remove.", "أدخل رقم القاعدة للحذف."),
121
+ });
122
+ }
123
+ autoDelete.deleteRule(id);
124
+ return sock.sendMessage(jid, {
125
+ text: tr(`Removed auto-delete rule #${id}.`, `تم حذف قاعدة الحذف التلقائي #${id}.`),
126
+ });
127
+ }
128
+
129
+ if (ON_WORDS.has(action) || OFF_WORDS.has(action)) {
130
+ const id = parseIdArg(args[1]);
131
+ if (!id) {
132
+ return sock.sendMessage(jid, {
133
+ text: tr("Give a rule id.", "أدخل رقم القاعدة."),
134
+ });
135
+ }
136
+ const enabled = ON_WORDS.has(action);
137
+ autoDelete.updateRule(id, { enabled });
138
+ return sock.sendMessage(jid, {
139
+ text: enabled
140
+ ? tr(`Auto-delete rule #${id} is on.`, `قاعدة الحذف التلقائي #${id} مفعّلة.`)
141
+ : tr(`Auto-delete rule #${id} is off.`, `قاعدة الحذف التلقائي #${id} موقوفة.`),
142
+ });
143
+ }
144
+
145
+ if (STATS_WORDS.has(action)) {
146
+ if (args[1]) {
147
+ const id = parseIdArg(args[1]);
148
+ if (!id) {
149
+ return sock.sendMessage(jid, {
150
+ text: tr("Give a rule id.", "أدخل رقم القاعدة."),
151
+ });
152
+ }
153
+ const rule = autoDelete.getRule(id);
154
+ return sock.sendMessage(jid, {
155
+ text: tr(
156
+ `*Rule #${rule.id}*${rule.name ? ` ${rule.name}` : ""}\nDeleted: ${rule.deletedCount}\nLast: ${formatWhen(rule.lastDeletedAt)}`,
157
+ `*القاعدة #${rule.id}*${rule.name ? ` ${rule.name}` : ""}\nحُذف: ${rule.deletedCount}\nآخر مرة: ${formatWhen(rule.lastDeletedAt)}`,
158
+ ),
159
+ });
160
+ }
161
+ const rules = autoDelete.listRules();
162
+ const total = rules.reduce((sum, rule) => sum + (rule.deletedCount || 0), 0);
163
+ return sock.sendMessage(jid, {
164
+ text: tr(
165
+ `*Auto-delete counters*\nRules: ${rules.length}\nDeleted: ${total}`,
166
+ `*عدادات الحذف التلقائي*\nالقواعد: ${rules.length}\nحُذف: ${total}`,
167
+ ),
168
+ });
169
+ }
170
+
171
+ if (RESET_WORDS.has(action)) {
172
+ const id = parseIdArg(args[1]);
173
+ if (!id) {
174
+ return sock.sendMessage(jid, {
175
+ text: tr("Give a rule id to reset.", "أدخل رقم القاعدة لتصفير العداد."),
176
+ });
177
+ }
178
+ autoDelete.resetCounter(id);
179
+ return sock.sendMessage(jid, {
180
+ text: tr(
181
+ `Reset the counter for auto-delete rule #${id}.`,
182
+ `تم تصفير عداد قاعدة الحذف التلقائي #${id}.`,
183
+ ),
184
+ });
185
+ }
186
+
187
+ return sock.sendMessage(jid, {
188
+ text: tr(
189
+ "Unknown sub-command. Try list, add, remove, on, off, stats, reset.",
190
+ "أمر فرعي غير معروف. جرّب list أو add أو remove أو on أو off أو stats أو reset.",
191
+ ),
192
+ });
193
+ } catch (error) {
194
+ if (error?.status === 404) {
195
+ return sock.sendMessage(jid, {
196
+ text: tr("No auto-delete rule with that id.", "لا توجد قاعدة حذف تلقائي بهذا الرقم."),
197
+ });
198
+ }
199
+ if (error?.name === "AutoDeleteError" || error?.status === 400) {
200
+ return sock.sendMessage(jid, {
201
+ text: tr(
202
+ `Could not update that rule: ${error.message}`,
203
+ `تعذر تحديث القاعدة: ${error.message}`,
204
+ ),
205
+ });
206
+ }
207
+ logger.error({ err: error, command: "autodelete" }, "auto-delete command failed");
208
+ return sock.sendMessage(jid, {
209
+ text: tr("Something went wrong with auto-delete.", "حدث خطأ أثناء معالجة الحذف التلقائي."),
210
+ });
211
+ }
212
+ },
213
+ };