levix-bot 4.2.0 → 4.3.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/app.cjs +50 -4
- package/package.json +1 -1
- package/public/dashboard/assets/index-BCXZoPGP.js +446 -0
- package/public/dashboard/index.html +1 -1
- package/public/dashboard.css +71 -1
- package/public/gateway.js +41 -0
- package/src/bootstrap/core.js +4 -0
- package/src/bootstrap/panel.js +2 -0
- package/src/commands/autoschedule.cjs +10 -13
- package/src/commands/block.cjs +1 -1
- package/src/commands/restart.cjs +46 -17
- package/src/commands/schedule.cjs +8 -10
- package/src/commands/send.cjs +116 -0
- package/src/commands/stopbot.cjs +68 -0
- package/src/commands/stt.cjs +10 -6
- package/src/commands/unblock.cjs +1 -1
- package/src/config/defaults.cjs +2 -1
- package/src/config/settings.cjs +4 -2
- package/src/core/session-holder.cjs +23 -0
- package/src/handlers/command.handler.js +3 -5
- package/src/panel/password-reset.cjs +187 -0
- package/src/routes/dashboard.api.esm.js +48 -78
- package/src/services/aiAgent.cjs +7 -11
- package/src/services/settingsTransfer.cjs +246 -0
- package/src/utils/geminiMedia.cjs +70 -1
- package/views/login.ejs +209 -9
- package/views/setup.ejs +19 -5
- package/public/dashboard/assets/index-4AuqfnH5.js +0 -431
- package/src/commands/shutdown.cjs +0 -55
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
11
11
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
12
12
|
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Tajawal:wght@400;500;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
|
13
|
-
<script type="module" crossorigin src="/dashboard/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/dashboard/assets/index-BCXZoPGP.js"></script>
|
|
14
14
|
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-LvfJ8ybs.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
package/public/dashboard.css
CHANGED
|
@@ -2902,4 +2902,74 @@ html[dir="rtl"] .logout-btn svg {
|
|
|
2902
2902
|
animation-iteration-count: 1 !important;
|
|
2903
2903
|
transition-duration: 0.001ms !important;
|
|
2904
2904
|
}
|
|
2905
|
-
}
|
|
2905
|
+
}
|
|
2906
|
+
/* --- gateway: password visibility, reset link, screen guard ------------- */
|
|
2907
|
+
|
|
2908
|
+
.input-wrap {
|
|
2909
|
+
position: relative;
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
.input-wrap input {
|
|
2913
|
+
padding-inline-end: 44px;
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
.eye-btn {
|
|
2917
|
+
position: absolute;
|
|
2918
|
+
inset-inline-end: 6px;
|
|
2919
|
+
top: 50%;
|
|
2920
|
+
transform: translateY(-50%);
|
|
2921
|
+
display: grid;
|
|
2922
|
+
place-items: center;
|
|
2923
|
+
width: 32px;
|
|
2924
|
+
height: 32px;
|
|
2925
|
+
border: none;
|
|
2926
|
+
border-radius: 8px;
|
|
2927
|
+
background: transparent;
|
|
2928
|
+
color: var(--faint);
|
|
2929
|
+
cursor: pointer;
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
.eye-btn:hover {
|
|
2933
|
+
color: var(--text);
|
|
2934
|
+
background: color-mix(in srgb, var(--line) 55%, transparent);
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
.eye-btn svg {
|
|
2938
|
+
width: 17px;
|
|
2939
|
+
height: 17px;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
.auth-alt {
|
|
2943
|
+
margin-top: 14px;
|
|
2944
|
+
text-align: center;
|
|
2945
|
+
}
|
|
2946
|
+
|
|
2947
|
+
.link-btn {
|
|
2948
|
+
padding: 0;
|
|
2949
|
+
border: none;
|
|
2950
|
+
background: none;
|
|
2951
|
+
color: #70a3ff;
|
|
2952
|
+
font-size: 0.8rem;
|
|
2953
|
+
font-weight: 600;
|
|
2954
|
+
cursor: pointer;
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
.link-btn:hover {
|
|
2958
|
+
text-decoration: underline;
|
|
2959
|
+
}
|
|
2960
|
+
|
|
2961
|
+
/* The password screens blur themselves whenever the page can't be watched —
|
|
2962
|
+
another tab, a minimised window, the task switcher. Best effort: the web
|
|
2963
|
+
platform cannot truly forbid screenshots, but this keeps the form out of
|
|
2964
|
+
task-switcher thumbnails and casual captures. Printing one of these pages
|
|
2965
|
+
gets a blank sheet instead. */
|
|
2966
|
+
html.screen-guard .gateway-panel {
|
|
2967
|
+
filter: blur(18px);
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
@media print {
|
|
2971
|
+
|
|
2972
|
+
.gateway-panel {
|
|
2973
|
+
display: none;
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Shared behaviour for the gateway pages (login · setup · reset).
|
|
2
|
+
//
|
|
3
|
+
// Two small things, both of which must never break the form if the script
|
|
4
|
+
// itself fails to load: the page works without either one.
|
|
5
|
+
|
|
6
|
+
(function () {
|
|
7
|
+
// Eye toggles. One delegated listener covers every password field on the
|
|
8
|
+
// page — the button carries two icons and swaps which one is visible.
|
|
9
|
+
document.addEventListener("click", function (event) {
|
|
10
|
+
var btn = event.target.closest ? event.target.closest(".eye-btn") : null;
|
|
11
|
+
if (!btn) return;
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
var input = btn.parentElement ? btn.parentElement.querySelector("input") : null;
|
|
14
|
+
if (!input) return;
|
|
15
|
+
var show = input.type === "password";
|
|
16
|
+
input.type = show ? "text" : "password";
|
|
17
|
+
var on = btn.querySelector(".eye-on");
|
|
18
|
+
var off = btn.querySelector(".eye-off");
|
|
19
|
+
if (on) on.style.display = show ? "none" : "";
|
|
20
|
+
if (off) off.style.display = show ? "" : "none";
|
|
21
|
+
btn.setAttribute("aria-label", show ? "Hide password" : "Show password");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Blur the password screens whenever the page can't be watched: another
|
|
25
|
+
// tab, a minimised window, the OS task switcher. This is best effort —
|
|
26
|
+
// the web platform cannot truly forbid screenshots — but it keeps the form
|
|
27
|
+
// out of task-switcher thumbnails and casual over-the-shoulder captures.
|
|
28
|
+
var root = document.documentElement;
|
|
29
|
+
function engage() {
|
|
30
|
+
root.classList.add("screen-guard");
|
|
31
|
+
}
|
|
32
|
+
function release() {
|
|
33
|
+
root.classList.remove("screen-guard");
|
|
34
|
+
}
|
|
35
|
+
document.addEventListener("visibilitychange", function () {
|
|
36
|
+
if (document.visibilityState === "hidden") engage();
|
|
37
|
+
else release();
|
|
38
|
+
});
|
|
39
|
+
window.addEventListener("blur", engage);
|
|
40
|
+
window.addEventListener("focus", release);
|
|
41
|
+
})();
|
package/src/bootstrap/core.js
CHANGED
|
@@ -66,6 +66,10 @@ export async function bootstrapCore({ autoStart = false } = {}) {
|
|
|
66
66
|
log: logger,
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
// WhatsApp commands (!stopbot, !restart) drive the same state machine the
|
|
70
|
+
// panel does — nothing here ever touches a socket directly.
|
|
71
|
+
require("../core/session-holder.cjs").setSession(session);
|
|
72
|
+
|
|
69
73
|
const startup = sessionStartupPolicy({ autoStart, wasPaired });
|
|
70
74
|
if (startup.start) await session.start({ reason: startup.reason });
|
|
71
75
|
|
package/src/bootstrap/panel.js
CHANGED
|
@@ -66,6 +66,8 @@ export async function bootstrapPanel({ core } = {}) {
|
|
|
66
66
|
// The routes read the live socket off the session manager, so a reconnect
|
|
67
67
|
// needs no re-wiring here.
|
|
68
68
|
if (core?.session) setSession(core.session);
|
|
69
|
+
// The WhatsApp-code password reset talks to the same session manager.
|
|
70
|
+
if (core?.session) require("../panel/password-reset.cjs").setSession(core.session);
|
|
69
71
|
|
|
70
72
|
// After every route is registered — the 404 and the error handler have to be
|
|
71
73
|
// last, or they swallow what comes after them.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { scheduleNewJob, saveScheduledJob } = require("../../scheduler.cjs");
|
|
2
2
|
const { randomUUID } = require("node:crypto");
|
|
3
|
-
const
|
|
3
|
+
const logger = require("../utils/logger.cjs");
|
|
4
4
|
const { parseRecurringArgs } = require("../utils/recurrence.cjs");
|
|
5
5
|
const { tr } = require("../utils/i18n.cjs");
|
|
6
6
|
|
|
@@ -71,17 +71,14 @@ module.exports = {
|
|
|
71
71
|
|
|
72
72
|
saveScheduledJob(newJob);
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
`✅ تم جدولة الرسالة يوميًا الساعة ${parsed.time} (${defaultTimezone()})`,
|
|
84
|
-
),
|
|
85
|
-
});
|
|
74
|
+
// تأكيد صامت: تفاعل على رسالة الإنشاء بدل رسالة "تم الجدولة" المنفصلة
|
|
75
|
+
try {
|
|
76
|
+
await sock.sendMessage(targetJid, { react: { text: "✅", key: msg.key } });
|
|
77
|
+
} catch (error) {
|
|
78
|
+
logger.warn(
|
|
79
|
+
{ err: error, command: "autoschedule" },
|
|
80
|
+
"failed to react to the scheduled message",
|
|
81
|
+
);
|
|
82
|
+
}
|
|
86
83
|
},
|
|
87
84
|
};
|
package/src/commands/block.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// file: /commands/block.js (Upgraded with private chat context)
|
|
2
2
|
const logger = require("../utils/logger.cjs");
|
|
3
3
|
const { isOwnerJidSync } = require("../utils/permissions.cjs");
|
|
4
|
-
const normalizeJid = require("../utils/normalizeJid.esm.js");
|
|
4
|
+
const normalizeJid = require("../utils/normalizeJid.esm.js").default;
|
|
5
5
|
const { tr } = require("../utils/i18n.cjs");
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
package/src/commands/restart.cjs
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
1
|
+
// Restarts the WhatsApp connection — not the process.
|
|
2
|
+
//
|
|
3
|
+
// It used to SIGTERM the whole bot and lean on the supervisor to bring it
|
|
4
|
+
// back, which took the control panel down with the socket. What people mean
|
|
5
|
+
// by restart here is the connection: session.reconnect() is the same
|
|
6
|
+
// stop()+start() the panel's Connection screen uses, so the state machine
|
|
7
|
+
// stays the only socket owner and a restart never kicks whoever is watching
|
|
8
|
+
// the panel out.
|
|
9
|
+
const { getSession } = require("../core/session-holder.cjs");
|
|
3
10
|
const logger = require("../utils/logger.cjs");
|
|
4
11
|
const { tr } = require("../utils/i18n.cjs");
|
|
5
12
|
|
|
6
13
|
module.exports = {
|
|
7
14
|
name: "restart",
|
|
8
15
|
description: {
|
|
9
|
-
en: "
|
|
10
|
-
ar: "يعيد تشغيل
|
|
16
|
+
en: "Reconnects WhatsApp (the process and panel stay up).",
|
|
17
|
+
ar: "يعيد تشغيل اتصال واتساب (عملية البوت واللوحة يفضلوا شغالين).",
|
|
11
18
|
},
|
|
12
19
|
usage: {
|
|
13
20
|
en: "restart",
|
|
@@ -16,24 +23,46 @@ module.exports = {
|
|
|
16
23
|
chat: "all",
|
|
17
24
|
|
|
18
25
|
async execute(sock, msg) {
|
|
19
|
-
|
|
26
|
+
const chatId = msg.key.remoteJid;
|
|
27
|
+
const session = getSession();
|
|
28
|
+
if (!session) {
|
|
29
|
+
return await sock.sendMessage(chatId, {
|
|
30
|
+
text: tr("The session manager isn't ready yet.", "مدير الجلسة لسه مش جاهز."),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
20
33
|
|
|
21
|
-
//
|
|
22
|
-
await sock.sendMessage(
|
|
34
|
+
// Goes out while the current socket is still alive.
|
|
35
|
+
await sock.sendMessage(chatId, {
|
|
23
36
|
text: tr(
|
|
24
|
-
"
|
|
25
|
-
"
|
|
37
|
+
"🔄 Reconnecting WhatsApp... back in a moment.",
|
|
38
|
+
"🔄 جاري إعادة تشغيل اتصال واتساب... هرجع في لحظة.",
|
|
26
39
|
),
|
|
27
40
|
});
|
|
28
41
|
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
let state = null;
|
|
43
|
+
try {
|
|
44
|
+
state = await session.reconnect({ reason: "command" });
|
|
45
|
+
logger.info("[commands] WhatsApp connection restarted by !restart");
|
|
46
|
+
} catch (error) {
|
|
47
|
+
logger.error({ err: error, command: "restart" }, "Failed to reconnect WhatsApp");
|
|
48
|
+
}
|
|
31
49
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
if (state?.connected) {
|
|
51
|
+
await sock.sendMessage(chatId, {
|
|
52
|
+
text: tr("✅ WhatsApp is back online.", "✅ اتصال واتساب رجع يشتغل."),
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
// Not connected (a QR wait, a retry, a failure) — say where things
|
|
56
|
+
// stand instead of claiming success. The old socket is gone either way,
|
|
57
|
+
// so this send is best-effort.
|
|
58
|
+
await sock
|
|
59
|
+
.sendMessage(chatId, {
|
|
60
|
+
text: tr(
|
|
61
|
+
`Connection state now: ${state?.status || "unknown"}. Check the panel's Connection screen.`,
|
|
62
|
+
`حالة الاتصال دلوقتي: ${state?.status || "غير معروفة"}. راجع شاشة Connection في لوحة التحكم.`,
|
|
63
|
+
),
|
|
64
|
+
})
|
|
65
|
+
.catch(() => {});
|
|
66
|
+
}
|
|
38
67
|
},
|
|
39
68
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// file: commands/schedule.js
|
|
2
2
|
const { scheduleNewJob, saveScheduledJob } = require("../../scheduler.cjs");
|
|
3
|
-
const { zonedTimeToDate
|
|
3
|
+
const { zonedTimeToDate } = require("../utils/datetime.cjs");
|
|
4
|
+
const logger = require("../utils/logger.cjs");
|
|
4
5
|
const { tr } = require("../utils/i18n.cjs");
|
|
5
6
|
|
|
6
7
|
const DATETIME_RE = /^(\d{1,2}):(\d{2})\s+(\d{1,2})-(\d{1,2})-(\d{4})$/;
|
|
@@ -92,14 +93,11 @@ module.exports = {
|
|
|
92
93
|
|
|
93
94
|
saveScheduledJob(newJob);
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
`✅ تم جدولة رسالتك بنجاح ليتم إرسالها في:\n*${when}*`,
|
|
102
|
-
),
|
|
103
|
-
});
|
|
96
|
+
// تأكيد صامت: تفاعل على رسالة الإنشاء بدل رسالة "تم الجدولة" المنفصلة
|
|
97
|
+
try {
|
|
98
|
+
await sock.sendMessage(targetJid, { react: { text: "✅", key: msg.key } });
|
|
99
|
+
} catch (error) {
|
|
100
|
+
logger.warn({ err: error, command: "schedule" }, "failed to react to the scheduled message");
|
|
101
|
+
}
|
|
104
102
|
},
|
|
105
103
|
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Re-sends content into the current chat. Built for statuses (stories): reply
|
|
2
|
+
// to one with !send and the bot re-posts it here, so a photo that lives 24
|
|
3
|
+
// hours on the status ring stays in the chat. Works on any replied message —
|
|
4
|
+
// photo, video, voice note, sticker, document or plain text.
|
|
5
|
+
//
|
|
6
|
+
// No storage is involved: the reply's quotedMessage carries the full media
|
|
7
|
+
// metadata (url, mediaKey, directPath), which is enough to download and
|
|
8
|
+
// decrypt it again — nothing is cached and nothing is archived.
|
|
9
|
+
const { downloadContentFromMessage } = require("@whiskeysockets/baileys");
|
|
10
|
+
const { downloadMedia } = require("../utils/geminiMedia.cjs");
|
|
11
|
+
const { unwrapMessage, visibleText } = require("../utils/messageContent.cjs");
|
|
12
|
+
const { createStatus } = require("../utils/statusMessage.cjs");
|
|
13
|
+
const logger = require("../utils/logger.cjs");
|
|
14
|
+
const { tr } = require("../utils/i18n.cjs");
|
|
15
|
+
|
|
16
|
+
// The media in a message plus the download type that decrypts it — the type
|
|
17
|
+
// WhatsApp filed it under, not the MIME type (same rule as the AI command).
|
|
18
|
+
function pickMedia(message) {
|
|
19
|
+
const inner = unwrapMessage(message);
|
|
20
|
+
if (inner.stickerMessage) return { media: inner.stickerMessage, type: "sticker" };
|
|
21
|
+
if (inner.imageMessage) return { media: inner.imageMessage, type: "image" };
|
|
22
|
+
if (inner.videoMessage) return { media: inner.videoMessage, type: "video" };
|
|
23
|
+
if (inner.audioMessage) return { media: inner.audioMessage, type: "audio" };
|
|
24
|
+
if (inner.documentMessage) return { media: inner.documentMessage, type: "document" };
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function quotedOf(msg) {
|
|
29
|
+
const own = unwrapMessage(msg.message);
|
|
30
|
+
return own.extendedTextMessage?.contextInfo?.quotedMessage || null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
name: "send",
|
|
35
|
+
description: {
|
|
36
|
+
en: "Re-sends the replied message here: a status/story, photo, video, voice note, sticker, document or text.",
|
|
37
|
+
ar: "يعيد إرسال الرسالة الموجّه لها الرد هنا: استوري، صورة، فيديو، رسالة صوتية، ستيكر، مستند أو نص.",
|
|
38
|
+
},
|
|
39
|
+
usage: {
|
|
40
|
+
en: "send (reply to a status or any message with it)",
|
|
41
|
+
ar: "send (اعمل رد على استوري أو أي رسالة بالأمر)",
|
|
42
|
+
},
|
|
43
|
+
chat: "all",
|
|
44
|
+
|
|
45
|
+
async execute(sock, msg) {
|
|
46
|
+
const chatId = msg.key.remoteJid;
|
|
47
|
+
const quoted = quotedOf(msg);
|
|
48
|
+
|
|
49
|
+
// Media attached to the command itself counts too — "send this" with a
|
|
50
|
+
// caption works like a reply does.
|
|
51
|
+
const target = pickMedia(msg.message) || (quoted ? pickMedia(quoted) : null);
|
|
52
|
+
|
|
53
|
+
if (!target) {
|
|
54
|
+
const quotedText = quoted ? visibleText(quoted) : "";
|
|
55
|
+
if (quotedText) {
|
|
56
|
+
return await sock.sendMessage(chatId, { text: quotedText });
|
|
57
|
+
}
|
|
58
|
+
return await sock.sendMessage(chatId, {
|
|
59
|
+
text: tr(
|
|
60
|
+
"Reply to a status or any message with `!send` and I'll re-send it here.",
|
|
61
|
+
"اعمل رد على استوري أو أي رسالة بالأمر `!send` وأنا هعيد إرسالها هنا.",
|
|
62
|
+
),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const status = await createStatus(sock, chatId, tr("📥 Sending...", "📥 جاري الإرسال..."), {
|
|
67
|
+
replyTo: msg,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const buffer = await downloadMedia(downloadContentFromMessage, target.media, target.type);
|
|
72
|
+
const media = target.media;
|
|
73
|
+
const { mimetype, caption } = media;
|
|
74
|
+
|
|
75
|
+
let content;
|
|
76
|
+
if (target.type === "image") {
|
|
77
|
+
content = {
|
|
78
|
+
image: buffer,
|
|
79
|
+
...(caption ? { caption } : {}),
|
|
80
|
+
...(mimetype ? { mimetype } : {}),
|
|
81
|
+
};
|
|
82
|
+
} else if (target.type === "video") {
|
|
83
|
+
content = {
|
|
84
|
+
video: buffer,
|
|
85
|
+
...(caption ? { caption } : {}),
|
|
86
|
+
...(mimetype ? { mimetype } : {}),
|
|
87
|
+
...(media.gifPlayback ? { gifPlayback: true } : {}),
|
|
88
|
+
};
|
|
89
|
+
} else if (target.type === "audio") {
|
|
90
|
+
content = { audio: buffer, ...(mimetype ? { mimetype } : {}), ptt: !!media.ptt };
|
|
91
|
+
} else if (target.type === "sticker") {
|
|
92
|
+
content = { sticker: buffer, ...(mimetype ? { mimetype } : {}) };
|
|
93
|
+
} else {
|
|
94
|
+
content = {
|
|
95
|
+
document: buffer,
|
|
96
|
+
...(mimetype ? { mimetype } : {}),
|
|
97
|
+
...(media.fileName ? { fileName: media.fileName } : {}),
|
|
98
|
+
...(caption ? { caption } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await sock.sendMessage(chatId, content);
|
|
103
|
+
// The media is the answer — the status line goes away.
|
|
104
|
+
await status.remove();
|
|
105
|
+
} catch (error) {
|
|
106
|
+
logger.error({ err: error, command: "send" }, "Failed to re-send replied media");
|
|
107
|
+
await status.fail(
|
|
108
|
+
error,
|
|
109
|
+
tr(
|
|
110
|
+
"Couldn't re-send it — the media may have expired",
|
|
111
|
+
"معرفتش أبعته — ممكن الميديا تكون انتهت",
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Pauses the WhatsApp connection without touching the process.
|
|
2
|
+
//
|
|
3
|
+
// It replaced `!shutdown`, which shelled out to `pm2 stop` — a command from an
|
|
4
|
+
// install shape Levix outgrew, and one that took the control panel down with
|
|
5
|
+
// the bot. This is the panel's own "Stop" from inside a chat: the same state
|
|
6
|
+
// machine call, pairing kept, panel up, no retry afterwards. Resuming is the
|
|
7
|
+
// Connection screen — once the socket is down no message can arrive, so there
|
|
8
|
+
// is no way to type a start command.
|
|
9
|
+
const { getSession } = require("../core/session-holder.cjs");
|
|
10
|
+
const logger = require("../utils/logger.cjs");
|
|
11
|
+
const { tr } = require("../utils/i18n.cjs");
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
name: "stopbot",
|
|
15
|
+
aliases: ["stop", "pause"],
|
|
16
|
+
description: {
|
|
17
|
+
en: "Pauses the WhatsApp connection (the bot process and panel keep running).",
|
|
18
|
+
ar: "يوقف اتصال واتساب مؤقتًا (عملية البوت ولوحة التحكم يفضلوا شغالين).",
|
|
19
|
+
},
|
|
20
|
+
usage: {
|
|
21
|
+
en: "stopbot",
|
|
22
|
+
ar: "stopbot",
|
|
23
|
+
},
|
|
24
|
+
chat: "all",
|
|
25
|
+
|
|
26
|
+
async execute(sock, msg) {
|
|
27
|
+
const chatId = msg.key.remoteJid;
|
|
28
|
+
const session = getSession();
|
|
29
|
+
if (!session) {
|
|
30
|
+
return await sock.sendMessage(chatId, {
|
|
31
|
+
text: tr("The session manager isn't ready yet.", "مدير الجلسة لسه مش جاهز."),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const state = session.getState();
|
|
36
|
+
if (!state.connected && !state.canStop) {
|
|
37
|
+
return await sock.sendMessage(chatId, {
|
|
38
|
+
text: tr(
|
|
39
|
+
"The WhatsApp connection isn't up — nothing to pause.",
|
|
40
|
+
"اتصال واتساب مش شغال أصلًا — مفيش حاجة أوقفها.",
|
|
41
|
+
),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The goodbye goes out before the socket comes down: once stop() runs,
|
|
46
|
+
// nothing can be sent through this chat until the session starts again.
|
|
47
|
+
await sock.sendMessage(chatId, {
|
|
48
|
+
text: tr(
|
|
49
|
+
"⏸️ Pausing the WhatsApp connection. The bot and the control panel stay up — resume from the Connection screen in the panel.",
|
|
50
|
+
"⏸️ جاري إيقاف اتصال واتساب مؤقتًا. البوت واللوحة هيفضلوا شغالين — شغّله تاني من شاشة Connection في لوحة التحكم.",
|
|
51
|
+
),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
await session.stop({ reason: "command" });
|
|
56
|
+
logger.warn("[commands] WhatsApp connection paused by !stopbot");
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logger.error({ err: error, command: "stopbot" }, "Failed to pause the WhatsApp connection");
|
|
59
|
+
// The socket may still be up, so the operator can actually read this.
|
|
60
|
+
await sock.sendMessage(chatId, {
|
|
61
|
+
text: tr(
|
|
62
|
+
"Couldn't pause the connection. Try the panel's Connection screen.",
|
|
63
|
+
"معرفتش أوقف الاتصال. جرب شاشة Connection في لوحة التحكم.",
|
|
64
|
+
),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
package/src/commands/stt.cjs
CHANGED
|
@@ -4,7 +4,12 @@ const { downloadContentFromMessage } = require("@whiskeysockets/baileys");
|
|
|
4
4
|
const logger = require("../utils/logger.cjs");
|
|
5
5
|
const { createStatus } = require("../utils/statusMessage.cjs");
|
|
6
6
|
const { unwrapMessage } = require("../utils/messageContent.cjs");
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
INLINE_MEDIA_LIMIT,
|
|
9
|
+
baseMimeType,
|
|
10
|
+
downloadMedia,
|
|
11
|
+
uploadToGemini,
|
|
12
|
+
} = require("../utils/geminiMedia.cjs");
|
|
8
13
|
|
|
9
14
|
const settings = require("../config/settings.cjs");
|
|
10
15
|
const {
|
|
@@ -63,10 +68,9 @@ const TRANSCRIBE_PROMPT =
|
|
|
63
68
|
"Please transcribe this audio message accurately. Return ONLY the transcription text without any additional commentary, explanations, or formatting. Just the raw transcribed text.";
|
|
64
69
|
|
|
65
70
|
// A voice note is a few hundred KB, so it rides inline in the request: one
|
|
66
|
-
// round trip, instead of an upload, a finalize and then the request. Past
|
|
67
|
-
//
|
|
68
|
-
// API instead.
|
|
69
|
-
const INLINE_AUDIO_LIMIT = 15 * 1024 * 1024;
|
|
71
|
+
// round trip, instead of an upload, a finalize and then the request. Past
|
|
72
|
+
// INLINE_MEDIA_LIMIT (Gemini caps a whole inline request at 20 MB) it goes
|
|
73
|
+
// through the Files API instead.
|
|
70
74
|
|
|
71
75
|
async function transcribeWithGemini(audioBuffer, mimetype) {
|
|
72
76
|
const gemini = geminiStt();
|
|
@@ -82,7 +86,7 @@ async function transcribeWithGemini(audioBuffer, mimetype) {
|
|
|
82
86
|
// `audio/ogg`, and the codec parameter is not part of it.
|
|
83
87
|
const mimeType = baseMimeType(mimetype, "audio");
|
|
84
88
|
let audioPart;
|
|
85
|
-
if (audioBuffer.length <=
|
|
89
|
+
if (audioBuffer.length <= INLINE_MEDIA_LIMIT) {
|
|
86
90
|
audioPart = { inlineData: { mimeType, data: audioBuffer.toString("base64") } };
|
|
87
91
|
} else {
|
|
88
92
|
const file = await uploadToGemini(gemini.genAI, audioBuffer, mimeType, {
|
package/src/commands/unblock.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// file: /commands/unblock.js (Upgraded with private chat context)
|
|
2
2
|
const logger = require("../utils/logger.cjs");
|
|
3
|
-
const normalizeJid = require("../utils/normalizeJid.esm.js");
|
|
3
|
+
const normalizeJid = require("../utils/normalizeJid.esm.js").default;
|
|
4
4
|
const { tr } = require("../utils/i18n.cjs");
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
package/src/config/defaults.cjs
CHANGED
|
@@ -47,12 +47,13 @@ const COMMAND_PERMISSIONS = Object.freeze({
|
|
|
47
47
|
perm: "OWNER_ONLY",
|
|
48
48
|
setprefix: "OWNER_ONLY",
|
|
49
49
|
restart: "OWNER_ONLY",
|
|
50
|
-
|
|
50
|
+
stopbot: "OWNER_ONLY",
|
|
51
51
|
status: "OWNER_ONLY",
|
|
52
52
|
lang: "MEMBERS",
|
|
53
53
|
digit: "MEMBERS",
|
|
54
54
|
block: "OWNER_ONLY",
|
|
55
55
|
unblock: "OWNER_ONLY",
|
|
56
|
+
send: "MEMBERS",
|
|
56
57
|
group: {
|
|
57
58
|
default_permission: "ADMINS_OWNER",
|
|
58
59
|
sub_commands: {
|
package/src/config/settings.cjs
CHANGED
|
@@ -586,8 +586,7 @@ function set(key, value) {
|
|
|
586
586
|
}
|
|
587
587
|
|
|
588
588
|
const clean = validate(definition, value);
|
|
589
|
-
const toStore =
|
|
590
|
-
definition.type === "secret" ? require("./vault.cjs").seal(String(clean)) : clean;
|
|
589
|
+
const toStore = definition.type === "secret" ? require("./vault.cjs").seal(String(clean)) : clean;
|
|
591
590
|
storage.saveBotSetting(`setting:${key}`, toStore);
|
|
592
591
|
// Never log the value of a secret.
|
|
593
592
|
logger.info(`[settings] ${key} -> ${definition.type === "secret" ? "(updated)" : clean}`);
|
|
@@ -629,4 +628,7 @@ module.exports = {
|
|
|
629
628
|
sourceOf,
|
|
630
629
|
SETTING_KEYS: [...BY_KEY.keys()],
|
|
631
630
|
SECRET_SETTING_KEYS: [...SECRET_SETTING_KEYS],
|
|
631
|
+
RESTART_SETTING_KEYS: SETTINGS.filter((definition) => definition.restart === true).map(
|
|
632
|
+
(definition) => definition.key,
|
|
633
|
+
),
|
|
632
634
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// A process-wide pointer to the backend's session manager.
|
|
2
|
+
//
|
|
3
|
+
// The state machine in session.js is the only thing allowed to create or
|
|
4
|
+
// destroy a Baileys socket, but it is built once in bootstrap/core.js and not
|
|
5
|
+
// every caller sits on that dependency path — the WhatsApp commands (!stopbot,
|
|
6
|
+
// !restart) don't (the panel gets its own hand-over in bootstrap/panel.js).
|
|
7
|
+
// bootstrapCore() sets this right after constructing the manager; commands
|
|
8
|
+
// read it at call time.
|
|
9
|
+
//
|
|
10
|
+
// Null until the core is up — callers answer that with a friendly line,
|
|
11
|
+
// never a crash.
|
|
12
|
+
|
|
13
|
+
let session = null;
|
|
14
|
+
|
|
15
|
+
function setSession(manager) {
|
|
16
|
+
session = manager;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getSession() {
|
|
20
|
+
return session;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { setSession, getSession };
|
|
@@ -3,8 +3,8 @@ import { createRequire } from "module";
|
|
|
3
3
|
import { dirname, join } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { checkBotAdmin, checkCommandPermission } from "../middleware/permissions.middleware.js";
|
|
6
|
-
import { sendBotMessage } from "../utils/sendBotMessage.esm.js";
|
|
7
6
|
import { resolveGroupMetadata } from "../utils/groupMetadataCache.cjs";
|
|
7
|
+
import { sendBotMessage } from "../utils/sendBotMessage.esm.js";
|
|
8
8
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
10
|
const __dirname = dirname(__filename);
|
|
@@ -32,6 +32,7 @@ const EDIT_IN_PLACE_EXCLUDE = new Set([
|
|
|
32
32
|
"prayer",
|
|
33
33
|
"tts",
|
|
34
34
|
"stt",
|
|
35
|
+
"send",
|
|
35
36
|
"weather",
|
|
36
37
|
"qr",
|
|
37
38
|
"status",
|
|
@@ -319,10 +320,7 @@ async function runCommand(sock, msg, body, { command, args, invokedName, isGroup
|
|
|
319
320
|
sock,
|
|
320
321
|
msg.key.remoteJid,
|
|
321
322
|
{
|
|
322
|
-
text: tr(
|
|
323
|
-
"⚠️ This command only works in groups.",
|
|
324
|
-
"⚠️ هذا الأمر يعمل في المجموعات فقط.",
|
|
325
|
-
),
|
|
323
|
+
text: tr("⚠️ This command only works in groups.", "⚠️ هذا الأمر يعمل في المجموعات فقط."),
|
|
326
324
|
},
|
|
327
325
|
{ replyTo: msg },
|
|
328
326
|
);
|