levix-bot 4.7.0 → 4.9.1

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 (62) hide show
  1. package/README.md +21 -7
  2. package/SETUP.md +21 -2
  3. package/app.cjs +69 -23
  4. package/package.json +3 -2
  5. package/public/dashboard/assets/index-B1sOW2VX.js +561 -0
  6. package/public/dashboard/assets/index-CK8osB4o.css +2 -0
  7. package/public/dashboard/index.html +2 -2
  8. package/public/dashboard.css +50 -0
  9. package/public/dashboard.js +25 -2
  10. package/public/gateway-i18n.js +26 -0
  11. package/src/bootstrap/session-startup-policy.js +6 -6
  12. package/src/commands/group/antilink.cjs +82 -59
  13. package/src/commands/group/antispam.cjs +112 -0
  14. package/src/commands/group/clearwarns.cjs +6 -6
  15. package/src/commands/group/demote.cjs +11 -13
  16. package/src/commands/group/flagged.cjs +52 -0
  17. package/src/commands/group/kick.cjs +25 -15
  18. package/src/commands/group/media.cjs +65 -29
  19. package/src/commands/group/policy.cjs +215 -0
  20. package/src/commands/group/promote.cjs +11 -12
  21. package/src/commands/group/rules.cjs +9 -6
  22. package/src/commands/group/setwarn.cjs +17 -27
  23. package/src/commands/group/warn.cjs +13 -63
  24. package/src/commands/group.cjs +5 -2
  25. package/src/commands/md.cjs +44 -0
  26. package/src/commands/mod.cjs +101 -26
  27. package/src/commands/translate.cjs +585 -0
  28. package/src/config/ai-identity.cjs +53 -1
  29. package/src/config/ai-persona.md +32 -73
  30. package/src/config/defaults.cjs +3 -0
  31. package/src/config/secrets.cjs +71 -3
  32. package/src/config/settings.cjs +22 -1
  33. package/src/core/socket.js +27 -5
  34. package/src/db/db.cjs +66 -0
  35. package/src/db/store.cjs +264 -16
  36. package/src/diagnostics/crashReports.cjs +35 -9
  37. package/src/diagnostics/debugLog.cjs +405 -0
  38. package/src/handlers/command.handler.js +3 -1
  39. package/src/handlers/group.handler.js +32 -1
  40. package/src/handlers/message.handler.js +53 -17
  41. package/src/middleware/antispam.middleware.js +95 -48
  42. package/src/panel/feedback.cjs +32 -5
  43. package/src/panel/one-time-code.cjs +156 -0
  44. package/src/panel/password-reset.cjs +187 -91
  45. package/src/panel/recovery-email.cjs +333 -0
  46. package/src/routes/dashboard.api.esm.js +341 -29
  47. package/src/services/aiAgent.cjs +25 -3
  48. package/src/services/moderationPolicy.cjs +895 -0
  49. package/src/services/settingsTransfer.cjs +4 -2
  50. package/src/utils/linkedCreds.cjs +22 -0
  51. package/src/utils/logger.cjs +93 -34
  52. package/src/utils/markdownParser.cjs +208 -136
  53. package/src/utils/moderationAction.cjs +637 -0
  54. package/src/utils/moderationSummary.cjs +225 -0
  55. package/src/utils/permissions.cjs +70 -0
  56. package/src/utils/permissions.esm.js +48 -8
  57. package/src/utils/storage.cjs +8 -0
  58. package/src/utils/storage.esm.js +4 -0
  59. package/views/login.ejs +100 -28
  60. package/public/dashboard/assets/index-RnT7DAde.js +0 -540
  61. package/public/dashboard/assets/index-UcqCdCvG.css +0 -2
  62. package/src/commands/group/antiSpam.cjs +0 -97
package/README.md CHANGED
@@ -16,11 +16,12 @@
16
16
  <p align="center">
17
17
  <a href="https://levix.leviro.net">Website</a> ·
18
18
  <a href="SETUP.md">Setup guide</a> ·
19
+ <a href="https://levix.leviro.net/docs/contributing">Contribute</a> ·
19
20
  <a href="https://github.com/Abdodiab2005/levix/releases/latest">Downloads</a> ·
20
21
  <a href="https://github.com/Abdodiab2005/levix/issues">Issues</a>
21
22
  </p>
22
23
 
23
- Levix is a personal WhatsApp bot with 55 commands, group moderation, scheduled
24
+ Levix is a personal WhatsApp bot with a growing command catalog, group moderation, scheduled
24
25
  messages, an AI agent, media tools, and a web control panel. You run it on your
25
26
  own computer or server, keep its database and session files yourself, and can
26
27
  change almost everything while it is running.
@@ -72,8 +73,8 @@ docker compose logs levix
72
73
  Run Levix directly on an Android device (Android 10+, ARM64 or ARMv7) as a self-contained background companion:
73
74
 
74
75
  1. Download **`levix-android-arm64.apk`** (64-bit phones) or **`levix-android-armv7.apk`** (32-bit phones) from [Releases](https://github.com/Abdodiab2005/levix/releases).
75
- 2. Install the APK and tap **Start Host**.
76
- 3. Tap **Open Panel** to set your master password and link WhatsApp via 8-digit Pairing Code.
76
+ 2. Install the APK and tap **Start Assistant** — the big circle on the home screen.
77
+ 3. Tap **Connect WhatsApp** to set your panel password and link WhatsApp via an 8-character pairing code.
77
78
 
78
79
  See [ANDROID.md](ANDROID.md) for full instructions, OEM battery optimizations (Xiaomi, Samsung, OnePlus), and offline handling.
79
80
 
@@ -98,8 +99,9 @@ proxies, headless mode, backups, and troubleshooting.
98
99
 
99
100
  | Area | What Levix provides |
100
101
  | --- | --- |
101
- | Commands | 55 commands for utilities, notes, reminders, polls, media, speech, weather, prayer times, and more |
102
- | Group moderation | Welcome messages, anti-link, anti-spam, media rules, warnings, auto-kick, roles, rules, and notes |
102
+ | Commands | Utilities, notes, reminders, polls, media, speech, weather, prayer times, and more — configurable from the panel |
103
+ | Translation | `!translate` between Arabic and English, or into a language you name — with an AI engine (your active AI provider, with its own editable prompt) or Google's translation engine, plus summary, tone, explain, and detect options |
104
+ | Group moderation | Welcome messages, anti-link, anti-spam, media rules, and forbidden words in one linked pipeline with a shared warning counter per member — at the limit the group removes the member automatically or flags them for admin review, guided by a per-group policy (Relaxed / Standard / Strict presets, warning limit, per-feature actions, warning expiry); warnings, roles, rules, and notes too |
103
105
  | AI agent | Pick Google Gemini, OpenAI / any OpenAI-compatible server, or Anthropic from the panel; each provider has its own endpoint, API key, and model, with tools for web search, page reading, memory, and role management |
104
106
  | Scheduling | One-off, daily, and weekly messages with durable jobs, delivery status, and manual retry |
105
107
  | Control panel | Live connection state, command settings, roles, permissions, keys, memory, schedules, and logs |
@@ -118,6 +120,19 @@ several tool rounds, search the web, read a page, save long-term memories, and
118
120
  manage bot roles. It narrates progress by editing one WhatsApp message and lists
119
121
  sources when it uses web search.
120
122
 
123
+ AI answers are formatted for WhatsApp automatically: `**bold**` becomes `*bold*`,
124
+ `__italic__` becomes `_italic_`, and tables become named entries with labeled
125
+ bullet points. Headings, lists, checkboxes, strikethrough and links are converted;
126
+ code contents and URLs are preserved.
127
+
128
+ Replies follow the language and dialect you write in — Egyptian Arabic in,
129
+ Egyptian Arabic out.
130
+
131
+ Use `!md` (or `!markdown`) to convert text from any other AI or message, without
132
+ an AI key. Reply to that message with `!md`, or paste Markdown after the command,
133
+ including multiline tables and code. For example: `!md **Bold** and __italic__`.
134
+ Existing WhatsApp `*bold*` and `_italic_` text keeps its formatting.
135
+
121
136
  AI is optional. The rest of Levix works without an AI key.
122
137
 
123
138
  ### Persistent schedules and memory
@@ -199,8 +214,7 @@ npm test # runs the full test suite
199
214
  npm start # starts Levix
200
215
  ```
201
216
 
202
- Please read [CONTRIBUTING.md](CONTRIBUTING.md) before proposing a substantial
203
- change. Bug reports and focused pull requests are welcome.
217
+ Read the [contributor walkthrough](https://levix.leviro.net/docs/contributing) for the fork-to-pull-request workflow, then check [CONTRIBUTING.md](CONTRIBUTING.md) for the official repository rules. Bug reports and focused pull requests are welcome.
204
218
 
205
219
  For security issues, follow [SECURITY.md](SECURITY.md) and report them
206
220
  privately rather than opening a public issue.
package/SETUP.md CHANGED
@@ -119,7 +119,7 @@ bot has never been paired it prints the QR straight into the terminal:
119
119
  ✓ WhatsApp connected
120
120
  ✓ Levix is ready
121
121
 
122
- 55 commands loaded
122
+ [command count] commands loaded
123
123
  ```
124
124
 
125
125
  You can switch modes freely: the data directory is the same either way.
@@ -191,7 +191,7 @@ That always installs the newest stable Levix. To stay on this release — the
191
191
  same script, pinned — use its own URL:
192
192
 
193
193
  ```bash
194
- curl -fsSL https://levix.leviro.net/install/v2.2.1.sh | bash
194
+ curl -fsSL https://levix.leviro.net/install/v4.9.0.sh | bash
195
195
  ```
196
196
 
197
197
  **Behind a proxy** — if this server reaches the internet through a proxy, the
@@ -238,6 +238,25 @@ Server → Control panel port, then restart.
238
238
 
239
239
  **Forgot the panel password**
240
240
 
241
+ Two ways to get a one-time reset code without touching the terminal:
242
+
243
+ - **WhatsApp code** — on the login screen, choose **WhatsApp**; the code arrives
244
+ in your own chat with the bot. Needs the WhatsApp session up.
245
+ - **Recovery email** — if you added and verified an address under **Settings**,
246
+ the same screen offers **Email**, and the code goes to that address. It is
247
+ delivered by a Levix mail relay, which emails the code and keeps neither the
248
+ address nor the code in readable form. Adding the address in Settings asks
249
+ for the panel password. Ten wrong codes in a day pause reset for a day.
250
+ If email recovery needs verification again, sign in using WhatsApp recovery or
251
+ the CLI alternative below, then verify the address in Settings. Older saved
252
+ addresses also need this one-time verification after upgrading. Verifying an
253
+ address again disables email recovery on other installations using that address.
254
+ Authorization expires after 365 days without an accepted email-reset request;
255
+ network and mail-service outages do not remove your saved recovery settings.
256
+
257
+ If the session is down and neither can arrive, `levix reset-password` still
258
+ works from the terminal:
259
+
241
260
  ```bash
242
261
  levix reset-password
243
262
  ```
package/app.cjs CHANGED
@@ -27,6 +27,7 @@ const { clientAddress, isDirectLocalRequest } = require("./src/utils/requestOrig
27
27
  const { blockedFor, recordFailure, clearAttempts } = require("./src/panel/login-throttle.cjs");
28
28
  const { isPanelSessionValid, stampPanelSession } = require("./src/panel/session-auth.cjs");
29
29
  const { requestResetCode, completeReset } = require("./src/panel/password-reset.cjs");
30
+ const recoveryEmail = require("./src/panel/recovery-email.cjs");
30
31
 
31
32
  const SESSION_COOKIE_NAME = "wa.sid";
32
33
  const SESSION_MAX_AGE_MS = 12 * 60 * 60 * 1000;
@@ -289,6 +290,27 @@ app.post("/setup", (req, res, next) => {
289
290
 
290
291
  // --- Routes ---------------------------------------------------------------
291
292
 
293
+ // The login page lists reset channels. The email channel is the masked address
294
+ // or nothing — never the address itself. A read failure still renders login.
295
+ function loginPageLocals(error, errorCode) {
296
+ let masked = null;
297
+ let verified = false;
298
+ try {
299
+ const status = recoveryEmail.publicStatus();
300
+ verified = status.verified === true;
301
+ if (verified && status.masked) masked = status.masked;
302
+ } catch (readError) {
303
+ logger.warn({ err: readError }, "[recovery-email] Could not read the recovery address");
304
+ }
305
+ return {
306
+ error,
307
+ errorCode,
308
+ minLength: secrets.MIN_PASSWORD_LENGTH,
309
+ recoveryEmail: masked,
310
+ recoveryEmailVerified: verified,
311
+ };
312
+ }
313
+
292
314
  app.get("/", noStore, (req, res) => {
293
315
  if (!secrets.hasDashboardPassword()) return res.redirect("/setup");
294
316
  if (isPanelSessionValid(req.session)) {
@@ -306,21 +328,13 @@ app.get("/", noStore, (req, res) => {
306
328
  }
307
329
  return res.render("dashboard");
308
330
  }
309
- return res.render("login", {
310
- error: null,
311
- errorCode: null,
312
- minLength: secrets.MIN_PASSWORD_LENGTH,
313
- });
331
+ return res.render("login", loginPageLocals(null, null));
314
332
  });
315
333
 
316
334
  app.get("/login", noStore, (req, res) => {
317
335
  if (!secrets.hasDashboardPassword()) return res.redirect("/setup");
318
336
  if (isPanelSessionValid(req.session)) return res.redirect("/");
319
- return res.render("login", {
320
- error: null,
321
- errorCode: null,
322
- minLength: secrets.MIN_PASSWORD_LENGTH,
323
- });
337
+ return res.render("login", loginPageLocals(null, null));
324
338
  });
325
339
 
326
340
  app.post("/login", (req, res, next) => {
@@ -330,20 +344,18 @@ app.post("/login", (req, res, next) => {
330
344
  const retryAfter = blockedFor(peer);
331
345
  if (retryAfter) {
332
346
  res.set("Retry-After", String(retryAfter));
333
- return res.status(429).render("login", {
334
- error: "Too many attempts. Try again later.",
335
- errorCode: "tooManyAttempts",
336
- minLength: secrets.MIN_PASSWORD_LENGTH,
337
- });
347
+ return res
348
+ .status(429)
349
+ .render("login", loginPageLocals("Too many attempts. Try again later.", "tooManyAttempts"));
338
350
  }
339
351
 
340
352
  if (!secrets.verifyDashboardPassword(req.body?.password)) {
341
353
  recordFailure(peer);
342
354
  logger.warn({ ip: peer }, "[dashboard] Failed login attempt");
343
355
  return res.status(401).render("login", {
356
+ ...loginPageLocals(null, null),
344
357
  error: "Incorrect Password",
345
358
  errorCode: "incorrectPassword",
346
- minLength: secrets.MIN_PASSWORD_LENGTH,
347
359
  });
348
360
  }
349
361
 
@@ -360,20 +372,41 @@ app.post("/login", (req, res, next) => {
360
372
  });
361
373
  });
362
374
 
363
- // --- Password reset over WhatsApp -----------------------------------------
375
+ // --- Password reset -------------------------------------------------------
364
376
  //
365
377
  // For the operator who forgot the panel password. The code goes to the linked
366
- // account's own WhatsApp chat; see src/panel/password-reset.cjs for why this
367
- // is the recovery path that fits Levix. The offline fallback is still
378
+ // account's own WhatsApp chat, or to the verified recovery email through the
379
+ // Levix relay. See src/panel/password-reset.cjs. The offline fallback is still
368
380
  // `levix reset-password` on the server.
381
+ //
382
+ // `channel` defaults to WhatsApp so an empty body keeps the original door.
383
+ // The response never includes the address; the login page already showed the
384
+ // mask to anyone who can see the channel list.
369
385
 
370
386
  app.post("/reset/request", async (req, res) => {
371
387
  if (!secrets.hasDashboardPassword()) {
372
388
  return res.status(400).json({ ok: false, reason: "no_password" });
373
389
  }
374
- const result = await requestResetCode(clientAddress(req));
375
- const status = { throttled: 429, no_session: 409, send_failed: 502 }[result.reason] ?? 200;
376
- if (result.ok) res.set("Cache-Control", "no-store");
390
+ const body = req.body || {};
391
+ const result = await requestResetCode(clientAddress(req), {
392
+ channel: body.channel,
393
+ lang: body.lang,
394
+ });
395
+ const status = result.ok
396
+ ? 200
397
+ : ({
398
+ throttled: 429,
399
+ no_session: 409,
400
+ send_failed: 502,
401
+ no_email: 409,
402
+ unverified: 409,
403
+ rate_limited: 429,
404
+ locked: 429,
405
+ invalid: 400,
406
+ unavailable: 502,
407
+ }[result.reason] ?? 400);
408
+ if (result.retryAfter) res.set("Retry-After", String(result.retryAfter));
409
+ res.set("Cache-Control", "no-store");
377
410
  return res.status(status).json(result);
378
411
  });
379
412
 
@@ -381,13 +414,26 @@ app.post("/reset/confirm", (req, res) => {
381
414
  if (!secrets.hasDashboardPassword()) {
382
415
  return res.status(400).json({ ok: false, reason: "no_password" });
383
416
  }
417
+ // The lockout works both ways: a peer locked out of /login by wrong
418
+ // passwords or wrong codes cannot keep guessing codes here either.
419
+ const peer = clientAddress(req);
420
+ const blocked = blockedFor(peer);
421
+ if (blocked) {
422
+ res.set("Retry-After", String(blocked));
423
+ return res.status(429).json({ ok: false, reason: "throttled", retryAfter: blocked });
424
+ }
425
+
384
426
  const { code, password, confirm } = req.body || {};
385
427
  const result = completeReset(code, password, confirm);
386
428
  if (!result.ok) {
387
429
  // A wrong code counts toward the login lockout, so spraying guesses at
388
430
  // this door locks the same peer out of /login too.
389
431
  if (result.reason === "wrong_code" || result.reason === "too_many_attempts") {
390
- recordFailure(clientAddress(req));
432
+ recordFailure(peer);
433
+ }
434
+ if (result.reason === "locked") {
435
+ res.set("Retry-After", String(result.retryAfter));
436
+ return res.status(429).json(result);
391
437
  }
392
438
  return res.status(result.reason === "invalid_password" ? 400 : 401).json(result);
393
439
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "levix-bot",
3
- "version": "4.7.0",
3
+ "version": "4.9.1",
4
4
  "description": "A self-hosted personal WhatsApp bot with an AI agent, group moderation and a web control panel.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -18,7 +18,8 @@
18
18
  "build:sea": "node scripts/build-sea.mjs",
19
19
  "validate:tarball": "node scripts/validate-tarball.mjs",
20
20
  "validate:sea": "node scripts/validate-sea.mjs",
21
- "validate:docker": "bash scripts/validate-docker.sh"
21
+ "validate:docker": "bash scripts/validate-docker.sh",
22
+ "validate:recovery": "node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON scripts/validate-recovery-contract.mjs"
22
23
  },
23
24
  "keywords": [
24
25
  "whatsapp",