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
|
@@ -31,30 +31,30 @@ async function primePermissions() {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function isOwnerJidSync(jid) {
|
|
34
|
+
function isOwnerJidSync(jid, groupMetadata) {
|
|
35
35
|
if (!mod) return false;
|
|
36
36
|
try {
|
|
37
|
-
return mod.isOwnerJid(jid);
|
|
37
|
+
return mod.isOwnerJid(jid, groupMetadata);
|
|
38
38
|
} catch (err) {
|
|
39
39
|
logger.error({ err }, "[permissions.cjs] isOwnerJidSync failed");
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function isBotAdminUserSync(jid) {
|
|
44
|
+
function isBotAdminUserSync(jid, groupMetadata) {
|
|
45
45
|
if (!mod) return false;
|
|
46
46
|
try {
|
|
47
|
-
return mod.isBotAdminUser(jid);
|
|
47
|
+
return mod.isBotAdminUser(jid, groupMetadata);
|
|
48
48
|
} catch (err) {
|
|
49
49
|
logger.error({ err }, "[permissions.cjs] isBotAdminUserSync failed");
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function hasBotPrivilegesSync(jid) {
|
|
54
|
+
function hasBotPrivilegesSync(jid, groupMetadata) {
|
|
55
55
|
if (!mod) return false;
|
|
56
56
|
try {
|
|
57
|
-
return mod.hasBotPrivileges(jid);
|
|
57
|
+
return mod.hasBotPrivileges(jid, groupMetadata);
|
|
58
58
|
} catch (err) {
|
|
59
59
|
logger.error({ err }, "[permissions.cjs] hasBotPrivilegesSync failed");
|
|
60
60
|
return false;
|
|
@@ -123,6 +123,14 @@ function getSenderCandidatesSync(msg, sock) {
|
|
|
123
123
|
return collectNormalized(raw);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
function participantIdsSync(participant) {
|
|
127
|
+
if (mod?.participantIds) return mod.participantIds(participant);
|
|
128
|
+
if (!participant) return [];
|
|
129
|
+
return [participant.id, participant.lid, participant.phoneNumber, participant.jid].filter(
|
|
130
|
+
Boolean,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
126
134
|
function findGroupParticipantSync(groupMetadata, jidOrList) {
|
|
127
135
|
if (mod?.findGroupParticipant) {
|
|
128
136
|
try {
|
|
@@ -156,9 +164,9 @@ function rosterJidForSync(groupMetadata, jidOrList) {
|
|
|
156
164
|
return collectNormalized(list)[0] || list.find(Boolean) || null;
|
|
157
165
|
}
|
|
158
166
|
|
|
159
|
-
async function isOwnerJid(jid) {
|
|
167
|
+
async function isOwnerJid(jid, groupMetadata) {
|
|
160
168
|
const m = await getMod();
|
|
161
|
-
return m.isOwnerJid(jid);
|
|
169
|
+
return m.isOwnerJid(jid, groupMetadata);
|
|
162
170
|
}
|
|
163
171
|
|
|
164
172
|
async function isAdminInGroup(groupMetadata, jid) {
|
|
@@ -171,9 +179,9 @@ async function isBotAdminInGroup(groupMetadata, sock) {
|
|
|
171
179
|
return m.isBotAdminInGroup(groupMetadata, sock);
|
|
172
180
|
}
|
|
173
181
|
|
|
174
|
-
async function bootstrapOwners(values) {
|
|
182
|
+
async function bootstrapOwners(values, verifiedSelf) {
|
|
175
183
|
const m = await getMod();
|
|
176
|
-
return m.bootstrapOwners(values);
|
|
184
|
+
return m.bootstrapOwners(values, verifiedSelf);
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
async function addBootstrapOwner(value) {
|
|
@@ -181,9 +189,9 @@ async function addBootstrapOwner(value) {
|
|
|
181
189
|
return m.addBootstrapOwner(value);
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
async function isBotAdminUser(jid) {
|
|
192
|
+
async function isBotAdminUser(jid, groupMetadata) {
|
|
185
193
|
const m = await getMod();
|
|
186
|
-
return m.isBotAdminUser(jid);
|
|
194
|
+
return m.isBotAdminUser(jid, groupMetadata);
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
async function grantRole(target, role) {
|
|
@@ -191,9 +199,9 @@ async function grantRole(target, role) {
|
|
|
191
199
|
return m.grantRole(target, role);
|
|
192
200
|
}
|
|
193
201
|
|
|
194
|
-
async function revokeRole(target, role) {
|
|
202
|
+
async function revokeRole(target, role, verifiedAliases) {
|
|
195
203
|
const m = await getMod();
|
|
196
|
-
return m.revokeRole(target, role);
|
|
204
|
+
return m.revokeRole(target, role, verifiedAliases);
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
async function listRoles() {
|
|
@@ -220,5 +228,6 @@ module.exports = {
|
|
|
220
228
|
sameUserSync,
|
|
221
229
|
getSenderCandidatesSync,
|
|
222
230
|
findGroupParticipantSync,
|
|
231
|
+
participantIdsSync,
|
|
223
232
|
rosterJidForSync,
|
|
224
233
|
};
|
|
@@ -1,68 +1,54 @@
|
|
|
1
|
-
// Centralized
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// * permissions.middleware.js — DB lookup + config.owners + fromMe
|
|
6
|
-
// * group.cjs — config.owners only (always empty)
|
|
7
|
-
// * group/media.cjs — config.owners on a `{}` parameter (throws!)
|
|
8
|
-
// * group/antilink.cjs — same as media.cjs
|
|
9
|
-
// * antispam.middleware.js — a legacy owner mirror (only the bot itself)
|
|
10
|
-
// * gemini.cjs — display-name match (fragile)
|
|
11
|
-
//
|
|
12
|
-
// This module is the single source of truth. It exposes:
|
|
13
|
-
//
|
|
14
|
-
// bootstrapOwners(list)
|
|
15
|
-
// Called once at connection time with the bot's own JID/LID plus every
|
|
16
|
-
// owner already recorded in user_metadata. Stored in a Set so subsequent
|
|
17
|
-
// checks are O(1) and don't hit the database on the hot path.
|
|
18
|
-
//
|
|
19
|
-
// isOwnerJid(jidOrLidOrPhone)
|
|
20
|
-
// Checks every direction we know about:
|
|
21
|
-
// - bootstrap set
|
|
22
|
-
// - user_metadata table (is_owner = 1) by jid, lid, or phone
|
|
23
|
-
// - cross-format: if given a LID, look up its PN and recheck; vice versa
|
|
24
|
-
// - phone-digit fallback (handles `:XX` device suffixes etc.)
|
|
25
|
-
//
|
|
26
|
-
// isAdminInGroup(groupMetadata, jid)
|
|
27
|
-
// LID/PN-aware admin check.
|
|
28
|
-
//
|
|
29
|
-
// isBotAdminInGroup(groupMetadata, sock)
|
|
30
|
-
// Same idea for the bot itself.
|
|
31
|
-
//
|
|
32
|
-
// sameUser(a, b)
|
|
33
|
-
// True if two identifiers refer to the same person (LID/PN/phone equiv).
|
|
34
|
-
|
|
35
|
-
import normalizeJid, { isLidJid, isPnJid } from "./normalizeJid.esm.js";
|
|
1
|
+
// Centralized role and WhatsApp identity checks. Numeric equality across the
|
|
2
|
+
// LID and PN namespaces is never evidence of identity.
|
|
3
|
+
import normalizeJid from "./normalizeJid.esm.js";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
36
5
|
import {
|
|
37
6
|
isUserBotAdmin as dbIsBotAdmin,
|
|
38
7
|
isUserOwner as dbIsOwner,
|
|
39
8
|
getAllBotAdmins,
|
|
40
9
|
getAllOwners,
|
|
41
|
-
getLidForPn,
|
|
42
|
-
getPnForLid,
|
|
43
10
|
setUserRole,
|
|
44
11
|
} from "./storage.esm.js";
|
|
45
12
|
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const { roleIdentityAliases, withImmediateTransaction } = require("../db/store.cjs");
|
|
15
|
+
|
|
46
16
|
// Two rosters, same mechanics:
|
|
47
17
|
// owners — full access, including OWNER_ONLY commands
|
|
48
18
|
// bot admins — treated as an admin in every chat (group admin OR this role
|
|
49
19
|
// satisfies ADMINS_ONLY / ADMINS_OWNER), but not OWNER_ONLY
|
|
50
20
|
const bootstrap = new Set();
|
|
51
21
|
const bootstrapAdminSet = new Set();
|
|
52
|
-
|
|
53
|
-
function digitsOnly(value) {
|
|
54
|
-
if (!value) return null;
|
|
55
|
-
const m = String(value).match(/\d+/);
|
|
56
|
-
return m ? m[0] : null;
|
|
57
|
-
}
|
|
22
|
+
const linkedSelf = new Set();
|
|
58
23
|
|
|
59
24
|
function pushInto(set, value) {
|
|
60
|
-
|
|
61
|
-
const norm = normalizeJid(value);
|
|
25
|
+
const norm = identityForms(value)[0];
|
|
62
26
|
if (norm) set.add(norm);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Connection bootstrap passes primary JIDs plus legacy user_lid columns.
|
|
30
|
+
// Do not freeze a secondary column into an independent grant. Current mapping
|
|
31
|
+
// aliases are resolved at check time, and unverified contact links grant nothing.
|
|
32
|
+
function replaceBootstrap(set, values, listAll) {
|
|
33
|
+
set.clear();
|
|
34
|
+
if (!Array.isArray(values)) return;
|
|
35
|
+
const secondary = new Set();
|
|
36
|
+
const primary = new Set();
|
|
37
|
+
try {
|
|
38
|
+
for (const row of listAll()) {
|
|
39
|
+
const jid = identityForms(row.jid)[0];
|
|
40
|
+
const lid = identityForms(row.lid)[0];
|
|
41
|
+
if (jid) primary.add(jid);
|
|
42
|
+
if (lid && lid !== jid && values.some((value) => identityForms(value)[0] === jid)) {
|
|
43
|
+
secondary.add(lid);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
return; // A bootstrap list may contain unverified contact aliases.
|
|
48
|
+
}
|
|
49
|
+
for (const value of values) {
|
|
50
|
+
const norm = identityForms(value)[0];
|
|
51
|
+
if (!secondary.has(norm) || primary.has(norm)) pushInto(set, value);
|
|
66
52
|
}
|
|
67
53
|
}
|
|
68
54
|
|
|
@@ -72,12 +58,14 @@ function pushBootstrap(value) {
|
|
|
72
58
|
|
|
73
59
|
/**
|
|
74
60
|
* Replace the bootstrap owner set. Pass an array of JIDs/LIDs/phones; we
|
|
75
|
-
* normalize and de-dupe them.
|
|
61
|
+
* normalize and de-dupe them. verifiedSelf contains only paired credentials.
|
|
76
62
|
*/
|
|
77
|
-
export function bootstrapOwners(values) {
|
|
78
|
-
bootstrap
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
export function bootstrapOwners(values, verifiedSelf = []) {
|
|
64
|
+
replaceBootstrap(bootstrap, values, getAllOwners);
|
|
65
|
+
// Cleared by lifecycle bootstrap (including unlink), never by revocation.
|
|
66
|
+
// Supplied only from paired credentials, never from contact metadata.
|
|
67
|
+
linkedSelf.clear();
|
|
68
|
+
for (const value of verifiedSelf) pushInto(linkedSelf, value);
|
|
81
69
|
}
|
|
82
70
|
|
|
83
71
|
/** Add an owner to the bootstrap set (does not touch the DB). */
|
|
@@ -86,16 +74,12 @@ export function addBootstrapOwner(value) {
|
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
export function getBootstrapOwners() {
|
|
89
|
-
return [...bootstrap];
|
|
77
|
+
return [...new Set([...bootstrap, ...linkedSelf])];
|
|
90
78
|
}
|
|
91
79
|
|
|
92
80
|
/** Same as bootstrapOwners, for the bot-admin roster. */
|
|
93
81
|
export function bootstrapAdmins(values) {
|
|
94
|
-
bootstrapAdminSet
|
|
95
|
-
if (!Array.isArray(values)) return;
|
|
96
|
-
values.forEach((value) => {
|
|
97
|
-
pushInto(bootstrapAdminSet, value);
|
|
98
|
-
});
|
|
82
|
+
replaceBootstrap(bootstrapAdminSet, values, getAllBotAdmins);
|
|
99
83
|
}
|
|
100
84
|
|
|
101
85
|
export function addBootstrapAdmin(value) {
|
|
@@ -106,80 +90,38 @@ export function getBootstrapAdmins() {
|
|
|
106
90
|
return [...bootstrapAdminSet];
|
|
107
91
|
}
|
|
108
92
|
|
|
109
|
-
/**
|
|
110
|
-
* Every identifier that could stand for the same person: the normalized form,
|
|
111
|
-
* its LID/PN counterpart, and the bare-phone JID. Both role checks walk this
|
|
112
|
-
* list so a user granted a role by phone still matches when they message under
|
|
113
|
-
* a LID (and vice-versa).
|
|
114
|
-
*/
|
|
93
|
+
/** Exact normalized identity and its current authoritative mapping only. */
|
|
115
94
|
function identityForms(jid) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (!norm) return forms;
|
|
124
|
-
push(norm);
|
|
125
|
-
|
|
126
|
-
if (isLidJid(norm)) {
|
|
127
|
-
try {
|
|
128
|
-
push(getPnForLid(norm));
|
|
129
|
-
} catch {}
|
|
130
|
-
}
|
|
131
|
-
if (isPnJid(norm)) {
|
|
132
|
-
try {
|
|
133
|
-
push(getLidForPn(norm));
|
|
134
|
-
} catch {}
|
|
95
|
+
if (!jid) return [];
|
|
96
|
+
try {
|
|
97
|
+
return roleIdentityAliases(jid);
|
|
98
|
+
} catch {
|
|
99
|
+
// A failed mapping read cannot establish another identity.
|
|
100
|
+
const norm = normalizeJid(jid);
|
|
101
|
+
return norm?.includes("@") ? [norm] : [];
|
|
135
102
|
}
|
|
136
|
-
|
|
137
|
-
const phone = digitsOnly(norm);
|
|
138
|
-
if (phone) push(`${phone}@s.whatsapp.net`);
|
|
139
|
-
|
|
140
|
-
return forms;
|
|
141
103
|
}
|
|
142
104
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
105
|
+
function hasRole(jid, { set, dbCheck, permanent }, groupMetadata) {
|
|
106
|
+
const forms = new Set(identityForms(jid));
|
|
107
|
+
// A transport roster object carrying both forms is proof even before the
|
|
108
|
+
// mapping table learns the pair. Never consult user_metadata aliases here.
|
|
109
|
+
const participant = findGroupParticipant(groupMetadata, jid);
|
|
110
|
+
for (const id of participantIds(participant)) {
|
|
111
|
+
for (const form of identityForms(id)) forms.add(form);
|
|
112
|
+
}
|
|
152
113
|
for (const form of forms) {
|
|
153
|
-
if (set.has(form)) return true;
|
|
114
|
+
if (set.has(form) || permanent?.has(form)) return true;
|
|
154
115
|
try {
|
|
155
116
|
if (dbCheck(form)) return true;
|
|
156
117
|
} catch {}
|
|
157
118
|
}
|
|
158
|
-
|
|
159
|
-
const phone = digitsOnly(forms[0]);
|
|
160
|
-
if (phone) {
|
|
161
|
-
try {
|
|
162
|
-
for (const entry of listAll()) {
|
|
163
|
-
const entryPhone =
|
|
164
|
-
digitsOnly(entry.phone) || digitsOnly(entry.jid) || digitsOnly(entry.lid);
|
|
165
|
-
if (entryPhone && entryPhone === phone) return true;
|
|
166
|
-
}
|
|
167
|
-
} catch {}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
119
|
return false;
|
|
171
120
|
}
|
|
172
121
|
|
|
173
|
-
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*/
|
|
177
|
-
export function isOwnerJid(jid) {
|
|
178
|
-
return hasRole(jid, {
|
|
179
|
-
set: bootstrap,
|
|
180
|
-
dbCheck: dbIsOwner,
|
|
181
|
-
listAll: getAllOwners,
|
|
182
|
-
});
|
|
122
|
+
/** Owner check by exact primary identity or verified current mapping. */
|
|
123
|
+
export function isOwnerJid(jid, groupMetadata) {
|
|
124
|
+
return hasRole(jid, { set: bootstrap, dbCheck: dbIsOwner, permanent: linkedSelf }, groupMetadata);
|
|
183
125
|
}
|
|
184
126
|
|
|
185
127
|
/**
|
|
@@ -188,18 +130,21 @@ export function isOwnerJid(jid) {
|
|
|
188
130
|
* the AI) that makes the user an admin everywhere the bot works.
|
|
189
131
|
* Owners always pass.
|
|
190
132
|
*/
|
|
191
|
-
export function isBotAdminUser(jid) {
|
|
192
|
-
if (isOwnerJid(jid)) return true;
|
|
193
|
-
return hasRole(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
133
|
+
export function isBotAdminUser(jid, groupMetadata) {
|
|
134
|
+
if (isOwnerJid(jid, groupMetadata)) return true;
|
|
135
|
+
return hasRole(
|
|
136
|
+
jid,
|
|
137
|
+
{
|
|
138
|
+
set: bootstrapAdminSet,
|
|
139
|
+
dbCheck: dbIsBotAdmin,
|
|
140
|
+
},
|
|
141
|
+
groupMetadata,
|
|
142
|
+
);
|
|
198
143
|
}
|
|
199
144
|
|
|
200
145
|
/** Owner or bot-admin — "this person may drive the bot". */
|
|
201
|
-
export function hasBotPrivileges(jid) {
|
|
202
|
-
return isOwnerJid(jid) || isBotAdminUser(jid);
|
|
146
|
+
export function hasBotPrivileges(jid, groupMetadata) {
|
|
147
|
+
return isOwnerJid(jid, groupMetadata) || isBotAdminUser(jid, groupMetadata);
|
|
203
148
|
}
|
|
204
149
|
|
|
205
150
|
/**
|
|
@@ -219,21 +164,33 @@ export function grantRole(target, role = "admin") {
|
|
|
219
164
|
}
|
|
220
165
|
|
|
221
166
|
/**
|
|
222
|
-
* Revoke a bot-level role
|
|
223
|
-
*
|
|
167
|
+
* Revoke a bot-level role and remove its proven aliases from the bootstrap
|
|
168
|
+
* set so the revocation takes effect without a restart. verifiedAliases must
|
|
169
|
+
* come from trusted target participant metadata.
|
|
224
170
|
*
|
|
225
171
|
* @returns {object|null} the stored user record
|
|
226
172
|
*/
|
|
227
|
-
export function revokeRole(target, role = "admin") {
|
|
173
|
+
export function revokeRole(target, role = "admin", verifiedAliases = []) {
|
|
228
174
|
const wanted = String(role).toLowerCase() === "owner" ? "owner" : "admin";
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const forms =
|
|
175
|
+
// Extra identities come from the target's trusted roster participant, never
|
|
176
|
+
// from model arguments or secondary user_metadata columns.
|
|
177
|
+
const forms = new Set([target, ...verifiedAliases].flatMap(identityForms));
|
|
178
|
+
if (wanted === "owner" && [...forms].some((form) => linkedSelf.has(form))) {
|
|
179
|
+
throw Object.assign(
|
|
180
|
+
new Error("The linked account is always an owner. Unlink WhatsApp to change it."),
|
|
181
|
+
{ code: "LINKED_ACCOUNT_OWNER" },
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const record = withImmediateTransaction(() => {
|
|
185
|
+
const result = setUserRole(target, wanted, false);
|
|
186
|
+
for (const form of forms) {
|
|
187
|
+
if (form !== result?.jid) setUserRole(form, wanted, false);
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
});
|
|
232
191
|
const set = wanted === "owner" ? bootstrap : bootstrapAdminSet;
|
|
233
192
|
for (const form of forms) {
|
|
234
193
|
set.delete(form);
|
|
235
|
-
const phone = digitsOnly(form);
|
|
236
|
-
if (phone) set.delete(`${phone}@s.whatsapp.net`);
|
|
237
194
|
}
|
|
238
195
|
return record;
|
|
239
196
|
}
|
|
@@ -257,37 +214,13 @@ export function listRoles() {
|
|
|
257
214
|
}
|
|
258
215
|
|
|
259
216
|
/**
|
|
260
|
-
*
|
|
261
|
-
* vs PN vs phone-with-device-suffix confusion.
|
|
217
|
+
* Exact identity (including bare PN/device suffix forms) or a current mapping.
|
|
262
218
|
*/
|
|
263
219
|
export function sameUser(a, b) {
|
|
264
220
|
if (!a || !b) return false;
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
const da = digitsOnly(na);
|
|
269
|
-
const db = digitsOnly(nb);
|
|
270
|
-
if (da && db && da === db) return true;
|
|
271
|
-
// Cross-format lookup
|
|
272
|
-
try {
|
|
273
|
-
if (isLidJid(na)) {
|
|
274
|
-
const pn = getPnForLid(na);
|
|
275
|
-
if (pn && normalizeJid(pn) === nb) return true;
|
|
276
|
-
}
|
|
277
|
-
if (isLidJid(nb)) {
|
|
278
|
-
const pn = getPnForLid(nb);
|
|
279
|
-
if (pn && normalizeJid(pn) === na) return true;
|
|
280
|
-
}
|
|
281
|
-
if (isPnJid(na)) {
|
|
282
|
-
const lid = getLidForPn(na);
|
|
283
|
-
if (lid && normalizeJid(lid) === nb) return true;
|
|
284
|
-
}
|
|
285
|
-
if (isPnJid(nb)) {
|
|
286
|
-
const lid = getLidForPn(nb);
|
|
287
|
-
if (lid && normalizeJid(lid) === na) return true;
|
|
288
|
-
}
|
|
289
|
-
} catch {}
|
|
290
|
-
return false;
|
|
221
|
+
const forms = identityForms(a);
|
|
222
|
+
const other = identityForms(b)[0];
|
|
223
|
+
return Boolean(other) && forms.includes(other);
|
|
291
224
|
}
|
|
292
225
|
|
|
293
226
|
/**
|