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
package/src/commands/perm.cjs
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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 =
|
|
80
|
-
const lines = [
|
|
87
|
+
const none = t("bot.tools.perm.none");
|
|
88
|
+
const lines = [t("bot.tools.perm.heading"), ""];
|
|
81
89
|
|
|
82
|
-
lines.push(
|
|
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("",
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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:
|
|
177
|
+
{ text: t("bot.tools.perm.ownerOnly") },
|
|
190
178
|
{ replyTo: msg },
|
|
191
179
|
);
|
|
192
180
|
}
|
|
193
181
|
|
|
194
182
|
try {
|
|
195
|
-
const
|
|
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 =
|
|
190
|
+
const roleLabel =
|
|
191
|
+
role === "owner" ? t("bot.tools.perm.ownerLabel") : t("bot.tools.perm.adminLabel");
|
|
198
192
|
|
|
199
|
-
logger.info({
|
|
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
|
-
?
|
|
207
|
-
:
|
|
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:
|
|
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
|
);
|
package/src/commands/ping.cjs
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
const {
|
|
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:
|
|
13
|
+
{ text: t("bot.core.ping.pong") },
|
|
22
14
|
{ quoted: msg },
|
|
23
15
|
);
|
|
24
16
|
},
|
package/src/commands/poll.cjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// and WhatsApp counts the results.
|
|
8
8
|
|
|
9
9
|
const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
|
|
10
|
-
const {
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
package/src/commands/prayer.cjs
CHANGED
|
@@ -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
|
|
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:
|
|
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.
|
|
44
|
-
const API_URL =
|
|
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
|
|
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
|
-
|
|
58
|
-
`${
|
|
59
|
-
`${
|
|
60
|
-
`${
|
|
61
|
-
`${
|
|
62
|
-
`${
|
|
63
|
-
`${
|
|
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.
|
|
66
|
-
await
|
|
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
|
|
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
|
};
|
package/src/commands/qr.cjs
CHANGED
|
@@ -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 {
|
|
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:
|
|
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:
|
|
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:
|
|
36
|
+
text: t("bot.core.qr.failed"),
|
|
51
37
|
});
|
|
52
38
|
}
|
|
53
39
|
},
|
package/src/commands/rand.cjs
CHANGED
|
@@ -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 {
|
|
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:
|
|
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 ?
|
|
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
|
-
|
|
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
|
-
|
|
163
|
-
|
|
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
|
};
|
package/src/commands/restart.cjs
CHANGED
|
@@ -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 {
|
|
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:
|
|
23
|
+
text: t("bot.core.restart.notReady"),
|
|
31
24
|
});
|
|
32
25
|
}
|
|
33
26
|
|
|
34
|
-
// Goes out while the current socket is still alive.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
};
|