levix-bot 4.8.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.
- package/README.md +9 -5
- package/SETUP.md +21 -2
- package/app.cjs +69 -23
- package/package.json +3 -2
- package/public/dashboard/assets/index-B1sOW2VX.js +561 -0
- package/public/dashboard/assets/index-CK8osB4o.css +2 -0
- package/public/dashboard/index.html +2 -2
- package/public/dashboard.css +21 -0
- package/public/dashboard.js +25 -2
- package/public/gateway-i18n.js +26 -0
- package/src/bootstrap/session-startup-policy.js +6 -6
- package/src/commands/group/antilink.cjs +82 -59
- package/src/commands/group/antispam.cjs +112 -0
- package/src/commands/group/clearwarns.cjs +6 -6
- package/src/commands/group/demote.cjs +11 -13
- package/src/commands/group/flagged.cjs +52 -0
- package/src/commands/group/kick.cjs +25 -15
- package/src/commands/group/media.cjs +65 -29
- package/src/commands/group/policy.cjs +215 -0
- package/src/commands/group/promote.cjs +11 -12
- package/src/commands/group/rules.cjs +9 -6
- package/src/commands/group/setwarn.cjs +17 -27
- package/src/commands/group/warn.cjs +13 -63
- package/src/commands/group.cjs +5 -2
- package/src/commands/mod.cjs +101 -26
- package/src/commands/translate.cjs +585 -0
- package/src/config/ai-identity.cjs +53 -1
- package/src/config/ai-persona.md +32 -73
- package/src/config/defaults.cjs +2 -0
- package/src/config/secrets.cjs +71 -3
- package/src/config/settings.cjs +22 -1
- package/src/core/socket.js +4 -5
- package/src/db/db.cjs +66 -0
- package/src/db/store.cjs +264 -16
- package/src/diagnostics/crashReports.cjs +35 -9
- package/src/diagnostics/debugLog.cjs +405 -0
- package/src/handlers/command.handler.js +1 -0
- package/src/handlers/group.handler.js +32 -1
- package/src/handlers/message.handler.js +53 -17
- package/src/middleware/antispam.middleware.js +95 -48
- package/src/panel/feedback.cjs +32 -5
- package/src/panel/one-time-code.cjs +156 -0
- package/src/panel/password-reset.cjs +187 -91
- package/src/panel/recovery-email.cjs +333 -0
- package/src/routes/dashboard.api.esm.js +267 -20
- package/src/services/aiAgent.cjs +25 -3
- package/src/services/moderationPolicy.cjs +895 -0
- package/src/services/settingsTransfer.cjs +4 -2
- package/src/utils/linkedCreds.cjs +22 -0
- package/src/utils/logger.cjs +5 -0
- package/src/utils/moderationAction.cjs +637 -0
- package/src/utils/moderationSummary.cjs +225 -0
- package/src/utils/permissions.cjs +70 -0
- package/src/utils/permissions.esm.js +48 -8
- package/src/utils/storage.cjs +8 -0
- package/src/utils/storage.esm.js +4 -0
- package/views/login.ejs +100 -28
- package/public/dashboard/assets/index-B8E5IYlB.js +0 -540
- package/public/dashboard/assets/index-C5D4wzm4.css +0 -2
- 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
|
|
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.
|
|
@@ -98,8 +99,9 @@ proxies, headless mode, backups, and troubleshooting.
|
|
|
98
99
|
|
|
99
100
|
| Area | What Levix provides |
|
|
100
101
|
| --- | --- |
|
|
101
|
-
| Commands |
|
|
102
|
-
|
|
|
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 |
|
|
@@ -123,6 +125,9 @@ AI answers are formatted for WhatsApp automatically: `**bold**` becomes `*bold*`
|
|
|
123
125
|
bullet points. Headings, lists, checkboxes, strikethrough and links are converted;
|
|
124
126
|
code contents and URLs are preserved.
|
|
125
127
|
|
|
128
|
+
Replies follow the language and dialect you write in — Egyptian Arabic in,
|
|
129
|
+
Egyptian Arabic out.
|
|
130
|
+
|
|
126
131
|
Use `!md` (or `!markdown`) to convert text from any other AI or message, without
|
|
127
132
|
an AI key. Reply to that message with `!md`, or paste Markdown after the command,
|
|
128
133
|
including multiline tables and code. For example: `!md **Bold** and __italic__`.
|
|
@@ -209,8 +214,7 @@ npm test # runs the full test suite
|
|
|
209
214
|
npm start # starts Levix
|
|
210
215
|
```
|
|
211
216
|
|
|
212
|
-
|
|
213
|
-
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.
|
|
214
218
|
|
|
215
219
|
For security issues, follow [SECURITY.md](SECURITY.md) and report them
|
|
216
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
|
-
|
|
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/
|
|
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
|
|
334
|
-
|
|
335
|
-
|
|
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
|
|
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
|
|
367
|
-
//
|
|
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
|
|
375
|
-
const
|
|
376
|
-
|
|
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(
|
|
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.
|
|
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",
|