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
@@ -4,7 +4,14 @@ const { getGroupSettings, saveGroupSettings } = require("../utils/storage.cjs");
4
4
  const { isOwnerJidSync, isAdminInGroupSync } = require("../utils/permissions.cjs");
5
5
  const { visibleText } = require("../utils/messageContent.cjs");
6
6
  const { resolveGroupMetadata } = require("../utils/groupMetadataCache.cjs");
7
+ const { enforceGroupRule, senderCandidates } = require("../utils/moderationAction.cjs");
8
+ const {
9
+ featureActionOf,
10
+ normalizeFeatureAction,
11
+ policyFromFeatureAction,
12
+ } = require("../utils/moderationSummary.cjs");
7
13
  const { tr } = require("../utils/i18n.cjs");
14
+ const { applyModerationPolicy } = require("../services/moderationPolicy.cjs");
8
15
 
9
16
  // الهيكل الافتراضي لإعدادات المراقبة
10
17
  const defaultModSettings = {
@@ -55,21 +62,21 @@ module.exports = {
55
62
  ar: "يتحكم في إعدادات الإشراف على المجموعة.",
56
63
  },
57
64
  usage: {
58
- en: "mod status\nmod <enable|disable> <antiLink|antiSpam|forbiddenWords>\nmod words <add|remove> <word>\nmod words list",
59
- ar: "mod status\nmod <enable|disable> <antiLink|antiSpam|forbiddenWords>\nmod words <add|remove> <الكلمة>\nmod words list",
65
+ en: "mod status\nmod <enable|disable> <antiLink|antiSpam|forbiddenWords>\nmod action <antiLink|forbiddenWords> <DELETE|WARN|KICK>\nmod action antiSpam <WARN|KICK>\nmod words <add|remove> <word>\nmod words list",
66
+ ar: "mod status\nmod <enable|disable> <antiLink|antiSpam|forbiddenWords>\nmod action <antiLink|forbiddenWords> <DELETE|WARN|KICK>\nmod action antiSpam <WARN|KICK>\nmod words <add|remove> <الكلمة>\nmod words list",
60
67
  },
61
68
  chat: "group", // يعمل في الجروبات فقط
62
69
  botAdminRequired: false, // لا يتطلب أن يكون البوت مشرفًا لتغيير الإعدادات
63
70
 
64
71
  async execute(sock, msg, args) {
65
72
  const groupId = msg.key.remoteJid;
66
- const senderId = msg.key.participant;
73
+ const senderIds = senderCandidates(msg, sock);
67
74
 
68
75
  // التحقق من صلاحيات المشرف (LID-aware via central module). Owners can
69
76
  // also drive moderation settings.
70
- const groupMetadata = await sock.groupMetadata(groupId);
71
- const senderIsAdmin = isAdminInGroupSync(groupMetadata, senderId);
72
- const isOwner = msg.key.fromMe || isOwnerJidSync(senderId);
77
+ const groupMetadata = await resolveGroupMetadata(sock, groupId);
78
+ const senderIsAdmin = senderIds.some((id) => isAdminInGroupSync(groupMetadata, id));
79
+ const isOwner = msg.key.fromMe || senderIds.some(isOwnerJidSync);
73
80
  if (!senderIsAdmin && !isOwner) {
74
81
  return sock.sendMessage(
75
82
  groupId,
@@ -130,13 +137,73 @@ module.exports = {
130
137
  );
131
138
  break;
132
139
 
140
+ case "action": {
141
+ if (!feature) {
142
+ return sock.sendMessage(
143
+ groupId,
144
+ {
145
+ text: tr(
146
+ `⚠️ There is no feature called "${args[1] || ""}".`,
147
+ `⚠️ الميزة "${args[1] || ""}" غير موجودة.`,
148
+ ),
149
+ },
150
+ { quoted: msg },
151
+ );
152
+ }
153
+ const allowDelete = feature !== "antiSpam";
154
+ const action = normalizeFeatureAction(args[2], { allowDelete });
155
+ if (!action) {
156
+ return sock.sendMessage(
157
+ groupId,
158
+ {
159
+ text: tr(
160
+ allowDelete
161
+ ? "Invalid action. Available: `DELETE`, `WARN`, `KICK`"
162
+ : "Invalid action. Available: `WARN`, `KICK`",
163
+ allowDelete
164
+ ? "الإجراء غير صالح. الإجراءات المتاحة: `DELETE`, `WARN`, `KICK`"
165
+ : "الإجراء غير صالح. الإجراءات المتاحة: `WARN`, `KICK`",
166
+ ),
167
+ },
168
+ { quoted: msg },
169
+ );
170
+ }
171
+ const featureName =
172
+ feature === "antiLink" ? "antilink" : feature === "antiSpam" ? "antispam" : "forbidden";
173
+ try {
174
+ applyModerationPolicy(groupId, { features: { [featureName]: action } });
175
+ } catch (error) {
176
+ return sock.sendMessage(
177
+ groupId,
178
+ {
179
+ text: tr(
180
+ error.errors?.[0]?.message || "That action is not allowed.",
181
+ "هذا الإجراء غير مسموح.",
182
+ ),
183
+ },
184
+ { quoted: msg },
185
+ );
186
+ }
187
+ await sock.sendMessage(
188
+ groupId,
189
+ { text: tr(`✅ *${feature}* action is now ${action}.`, `✅ تم تعيين إجراء *${feature}* إلى ${action}.`) },
190
+ { quoted: msg },
191
+ );
192
+ break;
193
+ }
194
+
133
195
  case "status": {
134
196
  let statusText = tr("📊 *Moderation settings* 📊\n\n", "📊 *حالة إعدادات المراقبة* 📊\n\n");
197
+ const actionOf = {
198
+ antiLink: featureActionOf(settings, "antilink"),
199
+ antiSpam: featureActionOf(settings, "antispam"),
200
+ forbiddenWords: featureActionOf(settings, "forbidden"),
201
+ };
135
202
  for (const key of Object.values(FEATURE_KEYS)) {
136
203
  const status = featureEnabled(settings, key)
137
204
  ? tr("✅ on", "✅ مفعل")
138
205
  : tr("❌ off", "❌ معطل");
139
- statusText += `› *${key}*: ${status}\n`;
206
+ statusText += `› *${key}*: ${status} · ${actionOf[key]}\n`;
140
207
  }
141
208
  statusText += tr(
142
209
  `\n- To see the forbidden words, type: \`!mod words list\``,
@@ -203,6 +270,7 @@ module.exports = {
203
270
  "🤖 *Moderation commands*\n\n" +
204
271
  "• `!mod enable <feature>`\nTurn a feature on (antilink, antispam, forbiddenwords)\n\n" +
205
272
  "• `!mod disable <feature>`\nTurn a feature off.\n\n" +
273
+ "• `!mod action <feature> <DELETE|WARN|KICK>`\nSet the feature action (antiSpam: WARN|KICK).\n\n" +
206
274
  "• `!mod status`\nShow which features are on.\n\n" +
207
275
  "• `!mod words add <word>`\nAdd a forbidden word.\n\n" +
208
276
  "• `!mod words remove <word>`\nRemove a forbidden word.\n\n" +
@@ -210,6 +278,7 @@ module.exports = {
210
278
  "🤖 *أوامر التحكم في المراقبة*\n\n" +
211
279
  "• `!mod enable <feature>`\nلتفعيل ميزة (antilink, antispam, forbiddenwords)\n\n" +
212
280
  "• `!mod disable <feature>`\nلتعطيل ميزة.\n\n" +
281
+ "• `!mod action <feature> <DELETE|WARN|KICK>`\nتعيين إجراء الميزة (antiSpam: WARN|KICK).\n\n" +
213
282
  "• `!mod status`\nلعرض حالة الميزات الحالية.\n\n" +
214
283
  "• `!mod words add <word>`\nلإضافة كلمة ممنوعة.\n\n" +
215
284
  "• `!mod words remove <word>`\nلإزالة كلمة ممنوعة.\n\n" +
@@ -222,22 +291,24 @@ module.exports = {
222
291
  },
223
292
  };
224
293
 
294
+ function detectForbiddenWords(msg, settings) {
295
+ const groupId = msg?.key?.remoteJid;
296
+ if (!groupId?.endsWith("@g.us")) return null;
297
+ const config = settings?.moderation?.forbiddenWords;
298
+ if (!config?.enabled || !Array.isArray(config.list) || !config.list.length) return null;
299
+ const body = visibleText(msg.message).toLowerCase();
300
+ if (!body || !config.list.some((word) => word && body.includes(String(word).toLowerCase()))) {
301
+ return null;
302
+ }
303
+ return { rule: "forbidden", reason: "forbidden-word" };
304
+ }
305
+
225
306
  async function handleForbiddenWords(sock, msg) {
226
307
  const groupId = msg.key.remoteJid;
227
308
  if (!groupId?.endsWith("@g.us")) return false;
228
309
 
229
310
  const settings = getGroupSettings(groupId) || {};
230
- const config = settings.moderation?.forbiddenWords;
231
- if (!config?.enabled || !Array.isArray(config.list) || !config.list.length) return false;
232
-
233
- const body = visibleText(msg.message).toLowerCase();
234
- if (!body || !config.list.some((word) => word && body.includes(String(word).toLowerCase()))) {
235
- return false;
236
- }
237
-
238
- const senderId = msg.key.participant || msg.key.remoteJid;
239
- const senderIds = [senderId, msg.key.participantAlt, msg.key.participantPn].filter(Boolean);
240
- // Cache-first: this runs on every group message while forbidden words are on.
311
+ const senderIds = senderCandidates(msg, sock);
241
312
  const groupMetadata = await resolveGroupMetadata(sock, groupId);
242
313
  if (
243
314
  msg.key.fromMe ||
@@ -247,15 +318,19 @@ async function handleForbiddenWords(sock, msg) {
247
318
  return false;
248
319
  }
249
320
 
250
- await sock.sendMessage(groupId, { delete: msg.key });
251
- await sock.sendMessage(groupId, {
252
- text: tr(
253
- `🚫 @${senderId.split("@")[0]}, that message had a forbidden word in it.`,
254
- `🚫 يا @${senderId.split("@")[0]}، الرسالة فيها كلمة ممنوعة.`,
255
- ),
256
- mentions: [senderId],
321
+ const hit = detectForbiddenWords(msg, settings);
322
+ if (!hit) return false;
323
+ const policy = policyFromFeatureAction(featureActionOf(settings, "forbidden"));
324
+ const result = await enforceGroupRule(sock, {
325
+ msg,
326
+ groupMetadata,
327
+ rule: "forbidden",
328
+ warningReason: hit.reason,
329
+ ...policy,
330
+ targetCandidates: senderIds,
257
331
  });
258
- return true;
332
+ return Boolean(result.acted);
259
333
  }
260
334
 
261
335
  module.exports.handleForbiddenWords = handleForbiddenWords;
336
+ module.exports.detectForbiddenWords = detectForbiddenWords;