levix-bot 4.8.0 → 4.9.1

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 (60) hide show
  1. package/README.md +9 -5
  2. package/SETUP.md +21 -2
  3. package/app.cjs +69 -23
  4. package/package.json +3 -2
  5. package/public/dashboard/assets/index-B1sOW2VX.js +561 -0
  6. package/public/dashboard/assets/index-CK8osB4o.css +2 -0
  7. package/public/dashboard/index.html +2 -2
  8. package/public/dashboard.css +21 -0
  9. package/public/dashboard.js +25 -2
  10. package/public/gateway-i18n.js +26 -0
  11. package/src/bootstrap/session-startup-policy.js +6 -6
  12. package/src/commands/group/antilink.cjs +82 -59
  13. package/src/commands/group/antispam.cjs +112 -0
  14. package/src/commands/group/clearwarns.cjs +6 -6
  15. package/src/commands/group/demote.cjs +11 -13
  16. package/src/commands/group/flagged.cjs +52 -0
  17. package/src/commands/group/kick.cjs +25 -15
  18. package/src/commands/group/media.cjs +65 -29
  19. package/src/commands/group/policy.cjs +215 -0
  20. package/src/commands/group/promote.cjs +11 -12
  21. package/src/commands/group/rules.cjs +9 -6
  22. package/src/commands/group/setwarn.cjs +17 -27
  23. package/src/commands/group/warn.cjs +13 -63
  24. package/src/commands/group.cjs +5 -2
  25. package/src/commands/mod.cjs +101 -26
  26. package/src/commands/translate.cjs +585 -0
  27. package/src/config/ai-identity.cjs +53 -1
  28. package/src/config/ai-persona.md +32 -73
  29. package/src/config/defaults.cjs +2 -0
  30. package/src/config/secrets.cjs +71 -3
  31. package/src/config/settings.cjs +22 -1
  32. package/src/core/socket.js +4 -5
  33. package/src/db/db.cjs +66 -0
  34. package/src/db/store.cjs +264 -16
  35. package/src/diagnostics/crashReports.cjs +35 -9
  36. package/src/diagnostics/debugLog.cjs +405 -0
  37. package/src/handlers/command.handler.js +1 -0
  38. package/src/handlers/group.handler.js +32 -1
  39. package/src/handlers/message.handler.js +53 -17
  40. package/src/middleware/antispam.middleware.js +95 -48
  41. package/src/panel/feedback.cjs +32 -5
  42. package/src/panel/one-time-code.cjs +156 -0
  43. package/src/panel/password-reset.cjs +187 -91
  44. package/src/panel/recovery-email.cjs +333 -0
  45. package/src/routes/dashboard.api.esm.js +267 -20
  46. package/src/services/aiAgent.cjs +25 -3
  47. package/src/services/moderationPolicy.cjs +895 -0
  48. package/src/services/settingsTransfer.cjs +4 -2
  49. package/src/utils/linkedCreds.cjs +22 -0
  50. package/src/utils/logger.cjs +5 -0
  51. package/src/utils/moderationAction.cjs +637 -0
  52. package/src/utils/moderationSummary.cjs +225 -0
  53. package/src/utils/permissions.cjs +70 -0
  54. package/src/utils/permissions.esm.js +48 -8
  55. package/src/utils/storage.cjs +8 -0
  56. package/src/utils/storage.esm.js +4 -0
  57. package/views/login.ejs +100 -28
  58. package/public/dashboard/assets/index-B8E5IYlB.js +0 -540
  59. package/public/dashboard/assets/index-C5D4wzm4.css +0 -2
  60. package/src/commands/group/antiSpam.cjs +0 -97
@@ -0,0 +1,215 @@
1
+ const { getGroupSettings } = require("../../utils/storage.cjs");
2
+ const { buildModerationSummary } = require("../../utils/moderationSummary.cjs");
3
+ const { tr } = require("../../utils/i18n.cjs");
4
+ const {
5
+ applyModerationPolicy,
6
+ applyModerationPreset,
7
+ } = require("../../services/moderationPolicy.cjs");
8
+
9
+ const ENUMS = {
10
+ mode: ["simple", "severity"],
11
+ limitaction: ["KICK", "FLAG"],
12
+ decay: ["off", "expire", "step"],
13
+ membership: ["keep", "clear"],
14
+ merge: ["max", "sum"],
15
+ notify: ["group", "silent"],
16
+ flagged: ["record", "hold", "escalate"],
17
+ preset: ["relaxed", "standard", "strict"],
18
+ "action.antilink": ["DELETE", "WARN", "KICK"],
19
+ "action.media": ["DELETE", "WARN", "KICK"],
20
+ "action.forbidden": ["DELETE", "WARN", "KICK"],
21
+ "action.antispam": ["WARN", "KICK"],
22
+ };
23
+
24
+ const INTS = {
25
+ limit: ["limit", 1, 50],
26
+ decaydays: ["decay.days", 1, 365],
27
+ flagat: ["flagAt", 1, 49],
28
+ kickat: ["kickAt", 2, 50],
29
+ cooldown: ["flag.cooldownMinutes", 0, 10080],
30
+ escalate: ["flag.escalateAfter", 1, 50],
31
+ };
32
+
33
+ const WEIGHTS = ["antilink", "media", "forbidden", "antispam", "manual"];
34
+ const ACTIONS = ["antilink", "media", "forbidden", "antispam"];
35
+
36
+ const FIELD_LIST = [
37
+ "mode",
38
+ "limit",
39
+ "limitaction",
40
+ "decay",
41
+ "decaydays",
42
+ "membership",
43
+ "merge",
44
+ "flagat",
45
+ "kickat",
46
+ ...WEIGHTS.map((name) => `weight.${name}`),
47
+ ...ACTIONS.map((name) => `action.${name}`),
48
+ "notify",
49
+ "mention",
50
+ "cooldown",
51
+ "flagged",
52
+ "escalate",
53
+ "preset",
54
+ ];
55
+
56
+ function assignPath(patch, path, value) {
57
+ const parts = path.split(".");
58
+ let cursor = patch;
59
+ for (let i = 0; i < parts.length - 1; i += 1) {
60
+ cursor[parts[i]] ||= {};
61
+ cursor = cursor[parts[i]];
62
+ }
63
+ cursor[parts[parts.length - 1]] = value;
64
+ }
65
+
66
+ function allowedReply(sock, groupId, allowed) {
67
+ const list = allowed.join(", ");
68
+ return sock.sendMessage(groupId, {
69
+ text: tr(`Invalid value. Available: ${list}`, `قيمة غير صالحة. المتاح: ${list}`),
70
+ });
71
+ }
72
+
73
+ function rangeReply(sock, groupId, min, max) {
74
+ return sock.sendMessage(groupId, {
75
+ text: tr(
76
+ `Give a whole number from ${min} to ${max}.`,
77
+ `يرجى تحديد عدد صحيح من ${min} إلى ${max}.`,
78
+ ),
79
+ });
80
+ }
81
+
82
+ function policyErrorReply(sock, groupId, error) {
83
+ const item = error?.errors?.[0];
84
+ if (item?.code === "conflict") {
85
+ return sock.sendMessage(groupId, {
86
+ text: tr(item.message, "يتعارض هذا الإعداد مع السياسة الحالية."),
87
+ });
88
+ }
89
+ return sock.sendMessage(groupId, {
90
+ text: tr(item?.message || "That value is not allowed.", "هذه القيمة غير مسموحة."),
91
+ });
92
+ }
93
+
94
+ function parsePatch(field, raw) {
95
+ if (ENUMS[field]) {
96
+ const canon = ENUMS[field].find((item) => item.toLowerCase() === raw.toLowerCase());
97
+ if (!canon) return { error: "enum", allowed: ENUMS[field] };
98
+ if (field === "preset") return { preset: canon.toLowerCase() };
99
+ if (field === "limitaction") return { patch: { limitAction: canon } };
100
+ if (field === "merge") return { patch: { hitMerge: canon.toLowerCase() } };
101
+ if (field === "decay") return { patch: { decay: { mode: canon.toLowerCase() } } };
102
+ if (field === "notify") return { patch: { flag: { notify: canon.toLowerCase() } } };
103
+ if (field === "flagged") return { patch: { flag: { whileFlagged: canon.toLowerCase() } } };
104
+ if (field.startsWith("action.")) {
105
+ const feature = field.slice("action.".length);
106
+ return { patch: { features: { [feature]: canon } } };
107
+ }
108
+ return { patch: { [field]: canon.toLowerCase() } };
109
+ }
110
+ if (INTS[field]) {
111
+ const [path, min, max] = INTS[field];
112
+ if (!/^-?\d+$/.test(raw)) return { error: "range", min, max };
113
+ const value = Number(raw);
114
+ if (!Number.isInteger(value) || value < min || value > max) return { error: "range", min, max };
115
+ const patch = {};
116
+ assignPath(patch, path, value);
117
+ return { patch };
118
+ }
119
+ if (field.startsWith("weight.")) {
120
+ const feature = field.slice("weight.".length);
121
+ if (!WEIGHTS.includes(feature)) return { error: "field" };
122
+ if (!/^-?\d+$/.test(raw)) return { error: "range", min: 1, max: 10 };
123
+ const value = Number(raw);
124
+ if (!Number.isInteger(value) || value < 1 || value > 10) return { error: "range", min: 1, max: 10 };
125
+ return { patch: { weights: { [feature]: value } } };
126
+ }
127
+ if (field === "mention") {
128
+ const token = raw.toLowerCase();
129
+ if (!["true", "false", "on", "off"].includes(token)) {
130
+ return { error: "enum", allowed: ["true", "false", "on", "off"] };
131
+ }
132
+ return { patch: { flag: { mentionAdmins: token === "true" || token === "on" } } };
133
+ }
134
+ return { error: "field" };
135
+ }
136
+
137
+ module.exports = {
138
+ name: "policy",
139
+ description: {
140
+ en: "Shows and changes this group's moderation policy.",
141
+ ar: "يعرض سياسة إشراف المجموعة ويغيّرها.",
142
+ },
143
+ usage: {
144
+ en: "policy\npolicy set <field> <value>\npolicy reset",
145
+ ar: "policy\npolicy set <حقل> <قيمة>\npolicy reset",
146
+ },
147
+ chat: "group",
148
+ userAdminRequired: true,
149
+
150
+ async execute(sock, msg, args) {
151
+ const groupId = msg.key.remoteJid;
152
+ const sub = String(args[0] || "").toLowerCase();
153
+
154
+ if (!sub) {
155
+ const settings = getGroupSettings(groupId) || {};
156
+ return sock.sendMessage(groupId, { text: buildModerationSummary(settings) });
157
+ }
158
+
159
+ if (sub === "reset") {
160
+ try {
161
+ applyModerationPreset(groupId, "standard");
162
+ } catch (error) {
163
+ return policyErrorReply(sock, groupId, error);
164
+ }
165
+ return sock.sendMessage(groupId, {
166
+ text: tr(
167
+ "✅ Moderation policy reset to standard.",
168
+ "✅ تمت إعادة سياسة الإشراف إلى الوضع القياسي.",
169
+ ),
170
+ });
171
+ }
172
+
173
+ if (sub !== "set") {
174
+ return sock.sendMessage(groupId, {
175
+ text: tr(
176
+ "Wrong format. Use:\n`!group policy`\n`!group policy set <field> <value>`\n`!group policy reset`",
177
+ "صيغة غير صحيحة. استخدم:\n`!group policy`\n`!group policy set <field> <value>`\n`!group policy reset`",
178
+ ),
179
+ });
180
+ }
181
+
182
+ const field = String(args[1] || "").toLowerCase();
183
+ const raw = args.slice(2).join(" ").trim();
184
+ if (!field || !raw) {
185
+ return sock.sendMessage(groupId, {
186
+ text: tr(
187
+ `Name a field and a value. Available: ${FIELD_LIST.join(", ")}`,
188
+ `حدد الحقل والقيمة. المتاح: ${FIELD_LIST.join(", ")}`,
189
+ ),
190
+ });
191
+ }
192
+
193
+ const parsed = parsePatch(field, raw);
194
+ if (parsed.error === "enum") return allowedReply(sock, groupId, parsed.allowed);
195
+ if (parsed.error === "range") return rangeReply(sock, groupId, parsed.min, parsed.max);
196
+ if (parsed.error) {
197
+ return sock.sendMessage(groupId, {
198
+ text: tr(
199
+ `Unknown field. Available: ${FIELD_LIST.join(", ")}`,
200
+ `حقل غير معروف. المتاح: ${FIELD_LIST.join(", ")}`,
201
+ ),
202
+ });
203
+ }
204
+
205
+ try {
206
+ if (parsed.preset) applyModerationPreset(groupId, parsed.preset);
207
+ else applyModerationPolicy(groupId, parsed.patch);
208
+ } catch (error) {
209
+ return policyErrorReply(sock, groupId, error);
210
+ }
211
+ return sock.sendMessage(groupId, {
212
+ text: tr(`✅ ${field} is now ${raw}.`, `✅ تم تعيين ${field} إلى ${raw}.`),
213
+ });
214
+ },
215
+ };
@@ -1,5 +1,10 @@
1
1
  // file: /commands/promote.js
2
2
  const logger = require("../../utils/logger.cjs");
3
+ const {
4
+ findGroupParticipantSync,
5
+ rosterJidForSync,
6
+ } = require("../../utils/permissions.cjs");
7
+ const { targetFromCommand } = require("../../utils/moderationAction.cjs");
3
8
  const { tr } = require("../../utils/i18n.cjs");
4
9
 
5
10
  module.exports = {
@@ -18,11 +23,8 @@ module.exports = {
18
23
 
19
24
  async execute(sock, msg, args, body, groupMetadata) {
20
25
  const groupId = msg.key.remoteJid;
21
-
22
- // Logic to identify the target user from mention or reply
23
- const targetJid =
24
- msg.message?.extendedTextMessage?.contextInfo?.mentionedJid?.[0] ||
25
- msg.message?.extendedTextMessage?.contextInfo?.participant;
26
+ const target = targetFromCommand(msg);
27
+ const targetJid = target?.jid;
26
28
 
27
29
  if (!targetJid) {
28
30
  return await sock.sendMessage(groupId, {
@@ -33,8 +35,9 @@ module.exports = {
33
35
  });
34
36
  }
35
37
 
36
- // Safety check: Is the target user already an admin?
37
- const targetUser = groupMetadata.participants.find((p) => p.id === targetJid);
38
+ const targetUser = findGroupParticipantSync(groupMetadata, target.candidates);
39
+ const rosterJid = rosterJidForSync(groupMetadata, target.candidates) || targetJid;
40
+
38
41
  if (targetUser && (targetUser.admin === "admin" || targetUser.admin === "superadmin")) {
39
42
  return await sock.sendMessage(groupId, {
40
43
  text: tr(
@@ -46,11 +49,7 @@ module.exports = {
46
49
  }
47
50
 
48
51
  try {
49
- await sock.groupParticipantsUpdate(
50
- groupId,
51
- [targetJid],
52
- "promote", // The action is 'promote'
53
- );
52
+ await sock.groupParticipantsUpdate(groupId, [rosterJid], "promote");
54
53
  await sock.sendMessage(groupId, {
55
54
  text: tr(
56
55
  `👑 @${targetJid.split("@")[0]} is now an admin.`,
@@ -1,5 +1,6 @@
1
1
  // file: /commands/group/rules.js
2
2
  const { getGroupSettings } = require("../../utils/storage.cjs");
3
+ const { buildModerationSummary } = require("../../utils/moderationSummary.cjs");
3
4
  const logger = require("../../utils/logger.cjs");
4
5
  const { tr } = require("../../utils/i18n.cjs");
5
6
 
@@ -21,19 +22,21 @@ module.exports = {
21
22
  try {
22
23
  const settings = getGroupSettings(groupId);
23
24
  const rules = settings.rules;
25
+ const summary = buildModerationSummary(settings);
24
26
 
25
27
  if (rules) {
26
28
  const reply = tr(
27
- `*📜 Rules of ${msg.pushName}'s group:*\n\n${rules}`,
28
- `*📜 قواعد جروب ${msg.pushName}:*\n\n${rules}`,
29
+ `*📜 Rules of ${msg.pushName}'s group:*\n\n${rules}\n\n${summary}`,
30
+ `*📜 قواعد جروب ${msg.pushName}:*\n\n${rules}\n\n${summary}`,
29
31
  );
30
32
  await sock.sendMessage(groupId, { text: reply });
31
33
  } else {
32
34
  await sock.sendMessage(groupId, {
33
- text: tr(
34
- "This group has no rules yet. Admins can set them with `!setrules`.",
35
- "لم يتم تعيين أي قواعد لهذه المجموعة حتى الآن. يمكن للمشرفين تعيينها باستخدام `!setrules`.",
36
- ),
35
+ text:
36
+ tr(
37
+ "This group has no rules yet. Admins can set them with `!setrules`.",
38
+ "لم يتم تعيين أي قواعد لهذه المجموعة حتى الآن. يمكن للمشرفين تعيينها باستخدام `!setrules`.",
39
+ ) + `\n\n${summary}`,
37
40
  });
38
41
  }
39
42
  } catch (error) {
@@ -1,6 +1,7 @@
1
1
  // file: /commands/group/setwarn.js
2
- const { getGroupSettings, saveGroupSettings } = require("../../utils/storage.cjs");
2
+ const { normalizeWarnAction } = require("../../utils/moderationSummary.cjs");
3
3
  const { tr } = require("../../utils/i18n.cjs");
4
+ const { applyModerationPolicy } = require("../../services/moderationPolicy.cjs");
4
5
 
5
6
  module.exports = {
6
7
  name: "setwarn",
@@ -9,8 +10,8 @@ module.exports = {
9
10
  ar: "يضبط نظام التحذيرات التلقائي.",
10
11
  },
11
12
  usage: {
12
- en: "setwarn max <count>\nsetwarn action <KICK|NONE>",
13
- ar: "setwarn max <عدد>\nsetwarn action <KICK|NONE>",
13
+ en: "setwarn max <count>\nsetwarn action <KICK|FLAG>",
14
+ ar: "setwarn max <عدد>\nsetwarn action <KICK|FLAG>",
14
15
  },
15
16
  chat: "group",
16
17
  userAdminRequired: true,
@@ -20,57 +21,46 @@ module.exports = {
20
21
  const subCommand = args[0]?.toLowerCase();
21
22
  const value = args[1];
22
23
 
23
- const settings = getGroupSettings(groupId);
24
- if (!settings.warn_system) {
25
- settings.warn_system = { max_warnings: 3, action: "NONE" };
26
- }
27
-
28
- const warnConfig = settings.warn_system;
29
-
30
24
  switch (subCommand) {
31
25
  case "max": {
32
26
  const max = parseInt(value, 10);
33
- if (isNaN(max) || max < 1) {
27
+ if (!Number.isInteger(max) || max < 1 || max > 50) {
34
28
  return await sock.sendMessage(groupId, {
35
29
  text: tr(
36
- "Give a valid whole number for the warning limit.",
37
- "يرجى تحديد عدد صحيح وصالح للحد الأقصى للتحذيرات.",
30
+ "Give a whole number from 1 to 50 for the warning limit.",
31
+ "يرجى تحديد عدد صحيح من 1 إلى 50 للحد الأقصى للتحذيرات.",
38
32
  ),
39
33
  });
40
34
  }
41
- warnConfig.max_warnings = max;
42
- await sock.sendMessage(groupId, {
35
+ applyModerationPolicy(groupId, { limit: max });
36
+ return await sock.sendMessage(groupId, {
43
37
  text: tr(`✅ The warning limit is now ${max}.`, `✅ تم تعيين الحد الأقصى للتحذيرات إلى ${max}.`),
44
38
  });
45
- break;
46
39
  }
47
40
 
48
41
  case "action": {
49
- const action = value?.toUpperCase();
50
- if (action !== "KICK" && action !== "NONE") {
42
+ const action = normalizeWarnAction(value);
43
+ if (!action) {
51
44
  return await sock.sendMessage(groupId, {
52
45
  text: tr(
53
- "Invalid action. Available: `KICK`, `NONE`",
54
- "الإجراء غير صالح. الإجراءات المتاحة: `KICK`, `NONE`",
46
+ "Invalid action. Available: `KICK`, `FLAG`",
47
+ "الإجراء غير صالح. الإجراءات المتاحة: `KICK`, `FLAG`",
55
48
  ),
56
49
  });
57
50
  }
58
- warnConfig.action = action;
59
- await sock.sendMessage(groupId, {
51
+ applyModerationPolicy(groupId, { limitAction: action });
52
+ return await sock.sendMessage(groupId, {
60
53
  text: tr(`✅ The automatic action is now ${action}.`, `✅ تم تعيين الإجراء التلقائي إلى ${action}.`),
61
54
  });
62
- break;
63
55
  }
64
56
 
65
57
  default:
66
58
  return await sock.sendMessage(groupId, {
67
59
  text: tr(
68
- "Wrong format. Use:\n`!setwarn max <number>`\n`!setwarn action <KICK|NONE>`",
69
- "صيغة غير صحيحة. استخدم:\n`!setwarn max <number>`\n`!setwarn action <KICK|NONE>`",
60
+ "Wrong format. Use:\n`!setwarn max <number>`\n`!setwarn action <KICK|FLAG>`",
61
+ "صيغة غير صحيحة. استخدم:\n`!setwarn max <number>`\n`!setwarn action <KICK|FLAG>`",
70
62
  ),
71
63
  });
72
64
  }
73
-
74
- saveGroupSettings(groupId, settings);
75
65
  },
76
66
  };
@@ -1,12 +1,11 @@
1
1
  // file: /commands/warn.js (Corrected Logic Flow)
2
- const { getGroupSettings } = require("../../utils/storage.cjs"); // <-- 1. Import getGroupSettings
3
- const { getUserWarnings, saveUserWarnings, clearUserWarnings } = require("../../utils/storage.cjs");
4
2
  const logger = require("../../utils/logger.cjs");
5
3
  const {
6
4
  hasBotPrivilegesSync,
7
5
  isAdminInGroupSync,
8
6
  sameUserSync,
9
7
  } = require("../../utils/permissions.cjs");
8
+ const { enforceGroupRule, senderCandidates } = require("../../utils/moderationAction.cjs");
10
9
  const { tr } = require("../../utils/i18n.cjs");
11
10
 
12
11
  module.exports = {
@@ -25,7 +24,6 @@ module.exports = {
25
24
  async execute(sock, msg, args, _body, groupMetadata) {
26
25
  try {
27
26
  const groupId = msg.key.remoteJid;
28
- const senderId = msg.key.participant;
29
27
  const mentionedJid = msg.message?.extendedTextMessage?.contextInfo?.mentionedJid?.[0];
30
28
  const reason = args.slice(1).join(" ");
31
29
 
@@ -56,67 +54,19 @@ module.exports = {
56
54
  });
57
55
  }
58
56
 
59
- // --- 2. Add the New Warning ---
60
- const userWarnings = getUserWarnings(groupId, mentionedJid);
61
- userWarnings.push({
62
- reason: reason,
63
- by: senderId,
64
- date: new Date().toISOString(),
57
+ const actor = senderCandidates(msg, sock)[0] || msg.key.participant;
58
+ await enforceGroupRule(sock, {
59
+ msg,
60
+ groupMetadata,
61
+ groupId,
62
+ rule: "warn",
63
+ detail: reason,
64
+ warningReason: reason,
65
+ recordWarning: true,
66
+ deleteMessage: false,
67
+ targetCandidates: [mentionedJid],
68
+ actorJid: actor,
65
69
  });
66
- saveUserWarnings(groupId, mentionedJid, userWarnings);
67
-
68
- const newWarnCount = userWarnings.length;
69
-
70
- // --- 3. Send Confirmation & Check for Action ---
71
- const replyText = tr(
72
- `✅ @${mentionedJid.split("@")[0]} has been warned.\n*Reason:* ${reason}`,
73
- `✅ تم توجيه تحذير إلى @${mentionedJid.split("@")[0]}.\n` + `*السبب:* ${reason}`,
74
- );
75
-
76
- await sock.sendMessage(groupId, {
77
- text: replyText,
78
- mentions: [mentionedJid],
79
- });
80
-
81
- const warnConfig = getGroupSettings(groupId)?.warn_system;
82
-
83
- if (warnConfig && warnConfig.action === "KICK" && newWarnCount >= warnConfig.max_warnings) {
84
- await sock.sendMessage(groupId, {
85
- text: tr(
86
- `🚫 @${
87
- mentionedJid.split("@")[0]
88
- } reached the warning limit (${newWarnCount}/${warnConfig.max_warnings}) and will be removed.`,
89
- `🚫 لقد وصل العضو @${
90
- mentionedJid.split("@")[0]
91
- } إلى الحد الأقصى للتحذيرات (${newWarnCount}/${warnConfig.max_warnings}). سيتم حذفه.`,
92
- ),
93
- mentions: [mentionedJid],
94
- });
95
-
96
- try {
97
- // Kick the user and then clear their warnings
98
- await sock.groupParticipantsUpdate(groupId, [mentionedJid], "remove");
99
- clearUserWarnings(groupId, mentionedJid);
100
- logger.info(
101
- `[Warn Kick] Kicked and cleared warnings for ${mentionedJid} from ${groupId}`,
102
- );
103
- } catch (kickError) {
104
- logger.error({ err: kickError }, "Failed to kick user after max warnings");
105
- await sock.sendMessage(groupId, {
106
- text: tr(
107
- "I tried to remove the member, but I don't have enough permissions.",
108
- "حاولت حذف العضو ولكني لا أملك صلاحية كافية لذلك.",
109
- ),
110
- });
111
- }
112
- } else {
113
- // If no action is taken, just inform about the new count
114
- await sock.sendMessage(groupId, {
115
- text:
116
- tr("*Warnings so far:* ", "*إجمالي التحذيرات الآن:* ") +
117
- `${newWarnCount}${warnConfig ? `/${warnConfig.max_warnings}` : ""}`,
118
- });
119
- }
120
70
  } catch (error) {
121
71
  logger.error({ err: error }, "An error occurred in the !warn command.");
122
72
  await sock.sendMessage(msg.key.remoteJid, {
@@ -13,6 +13,7 @@ const {
13
13
  isOwnerJidSync,
14
14
  isAdminInGroupSync,
15
15
  isBotAdminInGroupSync,
16
+ getSenderCandidatesSync,
16
17
  } = require("../utils/permissions.cjs");
17
18
  const normalizeJid = require("../utils/normalizeJid.cjs");
18
19
  const { langForCommand, withLang, tr } = require("../utils/i18n.cjs");
@@ -113,10 +114,12 @@ async function runSubCommand(sock, msg, args, body, groupMetadata, subCommand) {
113
114
  }
114
115
 
115
116
  const senderId = normalizeJid(msg.key.participant || msg.key.remoteJid);
117
+ const senderIds = getSenderCandidatesSync(msg, sock);
118
+ const senderCandidates = senderIds.length ? senderIds : [senderId].filter(Boolean);
116
119
  // Centralized owner check — covers the bot itself, LID<->PN,
117
120
  // and the user_metadata table.
118
- const isOwner = msg.key.fromMe || isOwnerJidSync(senderId);
119
- const isSenderAdmin = isAdminInGroupSync(groupMetadata, senderId);
121
+ const isOwner = msg.key.fromMe || senderCandidates.some(isOwnerJidSync);
122
+ const isSenderAdmin = senderCandidates.some((id) => isAdminInGroupSync(groupMetadata, id));
120
123
 
121
124
  // "group:kick" — the flat key runtime-config uses for sub-commands, so a
122
125
  // level changed from the dashboard applies here too.