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.
Files changed (245) hide show
  1. package/README.md +57 -3
  2. package/SETUP.md +63 -7
  3. package/app.cjs +159 -46
  4. package/deploy/install.sh +10 -5
  5. package/package.json +9 -6
  6. package/public/dashboard/assets/40af6d88b63079a0-BZ8ojJNu.woff2 +0 -0
  7. package/public/dashboard/assets/481acf6760031cee-BypgxfGb.woff2 +0 -0
  8. package/public/dashboard/assets/6d3351fc535f8ef3-D2-eand5.woff2 +0 -0
  9. package/public/dashboard/assets/8ab0af53a3bda9d3-CyCXRvzh.woff2 +0 -0
  10. package/public/dashboard/assets/8f262393e9249e61-TQp-UTiE.woff2 +0 -0
  11. package/public/dashboard/assets/94d65887a83f1282-DmpS2jIq.woff2 +0 -0
  12. package/public/dashboard/assets/99e400330f36ae77-D3oMJlXt.woff2 +0 -0
  13. package/public/dashboard/assets/9d1f41b13e519d90-BVNSOH3d.woff2 +0 -0
  14. package/public/dashboard/assets/a005256cb957ecc7-CoYeBiSI.woff2 +0 -0
  15. package/public/dashboard/assets/b19c2080652a3c2b-DIC32ArD.woff2 +0 -0
  16. package/public/dashboard/assets/c4064400db3750ce-BehTv68k.woff2 +0 -0
  17. package/public/dashboard/assets/c69d345fa1068c2d-CmI34b-g.woff2 +0 -0
  18. package/public/dashboard/assets/cc27b30471250057-6fWv1k7M.woff2 +0 -0
  19. package/public/dashboard/assets/d8c30647abfeffe6-eXO_dkmS.woff2 +0 -0
  20. package/public/dashboard/assets/eb83d8d40af4411f-Buze_B52.woff2 +0 -0
  21. package/public/dashboard/assets/effc6711249e7349-qRpaaN48.woff2 +0 -0
  22. package/public/dashboard/assets/gateway-BDYet0pI.css +1 -0
  23. package/public/dashboard/assets/gateway-BYt6-s1O.js +1 -0
  24. package/public/dashboard/assets/index-B9wFpD_z.css +2 -0
  25. package/public/dashboard/assets/index-DWcQmu0_.js +124 -0
  26. package/public/dashboard/assets/index-Da-j89O-.js +458 -0
  27. package/public/dashboard/font-licenses/jetbrainsmono-OFL.txt +93 -0
  28. package/public/dashboard/font-licenses/plusjakartasans-OFL.txt +93 -0
  29. package/public/dashboard/font-licenses/tajawal-OFL.txt +93 -0
  30. package/public/dashboard/gateway.html +17 -0
  31. package/public/dashboard/index.html +3 -5
  32. package/public/ui-boot.js +33 -14
  33. package/scheduler.cjs +76 -23
  34. package/src/auth/auth-storage.cjs +54 -7
  35. package/src/auth/use-database-auth-state.js +70 -39
  36. package/src/automation/engine.js +412 -0
  37. package/src/automation/limits.cjs +6 -0
  38. package/src/automation/manage.js +290 -0
  39. package/src/automation/reactions.js +471 -0
  40. package/src/automation/rules.cjs +114 -0
  41. package/src/automation/status.cjs +76 -0
  42. package/src/backup/account.cjs +29 -0
  43. package/src/backup/activation.cjs +247 -0
  44. package/src/backup/content.cjs +36 -0
  45. package/src/backup/create.cjs +280 -0
  46. package/src/backup/extensions.cjs +101 -0
  47. package/src/backup/format.cjs +565 -0
  48. package/src/backup/jobs.cjs +111 -0
  49. package/src/backup/journal.cjs +41 -0
  50. package/src/backup/plan.cjs +223 -0
  51. package/src/backup/recovery.cjs +110 -0
  52. package/src/backup/restore.cjs +460 -0
  53. package/src/backup/uploads.cjs +146 -0
  54. package/src/bootstrap/core.js +50 -12
  55. package/src/bootstrap/panel.js +53 -2
  56. package/src/bootstrap/session-startup-policy.js +8 -1
  57. package/src/cli.js +163 -22
  58. package/src/commands/autodelete.cjs +41 -57
  59. package/src/commands/autoschedule.cjs +7 -33
  60. package/src/commands/blacklist.cjs +17 -35
  61. package/src/commands/block.cjs +4 -18
  62. package/src/commands/calc.cjs +22 -74
  63. package/src/commands/debt.cjs +28 -59
  64. package/src/commands/deleteschedule.cjs +7 -23
  65. package/src/commands/digit.cjs +5 -39
  66. package/src/commands/gemini.cjs +135 -218
  67. package/src/commands/group/add.cjs +28 -76
  68. package/src/commands/group/all.cjs +4 -15
  69. package/src/commands/group/antilink.cjs +28 -41
  70. package/src/commands/group/antispam.cjs +25 -35
  71. package/src/commands/group/approveall.cjs +7 -21
  72. package/src/commands/group/clearwarns.cjs +4 -18
  73. package/src/commands/group/deletenote.cjs +4 -18
  74. package/src/commands/group/demote.cjs +6 -23
  75. package/src/commands/group/flagged.cjs +10 -19
  76. package/src/commands/group/kick.cjs +26 -36
  77. package/src/commands/group/media.cjs +21 -36
  78. package/src/commands/group/members.cjs +16 -28
  79. package/src/commands/group/note.cjs +3 -14
  80. package/src/commands/group/policy.cjs +16 -37
  81. package/src/commands/group/promote.cjs +5 -22
  82. package/src/commands/group/removeall.cjs +6 -38
  83. package/src/commands/group/rules.cjs +4 -19
  84. package/src/commands/group/save.cjs +4 -18
  85. package/src/commands/group/setname.cjs +5 -19
  86. package/src/commands/group/setpp.cjs +8 -26
  87. package/src/commands/group/setrules.cjs +4 -15
  88. package/src/commands/group/setwarn.cjs +6 -23
  89. package/src/commands/group/tagadmins.cjs +5 -16
  90. package/src/commands/group/warn.cjs +5 -16
  91. package/src/commands/group/warns.cjs +12 -33
  92. package/src/commands/group/welcome.cjs +17 -34
  93. package/src/commands/group.cjs +91 -68
  94. package/src/commands/help.cjs +48 -89
  95. package/src/commands/lang.cjs +38 -97
  96. package/src/commands/listschedules.cjs +19 -30
  97. package/src/commands/loop.cjs +9 -55
  98. package/src/commands/md.cjs +2 -13
  99. package/src/commands/memory.cjs +53 -87
  100. package/src/commands/mod.cjs +40 -79
  101. package/src/commands/notes.cjs +4 -15
  102. package/src/commands/pack.cjs +26 -49
  103. package/src/commands/packs.cjs +8 -18
  104. package/src/commands/perm.cjs +48 -51
  105. package/src/commands/ping.cjs +2 -10
  106. package/src/commands/poll.cjs +5 -38
  107. package/src/commands/prayer.cjs +55 -36
  108. package/src/commands/qr.cjs +4 -18
  109. package/src/commands/rand.cjs +9 -58
  110. package/src/commands/restart.cjs +15 -33
  111. package/src/commands/schedule.cjs +5 -25
  112. package/src/commands/score.cjs +6 -27
  113. package/src/commands/send.cjs +4 -18
  114. package/src/commands/setprefix.cjs +11 -23
  115. package/src/commands/shortlink.cjs +13 -39
  116. package/src/commands/status.cjs +188 -76
  117. package/src/commands/sticker.cjs +5 -16
  118. package/src/commands/stickers.cjs +16 -20
  119. package/src/commands/stopbot.cjs +9 -25
  120. package/src/commands/stt.cjs +75 -107
  121. package/src/commands/todo.cjs +11 -31
  122. package/src/commands/toimage.cjs +11 -27
  123. package/src/commands/translate.cjs +53 -36
  124. package/src/commands/tts.cjs +46 -40
  125. package/src/commands/unblock.cjs +3 -17
  126. package/src/commands/update.cjs +23 -0
  127. package/src/commands/weather.cjs +40 -47
  128. package/src/config/ai-identity.cjs +14 -1
  129. package/src/config/baileys.config.js +16 -3
  130. package/src/config/data-dir.cjs +37 -0
  131. package/src/config/defaults.cjs +1 -0
  132. package/src/config/exit-codes.cjs +11 -0
  133. package/src/config/lock.cjs +55 -81
  134. package/src/config/official-links.cjs +61 -0
  135. package/src/config/paths.cjs +4 -33
  136. package/src/config/release.cjs +87 -0
  137. package/src/config/settings.cjs +199 -10
  138. package/src/core/connection.js +77 -9
  139. package/src/core/events.js +119 -33
  140. package/src/core/session.js +536 -84
  141. package/src/core/socket.js +81 -10
  142. package/src/db/copy.cjs +136 -0
  143. package/src/db/db.cjs +241 -36
  144. package/src/db/startup-guard.js +5 -0
  145. package/src/db/store.cjs +561 -54
  146. package/src/diagnostics/baileysLog.cjs +87 -0
  147. package/src/diagnostics/debugLog.cjs +16 -4
  148. package/src/diagnostics/device.cjs +4 -2
  149. package/src/diagnostics/nodeRuntime.cjs +131 -0
  150. package/src/diagnostics/signalSessionInspect.cjs +38 -0
  151. package/src/domain/command.js +24 -22
  152. package/src/extensions/autoReply.cjs +521 -0
  153. package/src/extensions/context.cjs +73 -0
  154. package/src/extensions/contract.cjs +69 -0
  155. package/src/extensions/entitlement/client.cjs +381 -0
  156. package/src/extensions/entitlement/index.cjs +629 -0
  157. package/src/extensions/entitlement/installation.cjs +117 -0
  158. package/src/extensions/entitlement/keys.cjs +72 -0
  159. package/src/extensions/entitlement/state.cjs +201 -0
  160. package/src/extensions/entitlement/target.cjs +7 -0
  161. package/src/extensions/entitlement/token.cjs +225 -0
  162. package/src/extensions/host.cjs +519 -0
  163. package/src/extensions/templateKeys.cjs +81 -0
  164. package/src/handlers/command.handler.js +191 -64
  165. package/src/handlers/group.handler.js +78 -18
  166. package/src/handlers/message.handler.js +56 -25
  167. package/src/i18n/catalog.generated.cjs +3537 -0
  168. package/src/index.js +51 -12
  169. package/src/legal/bundled/ar.json +102 -0
  170. package/src/legal/bundled/en.json +102 -0
  171. package/src/legal/bundled/es-419.json +102 -0
  172. package/src/legal/bundled/pt-BR.json +102 -0
  173. package/src/legal/cli.cjs +200 -0
  174. package/src/legal/consent.cjs +187 -0
  175. package/src/legal/document.cjs +156 -0
  176. package/src/legal/keys.cjs +100 -0
  177. package/src/legal/release.cjs +226 -0
  178. package/src/legal/remote.cjs +419 -0
  179. package/src/legal/terms.cjs +142 -0
  180. package/src/messaging/escape.cjs +31 -0
  181. package/src/messaging/health.cjs +65 -0
  182. package/src/messaging/identity.cjs +42 -0
  183. package/src/messaging/message.cjs +136 -0
  184. package/src/messaging/parser.cjs +88 -0
  185. package/src/messaging/router.cjs +217 -0
  186. package/src/middleware/permissions.middleware.js +34 -2
  187. package/src/panel/account-profile.cjs +489 -0
  188. package/src/panel/fallback-page.cjs +177 -0
  189. package/src/panel/password-reset.cjs +13 -14
  190. package/src/panel/recovery-email.cjs +3 -1
  191. package/src/routes/backup.api.esm.js +175 -0
  192. package/src/routes/dashboard.api.esm.js +183 -7
  193. package/src/routes/plus.api.esm.js +172 -0
  194. package/src/routes/reactions.api.esm.js +60 -0
  195. package/src/services/aiAgent.cjs +56 -43
  196. package/src/services/aiDocs.cjs +187 -0
  197. package/src/services/aiImage.cjs +183 -0
  198. package/src/services/aiMedia.cjs +146 -0
  199. package/src/services/aiProviders.cjs +76 -80
  200. package/src/services/aiRouter.cjs +2 -2
  201. package/src/services/aiToolAuth.cjs +76 -4
  202. package/src/services/aiTools.cjs +431 -105
  203. package/src/services/autoDelete.cjs +9 -1
  204. package/src/services/levix-docs.generated.json +2623 -0
  205. package/src/services/memoryPolicy.cjs +56 -0
  206. package/src/services/updateCheck.cjs +362 -0
  207. package/src/stickers/errors.cjs +53 -97
  208. package/src/stickers/library.cjs +13 -6
  209. package/src/stickers/owner.cjs +1 -1
  210. package/src/utils/commandContext.cjs +13 -0
  211. package/src/utils/commandDocs.cjs +42 -20
  212. package/src/utils/geminiHttpOptions.cjs +56 -0
  213. package/src/utils/geminiMedia.cjs +28 -3
  214. package/src/utils/groupMetadataCache.cjs +386 -21
  215. package/src/utils/httpsFetch.cjs +113 -0
  216. package/src/utils/i18n.cjs +117 -7
  217. package/src/utils/linkPreview.cjs +90 -0
  218. package/src/utils/logger.cjs +6 -0
  219. package/src/utils/markdownParser.cjs +3 -3
  220. package/src/utils/memory.cjs +375 -28
  221. package/src/utils/messageContent.cjs +7 -1
  222. package/src/utils/moderationAction.cjs +116 -73
  223. package/src/utils/moderationSummary.cjs +32 -56
  224. package/src/utils/permissionLevel.cjs +7 -28
  225. package/src/utils/permissions.cjs +23 -14
  226. package/src/utils/permissions.esm.js +99 -166
  227. package/src/utils/recentMessageCache.esm.js +241 -37
  228. package/src/utils/recurrence.cjs +78 -66
  229. package/src/utils/sendBotMessage.cjs +14 -29
  230. package/src/utils/sendBotMessage.esm.js +28 -13
  231. package/src/utils/statusMessage.cjs +94 -33
  232. package/src/utils/stickerBot.cjs +18 -16
  233. package/src/utils/storage.cjs +2 -0
  234. package/src/utils/storage.esm.js +2 -0
  235. package/src/utils/thumbnail.cjs +5 -21
  236. package/public/dashboard/assets/index-B1sOW2VX.js +0 -561
  237. package/public/dashboard/assets/index-CK8osB4o.css +0 -2
  238. package/public/dashboard.css +0 -3127
  239. package/public/dashboard.js +0 -1981
  240. package/public/gateway-i18n.js +0 -321
  241. package/public/gateway.js +0 -70
  242. package/views/dashboard.ejs +0 -775
  243. package/views/login.ejs +0 -408
  244. package/views/qr.ejs +0 -155
  245. 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 { tr } = require("./i18n.cjs");
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 new Promise((resolve) => setTimeout(resolve, ms));
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, jid, presence }, "[sendBotMessage] presence failed");
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
- await sleep(typingDelayFor(content));
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 tr()
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 = tr("Something went wrong", "حدث خطأ"),
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 = tr(
147
- `❌ *${lead}*\n\n*Type:* \`${name}\`\n*Details:* ${message}`,
148
- `❌ *${lead}*\n\n*النوع:* \`${name}\`\n*التفاصيل:* ${message}`,
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 { tr } = require("./i18n.cjs");
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.sock,
46
- this.jid,
47
- { text },
48
- { replyTo: this.replyTo, quote: this.quote, typing: false, delayMs: 0 },
49
- );
50
- this.key = sent?.key || null;
51
- this.lastEditAt = Date.now();
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(text, { force = false } = {}) {
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 (initial send failed) — send one and adopt it.
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(this.jid, { text: next, edit: this.key }, { quoted: null });
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.sock,
89
- this.jid,
90
- { text },
91
- { replyTo: this.replyTo, quote: this.quote, typing: false, delayMs: 0 },
92
- );
93
- this.key = sent?.key || null;
94
- this.text = text;
95
- this.lastEditAt = Date.now();
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, { force: true });
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 tr().
173
+ * summary, already in the reply language — pass it through t().
113
174
  */
114
- async fail(err, lead = tr("Something went wrong", "حصلت مشكلة")) {
175
+ async fail(err, lead = t("bot.core.statusMessage.defaultLead")) {
115
176
  const name = err?.name || "Error";
116
- const message = err?.message || String(err || tr("unknown", "غير معروف"));
177
+ const message = err?.message || String(err || t("bot.core.statusMessage.unknownError"));
117
178
  return this.finish(
118
- tr(
119
- `❌ *${lead}*\n\n*Type:* \`${name}\`\n*Details:* ${message}`,
120
- `❌ *${lead}*\n\n*النوع:* \`${name}\`\n*التفاصيل:* ${message}`,
121
- ).slice(0, 1500),
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
 
@@ -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 { tr } = require("./i18n.cjs");
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 singular = kind === "pack" ? "pack" : "sticker";
56
- const english = `${n} ${singular}${n === 1 ? "" : "s"}`;
57
- if (kind === "pack") {
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 = {
@@ -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,
@@ -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;
@@ -29,15 +29,7 @@ const { spawn } = require("child_process");
29
29
 
30
30
  const logger = require("./logger.cjs");
31
31
 
32
- // Only used for remote sources; required lazily so a missing axios can never
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 axios = getAxios();
428
- if (!axios) return null;
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, url },
458
+ { err: err?.message },
475
459
  "[thumbnail] remote source could not be fetched for a preview",
476
460
  );
477
461
  return null;