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
@@ -12,11 +12,19 @@
12
12
  // Roles live in `user_metadata` (is_owner / is_admin) and in the in-memory
13
13
  // roster, so a grant is effective on the very next message — no restart.
14
14
 
15
- const { grantRole, revokeRole, listRoles, isOwnerJidSync } = require("../utils/permissions.cjs");
15
+ const {
16
+ grantRole,
17
+ revokeRole,
18
+ listRoles,
19
+ isOwnerJidSync,
20
+ getSenderCandidatesSync,
21
+ findGroupParticipantSync,
22
+ participantIdsSync,
23
+ } = require("../utils/permissions.cjs");
16
24
  const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
17
25
  const normalizeJid = require("../utils/normalizeJid.cjs");
18
26
  const logger = require("../utils/logger.cjs");
19
- const { tr } = require("../utils/i18n.cjs");
27
+ const { t } = require("../utils/i18n.cjs");
20
28
 
21
29
  const ROLE_WORDS = {
22
30
  owner: "owner",
@@ -76,13 +84,13 @@ function labelFor(user) {
76
84
  // is async — awaiting them is not optional.
77
85
  async function rolesReport() {
78
86
  const { owners, admins, bootstrapOwners, bootstrapAdmins } = await listRoles();
79
- const none = tr("• (none)", "• (لا شيء)");
80
- const lines = [tr("*🔑 Bot roles*", "*🔑 صلاحيات البوت*"), ""];
87
+ const none = t("bot.tools.perm.none");
88
+ const lines = [t("bot.tools.perm.heading"), ""];
81
89
 
82
- lines.push(tr(`*👑 Owners (${owners.length}):*`, `*👑 المالكين (${owners.length}):*`));
90
+ lines.push(t("bot.tools.perm.ownersHeader", { count: owners.length }));
83
91
  lines.push(owners.length ? owners.map((o) => `• ${labelFor(o)}`).join("\n") : none);
84
92
 
85
- lines.push("", tr(`*🛡️ Admins (${admins.length}):*`, `*🛡️ الأدمنز (${admins.length}):*`));
93
+ lines.push("", t("bot.tools.perm.adminsHeader", { count: admins.length }));
86
94
  lines.push(admins.length ? admins.map((a) => `• ${labelFor(a)}`).join("\n") : none);
87
95
 
88
96
  const envOnly = [
@@ -93,10 +101,7 @@ async function rolesReport() {
93
101
  const count = [...new Set(envOnly)].length;
94
102
  lines.push(
95
103
  "",
96
- tr(
97
- `_From settings (env/config): ${count} entries._`,
98
- `_من الإعدادات (env/config): ${count} إدخال._`,
99
- ),
104
+ t("bot.tools.perm.envOnly", { count }),
100
105
  );
101
106
  }
102
107
 
@@ -106,20 +111,16 @@ async function rolesReport() {
106
111
  module.exports = {
107
112
  name: "perm",
108
113
  aliases: ["perms", "owner", "admin", "role", "roles", "صلاحيات"],
109
- description: {
110
- en: "Manages bot roles: add or remove an owner or admin, and list the current ones.",
111
- ar: "يدير صلاحيات البوت: إضافة مالك أو أدمن أو إزالته، وعرض القائمة الحالية.",
112
- },
113
- usage: {
114
- en: "perm list\nperm add admin @member\nperm add owner <number>\nperm remove admin @member",
115
- ar: "perm list\nperm add admin @عضو\nperm add owner <رقم>\nperm remove admin @عضو",
116
- },
117
114
  chat: "all",
118
115
  // Accepted but not in the usage — syntax, not English (see utils/i18n.cjs).
119
116
  keywords: [...ADD_WORDS, ...DEL_WORDS, ...LIST_WORDS, ...Object.keys(ROLE_WORDS), "me"],
120
117
 
121
- async execute(sock, msg, args) {
118
+ async execute(sock, msg, args, body, groupMetadata, ctx) {
122
119
  const jid = msg.key.remoteJid;
120
+ const authMetadata =
121
+ ctx && Object.hasOwn(ctx, "authGroupMetadata")
122
+ ? ctx.authGroupMetadata
123
+ : groupMetadata;
123
124
  const action = String(args[0] || "").toLowerCase();
124
125
 
125
126
  if (!action || LIST_WORDS.has(action)) {
@@ -133,18 +134,7 @@ module.exports = {
133
134
  sock,
134
135
  jid,
135
136
  {
136
- text: tr(
137
- "Wrong usage.\n\n" +
138
- "`!perm list` — the current roles\n" +
139
- "`!perm add admin @member` — make an admin\n" +
140
- "`!perm add owner <number>` — make an owner\n" +
141
- "`!perm remove admin @member` — take the role away",
142
- "استخدام غير صحيح.\n\n" +
143
- "`!perm list` — القائمة الحالية\n" +
144
- "`!perm add admin @عضو` — تعيين أدمن\n" +
145
- "`!perm add owner <رقم>` — تعيين مالك\n" +
146
- "`!perm remove admin @عضو` — سحب الصلاحية",
147
- ),
137
+ text: t("bot.tools.perm.usage"),
148
138
  },
149
139
  { replyTo: msg },
150
140
  );
@@ -167,12 +157,7 @@ module.exports = {
167
157
  sock,
168
158
  jid,
169
159
  {
170
- text: tr(
171
- "Say who: mention them (@), reply to their message, or type their number.\n" +
172
- "Example: `!perm add admin @member`",
173
- "محتاج تحدد الشخص: منشن (@) أو رد على رسالته أو اكتب رقمه.\n" +
174
- "مثال: `!perm add admin @عضو`",
175
- ),
160
+ text: t("bot.tools.perm.missingTarget"),
176
161
  },
177
162
  { replyTo: msg },
178
163
  );
@@ -182,46 +167,58 @@ module.exports = {
182
167
  // already requires OWNER_ONLY by default — this is the belt to that
183
168
  // brace, and it also guards direct calls from elsewhere.)
184
169
  const sender = senderOf(msg);
185
- if (role === "owner" && !msg.key.fromMe && !isOwnerJidSync(sender)) {
170
+ const isOwner = msg.key.fromMe || getSenderCandidatesSync(msg, sock).some(
171
+ (id) => isOwnerJidSync(id, authMetadata),
172
+ );
173
+ if (role === "owner" && !isOwner) {
186
174
  return sendBotMessage(
187
175
  sock,
188
176
  jid,
189
- { text: tr("🚫 Only an owner can make a new owner.", "🚫 تعيين مالك جديد للمالك فقط.") },
177
+ { text: t("bot.tools.perm.ownerOnly") },
190
178
  { replyTo: msg },
191
179
  );
192
180
  }
193
181
 
194
182
  try {
195
- const record = isAdd ? await grantRole(target, role) : await revokeRole(target, role);
183
+ const aliases = isRemove
184
+ ? participantIdsSync(findGroupParticipantSync(authMetadata, target))
185
+ : [];
186
+ const record = isAdd
187
+ ? await grantRole(target, role)
188
+ : await revokeRole(target, role, aliases);
196
189
  const who = record ? labelFor(record) : target;
197
- const roleLabel = role === "owner" ? tr("owner 👑", "مالك 👑") : tr("admin 🛡️", "أدمن 🛡️");
190
+ const roleLabel =
191
+ role === "owner" ? t("bot.tools.perm.ownerLabel") : t("bot.tools.perm.adminLabel");
198
192
 
199
- logger.info({ target, role, granted: isAdd, by: sender }, "[perm] role change");
193
+ logger.info({ role, granted: isAdd }, "[perm] role change");
194
+ logger.debugOnly.info({ target, role, granted: isAdd, by: sender }, "[perm] role change");
200
195
 
201
196
  return sendBotMessage(
202
197
  sock,
203
198
  jid,
204
199
  {
205
200
  text: isAdd
206
- ? tr(`✅ *${who}* is now *${roleLabel}*.`, `✅ تم تعيين *${who}* كـ *${roleLabel}*.`)
207
- : tr(
208
- `✅ *${who}* is no longer *${roleLabel}*.`,
209
- `✅ تم سحب صلاحية *${roleLabel}* من *${who}*.`,
210
- ),
201
+ ? t("bot.tools.perm.granted", { who, role: roleLabel })
202
+ : t("bot.tools.perm.revoked", { who, role: roleLabel }),
211
203
  mentions: target.includes("@") ? [target] : undefined,
212
204
  },
213
205
  { replyTo: msg },
214
206
  );
215
207
  } catch (error) {
208
+ if (error?.code === "LINKED_ACCOUNT_OWNER") {
209
+ return sendBotMessage(
210
+ sock,
211
+ jid,
212
+ { text: t("bot.tools.perm.selfOwner") },
213
+ { replyTo: msg },
214
+ );
215
+ }
216
216
  logger.error({ err: error }, "[perm] role change failed");
217
217
  return sendBotMessage(
218
218
  sock,
219
219
  jid,
220
220
  {
221
- text: tr(
222
- `❌ *I couldn't change the role*\n\n*Details:* ${error.message}`,
223
- `❌ *تعذّر تعديل الصلاحية*\n\n*التفاصيل:* ${error.message}`,
224
- ),
221
+ text: t("bot.tools.perm.changeError", { details: error.message }),
225
222
  },
226
223
  { replyTo: msg },
227
224
  );
@@ -1,24 +1,16 @@
1
- const { tr } = require("../utils/i18n.cjs");
1
+ const { t } = require("../utils/i18n.cjs");
2
2
 
3
3
  // file: /commands/ping.js
4
4
 
5
5
  module.exports = {
6
6
  name: "ping",
7
- description: {
8
- en: "Checks that the bot is responding.",
9
- ar: "يتحقق من أن البوت يستجيب.",
10
- },
11
- usage: {
12
- en: "ping",
13
- ar: "ping",
14
- },
15
7
  chat: "all", // <-- الخاصية الجديدة. يمكن أن تكون 'group' أو 'private'
16
8
 
17
9
  async execute(sock, msg) {
18
10
  // The bot will reply with "Pong!" and quote the original message
19
11
  await sock.sendMessage(
20
12
  msg.key.remoteJid,
21
- { text: tr("Pong! 🏓", "بونج! 🏓") },
13
+ { text: t("bot.core.ping.pong") },
22
14
  { quoted: msg },
23
15
  );
24
16
  },
@@ -7,7 +7,7 @@
7
7
  // and WhatsApp counts the results.
8
8
 
9
9
  const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
10
- const { tr } = require("../utils/i18n.cjs");
10
+ const { t } = require("../utils/i18n.cjs");
11
11
 
12
12
  const MIN_OPTIONS = 2;
13
13
  const MAX_OPTIONS = 12; // WhatsApp's own ceiling
@@ -17,27 +17,7 @@ const MAX_OPTION_CHARS = 100;
17
17
  const MULTI_FLAGS = new Set(["--multi", "-m", "متعدد"]);
18
18
 
19
19
  const helpText = () =>
20
- tr(
21
- "📊 *Poll*\n\n" +
22
- "*Usage:*\n" +
23
- "`!poll <question> | <option> | <option> ...`\n\n" +
24
- "*Options:*\n" +
25
- "`--multi` allows more than one answer\n\n" +
26
- "*Example:*\n" +
27
- "`!poll Where to? | Cinema | Beach | Home`\n\n" +
28
- `_${MIN_OPTIONS} to ${MAX_OPTIONS} options._`,
29
- HELP_TEXT_AR,
30
- );
31
-
32
- const HELP_TEXT_AR =
33
- "📊 *استفتاء*\n\n" +
34
- "*الاستخدام:*\n" +
35
- "`!poll <السؤال> | <خيار> | <خيار> ...`\n\n" +
36
- "*خيارات:*\n" +
37
- "`--multi` يسمح باختيار أكتر من إجابة\n\n" +
38
- "*مثال:*\n" +
39
- "`!poll إلى أين نذهب؟ | السينما | البحر | البيت`\n\n" +
40
- `_من ${MIN_OPTIONS} لـ ${MAX_OPTIONS} خيارات._`;
20
+ t("bot.tools.poll.help", { min: MIN_OPTIONS, max: MAX_OPTIONS });
41
21
 
42
22
  /**
43
23
  * Validate question/options and build the exact `sendMessage` content for a
@@ -50,18 +30,13 @@ function buildPollContent(question, options, { multi = false } = {}) {
50
30
  const name = String(question || "").trim().slice(0, MAX_QUESTION_CHARS);
51
31
  const values = [...new Set((options || []).map((o) => String(o || "").trim().slice(0, MAX_OPTION_CHARS)).filter(Boolean))];
52
32
 
53
- if (!name) throw new Error(tr("A question is required.", "السؤال مطلوب."));
33
+ if (!name) throw new Error(t("bot.tools.poll.missingQuestion"));
54
34
  if (values.length < MIN_OPTIONS) {
55
- throw new Error(
56
- tr("At least two different options are needed.", "محتاج خيارين مختلفين على الأقل."),
57
- );
35
+ throw new Error(t("bot.tools.poll.needOptions"));
58
36
  }
59
37
  if (values.length > MAX_OPTIONS) {
60
38
  throw new Error(
61
- tr(
62
- `${MAX_OPTIONS} options at most (got ${values.length}).`,
63
- `الحد الأقصى ${MAX_OPTIONS} خيار (اتعطى ${values.length}).`,
64
- ),
39
+ t("bot.tools.poll.tooManyOptions", { count: MAX_OPTIONS, got: values.length }),
65
40
  );
66
41
  }
67
42
 
@@ -77,14 +52,6 @@ function buildPollContent(question, options, { multi = false } = {}) {
77
52
  module.exports = {
78
53
  name: "poll",
79
54
  aliases: ["vote", "استفتاء", "تصويت"],
80
- description: {
81
- en: "Creates a poll in the chat.",
82
- ar: "ينشئ استفتاءً (تصويتًا) داخل المحادثة.",
83
- },
84
- usage: {
85
- en: "poll <question> | <option 1> | <option 2> [| ...] [--multi]",
86
- ar: "poll <السؤال> | <خيار1> | <خيار2> [| ...] [--multi]",
87
- },
88
55
  chat: "all",
89
56
  keywords: [...MULTI_FLAGS],
90
57
 
@@ -9,18 +9,43 @@ function formatTime12Hour(time24) {
9
9
 
10
10
  const axios = require("axios");
11
11
  const logger = require("../utils/logger.cjs");
12
- const { tr } = require("../utils/i18n.cjs");
12
+ const settings = require("../config/settings.cjs");
13
+ const { t } = require("../utils/i18n.cjs");
14
+ const { createStatus } = require("../utils/statusMessage.cjs");
15
+
16
+ // The one HTTP GET the command performs. Exposed so tests can stub the network.
17
+ const http = {
18
+ get: (url, options) => axios.get(url, options),
19
+ };
20
+
21
+ // AlAdhan's path date is DD-MM-YYYY. Parts are taken in `timeZone` so the
22
+ // day is the local day, including just after midnight.
23
+ function prayerDate(now, timeZone) {
24
+ const parts = new Intl.DateTimeFormat("en-GB", {
25
+ timeZone,
26
+ day: "2-digit",
27
+ month: "2-digit",
28
+ year: "numeric",
29
+ }).formatToParts(now);
30
+ const value = (type) => parts.find((part) => part.type === type).value;
31
+ return `${value("day")}-${value("month")}-${value("year")}`;
32
+ }
33
+
34
+ function buildPrayerUrl(city, { now = new Date(), timeZone = settings.get("bot_timezone") } = {}) {
35
+ const url = new URL(`https://api.aladhan.com/v1/timingsByCity/${prayerDate(now, timeZone)}`);
36
+ url.searchParams.set("city", city);
37
+ url.searchParams.set("country", "EG");
38
+ url.searchParams.set("state", "Egypt");
39
+ url.searchParams.set("method", "5");
40
+ url.searchParams.set("shafaq", "general");
41
+ url.searchParams.set("tune", "5");
42
+ url.searchParams.set("timezonestring", timeZone);
43
+ url.searchParams.set("calendarMethod", "UAQ");
44
+ return url.toString();
45
+ }
13
46
 
14
47
  module.exports = {
15
48
  name: "prayer",
16
- description: {
17
- en: "Shows prayer times for a city.",
18
- ar: "يعرض مواقيت الصلاة لمدينة معيّنة.",
19
- },
20
- usage: {
21
- en: "prayer <city in English>",
22
- ar: "prayer <اسم المدينة بالإنجليزية>",
23
- },
24
49
  chat: "all", // This command can be used anywhere
25
50
  // The city is asked for in English whatever language you speak, so it says
26
51
  // nothing about which language to answer in (see utils/i18n.cjs).
@@ -30,51 +55,45 @@ module.exports = {
30
55
  // 2. Check if the user provided a city name
31
56
  if (!args || args.length === 0) {
32
57
  return await sock.sendMessage(msg.key.remoteJid, {
33
- text: tr(
34
- "Give the city's name in English.\n\n*Example:* `!prayer cairo`",
35
- "يرجى تقديم اسم المدينة باللغة الانجليزية.\n\nمثال:* `!prayer cairo`",
36
- ),
58
+ text: t("bot.tools.prayer.needCity"),
37
59
  });
38
60
  }
39
61
 
40
62
  // 3. Join the arguments to form the city name (in case it's multi-word like "New York")
41
63
  const city = args.join(" ");
42
64
 
43
- // 4. We will build the API URL here once you provide it
44
- const API_URL = `https://api.aladhan.com/v1/timingsByCity/06-06-2025?city=${city}&country=EG&state=Egypt&method=5&shafaq=general&tune=5&timezonestring=Africa%2FCairo&calendarMethod=UAQ`;
65
+ // 4. Today's date in the bot timezone, with the city encoded as a query value.
66
+ const API_URL = buildPrayerUrl(city);
45
67
 
68
+ const status = await createStatus(sock, msg.key.remoteJid, t("bot.tools.prayer.fetching"), {
69
+ replyTo: msg,
70
+ });
46
71
  try {
47
- await sock.sendMessage(msg.key.remoteJid, {
48
- text: tr("Fetching the times...", "يتم جلب البيانات..."),
49
- });
50
72
  // 5. We will make the API call using axios
51
- const response = await axios.get(API_URL);
73
+ const response = await http.get(API_URL);
52
74
  // 6. We will parse the prayer timings from the response data
53
75
  const timings = response.data.data.timings;
54
76
 
55
77
  // 7. We will format the reply message
56
78
  const reply =
57
- tr(`*Prayer times for ${city}:*\n\n`, `*مواقيت الصلاة لمدينة ${city}:*\n\n`) +
58
- `${tr("Fajr", "الفجر")}: ${formatTime12Hour(timings.Fajr)}\n` +
59
- `${tr("Sunrise", "الشروق")}: ${formatTime12Hour(timings.Sunrise)}\n` +
60
- `${tr("Dhuhr", "الظهر")}: ${formatTime12Hour(timings.Dhuhr)}\n` +
61
- `${tr("Asr", "العصر")}: ${formatTime12Hour(timings.Asr)}\n` +
62
- `${tr("Maghrib", "المغرب")}: ${formatTime12Hour(timings.Maghrib)}\n` +
63
- `${tr("Isha", "العشاء")}: ${formatTime12Hour(timings.Isha)}`;
79
+ t("bot.tools.prayer.header", { city }) +
80
+ `${t("bot.tools.prayer.fajr")}: ${formatTime12Hour(timings.Fajr)}\n` +
81
+ `${t("bot.tools.prayer.sunrise")}: ${formatTime12Hour(timings.Sunrise)}\n` +
82
+ `${t("bot.tools.prayer.dhuhr")}: ${formatTime12Hour(timings.Dhuhr)}\n` +
83
+ `${t("bot.tools.prayer.asr")}: ${formatTime12Hour(timings.Asr)}\n` +
84
+ `${t("bot.tools.prayer.maghrib")}: ${formatTime12Hour(timings.Maghrib)}\n` +
85
+ `${t("bot.tools.prayer.isha")}: ${formatTime12Hour(timings.Isha)}`;
64
86
 
65
- // 8. Send the formatted message
66
- await sock.sendMessage(msg.key.remoteJid, {
67
- text: reply,
68
- });
87
+ // 8. Rewrite the progress line into the times.
88
+ await status.finish(reply);
69
89
  } catch (error) {
70
90
  logger.error(error.message, "[Error] in Prayer API:");
71
91
  // 9. Handle errors, like city not found or API failure
72
- await sock.sendMessage(msg.key.remoteJid, {
73
- text: tr(
74
- `Sorry, I couldn't find prayer times for "${city}". Check the city's name and try again.`,
75
- `عذراً، لم أتمكن من العثور على وقت الصلاة في "${city}". يرجى التحقق من اسم المدينة ومحاولة مرة أخرى.`,
76
- ),
77
- });
92
+ await status.finish(t("bot.tools.prayer.cityNotFound", { city }));
78
93
  }
79
94
  },
95
+
96
+ // Pure helper and the HTTP seam, kept for tests.
97
+ http,
98
+ buildPrayerUrl,
80
99
  };
@@ -1,18 +1,10 @@
1
1
  // file: /commands/qr.js
2
2
  const qrcode = require("qrcode");
3
3
  const logger = require("../utils/logger.cjs");
4
- const { tr } = require("../utils/i18n.cjs");
4
+ const { t } = require("../utils/i18n.cjs");
5
5
 
6
6
  module.exports = {
7
7
  name: "qr",
8
- description: {
9
- en: "Generates a QR code from text.",
10
- ar: "ينشئ رمز QR من نص.",
11
- },
12
- usage: {
13
- en: "qr <text|link>",
14
- ar: "qr <نص|رابط>",
15
- },
16
8
  chat: "all",
17
9
  // What goes in the code is data, not the language you are talking in.
18
10
  neutralArgs: true,
@@ -23,10 +15,7 @@ module.exports = {
23
15
 
24
16
  if (!textToEncode) {
25
17
  return await sock.sendMessage(remoteJid, {
26
- text: tr(
27
- "Write the text or link to encode after the command.\n*Example:*\n`!qr https://google.com`",
28
- "يرجى كتابة النص أو الرابط الذي تريد تحويله بعد الأمر.\n*مثال:*\n`!qr https://google.com`",
29
- ),
18
+ text: t("bot.core.qr.usage"),
30
19
  });
31
20
  }
32
21
 
@@ -39,15 +28,12 @@ module.exports = {
39
28
  // Send the image buffer as a photo
40
29
  await sock.sendMessage(remoteJid, {
41
30
  image: qrImageBuffer,
42
- caption: tr(
43
- `*QR code for:*\n\`\`\`${textToEncode}\`\`\``,
44
- `*رمز QR لـ:*\n\`\`\`${textToEncode}\`\`\``,
45
- ),
31
+ caption: t("bot.core.qr.caption", { text: textToEncode }),
46
32
  });
47
33
  } catch (error) {
48
34
  logger.error({ err: error }, "Failed to generate QR code");
49
35
  await sock.sendMessage(remoteJid, {
50
- text: tr("Something went wrong while making the QR code.", "حدث خطأ أثناء إنشاء QR code."),
36
+ text: t("bot.core.qr.failed"),
51
37
  });
52
38
  }
53
39
  },
@@ -11,7 +11,7 @@
11
11
  // Used for settling arguments in the group. No dependencies, no state.
12
12
 
13
13
  const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
14
- const { tr } = require("../utils/i18n.cjs");
14
+ const { t } = require("../utils/i18n.cjs");
15
15
 
16
16
  const MAX_DICE = 20;
17
17
  const MAX_SIDES = 1000;
@@ -30,26 +30,7 @@ function toNumber(token) {
30
30
  return Number.isFinite(value) ? Math.trunc(value) : null;
31
31
  }
32
32
 
33
- const helpText = () =>
34
- tr(
35
- "🎲 *Random*\n\n" +
36
- "`!rand` a number from 1 to 100\n" +
37
- "`!rand <max>` a number from 1 to that number\n" +
38
- "`!rand <min> <max>` a number between the two\n" +
39
- "`!rand dice [count d sides]` dice — e.g. `!rand dice 2d6`\n" +
40
- "`!rand coin` heads or tails\n" +
41
- "`!rand pick option | option | option` picks one",
42
- HELP_TEXT_AR,
43
- );
44
-
45
- const HELP_TEXT_AR =
46
- "🎲 *عشوائي*\n\n" +
47
- "`!rand` رقم من 1 لـ 100\n" +
48
- "`!rand <أقصى>` رقم من 1 للرقم ده\n" +
49
- "`!rand <أدنى> <أقصى>` رقم بين الحدّين\n" +
50
- "`!rand dice [عدد d أوجه]` نرد — مثال `!rand dice 2d6`\n" +
51
- "`!rand coin` ملك ولا كتابة\n" +
52
- "`!rand pick خيار | خيار | خيار` يختار واحد";
33
+ const helpText = () => t("bot.tools.rand.help");
53
34
 
54
35
  function rollDice(spec) {
55
36
  const match = String(spec || "1d6")
@@ -60,12 +41,7 @@ function rollDice(spec) {
60
41
 
61
42
  if (!match || count < 1 || count > MAX_DICE || sides < 2 || sides > MAX_SIDES) {
62
43
  return {
63
- error: tr(
64
- `❌ Wrong dice format. Use \`<count>d<sides>\` — e.g. \`2d6\`.\n` +
65
- `(at most ${MAX_DICE} dice and ${MAX_SIDES} sides)`,
66
- `❌ صيغة النرد غلط. استخدم \`عددdأوجه\` — مثال \`2d6\`.\n` +
67
- `(حد أقصى ${MAX_DICE} نرد و ${MAX_SIDES} وجه)`,
68
- ),
44
+ error: t("bot.tools.rand.diceError", { maxDice: MAX_DICE, maxSides: MAX_SIDES }),
69
45
  };
70
46
  }
71
47
 
@@ -77,14 +53,6 @@ function rollDice(spec) {
77
53
  module.exports = {
78
54
  name: "rand",
79
55
  aliases: ["random", "roll", "عشوائي", "قرعة"],
80
- description: {
81
- en: "Random numbers, dice, a coin flip, or a pick from a list.",
82
- ar: "أرقام عشوائية، أو نرد، أو رمي عملة، أو اختيار من قائمة.",
83
- },
84
- usage: {
85
- en: "rand [<max> | <min> <max> | dice [2d6] | coin | pick a | b | c]",
86
- ar: "rand [<أقصى> | <أدنى> <أقصى> | dice [2d6] | coin | pick أ | ب | ج]",
87
- },
88
56
  chat: "all",
89
57
 
90
58
  async execute(sock, msg, args) {
@@ -97,7 +65,7 @@ module.exports = {
97
65
 
98
66
  if (["coin", "flip", "عملة", "معملة"].includes(mode)) {
99
67
  const heads = Math.random() < 0.5;
100
- return reply(`🪙 *${heads ? tr("Heads 👑", "ملك 👑") : tr("Tails ✍️", "كتابة ✍️")}*`);
68
+ return reply(`🪙 *${heads ? t("bot.tools.rand.heads") : t("bot.tools.rand.tails")}*`);
101
69
  }
102
70
 
103
71
  if (["dice", "die", "نرد", "زهر"].includes(mode)) {
@@ -116,28 +84,15 @@ module.exports = {
116
84
  .filter(Boolean);
117
85
 
118
86
  if (choices.length < 2) {
119
- return reply(
120
- tr(
121
- "❌ Give me at least two options separated by `|`.\nExample: `!rand pick tea | coffee`",
122
- "❌ اديني خيارين على الأقل مفصولين بـ `|`.\nمثال: `!rand pick شاي | قهوة`",
123
- ),
124
- );
87
+ return reply(t("bot.tools.rand.pickTooFew"));
125
88
  }
126
89
  if (choices.length > MAX_CHOICES) {
127
- return reply(
128
- tr(
129
- `❌ Too many options (the limit is ${MAX_CHOICES}).`,
130
- `❌ الخيارات كثيرة جدًا (الحد ${MAX_CHOICES}).`,
131
- ),
132
- );
90
+ return reply(t("bot.tools.rand.pickTooMany", { limit: MAX_CHOICES }));
133
91
  }
134
92
 
135
93
  const winner = choices[randomInt(0, choices.length - 1)];
136
94
  return reply(
137
- tr(
138
- `🎯 I picked: *${winner}*\n_(out of ${choices.length} options)_`,
139
- `🎯 اخترت: *${winner}*\n_(من ${choices.length} خيارات)_`,
140
- ),
95
+ t("bot.tools.rand.picked", { winner, count: choices.length }),
141
96
  );
142
97
  }
143
98
 
@@ -159,11 +114,7 @@ module.exports = {
159
114
 
160
115
  if (min === max) return reply(`🎲 *${min}*`);
161
116
 
162
- return reply(
163
- tr(
164
- `🎲 *${randomInt(min, max)}*\n_(between ${min} and ${max})_`,
165
- `🎲 *${randomInt(min, max)}*\n_(بين ${min} و ${max})_`,
166
- ),
167
- );
117
+ const value = randomInt(min, max);
118
+ return reply(t("bot.tools.rand.rolled", { value, min, max }));
168
119
  },
169
120
  };
@@ -8,18 +8,11 @@
8
8
  // the panel out.
9
9
  const { getSession } = require("../core/session-holder.cjs");
10
10
  const logger = require("../utils/logger.cjs");
11
- const { tr } = require("../utils/i18n.cjs");
11
+ const { t } = require("../utils/i18n.cjs");
12
+ const { createStatus } = require("../utils/statusMessage.cjs");
12
13
 
13
14
  module.exports = {
14
15
  name: "restart",
15
- description: {
16
- en: "Reconnects WhatsApp (the process and panel stay up).",
17
- ar: "يعيد تشغيل اتصال واتساب (مع استمرار تشغيل البوت ولوحة التحكم).",
18
- },
19
- usage: {
20
- en: "restart",
21
- ar: "restart",
22
- },
23
16
  chat: "all",
24
17
 
25
18
  async execute(sock, msg) {
@@ -27,16 +20,15 @@ module.exports = {
27
20
  const session = getSession();
28
21
  if (!session) {
29
22
  return await sock.sendMessage(chatId, {
30
- text: tr("The session manager isn't ready yet.", "مدير الجلسة غير جاهز بعد."),
23
+ text: t("bot.core.restart.notReady"),
31
24
  });
32
25
  }
33
26
 
34
- // Goes out while the current socket is still alive.
35
- await sock.sendMessage(chatId, {
36
- text: tr(
37
- "🔄 Reconnecting WhatsApp... back in a moment.",
38
- "🔄 جارٍ إعادة تشغيل اتصال واتساب... سأعود خلال لحظات.",
39
- ),
27
+ // Goes out while the current socket is still alive. This line is the
28
+ // result of asking for a restart, so hiding progress cannot swallow it.
29
+ const status = await createStatus(sock, chatId, t("bot.core.restart.reconnecting"), {
30
+ replyTo: msg,
31
+ category: "system",
40
32
  });
41
33
 
42
34
  let state = null;
@@ -47,22 +39,12 @@ module.exports = {
47
39
  logger.error({ err: error, command: "restart" }, "Failed to reconnect WhatsApp");
48
40
  }
49
41
 
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 || "غير معروفة"}. راجع صفحة الاتصال في لوحة التحكم.`,
63
- ),
64
- })
65
- .catch(() => {});
66
- }
42
+ const done = state?.connected
43
+ ? t("bot.core.restart.backOnline")
44
+ : t("bot.core.restart.stateNow", {
45
+ status: state?.status || t("bot.core.restart.unknownState"),
46
+ });
47
+ // The socket may already be gone. The edit is best-effort.
48
+ await status.finish(done).catch(() => {});
67
49
  },
68
50
  };