levix-bot 4.9.1 → 5.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 +57 -3
- package/SETUP.md +63 -7
- package/app.cjs +159 -46
- package/deploy/install.sh +10 -5
- package/package.json +9 -6
- package/public/dashboard/assets/40af6d88b63079a0-BZ8ojJNu.woff2 +0 -0
- package/public/dashboard/assets/481acf6760031cee-BypgxfGb.woff2 +0 -0
- package/public/dashboard/assets/6d3351fc535f8ef3-D2-eand5.woff2 +0 -0
- package/public/dashboard/assets/8ab0af53a3bda9d3-CyCXRvzh.woff2 +0 -0
- package/public/dashboard/assets/8f262393e9249e61-TQp-UTiE.woff2 +0 -0
- package/public/dashboard/assets/94d65887a83f1282-DmpS2jIq.woff2 +0 -0
- package/public/dashboard/assets/99e400330f36ae77-D3oMJlXt.woff2 +0 -0
- package/public/dashboard/assets/9d1f41b13e519d90-BVNSOH3d.woff2 +0 -0
- package/public/dashboard/assets/a005256cb957ecc7-CoYeBiSI.woff2 +0 -0
- package/public/dashboard/assets/b19c2080652a3c2b-DIC32ArD.woff2 +0 -0
- package/public/dashboard/assets/c4064400db3750ce-BehTv68k.woff2 +0 -0
- package/public/dashboard/assets/c69d345fa1068c2d-CmI34b-g.woff2 +0 -0
- package/public/dashboard/assets/cc27b30471250057-6fWv1k7M.woff2 +0 -0
- package/public/dashboard/assets/d8c30647abfeffe6-eXO_dkmS.woff2 +0 -0
- package/public/dashboard/assets/eb83d8d40af4411f-Buze_B52.woff2 +0 -0
- package/public/dashboard/assets/effc6711249e7349-qRpaaN48.woff2 +0 -0
- package/public/dashboard/assets/gateway-BDYet0pI.css +1 -0
- package/public/dashboard/assets/gateway-BYt6-s1O.js +1 -0
- package/public/dashboard/assets/index-B9wFpD_z.css +2 -0
- package/public/dashboard/assets/index-DWcQmu0_.js +124 -0
- package/public/dashboard/assets/index-Da-j89O-.js +458 -0
- package/public/dashboard/font-licenses/jetbrainsmono-OFL.txt +93 -0
- package/public/dashboard/font-licenses/plusjakartasans-OFL.txt +93 -0
- package/public/dashboard/font-licenses/tajawal-OFL.txt +93 -0
- package/public/dashboard/gateway.html +17 -0
- package/public/dashboard/index.html +3 -5
- package/public/ui-boot.js +33 -14
- package/scheduler.cjs +76 -23
- package/src/auth/auth-storage.cjs +54 -7
- package/src/auth/use-database-auth-state.js +70 -39
- package/src/automation/engine.js +412 -0
- package/src/automation/limits.cjs +6 -0
- package/src/automation/manage.js +290 -0
- package/src/automation/reactions.js +471 -0
- package/src/automation/rules.cjs +114 -0
- package/src/automation/status.cjs +76 -0
- package/src/backup/account.cjs +29 -0
- package/src/backup/activation.cjs +247 -0
- package/src/backup/content.cjs +36 -0
- package/src/backup/create.cjs +280 -0
- package/src/backup/extensions.cjs +101 -0
- package/src/backup/format.cjs +565 -0
- package/src/backup/jobs.cjs +111 -0
- package/src/backup/journal.cjs +41 -0
- package/src/backup/plan.cjs +223 -0
- package/src/backup/recovery.cjs +110 -0
- package/src/backup/restore.cjs +460 -0
- package/src/backup/uploads.cjs +146 -0
- package/src/bootstrap/core.js +50 -12
- package/src/bootstrap/panel.js +53 -2
- package/src/bootstrap/session-startup-policy.js +8 -1
- package/src/cli.js +163 -22
- package/src/commands/autodelete.cjs +41 -57
- package/src/commands/autoschedule.cjs +7 -33
- package/src/commands/blacklist.cjs +17 -35
- package/src/commands/block.cjs +4 -18
- package/src/commands/calc.cjs +22 -74
- package/src/commands/debt.cjs +28 -59
- package/src/commands/deleteschedule.cjs +7 -23
- package/src/commands/digit.cjs +5 -39
- package/src/commands/gemini.cjs +135 -218
- package/src/commands/group/add.cjs +28 -76
- package/src/commands/group/all.cjs +4 -15
- package/src/commands/group/antilink.cjs +28 -41
- package/src/commands/group/antispam.cjs +25 -35
- package/src/commands/group/approveall.cjs +7 -21
- package/src/commands/group/clearwarns.cjs +4 -18
- package/src/commands/group/deletenote.cjs +4 -18
- package/src/commands/group/demote.cjs +6 -23
- package/src/commands/group/flagged.cjs +10 -19
- package/src/commands/group/kick.cjs +26 -36
- package/src/commands/group/media.cjs +21 -36
- package/src/commands/group/members.cjs +16 -28
- package/src/commands/group/note.cjs +3 -14
- package/src/commands/group/policy.cjs +16 -37
- package/src/commands/group/promote.cjs +5 -22
- package/src/commands/group/removeall.cjs +6 -38
- package/src/commands/group/rules.cjs +4 -19
- package/src/commands/group/save.cjs +4 -18
- package/src/commands/group/setname.cjs +5 -19
- package/src/commands/group/setpp.cjs +8 -26
- package/src/commands/group/setrules.cjs +4 -15
- package/src/commands/group/setwarn.cjs +6 -23
- package/src/commands/group/tagadmins.cjs +5 -16
- package/src/commands/group/warn.cjs +5 -16
- package/src/commands/group/warns.cjs +12 -33
- package/src/commands/group/welcome.cjs +17 -34
- package/src/commands/group.cjs +91 -68
- package/src/commands/help.cjs +48 -89
- package/src/commands/lang.cjs +38 -97
- package/src/commands/listschedules.cjs +19 -30
- package/src/commands/loop.cjs +9 -55
- package/src/commands/md.cjs +2 -13
- package/src/commands/memory.cjs +53 -87
- package/src/commands/mod.cjs +40 -79
- package/src/commands/notes.cjs +4 -15
- package/src/commands/pack.cjs +26 -49
- package/src/commands/packs.cjs +8 -18
- package/src/commands/perm.cjs +48 -51
- package/src/commands/ping.cjs +2 -10
- package/src/commands/poll.cjs +5 -38
- package/src/commands/prayer.cjs +55 -36
- package/src/commands/qr.cjs +4 -18
- package/src/commands/rand.cjs +9 -58
- package/src/commands/restart.cjs +15 -33
- package/src/commands/schedule.cjs +5 -25
- package/src/commands/score.cjs +6 -27
- package/src/commands/send.cjs +4 -18
- package/src/commands/setprefix.cjs +11 -23
- package/src/commands/shortlink.cjs +13 -39
- package/src/commands/status.cjs +188 -76
- package/src/commands/sticker.cjs +5 -16
- package/src/commands/stickers.cjs +16 -20
- package/src/commands/stopbot.cjs +9 -25
- package/src/commands/stt.cjs +75 -107
- package/src/commands/todo.cjs +11 -31
- package/src/commands/toimage.cjs +11 -27
- package/src/commands/translate.cjs +53 -36
- package/src/commands/tts.cjs +46 -40
- package/src/commands/unblock.cjs +3 -17
- package/src/commands/update.cjs +23 -0
- package/src/commands/weather.cjs +40 -47
- package/src/config/ai-identity.cjs +14 -1
- package/src/config/baileys.config.js +16 -3
- package/src/config/data-dir.cjs +37 -0
- package/src/config/defaults.cjs +1 -0
- package/src/config/exit-codes.cjs +11 -0
- package/src/config/lock.cjs +55 -81
- package/src/config/official-links.cjs +61 -0
- package/src/config/paths.cjs +4 -33
- package/src/config/release.cjs +87 -0
- package/src/config/settings.cjs +199 -10
- package/src/core/connection.js +77 -9
- package/src/core/events.js +119 -33
- package/src/core/session.js +536 -84
- package/src/core/socket.js +81 -10
- package/src/db/copy.cjs +136 -0
- package/src/db/db.cjs +241 -36
- package/src/db/startup-guard.js +5 -0
- package/src/db/store.cjs +561 -54
- package/src/diagnostics/baileysLog.cjs +87 -0
- package/src/diagnostics/debugLog.cjs +16 -4
- package/src/diagnostics/device.cjs +4 -2
- package/src/diagnostics/nodeRuntime.cjs +131 -0
- package/src/diagnostics/signalSessionInspect.cjs +38 -0
- package/src/domain/command.js +24 -22
- package/src/extensions/autoReply.cjs +521 -0
- package/src/extensions/context.cjs +73 -0
- package/src/extensions/contract.cjs +69 -0
- package/src/extensions/entitlement/client.cjs +381 -0
- package/src/extensions/entitlement/index.cjs +629 -0
- package/src/extensions/entitlement/installation.cjs +117 -0
- package/src/extensions/entitlement/keys.cjs +72 -0
- package/src/extensions/entitlement/state.cjs +201 -0
- package/src/extensions/entitlement/target.cjs +7 -0
- package/src/extensions/entitlement/token.cjs +225 -0
- package/src/extensions/host.cjs +519 -0
- package/src/extensions/templateKeys.cjs +81 -0
- package/src/handlers/command.handler.js +191 -64
- package/src/handlers/group.handler.js +78 -18
- package/src/handlers/message.handler.js +56 -25
- package/src/i18n/catalog.generated.cjs +3537 -0
- package/src/index.js +51 -12
- package/src/legal/bundled/ar.json +102 -0
- package/src/legal/bundled/en.json +102 -0
- package/src/legal/bundled/es-419.json +102 -0
- package/src/legal/bundled/pt-BR.json +102 -0
- package/src/legal/cli.cjs +200 -0
- package/src/legal/consent.cjs +187 -0
- package/src/legal/document.cjs +156 -0
- package/src/legal/keys.cjs +100 -0
- package/src/legal/release.cjs +226 -0
- package/src/legal/remote.cjs +419 -0
- package/src/legal/terms.cjs +142 -0
- package/src/messaging/escape.cjs +31 -0
- package/src/messaging/health.cjs +65 -0
- package/src/messaging/identity.cjs +42 -0
- package/src/messaging/message.cjs +136 -0
- package/src/messaging/parser.cjs +88 -0
- package/src/messaging/router.cjs +217 -0
- package/src/middleware/permissions.middleware.js +34 -2
- package/src/panel/account-profile.cjs +489 -0
- package/src/panel/fallback-page.cjs +177 -0
- package/src/panel/password-reset.cjs +13 -14
- package/src/panel/recovery-email.cjs +3 -1
- package/src/routes/backup.api.esm.js +175 -0
- package/src/routes/dashboard.api.esm.js +183 -7
- package/src/routes/plus.api.esm.js +172 -0
- package/src/routes/reactions.api.esm.js +60 -0
- package/src/services/aiAgent.cjs +56 -43
- package/src/services/aiDocs.cjs +187 -0
- package/src/services/aiImage.cjs +183 -0
- package/src/services/aiMedia.cjs +146 -0
- package/src/services/aiProviders.cjs +76 -80
- package/src/services/aiRouter.cjs +2 -2
- package/src/services/aiToolAuth.cjs +76 -4
- package/src/services/aiTools.cjs +431 -105
- package/src/services/autoDelete.cjs +9 -1
- package/src/services/levix-docs.generated.json +2623 -0
- package/src/services/memoryPolicy.cjs +56 -0
- package/src/services/updateCheck.cjs +362 -0
- package/src/stickers/errors.cjs +53 -97
- package/src/stickers/library.cjs +13 -6
- package/src/stickers/owner.cjs +1 -1
- package/src/utils/commandContext.cjs +13 -0
- package/src/utils/commandDocs.cjs +42 -20
- package/src/utils/geminiHttpOptions.cjs +56 -0
- package/src/utils/geminiMedia.cjs +28 -3
- package/src/utils/groupMetadataCache.cjs +386 -21
- package/src/utils/httpsFetch.cjs +113 -0
- package/src/utils/i18n.cjs +117 -7
- package/src/utils/linkPreview.cjs +90 -0
- package/src/utils/logger.cjs +6 -0
- package/src/utils/markdownParser.cjs +3 -3
- package/src/utils/memory.cjs +375 -28
- package/src/utils/messageContent.cjs +7 -1
- package/src/utils/moderationAction.cjs +116 -73
- package/src/utils/moderationSummary.cjs +32 -56
- package/src/utils/permissionLevel.cjs +7 -28
- package/src/utils/permissions.cjs +23 -14
- package/src/utils/permissions.esm.js +99 -166
- package/src/utils/recentMessageCache.esm.js +241 -37
- package/src/utils/recurrence.cjs +78 -66
- package/src/utils/sendBotMessage.cjs +14 -29
- package/src/utils/sendBotMessage.esm.js +28 -13
- package/src/utils/statusMessage.cjs +94 -33
- package/src/utils/stickerBot.cjs +18 -16
- package/src/utils/storage.cjs +2 -0
- package/src/utils/storage.esm.js +2 -0
- package/src/utils/thumbnail.cjs +5 -21
- package/public/dashboard/assets/index-B1sOW2VX.js +0 -561
- package/public/dashboard/assets/index-CK8osB4o.css +0 -2
- package/public/dashboard.css +0 -3127
- package/public/dashboard.js +0 -1981
- package/public/gateway-i18n.js +0 -321
- package/public/gateway.js +0 -70
- package/views/dashboard.ejs +0 -775
- package/views/login.ejs +0 -408
- package/views/qr.ejs +0 -155
- package/views/setup.ejs +0 -118
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
// message itself is still sent.
|
|
16
16
|
|
|
17
17
|
import { createRequire } from "module";
|
|
18
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
18
19
|
|
|
19
20
|
const require = createRequire(import.meta.url);
|
|
20
21
|
const logger = require("./logger.cjs");
|
|
21
|
-
const {
|
|
22
|
+
const { t } = require("./i18n.cjs");
|
|
22
23
|
const settings = require("../config/settings.cjs");
|
|
23
24
|
|
|
24
25
|
const lastSendTime = new Map(); // chatJid -> timestamp ms
|
|
@@ -34,11 +35,15 @@ function jitter(min, max) {
|
|
|
34
35
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
function sleep(ms) {
|
|
38
|
+
function sleep(ms, signal) {
|
|
38
39
|
if (!ms || ms <= 0) return Promise.resolve();
|
|
39
|
-
return
|
|
40
|
+
return delay(ms, undefined, { signal });
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// Tests replace timing.sleep to skip the real wait; the bot still computes and
|
|
44
|
+
// requests the same delays.
|
|
45
|
+
export const timing = { sleep };
|
|
46
|
+
|
|
42
47
|
function typingDelayFor(content) {
|
|
43
48
|
const text = content?.text || content?.caption || "";
|
|
44
49
|
if (!text) return jitter(300, 700);
|
|
@@ -51,7 +56,7 @@ async function safePresence(sock, jid, presence) {
|
|
|
51
56
|
try {
|
|
52
57
|
await sock.sendPresenceUpdate(presence, jid);
|
|
53
58
|
} catch (err) {
|
|
54
|
-
logger.debug({ err: err?.message,
|
|
59
|
+
logger.debug({ err: err?.message, presence }, "[sendBotMessage] presence failed");
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
|
|
@@ -67,10 +72,12 @@ async function safePresence(sock, jid, presence) {
|
|
|
67
72
|
* @param {boolean} [options.quote=true] - Set false to skip auto-quoting.
|
|
68
73
|
* @param {boolean} [options.typing=true] - Set false to skip typing presence.
|
|
69
74
|
* @param {number} [options.delayMs] - Override the inter-message gap.
|
|
75
|
+
* @param {AbortSignal} [options.signal] - Cancel before initiating delivery.
|
|
70
76
|
* @returns {Promise<object>} Baileys send result
|
|
71
77
|
*/
|
|
72
78
|
export async function sendBotMessage(sock, jid, content, options = {}) {
|
|
73
|
-
const { replyTo = null, quoted = null, quote = true, typing = true, delayMs } = options;
|
|
79
|
+
const { replyTo = null, quoted = null, quote = true, typing = true, delayMs, signal } = options;
|
|
80
|
+
signal?.throwIfAborted();
|
|
74
81
|
|
|
75
82
|
// Respect the per-chat cooldown so multiple replies don't pile up instantly.
|
|
76
83
|
const now = Date.now();
|
|
@@ -83,11 +90,14 @@ export async function sendBotMessage(sock, jid, content, options = {}) {
|
|
|
83
90
|
const { min, max } = sendGap();
|
|
84
91
|
targetGap = jitter(min, max);
|
|
85
92
|
}
|
|
86
|
-
if (elapsed < targetGap) await sleep(targetGap - elapsed);
|
|
93
|
+
if (elapsed < targetGap) await timing.sleep(targetGap - elapsed, signal);
|
|
94
|
+
signal?.throwIfAborted();
|
|
87
95
|
|
|
88
96
|
if (typing) {
|
|
89
97
|
await safePresence(sock, jid, "composing");
|
|
90
|
-
|
|
98
|
+
signal?.throwIfAborted();
|
|
99
|
+
await timing.sleep(typingDelayFor(content), signal);
|
|
100
|
+
signal?.throwIfAborted();
|
|
91
101
|
await safePresence(sock, jid, "paused");
|
|
92
102
|
}
|
|
93
103
|
|
|
@@ -96,6 +106,11 @@ export async function sendBotMessage(sock, jid, content, options = {}) {
|
|
|
96
106
|
const quotedMsg = quoted || replyTo;
|
|
97
107
|
if (quotedMsg) opts.quoted = quotedMsg;
|
|
98
108
|
}
|
|
109
|
+
// The command proxy reads this and strips it before Baileys sees the call.
|
|
110
|
+
if (options.levix) opts.levix = options.levix;
|
|
111
|
+
// The socket consumes this after its asynchronous media preparation.
|
|
112
|
+
if (signal) opts.signal = signal;
|
|
113
|
+
if (options.deliveryGuard) opts.deliveryGuard = options.deliveryGuard;
|
|
99
114
|
|
|
100
115
|
// Link previews are opt-in (default off, see `link_previews_enabled`):
|
|
101
116
|
// without an explicit `linkPreview`, Baileys fetches the page behind any URL
|
|
@@ -111,6 +126,7 @@ export async function sendBotMessage(sock, jid, content, options = {}) {
|
|
|
111
126
|
content = { ...content, linkPreview: null };
|
|
112
127
|
}
|
|
113
128
|
|
|
129
|
+
signal?.throwIfAborted();
|
|
114
130
|
try {
|
|
115
131
|
const sent = await sock.sendMessage(jid, content, opts);
|
|
116
132
|
lastSendTime.set(jid, Date.now());
|
|
@@ -131,22 +147,21 @@ export async function sendBotMessage(sock, jid, content, options = {}) {
|
|
|
131
147
|
* @param {object} sock
|
|
132
148
|
* @param {string} jid
|
|
133
149
|
* @param {Error|string} err
|
|
134
|
-
* @param {string} [lead] - one-line summary in the reply language, via
|
|
150
|
+
* @param {string} [lead] - one-line summary in the reply language, via t()
|
|
135
151
|
* @param {object} [options] - forwarded to sendBotMessage
|
|
136
152
|
*/
|
|
137
153
|
export async function sendBotError(
|
|
138
154
|
sock,
|
|
139
155
|
jid,
|
|
140
156
|
err,
|
|
141
|
-
lead =
|
|
157
|
+
lead = t("bot.core.sendBotMessage.defaultLead"),
|
|
142
158
|
options = {},
|
|
143
159
|
) {
|
|
144
160
|
const name = err?.name || (typeof err === "string" ? "Error" : "Error");
|
|
145
161
|
const message = err?.message || (typeof err === "string" ? err : JSON.stringify(err));
|
|
146
|
-
const text =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
).slice(0, 1500);
|
|
162
|
+
const text = settings
|
|
163
|
+
.redactSecrets(t("bot.core.sendBotMessage.errorCard", { lead, name, message }))
|
|
164
|
+
.slice(0, 1500);
|
|
150
165
|
return sendBotMessage(sock, jid, { text }, options);
|
|
151
166
|
}
|
|
152
167
|
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
|
|
16
16
|
const logger = require("./logger.cjs");
|
|
17
17
|
const { sendBotMessage } = require("./sendBotMessage.cjs");
|
|
18
|
-
const {
|
|
18
|
+
const { t } = require("./i18n.cjs");
|
|
19
|
+
const settings = require("../config/settings.cjs");
|
|
20
|
+
const { currentCommand } = require("./commandContext.cjs");
|
|
19
21
|
|
|
20
22
|
// WhatsApp tolerates a few edits per message; spacing them out keeps the
|
|
21
23
|
// server happy and the animation readable.
|
|
@@ -32,23 +34,49 @@ class StatusMessage {
|
|
|
32
34
|
this.jid = jid;
|
|
33
35
|
this.replyTo = options.replyTo || null;
|
|
34
36
|
this.quote = options.quote !== false;
|
|
37
|
+
this.category = options.category || "progress";
|
|
38
|
+
this.sensitivity = options.sensitivity || "source";
|
|
39
|
+
this.mentions = Array.isArray(options.mentions) ? options.mentions : null;
|
|
40
|
+
this.command = options.command === undefined ? currentCommand() : options.command;
|
|
35
41
|
this.key = null;
|
|
36
42
|
this.text = "";
|
|
37
43
|
this.lastEditAt = 0;
|
|
38
44
|
this.closed = false;
|
|
45
|
+
this.suppressed = false;
|
|
46
|
+
this.plusSuppressed = false;
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
async start(text) {
|
|
42
50
|
this.text = text;
|
|
51
|
+
// Hiding progress never hides a later result, error, or security notice.
|
|
52
|
+
if (this.category === "progress") {
|
|
53
|
+
let plusHide = false;
|
|
54
|
+
try {
|
|
55
|
+
plusHide = require("../extensions/host.cjs").host.hideProgress({
|
|
56
|
+
command: this.command,
|
|
57
|
+
});
|
|
58
|
+
} catch {}
|
|
59
|
+
this.plusSuppressed = plusHide;
|
|
60
|
+
}
|
|
61
|
+
if (this.category === "progress" && settings.get("reply_hide_progress")) {
|
|
62
|
+
this.suppressed = true;
|
|
63
|
+
this.text = "";
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
if (this.category === "progress" && this.plusSuppressed) {
|
|
67
|
+
this.suppressed = true;
|
|
68
|
+
this.text = "";
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
43
71
|
try {
|
|
44
|
-
const sent = await sendBotMessage(
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
72
|
+
const sent = await sendBotMessage(this.sock, this.jid, this.payload(text, this.mentions), {
|
|
73
|
+
replyTo: this.replyTo,
|
|
74
|
+
quote: this.quote,
|
|
75
|
+
typing: false,
|
|
76
|
+
delayMs: 0,
|
|
77
|
+
levix: { category: this.category, sensitivity: this.sensitivity },
|
|
78
|
+
});
|
|
79
|
+
this.adopt(sent, text);
|
|
52
80
|
} catch (err) {
|
|
53
81
|
logger.warn({ err: err?.message }, "[status] initial send failed");
|
|
54
82
|
this.key = null;
|
|
@@ -56,14 +84,34 @@ class StatusMessage {
|
|
|
56
84
|
return this;
|
|
57
85
|
}
|
|
58
86
|
|
|
87
|
+
payload(text, mentions) {
|
|
88
|
+
const content = { text };
|
|
89
|
+
if (mentions?.length) content.mentions = mentions;
|
|
90
|
+
return content;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
adopt(sent, text) {
|
|
94
|
+
this.key = sent?.key || null;
|
|
95
|
+
if (sent?.key?.remoteJid) this.jid = sent.key.remoteJid;
|
|
96
|
+
this.text = text;
|
|
97
|
+
this.lastEditAt = Date.now();
|
|
98
|
+
}
|
|
99
|
+
|
|
59
100
|
/** Rewrite the line. Identical text is skipped so we don't burn an edit. */
|
|
60
|
-
async update(
|
|
101
|
+
async update(
|
|
102
|
+
text,
|
|
103
|
+
{ force = false, mentions = undefined, category = undefined, sensitivity = undefined } = {},
|
|
104
|
+
) {
|
|
61
105
|
if (this.closed && !force) return false;
|
|
62
106
|
const next = String(text || "").trim();
|
|
63
107
|
if (!next || next === this.text) return false;
|
|
108
|
+
if (category) this.category = category;
|
|
109
|
+
if (sensitivity) this.sensitivity = sensitivity;
|
|
110
|
+
if (this.plusSuppressed && this.category === "progress") return false;
|
|
111
|
+
const mentionList = mentions === undefined ? this.mentions : mentions;
|
|
64
112
|
|
|
65
|
-
// No message to edit (
|
|
66
|
-
if (!this.key) return this._sendFresh(next);
|
|
113
|
+
// No message to edit (hidden progress, or the first send failed).
|
|
114
|
+
if (!this.key) return this._sendFresh(next, mentionList);
|
|
67
115
|
|
|
68
116
|
const wait = MIN_EDIT_GAP_MS - (Date.now() - this.lastEditAt);
|
|
69
117
|
if (wait > 0) await sleep(wait);
|
|
@@ -72,27 +120,36 @@ class StatusMessage {
|
|
|
72
120
|
// `quoted: null` on purpose: the command handler wraps sock.sendMessage
|
|
73
121
|
// and auto-quotes anything that doesn't set it, and an edit/delete is a
|
|
74
122
|
// protocolMessage — there is nowhere to hang a contextInfo.
|
|
75
|
-
await this.sock.sendMessage(
|
|
123
|
+
const sent = await this.sock.sendMessage(
|
|
124
|
+
this.jid,
|
|
125
|
+
{ ...this.payload(next, mentionList), edit: this.key },
|
|
126
|
+
{ quoted: null, levix: { category: this.category, sensitivity: this.sensitivity } },
|
|
127
|
+
);
|
|
76
128
|
this.text = next;
|
|
129
|
+
this.mentions = mentionList;
|
|
77
130
|
this.lastEditAt = Date.now();
|
|
131
|
+
if (sent?.key?.remoteJid) this.jid = sent.key.remoteJid;
|
|
78
132
|
return true;
|
|
79
133
|
} catch (err) {
|
|
80
134
|
logger.debug({ err: err?.message }, "[status] edit failed — sending instead");
|
|
81
|
-
return this._sendFresh(next);
|
|
135
|
+
return this._sendFresh(next, mentionList);
|
|
82
136
|
}
|
|
83
137
|
}
|
|
84
138
|
|
|
85
|
-
async _sendFresh(text) {
|
|
139
|
+
async _sendFresh(text, mentions) {
|
|
86
140
|
try {
|
|
87
|
-
const sent = await sendBotMessage(
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
141
|
+
const sent = await sendBotMessage(this.sock, this.jid, this.payload(text, mentions), {
|
|
142
|
+
replyTo: this.replyTo,
|
|
143
|
+
quote: this.quote,
|
|
144
|
+
typing: false,
|
|
145
|
+
delayMs: 0,
|
|
146
|
+
levix: {
|
|
147
|
+
category: this.category === "progress" ? "result" : this.category,
|
|
148
|
+
sensitivity: this.sensitivity,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
this.adopt(sent, text);
|
|
152
|
+
this.mentions = mentions;
|
|
96
153
|
return true;
|
|
97
154
|
} catch (err) {
|
|
98
155
|
logger.warn({ err: err?.message }, "[status] fallback send failed");
|
|
@@ -101,24 +158,28 @@ class StatusMessage {
|
|
|
101
158
|
}
|
|
102
159
|
|
|
103
160
|
/** Last update for this run. Always delivered, even if an edit is refused. */
|
|
104
|
-
async finish(text) {
|
|
105
|
-
const ok = await this.update(text, {
|
|
161
|
+
async finish(text, options = {}) {
|
|
162
|
+
const ok = await this.update(text, {
|
|
163
|
+
...options,
|
|
164
|
+
force: true,
|
|
165
|
+
category: options.category || "result",
|
|
166
|
+
});
|
|
106
167
|
this.closed = true;
|
|
107
168
|
return ok;
|
|
108
169
|
}
|
|
109
170
|
|
|
110
171
|
/**
|
|
111
172
|
* Turn the line into the standard error card. `lead` is the one-line
|
|
112
|
-
* summary, already in the reply language — pass it through
|
|
173
|
+
* summary, already in the reply language — pass it through t().
|
|
113
174
|
*/
|
|
114
|
-
async fail(err, lead =
|
|
175
|
+
async fail(err, lead = t("bot.core.statusMessage.defaultLead")) {
|
|
115
176
|
const name = err?.name || "Error";
|
|
116
|
-
const message = err?.message || String(err ||
|
|
177
|
+
const message = err?.message || String(err || t("bot.core.statusMessage.unknownError"));
|
|
117
178
|
return this.finish(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
179
|
+
settings
|
|
180
|
+
.redactSecrets(t("bot.core.statusMessage.errorCard", { lead, name, message }))
|
|
181
|
+
.slice(0, 1500),
|
|
182
|
+
{ category: "error" },
|
|
122
183
|
);
|
|
123
184
|
}
|
|
124
185
|
|
package/src/utils/stickerBot.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const media = require("../stickers/media.cjs");
|
|
|
7
7
|
const library = require("../stickers/library.cjs");
|
|
8
8
|
const { StickerError, isStickerError, userMessage } = require("../stickers/errors.cjs");
|
|
9
9
|
const { WHATSAPP_MEDIA_MAX_BYTES } = require("../stickers/limits.cjs");
|
|
10
|
-
const {
|
|
10
|
+
const { t, currentLang } = require("./i18n.cjs");
|
|
11
11
|
|
|
12
12
|
function targetOf(msg, { quotedOnly = false } = {}) {
|
|
13
13
|
const quoted = quotedOf(msg);
|
|
@@ -50,26 +50,28 @@ function commandHint(name, args = "") {
|
|
|
50
50
|
return `${runtimeConfig.getPrefix()}${name}${args ? ` ${args}` : ""}`;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// The old Arabic phrase uses one form through 10 and another after that.
|
|
54
|
+
// CLDR "few" also covers 103 and 203, so the count passed to t() is a number
|
|
55
|
+
// in the category that matches the old phrase. {n} is the number shown.
|
|
56
|
+
// Arabic for 1 and 2 has no digit. Every plural category still has to contain
|
|
57
|
+
// {n}, so those two pass an empty {n}.
|
|
58
|
+
function countPluralCount(n) {
|
|
59
|
+
if (n === 1 || n === 2 || n === 0) return n;
|
|
60
|
+
if (n <= 10) return 3;
|
|
61
|
+
const mod = Math.abs(n % 100);
|
|
62
|
+
if (mod >= 3 && mod <= 10) return 11;
|
|
63
|
+
return n;
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
function countLabel(count, kind = "sticker") {
|
|
54
67
|
const n = Number(count);
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
return tr(
|
|
59
|
-
english,
|
|
60
|
-
n === 1 ? "حزمة واحدة" : n === 2 ? "حزمتان" : n <= 10 ? `${n} حزم` : `${n} حزمة`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
return tr(
|
|
64
|
-
english,
|
|
65
|
-
n === 1 ? "ملصق واحد" : n === 2 ? "ملصقان" : n <= 10 ? `${n} ملصقات` : `${n} ملصقًا`,
|
|
66
|
-
);
|
|
68
|
+
const key = kind === "pack" ? "bot.stickers.count.pack" : "bot.stickers.count.sticker";
|
|
69
|
+
const bare = currentLang() === "ar" && (n === 1 || n === 2);
|
|
70
|
+
return t(key, { count: countPluralCount(n), n: bare ? "" : n });
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
function errorText(error) {
|
|
70
|
-
return isStickerError(error)
|
|
71
|
-
? userMessage(error)
|
|
72
|
-
: tr("Something went wrong with the sticker.", "حدث خطأ في الملصق.");
|
|
74
|
+
return isStickerError(error) ? userMessage(error) : t("bot.stickers.errors.internal");
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
module.exports = {
|
package/src/utils/storage.cjs
CHANGED
|
@@ -20,6 +20,8 @@ module.exports = {
|
|
|
20
20
|
upsertGroupDirectory: store.upsertGroupDirectory,
|
|
21
21
|
getGroupDirectory: store.getGroupDirectory,
|
|
22
22
|
getAllGroupDirectory: store.getAllGroupDirectory,
|
|
23
|
+
accountEpoch: store.accountEpoch,
|
|
24
|
+
advanceAccountEpoch: store.advanceAccountEpoch,
|
|
23
25
|
clearWhatsAppDirectory: store.clearWhatsAppDirectory,
|
|
24
26
|
isPairedSession: store.isPairedSession,
|
|
25
27
|
resolveUserPhone: store.resolveUserPhone,
|
package/src/utils/storage.esm.js
CHANGED
|
@@ -19,6 +19,8 @@ export const getAllGroupSettings = store.getAllGroupSettings;
|
|
|
19
19
|
export const upsertGroupDirectory = store.upsertGroupDirectory;
|
|
20
20
|
export const getGroupDirectory = store.getGroupDirectory;
|
|
21
21
|
export const getAllGroupDirectory = store.getAllGroupDirectory;
|
|
22
|
+
export const accountEpoch = store.accountEpoch;
|
|
23
|
+
export const advanceAccountEpoch = store.advanceAccountEpoch;
|
|
22
24
|
export const clearWhatsAppDirectory = store.clearWhatsAppDirectory;
|
|
23
25
|
export const isPairedSession = store.isPairedSession;
|
|
24
26
|
export const resolveUserPhone = store.resolveUserPhone;
|
package/src/utils/thumbnail.cjs
CHANGED
|
@@ -29,15 +29,7 @@ const { spawn } = require("child_process");
|
|
|
29
29
|
|
|
30
30
|
const logger = require("./logger.cjs");
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
// take the send path down.
|
|
34
|
-
function getAxios() {
|
|
35
|
-
try {
|
|
36
|
-
return require("axios");
|
|
37
|
-
} catch {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
32
|
+
const { fetchHttpsBuffer } = require("./httpsFetch.cjs");
|
|
41
33
|
|
|
42
34
|
const ffmpegStatic = (() => {
|
|
43
35
|
try {
|
|
@@ -424,18 +416,10 @@ function extensionFor(buffer, kind) {
|
|
|
424
416
|
|
|
425
417
|
/** Fetch a remote asset to a temp file so we can build a preview from it. */
|
|
426
418
|
async function downloadToTemp(url, kind) {
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const response = await axios.get(url, {
|
|
431
|
-
responseType: "arraybuffer",
|
|
432
|
-
timeout: remoteTimeoutMs(),
|
|
433
|
-
maxRedirects: 4,
|
|
434
|
-
maxContentLength: remoteMaxBytes(),
|
|
435
|
-
headers: { Accept: "*/*" },
|
|
419
|
+
const { buffer } = await fetchHttpsBuffer(url, {
|
|
420
|
+
timeoutMs: remoteTimeoutMs(),
|
|
421
|
+
maxBytes: remoteMaxBytes(),
|
|
436
422
|
});
|
|
437
|
-
|
|
438
|
-
const buffer = Buffer.from(response.data);
|
|
439
423
|
if (!buffer.length) return null;
|
|
440
424
|
|
|
441
425
|
const file = tmpPath(extensionFor(buffer, kind));
|
|
@@ -471,7 +455,7 @@ async function resolveSource(media, kind) {
|
|
|
471
455
|
return await downloadToTemp(url, kind);
|
|
472
456
|
} catch (err) {
|
|
473
457
|
logger.debug(
|
|
474
|
-
{ err: err?.message
|
|
458
|
+
{ err: err?.message },
|
|
475
459
|
"[thumbnail] remote source could not be fetched for a preview",
|
|
476
460
|
);
|
|
477
461
|
return null;
|