levix-bot 4.9.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +57 -3
  2. package/SETUP.md +63 -7
  3. package/app.cjs +159 -46
  4. package/deploy/install.sh +10 -5
  5. package/package.json +9 -6
  6. package/public/dashboard/assets/40af6d88b63079a0-BZ8ojJNu.woff2 +0 -0
  7. package/public/dashboard/assets/481acf6760031cee-BypgxfGb.woff2 +0 -0
  8. package/public/dashboard/assets/6d3351fc535f8ef3-D2-eand5.woff2 +0 -0
  9. package/public/dashboard/assets/8ab0af53a3bda9d3-CyCXRvzh.woff2 +0 -0
  10. package/public/dashboard/assets/8f262393e9249e61-TQp-UTiE.woff2 +0 -0
  11. package/public/dashboard/assets/94d65887a83f1282-DmpS2jIq.woff2 +0 -0
  12. package/public/dashboard/assets/99e400330f36ae77-D3oMJlXt.woff2 +0 -0
  13. package/public/dashboard/assets/9d1f41b13e519d90-BVNSOH3d.woff2 +0 -0
  14. package/public/dashboard/assets/a005256cb957ecc7-CoYeBiSI.woff2 +0 -0
  15. package/public/dashboard/assets/b19c2080652a3c2b-DIC32ArD.woff2 +0 -0
  16. package/public/dashboard/assets/c4064400db3750ce-BehTv68k.woff2 +0 -0
  17. package/public/dashboard/assets/c69d345fa1068c2d-CmI34b-g.woff2 +0 -0
  18. package/public/dashboard/assets/cc27b30471250057-6fWv1k7M.woff2 +0 -0
  19. package/public/dashboard/assets/d8c30647abfeffe6-eXO_dkmS.woff2 +0 -0
  20. package/public/dashboard/assets/eb83d8d40af4411f-Buze_B52.woff2 +0 -0
  21. package/public/dashboard/assets/effc6711249e7349-qRpaaN48.woff2 +0 -0
  22. package/public/dashboard/assets/gateway-BDYet0pI.css +1 -0
  23. package/public/dashboard/assets/gateway-BYt6-s1O.js +1 -0
  24. package/public/dashboard/assets/index-B9wFpD_z.css +2 -0
  25. package/public/dashboard/assets/index-DWcQmu0_.js +124 -0
  26. package/public/dashboard/assets/index-Da-j89O-.js +458 -0
  27. package/public/dashboard/font-licenses/jetbrainsmono-OFL.txt +93 -0
  28. package/public/dashboard/font-licenses/plusjakartasans-OFL.txt +93 -0
  29. package/public/dashboard/font-licenses/tajawal-OFL.txt +93 -0
  30. package/public/dashboard/gateway.html +17 -0
  31. package/public/dashboard/index.html +3 -5
  32. package/public/ui-boot.js +33 -14
  33. package/scheduler.cjs +76 -23
  34. package/src/auth/auth-storage.cjs +54 -7
  35. package/src/auth/use-database-auth-state.js +70 -39
  36. package/src/automation/engine.js +412 -0
  37. package/src/automation/limits.cjs +6 -0
  38. package/src/automation/manage.js +290 -0
  39. package/src/automation/reactions.js +471 -0
  40. package/src/automation/rules.cjs +114 -0
  41. package/src/automation/status.cjs +76 -0
  42. package/src/backup/account.cjs +29 -0
  43. package/src/backup/activation.cjs +247 -0
  44. package/src/backup/content.cjs +36 -0
  45. package/src/backup/create.cjs +280 -0
  46. package/src/backup/extensions.cjs +101 -0
  47. package/src/backup/format.cjs +565 -0
  48. package/src/backup/jobs.cjs +111 -0
  49. package/src/backup/journal.cjs +41 -0
  50. package/src/backup/plan.cjs +223 -0
  51. package/src/backup/recovery.cjs +110 -0
  52. package/src/backup/restore.cjs +460 -0
  53. package/src/backup/uploads.cjs +146 -0
  54. package/src/bootstrap/core.js +50 -12
  55. package/src/bootstrap/panel.js +53 -2
  56. package/src/bootstrap/session-startup-policy.js +8 -1
  57. package/src/cli.js +163 -22
  58. package/src/commands/autodelete.cjs +41 -57
  59. package/src/commands/autoschedule.cjs +7 -33
  60. package/src/commands/blacklist.cjs +17 -35
  61. package/src/commands/block.cjs +4 -18
  62. package/src/commands/calc.cjs +22 -74
  63. package/src/commands/debt.cjs +28 -59
  64. package/src/commands/deleteschedule.cjs +7 -23
  65. package/src/commands/digit.cjs +5 -39
  66. package/src/commands/gemini.cjs +135 -218
  67. package/src/commands/group/add.cjs +28 -76
  68. package/src/commands/group/all.cjs +4 -15
  69. package/src/commands/group/antilink.cjs +28 -41
  70. package/src/commands/group/antispam.cjs +25 -35
  71. package/src/commands/group/approveall.cjs +7 -21
  72. package/src/commands/group/clearwarns.cjs +4 -18
  73. package/src/commands/group/deletenote.cjs +4 -18
  74. package/src/commands/group/demote.cjs +6 -23
  75. package/src/commands/group/flagged.cjs +10 -19
  76. package/src/commands/group/kick.cjs +26 -36
  77. package/src/commands/group/media.cjs +21 -36
  78. package/src/commands/group/members.cjs +16 -28
  79. package/src/commands/group/note.cjs +3 -14
  80. package/src/commands/group/policy.cjs +16 -37
  81. package/src/commands/group/promote.cjs +5 -22
  82. package/src/commands/group/removeall.cjs +6 -38
  83. package/src/commands/group/rules.cjs +4 -19
  84. package/src/commands/group/save.cjs +4 -18
  85. package/src/commands/group/setname.cjs +5 -19
  86. package/src/commands/group/setpp.cjs +8 -26
  87. package/src/commands/group/setrules.cjs +4 -15
  88. package/src/commands/group/setwarn.cjs +6 -23
  89. package/src/commands/group/tagadmins.cjs +5 -16
  90. package/src/commands/group/warn.cjs +5 -16
  91. package/src/commands/group/warns.cjs +12 -33
  92. package/src/commands/group/welcome.cjs +17 -34
  93. package/src/commands/group.cjs +91 -68
  94. package/src/commands/help.cjs +48 -89
  95. package/src/commands/lang.cjs +38 -97
  96. package/src/commands/listschedules.cjs +19 -30
  97. package/src/commands/loop.cjs +9 -55
  98. package/src/commands/md.cjs +2 -13
  99. package/src/commands/memory.cjs +53 -87
  100. package/src/commands/mod.cjs +40 -79
  101. package/src/commands/notes.cjs +4 -15
  102. package/src/commands/pack.cjs +26 -49
  103. package/src/commands/packs.cjs +8 -18
  104. package/src/commands/perm.cjs +48 -51
  105. package/src/commands/ping.cjs +2 -10
  106. package/src/commands/poll.cjs +5 -38
  107. package/src/commands/prayer.cjs +55 -36
  108. package/src/commands/qr.cjs +4 -18
  109. package/src/commands/rand.cjs +9 -58
  110. package/src/commands/restart.cjs +15 -33
  111. package/src/commands/schedule.cjs +5 -25
  112. package/src/commands/score.cjs +6 -27
  113. package/src/commands/send.cjs +4 -18
  114. package/src/commands/setprefix.cjs +11 -23
  115. package/src/commands/shortlink.cjs +13 -39
  116. package/src/commands/status.cjs +188 -76
  117. package/src/commands/sticker.cjs +5 -16
  118. package/src/commands/stickers.cjs +16 -20
  119. package/src/commands/stopbot.cjs +9 -25
  120. package/src/commands/stt.cjs +75 -107
  121. package/src/commands/todo.cjs +11 -31
  122. package/src/commands/toimage.cjs +11 -27
  123. package/src/commands/translate.cjs +53 -36
  124. package/src/commands/tts.cjs +46 -40
  125. package/src/commands/unblock.cjs +3 -17
  126. package/src/commands/update.cjs +23 -0
  127. package/src/commands/weather.cjs +40 -47
  128. package/src/config/ai-identity.cjs +14 -1
  129. package/src/config/baileys.config.js +16 -3
  130. package/src/config/data-dir.cjs +37 -0
  131. package/src/config/defaults.cjs +1 -0
  132. package/src/config/exit-codes.cjs +11 -0
  133. package/src/config/lock.cjs +55 -81
  134. package/src/config/official-links.cjs +61 -0
  135. package/src/config/paths.cjs +4 -33
  136. package/src/config/release.cjs +87 -0
  137. package/src/config/settings.cjs +199 -10
  138. package/src/core/connection.js +77 -9
  139. package/src/core/events.js +119 -33
  140. package/src/core/session.js +536 -84
  141. package/src/core/socket.js +81 -10
  142. package/src/db/copy.cjs +136 -0
  143. package/src/db/db.cjs +241 -36
  144. package/src/db/startup-guard.js +5 -0
  145. package/src/db/store.cjs +561 -54
  146. package/src/diagnostics/baileysLog.cjs +87 -0
  147. package/src/diagnostics/debugLog.cjs +16 -4
  148. package/src/diagnostics/device.cjs +4 -2
  149. package/src/diagnostics/nodeRuntime.cjs +131 -0
  150. package/src/diagnostics/signalSessionInspect.cjs +38 -0
  151. package/src/domain/command.js +24 -22
  152. package/src/extensions/autoReply.cjs +521 -0
  153. package/src/extensions/context.cjs +73 -0
  154. package/src/extensions/contract.cjs +69 -0
  155. package/src/extensions/entitlement/client.cjs +381 -0
  156. package/src/extensions/entitlement/index.cjs +629 -0
  157. package/src/extensions/entitlement/installation.cjs +117 -0
  158. package/src/extensions/entitlement/keys.cjs +72 -0
  159. package/src/extensions/entitlement/state.cjs +201 -0
  160. package/src/extensions/entitlement/target.cjs +7 -0
  161. package/src/extensions/entitlement/token.cjs +225 -0
  162. package/src/extensions/host.cjs +519 -0
  163. package/src/extensions/templateKeys.cjs +81 -0
  164. package/src/handlers/command.handler.js +191 -64
  165. package/src/handlers/group.handler.js +78 -18
  166. package/src/handlers/message.handler.js +56 -25
  167. package/src/i18n/catalog.generated.cjs +3537 -0
  168. package/src/index.js +51 -12
  169. package/src/legal/bundled/ar.json +102 -0
  170. package/src/legal/bundled/en.json +102 -0
  171. package/src/legal/bundled/es-419.json +102 -0
  172. package/src/legal/bundled/pt-BR.json +102 -0
  173. package/src/legal/cli.cjs +200 -0
  174. package/src/legal/consent.cjs +187 -0
  175. package/src/legal/document.cjs +156 -0
  176. package/src/legal/keys.cjs +100 -0
  177. package/src/legal/release.cjs +226 -0
  178. package/src/legal/remote.cjs +419 -0
  179. package/src/legal/terms.cjs +142 -0
  180. package/src/messaging/escape.cjs +31 -0
  181. package/src/messaging/health.cjs +65 -0
  182. package/src/messaging/identity.cjs +42 -0
  183. package/src/messaging/message.cjs +136 -0
  184. package/src/messaging/parser.cjs +88 -0
  185. package/src/messaging/router.cjs +217 -0
  186. package/src/middleware/permissions.middleware.js +34 -2
  187. package/src/panel/account-profile.cjs +489 -0
  188. package/src/panel/fallback-page.cjs +177 -0
  189. package/src/panel/password-reset.cjs +13 -14
  190. package/src/panel/recovery-email.cjs +3 -1
  191. package/src/routes/backup.api.esm.js +175 -0
  192. package/src/routes/dashboard.api.esm.js +183 -7
  193. package/src/routes/plus.api.esm.js +172 -0
  194. package/src/routes/reactions.api.esm.js +60 -0
  195. package/src/services/aiAgent.cjs +56 -43
  196. package/src/services/aiDocs.cjs +187 -0
  197. package/src/services/aiImage.cjs +183 -0
  198. package/src/services/aiMedia.cjs +146 -0
  199. package/src/services/aiProviders.cjs +76 -80
  200. package/src/services/aiRouter.cjs +2 -2
  201. package/src/services/aiToolAuth.cjs +76 -4
  202. package/src/services/aiTools.cjs +431 -105
  203. package/src/services/autoDelete.cjs +9 -1
  204. package/src/services/levix-docs.generated.json +2623 -0
  205. package/src/services/memoryPolicy.cjs +56 -0
  206. package/src/services/updateCheck.cjs +362 -0
  207. package/src/stickers/errors.cjs +53 -97
  208. package/src/stickers/library.cjs +13 -6
  209. package/src/stickers/owner.cjs +1 -1
  210. package/src/utils/commandContext.cjs +13 -0
  211. package/src/utils/commandDocs.cjs +42 -20
  212. package/src/utils/geminiHttpOptions.cjs +56 -0
  213. package/src/utils/geminiMedia.cjs +28 -3
  214. package/src/utils/groupMetadataCache.cjs +386 -21
  215. package/src/utils/httpsFetch.cjs +113 -0
  216. package/src/utils/i18n.cjs +117 -7
  217. package/src/utils/linkPreview.cjs +90 -0
  218. package/src/utils/logger.cjs +6 -0
  219. package/src/utils/markdownParser.cjs +3 -3
  220. package/src/utils/memory.cjs +375 -28
  221. package/src/utils/messageContent.cjs +7 -1
  222. package/src/utils/moderationAction.cjs +116 -73
  223. package/src/utils/moderationSummary.cjs +32 -56
  224. package/src/utils/permissionLevel.cjs +7 -28
  225. package/src/utils/permissions.cjs +23 -14
  226. package/src/utils/permissions.esm.js +99 -166
  227. package/src/utils/recentMessageCache.esm.js +241 -37
  228. package/src/utils/recurrence.cjs +78 -66
  229. package/src/utils/sendBotMessage.cjs +14 -29
  230. package/src/utils/sendBotMessage.esm.js +28 -13
  231. package/src/utils/statusMessage.cjs +94 -33
  232. package/src/utils/stickerBot.cjs +18 -16
  233. package/src/utils/storage.cjs +2 -0
  234. package/src/utils/storage.esm.js +2 -0
  235. package/src/utils/thumbnail.cjs +5 -21
  236. package/public/dashboard/assets/index-B1sOW2VX.js +0 -561
  237. package/public/dashboard/assets/index-CK8osB4o.css +0 -2
  238. package/public/dashboard.css +0 -3127
  239. package/public/dashboard.js +0 -1981
  240. package/public/gateway-i18n.js +0 -321
  241. package/public/gateway.js +0 -70
  242. package/views/dashboard.ejs +0 -775
  243. package/views/login.ejs +0 -408
  244. package/views/qr.ejs +0 -155
  245. package/views/setup.ejs +0 -118
@@ -0,0 +1,217 @@
1
+ // Reply Router.
2
+ //
3
+ // The default destination is the chat the command was typed in. Another
4
+ // destination is allowed only when this module says so. The dashboard stores
5
+ // the choice; it does not send. A forged chat id on a message context is not
6
+ // read here. Callers pass the Baileys key's remote JID as `sourceJid`.
7
+ //
8
+ // Named exceptions, decided with the owner (Q-21): `!schedule` and
9
+ // `!autoschedule` errors still go to the creator's private chat.
10
+ // Password-reset codes use `assertSelfDelivery` and never a group.
11
+ //
12
+ // When a destination is missing or not allowed, the answer is a refusal.
13
+ // The caller tells the source chat with a neutral notice. Nothing in here
14
+ // falls back to a group.
15
+
16
+ const normalizeJid = require("../utils/normalizeJid.cjs");
17
+ const { getCached } = require("../utils/groupMetadataCache.cjs");
18
+ const { linkedIdentity } = require("./identity.cjs");
19
+
20
+ const MODES = new Set(["same_chat", "owner_private", "authorized_chat"]);
21
+ const JID_RE = /^(?:[0-9]{1,30}@(s\.whatsapp\.net|lid|g\.us)|[0-9]{1,30}-[0-9]{1,30}@g\.us)$/;
22
+ const SCHEDULE_COMMANDS = new Set(["schedule", "autoschedule"]);
23
+
24
+ function canonicalJid(jid) {
25
+ if (!jid || typeof jid !== "string") return null;
26
+ const norm = normalizeJid(jid.trim());
27
+ if (!norm || !JID_RE.test(norm)) return null;
28
+ return norm;
29
+ }
30
+
31
+ function resolveMode(input) {
32
+ const commands = input.overrides?.commands;
33
+ const categories = input.overrides?.categories;
34
+ const chosen =
35
+ commands?.[input.commandName] || categories?.[input.category] || input.routeMode || "same_chat";
36
+ return MODES.has(chosen) ? chosen : "same_chat";
37
+ }
38
+
39
+ function ownerDestination(identity) {
40
+ if (!identity) return null;
41
+ return canonicalJid(identity.phone) || canonicalJid(identity.lid) || null;
42
+ }
43
+
44
+ function classify(dest, input) {
45
+ const source = canonicalJid(input.sourceJid);
46
+ if (dest === source) return { ok: true, kind: "source" };
47
+ const self = input.identity?.selfJids || [];
48
+ if (self.includes(dest)) return { ok: true, kind: "owner_private" };
49
+ if (dest.endsWith("@g.us")) {
50
+ const known = input.knownGroups?.[dest];
51
+ if (!known?.member) return { ok: false, kind: "group" };
52
+ return { ok: true, kind: "group" };
53
+ }
54
+ return { ok: true, kind: "other" };
55
+ }
56
+
57
+ function allow(destination, quote) {
58
+ return { allow: true, destination, quote: Boolean(quote), noticeKey: null };
59
+ }
60
+
61
+ function refuse() {
62
+ return {
63
+ allow: false,
64
+ destination: null,
65
+ quote: false,
66
+ noticeKey: "bot.core.message.routeFailed",
67
+ };
68
+ }
69
+
70
+ /**
71
+ * Decide one delivery. Pure: no settings read, no socket, no network.
72
+ *
73
+ * @returns {{allow: boolean, destination: string|null, quote: boolean, noticeKey: string|null}}
74
+ */
75
+ function planDelivery(input = {}) {
76
+ const source = canonicalJid(input.sourceJid);
77
+ if (!source) return refuse();
78
+ if (input.terminal) return allow(source, true);
79
+
80
+ const requested = canonicalJid(input.requestedJid) || source;
81
+ const sensitivity = input.sensitivity || "source";
82
+ const sender = canonicalJid(input.senderJid);
83
+ const commandName = input.commandName || "";
84
+
85
+ // Q-21. The creator's own private chat, never a group, never a third person.
86
+ if (
87
+ SCHEDULE_COMMANDS.has(commandName) &&
88
+ sender &&
89
+ requested === sender &&
90
+ !requested.endsWith("@g.us")
91
+ ) {
92
+ return allow(requested, requested === source);
93
+ }
94
+
95
+ const mode = resolveMode(input);
96
+
97
+ if (mode === "same_chat") {
98
+ if (requested !== source) return refuse();
99
+ return allow(source, true);
100
+ }
101
+
102
+ // Security text stays in the chat that produced it.
103
+ if (sensitivity === "secret") {
104
+ if (requested !== source) return refuse();
105
+ return allow(source, true);
106
+ }
107
+
108
+ if (mode === "owner_private") {
109
+ const owner = ownerDestination(input.identity);
110
+ if (!owner) return refuse();
111
+ return allow(owner, owner === source);
112
+ }
113
+
114
+ if (mode === "authorized_chat") {
115
+ const dest = canonicalJid(input.routeChat);
116
+ if (!dest) return refuse();
117
+ const kind = classify(dest, input);
118
+ if (!kind.ok) return refuse();
119
+ if (kind.kind === "other" || kind.kind === "group") {
120
+ if (sensitivity !== "operational") return refuse();
121
+ }
122
+ return allow(dest, dest === source);
123
+ }
124
+
125
+ return refuse();
126
+ }
127
+
128
+ function readOverrides() {
129
+ try {
130
+ const settings = require("../config/settings.cjs");
131
+ const raw = settings.get("reply_route_overrides");
132
+ if (!raw) return { commands: {}, categories: {} };
133
+ const parsed = JSON.parse(raw);
134
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
135
+ return { commands: {}, categories: {} };
136
+ }
137
+ return {
138
+ commands: parsed.commands && typeof parsed.commands === "object" ? parsed.commands : {},
139
+ categories:
140
+ parsed.categories && typeof parsed.categories === "object" ? parsed.categories : {},
141
+ };
142
+ } catch {
143
+ return { commands: {}, categories: {} };
144
+ }
145
+ }
146
+
147
+ function groupMembership(jid, identity) {
148
+ const meta = getCached(jid);
149
+ if (!meta || !Array.isArray(meta.participants)) return null;
150
+ const self = new Set(identity.selfJids || []);
151
+ const member = meta.participants.some((participant) => self.has(normalizeJid(participant?.id)));
152
+ return { member };
153
+ }
154
+
155
+ /** Settings, and creds only when the route can leave the source chat. No network. */
156
+ function routeSend(input = {}) {
157
+ const settings = require("../config/settings.cjs");
158
+ const overrides = readOverrides();
159
+ const routeMode = settings.get("reply_route");
160
+ const chosen =
161
+ overrides.commands?.[input.commandName] ||
162
+ overrides.categories?.[input.category] ||
163
+ routeMode ||
164
+ "same_chat";
165
+ // The default path does not read pairing credentials.
166
+ if (!MODES.has(chosen) || chosen === "same_chat") {
167
+ return planDelivery({
168
+ ...input,
169
+ routeMode: "same_chat",
170
+ routeChat: "",
171
+ overrides,
172
+ identity: { selfJids: [] },
173
+ knownGroups: {},
174
+ });
175
+ }
176
+ const routeChat = settings.get("reply_route_chat");
177
+ const identity = linkedIdentity();
178
+ const knownGroups = {};
179
+ const dest = canonicalJid(routeChat);
180
+ if (dest?.endsWith("@g.us")) {
181
+ const known = groupMembership(dest, identity);
182
+ if (known) knownGroups[dest] = known;
183
+ }
184
+ return planDelivery({
185
+ ...input,
186
+ routeMode,
187
+ routeChat,
188
+ overrides,
189
+ identity,
190
+ knownGroups,
191
+ });
192
+ }
193
+
194
+ /**
195
+ * Password-reset codes (and anything else that must reach only the linked
196
+ * account) call this before they send. A group, a broadcast, or a different
197
+ * person throws. There is no fallback.
198
+ */
199
+ function assertSelfDelivery(destination, selfId) {
200
+ const dest = canonicalJid(destination);
201
+ const self = canonicalJid(selfId);
202
+ if (!dest || !self || dest !== self || dest.endsWith("@g.us")) {
203
+ const error = new Error("refusing to deliver outside the linked account chat");
204
+ error.code = "ROUTE_REFUSED";
205
+ throw error;
206
+ }
207
+ return dest;
208
+ }
209
+
210
+ module.exports = {
211
+ MODES,
212
+ canonicalJid,
213
+ planDelivery,
214
+ routeSend,
215
+ assertSelfDelivery,
216
+ resolveMode,
217
+ };
@@ -13,6 +13,38 @@ const require = createRequire(import.meta.url);
13
13
  const runtimeConfig = require("../config/runtime-config.cjs");
14
14
  const { evaluatePermissionLevel } = require("../utils/permissionLevel.cjs");
15
15
  const logger = require("../utils/logger.cjs");
16
+ const store = require("../db/store.cjs");
17
+ const { canonicalJid } = require("../messaging/router.cjs");
18
+ const { MAX_IDENTITY_ALIASES } = require("../automation/limits.cjs");
19
+
20
+ // Automation uses exact primary role rows and current authoritative mappings.
21
+ // Roles still use the same backend roster and level evaluator.
22
+ export function verifiedIdentityAliases(value) {
23
+ const jid = canonicalJid(value);
24
+ if (!jid || jid.endsWith("@g.us")) return [];
25
+ const ids = store.roleIdentityAliases(jid);
26
+ return ids.length <= MAX_IDENTITY_ALIASES ? ids : [];
27
+ }
28
+ export function verifiedParticipant(metadata, value) {
29
+ const ids = verifiedIdentityAliases(value);
30
+ return metadata?.participants?.find((p) =>
31
+ [p.id, p.lid, p.phoneNumber, p.jid].some((id) => ids.includes(canonicalJid(id)))) || null;
32
+ }
33
+ export function resolveVerifiedSender(msg, groupMetadata, sock) {
34
+ const key = msg?.key;
35
+ if (key?.fromMe !== false) throw new Error("REACTION_IDENTITY_INVALID");
36
+ const isGroup = Boolean(key.remoteJid?.endsWith("@g.us"));
37
+ const senderId = canonicalJid(isGroup ? key.participant : key.remoteJid);
38
+ const candidates = verifiedIdentityAliases(senderId);
39
+ if (!candidates.length) throw new Error("REACTION_IDENTITY_INVALID");
40
+ const roles = store.verifiedUserRoles(candidates);
41
+ const self = [sock?.user?.id, sock?.user?.lid].some((id) => candidates.includes(canonicalJid(id)));
42
+ const isOwner = roles.isOwner || self;
43
+ const isBotAdmin = !isOwner && roles.isBotAdmin;
44
+ const isGroupAdmin = isGroup && ["admin", "superadmin"].includes(verifiedParticipant(groupMetadata, senderId)?.admin);
45
+ return { isGroup, senderId, candidates, isOwner, isBotAdmin, isGroupAdmin,
46
+ isSenderAdmin: isBotAdmin || isGroupAdmin };
47
+ }
16
48
 
17
49
  /**
18
50
  * Resolves the permission level in force for a command name — the dashboard
@@ -50,12 +82,12 @@ export function resolveSender(msg, groupMetadata, sock) {
50
82
  const candidates = senderCandidates.length ? senderCandidates : [senderId].filter(Boolean);
51
83
 
52
84
  // fromMe is an immediate owner indicator (the bot is always its own owner).
53
- const isOwner = Boolean(msg?.key?.fromMe) || candidates.some((c) => isOwnerJid(c));
85
+ const isOwner = Boolean(msg?.key?.fromMe) || candidates.some((c) => isOwnerJid(c, groupMetadata));
54
86
 
55
87
  // Bot-level admins (granted with `!perm add admin`, from the dashboard, or by
56
88
  // asking the AI) count as admins everywhere — including DMs, where there is
57
89
  // no group roster to consult.
58
- const isBotAdmin = !isOwner && candidates.some((c) => isBotAdminUser(c));
90
+ const isBotAdmin = !isOwner && candidates.some((c) => isBotAdminUser(c, groupMetadata));
59
91
 
60
92
  const isGroupAdmin = isGroup && candidates.some((c) => isAdminInGroup(groupMetadata, c));
61
93
  const isSenderAdmin = isBotAdmin || isGroupAdmin;