levix-bot 3.3.0-rc.2 → 4.0.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.
- package/README.md +13 -9
- package/app.cjs +49 -46
- package/package.json +9 -1
- package/public/dashboard/assets/index-BBBXWzM0.js +391 -0
- package/public/dashboard/assets/index-pYaivHON.css +1 -0
- package/public/dashboard/index.html +19 -0
- package/public/dashboard.css +391 -66
- package/public/dashboard.js +593 -42
- package/scheduler.cjs +9 -14
- package/src/auth/use-database-auth-state.js +2 -4
- package/src/bootstrap/core.js +2 -5
- package/src/bootstrap/panel.js +10 -5
- package/src/cli.js +3 -5
- package/src/commands/autoschedule.cjs +1 -4
- package/src/commands/blacklist.cjs +22 -20
- package/src/commands/block.cjs +2 -4
- package/src/commands/calc.cjs +9 -16
- package/src/commands/digit.cjs +97 -0
- package/src/commands/gemini.cjs +147 -161
- package/src/commands/group/add.cjs +7 -16
- package/src/commands/group/antiSpam.cjs +5 -11
- package/src/commands/group/antilink.cjs +34 -28
- package/src/commands/group/approveall.cjs +3 -11
- package/src/commands/group/clearwarns.cjs +2 -5
- package/src/commands/group/demote.cjs +3 -8
- package/src/commands/group/kick.cjs +12 -15
- package/src/commands/group/media.cjs +17 -24
- package/src/commands/group/members.cjs +1 -2
- package/src/commands/group/promote.cjs +4 -12
- package/src/commands/group/removeall.cjs +2 -5
- package/src/commands/group/setpp.cjs +1 -1
- package/src/commands/group/setrules.cjs +2 -8
- package/src/commands/group/setwarn.cjs +4 -2
- package/src/commands/group/tagadmins.cjs +2 -5
- package/src/commands/group/warn.cjs +26 -24
- package/src/commands/group/warns.cjs +1 -2
- package/src/commands/group/welcome.cjs +13 -17
- package/src/commands/group.cjs +7 -10
- package/src/commands/help.cjs +6 -12
- package/src/commands/lang.cjs +104 -0
- package/src/commands/listschedules.cjs +2 -6
- package/src/commands/loop.cjs +6 -13
- package/src/commands/memory.cjs +19 -32
- package/src/commands/mod.cjs +97 -35
- package/src/commands/perm.cjs +18 -56
- package/src/commands/ping.cjs +1 -5
- package/src/commands/poll.cjs +1 -1
- package/src/commands/rand.cjs +2 -5
- package/src/commands/schedule.cjs +4 -8
- package/src/commands/score.cjs +8 -2
- package/src/commands/setprefix.cjs +2 -2
- package/src/commands/shortlink.cjs +7 -15
- package/src/commands/shutdown.cjs +1 -1
- package/src/commands/sticker.cjs +222 -0
- package/src/commands/stt.cjs +136 -68
- package/src/commands/todo.cjs +9 -15
- package/src/commands/tts.cjs +10 -16
- package/src/commands/unblock.cjs +2 -6
- package/src/commands/weather.cjs +5 -12
- package/src/config/ai-persona.md +5 -3
- package/src/config/available-models.json +1156 -0
- package/src/config/baileys.config.js +2 -1
- package/src/config/brand.esm.js +1 -10
- package/src/config/constants.js +1 -1
- package/src/config/defaults.cjs +66 -66
- package/src/config/lock.cjs +2 -2
- package/src/config/modelCapabilities.cjs +172 -0
- package/src/config/runtime-config.cjs +8 -13
- package/src/config/secrets.cjs +18 -10
- package/src/config/settings.cjs +94 -10
- package/src/config/vault.cjs +107 -0
- package/src/core/connection.js +13 -12
- package/src/core/events.js +41 -23
- package/src/core/proxy.js +7 -7
- package/src/core/session.js +91 -48
- package/src/core/socket.js +12 -15
- package/src/db/db.cjs +14 -6
- package/src/db/store.cjs +221 -87
- package/src/domain/caddy.js +1 -1
- package/src/domain/command.js +40 -19
- package/src/domain/detect.js +1 -1
- package/src/domain/system.js +2 -5
- package/src/handlers/command.handler.js +22 -43
- package/src/handlers/group.handler.js +13 -13
- package/src/handlers/message.handler.js +11 -21
- package/src/index.js +8 -4
- package/src/middleware/antispam.middleware.js +46 -23
- package/src/middleware/blacklist.middleware.js +14 -9
- package/src/middleware/forward-tracking.middleware.js +3 -2
- package/src/middleware/permissions.middleware.js +7 -10
- package/src/panel/login-throttle.cjs +43 -0
- package/src/panel/session-auth.cjs +17 -0
- package/src/routes/dashboard.api.esm.js +394 -72
- package/src/services/aiAgent.cjs +136 -49
- package/src/services/aiProviders.cjs +193 -47
- package/src/services/aiRouter.cjs +137 -0
- package/src/services/aiTools.cjs +305 -128
- package/src/services/llmDiscovery.cjs +481 -0
- package/src/services/modelRegistry.cjs +412 -0
- package/src/utils/datetime.cjs +2 -2
- package/src/utils/lid-helper.esm.js +7 -7
- package/src/utils/logger.cjs +1 -1
- package/src/utils/markdownParser.cjs +159 -0
- package/src/utils/memory.cjs +43 -13
- package/src/utils/messageContent.cjs +40 -0
- package/src/utils/normalizeJid.esm.js +7 -7
- package/src/utils/numerals.cjs +75 -0
- package/src/utils/permissions.esm.js +10 -15
- package/src/utils/providerUrl.cjs +281 -0
- package/src/utils/recurrence.cjs +7 -11
- package/src/utils/sendBotMessage.esm.js +4 -14
- package/src/utils/statusMessage.cjs +5 -13
- package/src/utils/storage.cjs +10 -0
- package/src/utils/storage.esm.js +11 -0
- package/src/utils/textDecode.cjs +4 -9
- package/src/utils/thumbnail.cjs +8 -14
- package/src/utils/typing.esm.js +12 -12
- package/views/dashboard.ejs +134 -106
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// file: /middleware/forward-tracking.middleware.js
|
|
2
2
|
import { createRequire } from "module";
|
|
3
|
-
import { incrementForwardScore } from "../utils/storage.esm.js";
|
|
4
3
|
import normalizeJid from "../utils/normalizeJid.esm.js";
|
|
4
|
+
import { incrementForwardScore } from "../utils/storage.esm.js";
|
|
5
5
|
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
const logger = require("../utils/logger.cjs");
|
|
@@ -21,7 +21,8 @@ export async function trackForwardedMessage(msg) {
|
|
|
21
21
|
msg.message?.audioMessage?.contextInfo;
|
|
22
22
|
|
|
23
23
|
// A message is considered forwarded if it has isForwarded flag or forwardingScore > 0
|
|
24
|
-
const isForwarded =
|
|
24
|
+
const isForwarded =
|
|
25
|
+
contextInfo?.isForwarded || (contextInfo?.forwardingScore && contextInfo.forwardingScore > 0);
|
|
25
26
|
|
|
26
27
|
if (!isForwarded) {
|
|
27
28
|
return false;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// file: /middleware/permissions.middleware.js
|
|
2
2
|
import { createRequire } from "module";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
getSenderCandidates,
|
|
5
|
+
getSenderId,
|
|
6
6
|
isAdminInGroup,
|
|
7
7
|
isBotAdminInGroup,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
isBotAdminUser,
|
|
9
|
+
isOwnerJid,
|
|
10
10
|
} from "../utils/permissions.esm.js";
|
|
11
11
|
|
|
12
12
|
const require = createRequire(import.meta.url);
|
|
@@ -46,7 +46,7 @@ export function checkCommandPermission(commandName, msg, groupMetadata, sock) {
|
|
|
46
46
|
const candidates = senderCandidates.length ? senderCandidates : [senderId];
|
|
47
47
|
|
|
48
48
|
// fromMe is an immediate owner indicator (the bot is always its own owner).
|
|
49
|
-
|
|
49
|
+
const isOwner = msg.key.fromMe || candidates.some((c) => isOwnerJid(c));
|
|
50
50
|
|
|
51
51
|
// Bot-level admins (granted with `!perm add admin`, from the dashboard, or by
|
|
52
52
|
// asking the AI) count as admins everywhere — including DMs, where there is
|
|
@@ -54,8 +54,7 @@ export function checkCommandPermission(commandName, msg, groupMetadata, sock) {
|
|
|
54
54
|
const isBotAdmin = !isOwner && candidates.some((c) => isBotAdminUser(c));
|
|
55
55
|
|
|
56
56
|
const isSenderAdmin =
|
|
57
|
-
isBotAdmin ||
|
|
58
|
-
(isGroup ? candidates.some((c) => isAdminInGroup(groupMetadata, c)) : false);
|
|
57
|
+
isBotAdmin || (isGroup ? candidates.some((c) => isAdminInGroup(groupMetadata, c)) : false);
|
|
59
58
|
|
|
60
59
|
const permissionLevel = resolvePermissionLevel(commandName);
|
|
61
60
|
|
|
@@ -96,9 +95,7 @@ export function checkCommandPermission(commandName, msg, groupMetadata, sock) {
|
|
|
96
95
|
break;
|
|
97
96
|
|
|
98
97
|
default:
|
|
99
|
-
logger.warn(
|
|
100
|
-
`Unknown permission level: ${permissionLevel} for command: ${commandName}`
|
|
101
|
-
);
|
|
98
|
+
logger.warn(`Unknown permission level: ${permissionLevel} for command: ${commandName}`);
|
|
102
99
|
hasPermission = false;
|
|
103
100
|
reason = "🚫 مستوى الصلاحية غير معروف.";
|
|
104
101
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Guess-throttling for the panel password. Shared by /login, /setup, and
|
|
2
|
+
// POST /dashboard/api/security/password so a locked-out peer cannot keep
|
|
3
|
+
// trying the same secret on another door.
|
|
4
|
+
//
|
|
5
|
+
// Keyed on the TCP peer, never on `req.ip`: with `trust proxy` set, a client
|
|
6
|
+
// picks its own `req.ip` by writing a header.
|
|
7
|
+
|
|
8
|
+
const ATTEMPT_WINDOW_MS = 15 * 60 * 1000;
|
|
9
|
+
const MAX_ATTEMPTS = 5;
|
|
10
|
+
const attempts = new Map();
|
|
11
|
+
|
|
12
|
+
function blockedFor(ip) {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
for (const [key, entry] of attempts) {
|
|
15
|
+
if (now - entry.firstAt > ATTEMPT_WINDOW_MS) attempts.delete(key);
|
|
16
|
+
}
|
|
17
|
+
const entry = attempts.get(ip);
|
|
18
|
+
if (!entry || entry.count < MAX_ATTEMPTS) return 0;
|
|
19
|
+
const remaining = ATTEMPT_WINDOW_MS - (now - entry.firstAt);
|
|
20
|
+
return remaining > 0 ? Math.ceil(remaining / 1000) : 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function recordFailure(ip) {
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
const entry = attempts.get(ip);
|
|
26
|
+
if (!entry || now - entry.firstAt > ATTEMPT_WINDOW_MS) {
|
|
27
|
+
attempts.set(ip, { count: 1, firstAt: now });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
entry.count += 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function clearAttempts(ip) {
|
|
34
|
+
attempts.delete(ip);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
ATTEMPT_WINDOW_MS,
|
|
39
|
+
MAX_ATTEMPTS,
|
|
40
|
+
blockedFor,
|
|
41
|
+
recordFailure,
|
|
42
|
+
clearAttempts,
|
|
43
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Panel session validity. `loggedIn` alone is not enough: a leftover cookie
|
|
2
|
+
// must stop working when the password is changed or wiped.
|
|
3
|
+
|
|
4
|
+
const secrets = require("../config/secrets.cjs");
|
|
5
|
+
|
|
6
|
+
function isPanelSessionValid(session) {
|
|
7
|
+
if (!session?.loggedIn) return false;
|
|
8
|
+
if (!secrets.hasDashboardPassword()) return false;
|
|
9
|
+
return session.passwordUpdatedAt === secrets.getPasswordUpdatedAt();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function stampPanelSession(session) {
|
|
13
|
+
session.loggedIn = true;
|
|
14
|
+
session.passwordUpdatedAt = secrets.getPasswordUpdatedAt();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { isPanelSessionValid, stampPanelSession };
|