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
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
// file: /commands/welcome.js
|
|
2
2
|
const { getGroupSettings, saveGroupSettings } = require("../../utils/storage.cjs");
|
|
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: "welcome",
|
|
8
|
-
description: {
|
|
9
|
-
en: "Manages the group's welcome messages.",
|
|
10
|
-
ar: "يدير رسائل الترحيب في المجموعة.",
|
|
11
|
-
},
|
|
12
|
-
usage: {
|
|
13
|
-
en: "welcome [status]\nwelcome <on|off>\nwelcome add <welcome text>\nwelcome list\nwelcome delete <number>",
|
|
14
|
-
ar: "welcome [status]\nwelcome <on|off>\nwelcome add <نص الترحيب>\nwelcome list\nwelcome delete <رقم>",
|
|
15
|
-
},
|
|
16
8
|
chat: "group",
|
|
17
9
|
userAdminRequired: true,
|
|
18
10
|
|
|
@@ -33,14 +25,14 @@ module.exports = {
|
|
|
33
25
|
case "on":
|
|
34
26
|
welcomeConfig.enabled = true;
|
|
35
27
|
await sock.sendMessage(groupId, {
|
|
36
|
-
text:
|
|
28
|
+
text: t("bot.group.welcome.enabled"),
|
|
37
29
|
});
|
|
38
30
|
break;
|
|
39
31
|
|
|
40
32
|
case "off":
|
|
41
33
|
welcomeConfig.enabled = false;
|
|
42
34
|
await sock.sendMessage(groupId, {
|
|
43
|
-
text:
|
|
35
|
+
text: t("bot.group.welcome.disabled"),
|
|
44
36
|
});
|
|
45
37
|
break;
|
|
46
38
|
|
|
@@ -48,15 +40,12 @@ module.exports = {
|
|
|
48
40
|
const messageToAdd = args.slice(1).join(" ");
|
|
49
41
|
if (!messageToAdd || !messageToAdd.includes("${user}")) {
|
|
50
42
|
return await sock.sendMessage(groupId, {
|
|
51
|
-
text:
|
|
52
|
-
"Write a welcome message containing ${user} to mention the new member.",
|
|
53
|
-
"يرجى كتابة رسالة ترحيب تحتوي على المتغير ${user} لعمل منشن للعضو الجديد.",
|
|
54
|
-
),
|
|
43
|
+
text: t("bot.group.welcome.addUsage"),
|
|
55
44
|
});
|
|
56
45
|
}
|
|
57
46
|
welcomeConfig.messages.push(messageToAdd);
|
|
58
47
|
await sock.sendMessage(groupId, {
|
|
59
|
-
text:
|
|
48
|
+
text: t("bot.group.welcome.added"),
|
|
60
49
|
});
|
|
61
50
|
break;
|
|
62
51
|
}
|
|
@@ -64,10 +53,10 @@ module.exports = {
|
|
|
64
53
|
case "list": {
|
|
65
54
|
if (welcomeConfig.messages.length === 0) {
|
|
66
55
|
return await sock.sendMessage(groupId, {
|
|
67
|
-
text:
|
|
56
|
+
text: t("bot.group.welcome.listEmpty"),
|
|
68
57
|
});
|
|
69
58
|
}
|
|
70
|
-
let listReply =
|
|
59
|
+
let listReply = t("bot.group.welcome.listHeader");
|
|
71
60
|
welcomeConfig.messages.forEach((message, index) => {
|
|
72
61
|
listReply += `#${index + 1}: ${message}\n`;
|
|
73
62
|
});
|
|
@@ -83,31 +72,25 @@ module.exports = {
|
|
|
83
72
|
indexToDelete >= welcomeConfig.messages.length
|
|
84
73
|
) {
|
|
85
74
|
return await sock.sendMessage(groupId, {
|
|
86
|
-
text:
|
|
87
|
-
"Invalid message number. Use `!welcome list` to see the numbers.",
|
|
88
|
-
"رقم الرسالة غير صالح. استخدم `!welcome list` لمعرفة الأرقام.",
|
|
89
|
-
),
|
|
75
|
+
text: t("bot.group.welcome.deleteInvalid"),
|
|
90
76
|
});
|
|
91
77
|
}
|
|
92
78
|
const deletedMessage = welcomeConfig.messages.splice(indexToDelete, 1);
|
|
93
79
|
await sock.sendMessage(groupId, {
|
|
94
|
-
text:
|
|
95
|
-
`☑️ Deleted the message:\n*${deletedMessage[0]}*`,
|
|
96
|
-
`☑️ تم حذف الرسالة بنجاح:\n*${deletedMessage[0]}*`,
|
|
97
|
-
),
|
|
80
|
+
text: t("bot.group.welcome.deleted", { message: deletedMessage[0] }),
|
|
98
81
|
});
|
|
99
82
|
break;
|
|
100
83
|
}
|
|
101
84
|
|
|
102
85
|
case "status":
|
|
103
86
|
default: {
|
|
104
|
-
const state = welcomeConfig.enabled
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
87
|
+
const state = welcomeConfig.enabled
|
|
88
|
+
? t("bot.group.welcome.stateOn")
|
|
89
|
+
: t("bot.group.welcome.stateOff");
|
|
90
|
+
const statusReply = t("bot.group.welcome.status", {
|
|
91
|
+
state,
|
|
92
|
+
count: welcomeConfig.messages.length,
|
|
93
|
+
});
|
|
111
94
|
await sock.sendMessage(groupId, { text: statusReply });
|
|
112
95
|
break;
|
|
113
96
|
}
|
|
@@ -117,7 +100,7 @@ module.exports = {
|
|
|
117
100
|
saveGroupSettings(groupId, settings);
|
|
118
101
|
} catch (error) {
|
|
119
102
|
logger.error({ err: error, command: "welcome" }, "Error in !welcome command");
|
|
120
|
-
await sock.sendMessage(groupId, { text:
|
|
103
|
+
await sock.sendMessage(groupId, { text: t("bot.group.welcome.failed") });
|
|
121
104
|
}
|
|
122
105
|
},
|
|
123
106
|
};
|
package/src/commands/group.cjs
CHANGED
|
@@ -13,10 +13,15 @@ const {
|
|
|
13
13
|
isOwnerJidSync,
|
|
14
14
|
isAdminInGroupSync,
|
|
15
15
|
isBotAdminInGroupSync,
|
|
16
|
+
isBotAdminUserSync,
|
|
16
17
|
getSenderCandidatesSync,
|
|
17
18
|
} = require("../utils/permissions.cjs");
|
|
19
|
+
const { evaluatePermissionLevel } = require("../utils/permissionLevel.cjs");
|
|
20
|
+
const { resolveGroupMetadata } = require("../utils/groupMetadataCache.cjs");
|
|
21
|
+
const { accountEpoch } = require("../utils/storage.cjs");
|
|
18
22
|
const normalizeJid = require("../utils/normalizeJid.cjs");
|
|
19
|
-
const { langForCommand, withLang,
|
|
23
|
+
const { langForCommand, withLang, t } = require("../utils/i18n.cjs");
|
|
24
|
+
const { attachCommandDocs } = require("../utils/commandDocs.cjs");
|
|
20
25
|
|
|
21
26
|
// --- Sub-command Loader ---
|
|
22
27
|
//
|
|
@@ -28,6 +33,7 @@ const subCommands = new Map();
|
|
|
28
33
|
function register(command, label) {
|
|
29
34
|
try {
|
|
30
35
|
if (!command?.name) return;
|
|
36
|
+
attachCommandDocs(command, "group");
|
|
31
37
|
subCommands.set(command.name, command);
|
|
32
38
|
if (Array.isArray(command.aliases)) {
|
|
33
39
|
command.aliases.forEach((alias) => {
|
|
@@ -63,34 +69,70 @@ if (manifest) {
|
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Who is asking, in the shape `evaluatePermissionLevel` already understands.
|
|
74
|
+
* Bot-admin is honored inside a group (the direct command does the same) and
|
|
75
|
+
* ignored in a private chat so a private `!group` does not widen.
|
|
76
|
+
*/
|
|
77
|
+
function senderFor(msg, sock, groupMetadata) {
|
|
78
|
+
const remote = msg?.key?.remoteJid || "";
|
|
79
|
+
const isGroup = remote.endsWith("@g.us");
|
|
80
|
+
const senderId = normalizeJid(msg?.key?.participant || remote);
|
|
81
|
+
const senderIds = getSenderCandidatesSync(msg, sock);
|
|
82
|
+
const senderCandidates = senderIds.length ? senderIds : [senderId].filter(Boolean);
|
|
83
|
+
const isOwner =
|
|
84
|
+
Boolean(msg?.key?.fromMe) || senderCandidates.some((id) => isOwnerJidSync(id, groupMetadata));
|
|
85
|
+
const groupAdmin =
|
|
86
|
+
isGroup && senderCandidates.some((id) => isAdminInGroupSync(groupMetadata, id));
|
|
87
|
+
const isBotAdmin =
|
|
88
|
+
isGroup && !isOwner && senderCandidates.some((id) => isBotAdminUserSync(id, groupMetadata));
|
|
89
|
+
return {
|
|
90
|
+
isGroup,
|
|
91
|
+
isOwner,
|
|
92
|
+
isBotAdmin,
|
|
93
|
+
isSenderAdmin: Boolean(isBotAdmin || groupAdmin),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// The dispatcher passes the fresh roster it already read. A direct call reads
|
|
98
|
+
// with `{ fresh: true }` so a stale admin flag cannot grant the sub-command.
|
|
99
|
+
async function authMetadataFor(sock, msg, ctx) {
|
|
100
|
+
if (ctx && Object.prototype.hasOwnProperty.call(ctx, "authGroupMetadata")) {
|
|
101
|
+
return ctx.authGroupMetadata;
|
|
102
|
+
}
|
|
103
|
+
const jid = msg?.key?.remoteJid;
|
|
104
|
+
if (!jid || !String(jid).endsWith("@g.us")) return null;
|
|
105
|
+
return resolveGroupMetadata(sock, jid, { fresh: true });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The level check for one group sub-command. Exported for the permission matrix. */
|
|
109
|
+
function subCommandAccess(subCommandName, sender) {
|
|
110
|
+
const level = runtimeConfig.getPermission(`group:${subCommandName}`);
|
|
111
|
+
return { ...evaluatePermissionLevel(level, sender), level };
|
|
112
|
+
}
|
|
113
|
+
|
|
66
114
|
module.exports = {
|
|
67
115
|
name: "group",
|
|
68
|
-
description: {
|
|
69
|
-
en: "Main command for all group management actions.",
|
|
70
|
-
ar: "الأمر الرئيسي لكل إجراءات إدارة المجموعة.",
|
|
71
|
-
},
|
|
72
|
-
usage: {
|
|
73
|
-
en: "group <sub-command> [arguments]",
|
|
74
|
-
ar: "group <أمر فرعي> [المعاملات]",
|
|
75
|
-
},
|
|
76
116
|
chat: "group",
|
|
117
|
+
subCommandAccess,
|
|
118
|
+
senderFor,
|
|
77
119
|
|
|
78
|
-
async execute(sock, msg, args, body, groupMetadata) {
|
|
120
|
+
async execute(sock, msg, args, body, groupMetadata, ctx) {
|
|
79
121
|
const subCommandName = args.shift()?.toLowerCase();
|
|
80
122
|
|
|
81
123
|
if (!subCommandName) {
|
|
82
124
|
return await sock.sendMessage(msg.key.remoteJid, {
|
|
83
|
-
text:
|
|
125
|
+
text: t("bot.group.group.missingSubCommand"),
|
|
84
126
|
});
|
|
85
127
|
}
|
|
86
128
|
|
|
87
129
|
const subCommand = subCommands.get(subCommandName);
|
|
88
130
|
if (!subCommand) {
|
|
89
131
|
return await sock.sendMessage(msg.key.remoteJid, {
|
|
90
|
-
text:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
),
|
|
132
|
+
text: t("bot.group.group.unknownSubCommand", {
|
|
133
|
+
name: subCommandName,
|
|
134
|
+
prefix: runtimeConfig.getPrefix(),
|
|
135
|
+
}),
|
|
94
136
|
});
|
|
95
137
|
}
|
|
96
138
|
|
|
@@ -98,89 +140,70 @@ module.exports = {
|
|
|
98
140
|
// `kick` looks like an English word. Judge it again against the
|
|
99
141
|
// sub-command's, the way a direct `!kick` is judged.
|
|
100
142
|
const lang = langForCommand(subCommand, args);
|
|
101
|
-
return withLang(lang, () =>
|
|
143
|
+
return withLang(lang, () =>
|
|
144
|
+
runSubCommand(sock, msg, args, body, groupMetadata, subCommand, ctx),
|
|
145
|
+
);
|
|
102
146
|
},
|
|
103
147
|
};
|
|
104
148
|
|
|
105
|
-
async function runSubCommand(sock, msg, args, body, groupMetadata, subCommand) {
|
|
149
|
+
async function runSubCommand(sock, msg, args, body, groupMetadata, subCommand, ctx) {
|
|
106
150
|
const subCommandName = subCommand.name;
|
|
151
|
+
const authMetadata = await authMetadataFor(sock, msg, ctx);
|
|
107
152
|
|
|
108
153
|
// Switched off from the dashboard: `!group kick` has to refuse it too, not
|
|
109
154
|
// just the direct `!kick`.
|
|
110
155
|
if (runtimeConfig.isDisabled(subCommand.name)) {
|
|
111
156
|
return await sock.sendMessage(msg.key.remoteJid, {
|
|
112
|
-
text:
|
|
157
|
+
text: t("bot.group.group.disabled"),
|
|
113
158
|
});
|
|
114
159
|
}
|
|
115
160
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// level changed from the dashboard applies here too.
|
|
126
|
-
const permissionLevel = runtimeConfig.getPermission(`group:${subCommand.name}`);
|
|
127
|
-
|
|
128
|
-
let hasPermission = false;
|
|
129
|
-
switch (permissionLevel) {
|
|
130
|
-
case "MEMBERS":
|
|
131
|
-
case "ALL":
|
|
132
|
-
hasPermission = true;
|
|
133
|
-
break;
|
|
134
|
-
case "OWNER_ONLY":
|
|
135
|
-
hasPermission = isOwner;
|
|
136
|
-
break;
|
|
137
|
-
case "ADMINS_ONLY":
|
|
138
|
-
hasPermission = isSenderAdmin || isOwner;
|
|
139
|
-
break;
|
|
140
|
-
case "ADMINS_OWNER":
|
|
141
|
-
hasPermission = isOwner || isSenderAdmin;
|
|
142
|
-
break;
|
|
143
|
-
default:
|
|
144
|
-
logger.warn(
|
|
145
|
-
`[group] Unknown permission level "${permissionLevel}" for sub-command "${subCommand.name}"`,
|
|
146
|
-
);
|
|
161
|
+
const sender = senderFor(msg, sock, authMetadata);
|
|
162
|
+
// The same level check the direct `!kick` path uses. A bot admin in the
|
|
163
|
+
// group is included. A bot admin in a private chat is not, so this door
|
|
164
|
+
// does not open a private chat the direct command already refuses.
|
|
165
|
+
const permission = subCommandAccess(subCommand.name, sender);
|
|
166
|
+
if (permission.unknownLevel) {
|
|
167
|
+
logger.warn(
|
|
168
|
+
`[group] Unknown permission level "${permission.level}" for sub-command "${subCommand.name}"`,
|
|
169
|
+
);
|
|
147
170
|
}
|
|
148
171
|
|
|
149
|
-
if (!hasPermission) {
|
|
172
|
+
if (!permission.hasPermission) {
|
|
150
173
|
return await sock.sendMessage(msg.key.remoteJid, {
|
|
151
|
-
text:
|
|
152
|
-
"🚫 You don't have permission to use this command.",
|
|
153
|
-
"🚫 ليس لديك الصلاحية لاستخدام هذا الأمر.",
|
|
154
|
-
),
|
|
174
|
+
text: permission.reason || t("bot.group.group.noPermission"),
|
|
155
175
|
});
|
|
156
176
|
}
|
|
157
177
|
|
|
158
|
-
const isBotAdmin = isBotAdminInGroupSync(
|
|
159
|
-
if (subCommand.userAdminRequired && !isSenderAdmin && !isOwner) {
|
|
178
|
+
const isBotAdmin = isBotAdminInGroupSync(authMetadata, sock);
|
|
179
|
+
if (subCommand.userAdminRequired && !sender.isSenderAdmin && !sender.isOwner) {
|
|
160
180
|
return await sock.sendMessage(msg.key.remoteJid, {
|
|
161
|
-
text:
|
|
162
|
-
"⚠️ You need to be a group admin to use this command.",
|
|
163
|
-
"⚠️ هذا الأمر يتطلب أن تكون مشرفًا.",
|
|
164
|
-
),
|
|
181
|
+
text: t("bot.group.group.userAdminRequired"),
|
|
165
182
|
});
|
|
166
183
|
}
|
|
167
184
|
if (subCommand.botAdminRequired && !isBotAdmin) {
|
|
168
185
|
return await sock.sendMessage(msg.key.remoteJid, {
|
|
169
|
-
text:
|
|
186
|
+
text: t("bot.group.group.botAdminRequired"),
|
|
170
187
|
});
|
|
171
188
|
}
|
|
172
189
|
|
|
173
190
|
try {
|
|
174
|
-
|
|
191
|
+
const entryEpoch = ctx?.accountEpoch;
|
|
192
|
+
if (Number.isInteger(entryEpoch) && entryEpoch !== accountEpoch()) {
|
|
193
|
+
logger.debug("[group] skipped account work after account change");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
await subCommand.execute(sock, msg, args, body, groupMetadata, {
|
|
197
|
+
nested: true,
|
|
198
|
+
accountEpoch: ctx?.accountEpoch,
|
|
199
|
+
});
|
|
175
200
|
} catch (error) {
|
|
176
201
|
logger.error({ err: error, subCommand: subCommandName }, "Error executing a group sub-command");
|
|
177
202
|
await sock.sendMessage(msg.key.remoteJid, {
|
|
178
|
-
text:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}`,
|
|
183
|
-
),
|
|
203
|
+
text: t("bot.group.group.failed", {
|
|
204
|
+
errorName: error.name || "Error",
|
|
205
|
+
errorMessage: error.message || t("bot.group.group.unknownError"),
|
|
206
|
+
}),
|
|
184
207
|
});
|
|
185
208
|
}
|
|
186
209
|
}
|
package/src/commands/help.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// !help
|
|
1
|
+
// !help lists commands or shows one command in the selected locale.
|
|
2
2
|
//
|
|
3
3
|
// help the list, in the bot's language
|
|
4
|
-
// help ar |
|
|
4
|
+
// help ar | en | pt | es the list, in that language
|
|
5
5
|
// help <command> one command, in the bot's language
|
|
6
6
|
// help <command> ar one command, in that language (`help ar <command>` too)
|
|
7
7
|
//
|
|
8
8
|
// "The bot's language" is the language every reply uses (utils/i18n.cjs): the
|
|
9
9
|
// `bot_language` setting, and in "auto" the language the message is written
|
|
10
10
|
// in — with command names counted as syntax, so `!help kick` is not English.
|
|
11
|
-
//
|
|
11
|
+
// Command documentation comes from the catalog.
|
|
12
12
|
|
|
13
13
|
const fs = require("fs");
|
|
14
14
|
const path = require("path");
|
|
@@ -16,8 +16,8 @@ const logger = require("../utils/logger.cjs");
|
|
|
16
16
|
const brand = require("../config/brand.cjs");
|
|
17
17
|
const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
|
|
18
18
|
const runtimeConfig = require("../config/runtime-config.cjs");
|
|
19
|
-
const { parseLang, localize } = require("../utils/commandDocs.cjs");
|
|
20
|
-
const { detectLang, syntaxWords } = require("../utils/i18n.cjs");
|
|
19
|
+
const { parseLang, localize, attachCommandDocs } = require("../utils/commandDocs.cjs");
|
|
20
|
+
const { detectLang, syntaxWords, t, withLang } = require("../utils/i18n.cjs");
|
|
21
21
|
|
|
22
22
|
// Every command module, the way the loader finds them: from the generated
|
|
23
23
|
// manifest in a packaged build (there is no directory to read inside an
|
|
@@ -62,9 +62,12 @@ function loadAllCommands() {
|
|
|
62
62
|
|
|
63
63
|
const commands = { general: [], group: [] };
|
|
64
64
|
for (const { module: command, category } of commandModules()) {
|
|
65
|
-
if (!command?.name ||
|
|
65
|
+
if (!command?.name || command === module.exports) continue;
|
|
66
|
+
attachCommandDocs(command, category);
|
|
67
|
+
if (!command.description) continue;
|
|
66
68
|
(category === "group" ? commands.group : commands.general).push(command);
|
|
67
69
|
}
|
|
70
|
+
attachCommandDocs(module.exports);
|
|
68
71
|
commands.general.push(module.exports);
|
|
69
72
|
|
|
70
73
|
// Build alias index for inverse lookup.
|
|
@@ -131,76 +134,40 @@ function examplesOf(command, lang) {
|
|
|
131
134
|
return Array.isArray(picked) ? picked : [];
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
title:
|
|
138
|
-
general: "
|
|
139
|
-
group: "
|
|
140
|
-
legendTitle: "
|
|
141
|
-
legend: "
|
|
142
|
-
languageTitle: "
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
permissions:
|
|
158
|
-
MEMBERS
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
ar: {
|
|
171
|
-
title: `🤖 أوامر ${brand.name}`,
|
|
172
|
-
general: "الأوامر العامة",
|
|
173
|
-
group: "أوامر المجموعات",
|
|
174
|
-
legendTitle: "الرموز",
|
|
175
|
-
legend: "`<...>` مطلوب · `[...]` اختياري · `a|b` اختر واحدًا",
|
|
176
|
-
languageTitle: "اللغة",
|
|
177
|
-
footer: (p) => `اكتب *${p}help <أمر>* لمزيد من التفاصيل`,
|
|
178
|
-
detailTitle: "تفاصيل الأمر",
|
|
179
|
-
command: "الأمر:",
|
|
180
|
-
aliases: "الاختصارات:",
|
|
181
|
-
description: "الوصف:",
|
|
182
|
-
usage: "الاستخدام:",
|
|
183
|
-
examples: "أمثلة:",
|
|
184
|
-
where: "المكان:",
|
|
185
|
-
permission: "الصلاحية:",
|
|
186
|
-
userAdmin: "⚠️ يجب أن تكون مشرفًا",
|
|
187
|
-
botAdmin: "⚠️ يجب أن يكون البوت مشرفًا",
|
|
188
|
-
detailLegend: "`<...>` مطلوب · `[...]` اختياري",
|
|
189
|
-
notFound: (query, p) => `❌ الأمر "*${query}*" غير موجود.\nاكتب \`${p}help\` لعرض كل الأوامر.`,
|
|
190
|
-
permissions: {
|
|
191
|
-
MEMBERS: "الجميع",
|
|
192
|
-
ALL: "الجميع",
|
|
193
|
-
ADMINS_ONLY: "المشرفون فقط",
|
|
194
|
-
ADMINS_OWNER: "المشرفون والمالك",
|
|
195
|
-
OWNER_ONLY: "المالك فقط",
|
|
196
|
-
},
|
|
197
|
-
chats: {
|
|
198
|
-
all: "كل المحادثات",
|
|
199
|
-
group: "المجموعات فقط",
|
|
200
|
-
private: "المحادثات الخاصة فقط",
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
};
|
|
137
|
+
function helpText(lang) {
|
|
138
|
+
const get = (key, params) => withLang(lang, () => t(`bot.help.${key}`, params));
|
|
139
|
+
return {
|
|
140
|
+
title: get("title", { name: brand.name }),
|
|
141
|
+
general: get("general"),
|
|
142
|
+
group: get("group"),
|
|
143
|
+
legendTitle: get("legendTitle"),
|
|
144
|
+
legend: get("legend"),
|
|
145
|
+
languageTitle: get("languageTitle"),
|
|
146
|
+
languages: (prefix) => get("languages", { prefix }),
|
|
147
|
+
footer: (prefix) => get("footer", { prefix }),
|
|
148
|
+
detailTitle: get("detailTitle"),
|
|
149
|
+
command: get("command"),
|
|
150
|
+
aliases: get("aliases"),
|
|
151
|
+
description: get("description"),
|
|
152
|
+
usage: get("usage"),
|
|
153
|
+
examples: get("examples"),
|
|
154
|
+
where: get("where"),
|
|
155
|
+
permission: get("permission"),
|
|
156
|
+
userAdmin: get("userAdmin"),
|
|
157
|
+
botAdmin: get("botAdmin"),
|
|
158
|
+
detailLegend: get("detailLegend"),
|
|
159
|
+
notFound: (query, prefix) => get("notFound", { query, prefix }),
|
|
160
|
+
permissions: Object.fromEntries(
|
|
161
|
+
["MEMBERS", "ALL", "ADMINS_ONLY", "ADMINS_OWNER", "OWNER_ONLY"].map((level) => [
|
|
162
|
+
level,
|
|
163
|
+
get(`permissions.${level}`),
|
|
164
|
+
]),
|
|
165
|
+
),
|
|
166
|
+
chats: Object.fromEntries(
|
|
167
|
+
["all", "group", "private"].map((chat) => [chat, get(`chats.${chat}`)]),
|
|
168
|
+
),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
204
171
|
|
|
205
172
|
// Permission level as configured for this command (group sub-commands live in
|
|
206
173
|
// their own map). Shown in the detail view so members know why a command is
|
|
@@ -225,7 +192,7 @@ function parseArgs(args = []) {
|
|
|
225
192
|
}
|
|
226
193
|
|
|
227
194
|
function renderList(commands, prefix, lang) {
|
|
228
|
-
const t =
|
|
195
|
+
const t = helpText(lang);
|
|
229
196
|
const section = (title, list) => {
|
|
230
197
|
let text = `├─ *${title}*\n`;
|
|
231
198
|
list.forEach((cmd) => {
|
|
@@ -262,13 +229,13 @@ function renderList(commands, prefix, lang) {
|
|
|
262
229
|
// Starts with the LTR command, so the line lays out left-to-right in both
|
|
263
230
|
// menus and each language name stays next to its own command.
|
|
264
231
|
text += `├─ *${t.languageTitle}*\n`;
|
|
265
|
-
text += `│
|
|
232
|
+
text += `│ ${t.languages(prefix)}\n│\n`;
|
|
266
233
|
text += `╰───「 ${t.footer(prefix)} 」`;
|
|
267
234
|
return text;
|
|
268
235
|
}
|
|
269
236
|
|
|
270
237
|
function renderDetail(command, isGroupCommand, prefix, lang) {
|
|
271
|
-
const t =
|
|
238
|
+
const t = helpText(lang);
|
|
272
239
|
// Same bidi rule as the list: a label ends its own line and the value
|
|
273
240
|
// starts the next one, so no line mixes RTL and LTR content.
|
|
274
241
|
let text = `╭───「 *${t.detailTitle}* 」\n│\n`;
|
|
@@ -311,14 +278,6 @@ function renderDetail(command, isGroupCommand, prefix, lang) {
|
|
|
311
278
|
module.exports = {
|
|
312
279
|
name: "help",
|
|
313
280
|
aliases: ["menu", "commands", "h", "مساعدة", "الاوامر", "اوامر"],
|
|
314
|
-
description: {
|
|
315
|
-
en: "Lists every command, or shows the details of one — in Arabic or English.",
|
|
316
|
-
ar: "يعرض كل الأوامر أو تفاصيل أمر واحد — بالعربية أو الإنجليزية.",
|
|
317
|
-
},
|
|
318
|
-
usage: {
|
|
319
|
-
en: "help [ar|en]\nhelp <command> [ar|en]",
|
|
320
|
-
ar: "help [ar|en]\nhelp <اسم الأمر> [ar|en]",
|
|
321
|
-
},
|
|
322
281
|
chat: "all",
|
|
323
282
|
|
|
324
283
|
async execute(sock, msg, args = [], _body = "", _groupMetadata = null, ctx = {}) {
|
|
@@ -349,8 +308,8 @@ module.exports = {
|
|
|
349
308
|
return sendBotMessage(
|
|
350
309
|
sock,
|
|
351
310
|
msg.key.remoteJid,
|
|
352
|
-
{ text:
|
|
353
|
-
{ replyTo: msg },
|
|
311
|
+
{ text: helpText(lang).notFound(parsed.query, prefix) },
|
|
312
|
+
{ replyTo: msg, levix: { category: "error" } },
|
|
354
313
|
);
|
|
355
314
|
}
|
|
356
315
|
|