levix-bot 4.7.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.
- package/README.md +21 -7
- package/SETUP.md +21 -2
- package/app.cjs +69 -23
- package/package.json +3 -2
- package/public/dashboard/assets/index-B1sOW2VX.js +561 -0
- package/public/dashboard/assets/index-CK8osB4o.css +2 -0
- package/public/dashboard/index.html +2 -2
- package/public/dashboard.css +50 -0
- package/public/dashboard.js +25 -2
- package/public/gateway-i18n.js +26 -0
- package/src/bootstrap/session-startup-policy.js +6 -6
- package/src/commands/group/antilink.cjs +82 -59
- package/src/commands/group/antispam.cjs +112 -0
- package/src/commands/group/clearwarns.cjs +6 -6
- package/src/commands/group/demote.cjs +11 -13
- package/src/commands/group/flagged.cjs +52 -0
- package/src/commands/group/kick.cjs +25 -15
- package/src/commands/group/media.cjs +65 -29
- package/src/commands/group/policy.cjs +215 -0
- package/src/commands/group/promote.cjs +11 -12
- package/src/commands/group/rules.cjs +9 -6
- package/src/commands/group/setwarn.cjs +17 -27
- package/src/commands/group/warn.cjs +13 -63
- package/src/commands/group.cjs +5 -2
- package/src/commands/md.cjs +44 -0
- package/src/commands/mod.cjs +101 -26
- package/src/commands/translate.cjs +585 -0
- package/src/config/ai-identity.cjs +53 -1
- package/src/config/ai-persona.md +32 -73
- package/src/config/defaults.cjs +3 -0
- package/src/config/secrets.cjs +71 -3
- package/src/config/settings.cjs +22 -1
- package/src/core/socket.js +27 -5
- package/src/db/db.cjs +66 -0
- package/src/db/store.cjs +264 -16
- package/src/diagnostics/crashReports.cjs +35 -9
- package/src/diagnostics/debugLog.cjs +405 -0
- package/src/handlers/command.handler.js +3 -1
- package/src/handlers/group.handler.js +32 -1
- package/src/handlers/message.handler.js +53 -17
- package/src/middleware/antispam.middleware.js +95 -48
- package/src/panel/feedback.cjs +32 -5
- package/src/panel/one-time-code.cjs +156 -0
- package/src/panel/password-reset.cjs +187 -91
- package/src/panel/recovery-email.cjs +333 -0
- package/src/routes/dashboard.api.esm.js +341 -29
- package/src/services/aiAgent.cjs +25 -3
- package/src/services/moderationPolicy.cjs +895 -0
- package/src/services/settingsTransfer.cjs +4 -2
- package/src/utils/linkedCreds.cjs +22 -0
- package/src/utils/logger.cjs +93 -34
- package/src/utils/markdownParser.cjs +208 -136
- package/src/utils/moderationAction.cjs +637 -0
- package/src/utils/moderationSummary.cjs +225 -0
- package/src/utils/permissions.cjs +70 -0
- package/src/utils/permissions.esm.js +48 -8
- package/src/utils/storage.cjs +8 -0
- package/src/utils/storage.esm.js +4 -0
- package/views/login.ejs +100 -28
- package/public/dashboard/assets/index-RnT7DAde.js +0 -540
- package/public/dashboard/assets/index-UcqCdCvG.css +0 -2
- package/src/commands/group/antiSpam.cjs +0 -97
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const { getGroupSettings, saveGroupSettings } = require("../../utils/storage.cjs");
|
|
2
|
+
const { featureActionOf, normalizeFeatureAction } = require("../../utils/moderationSummary.cjs");
|
|
3
|
+
const { tr } = require("../../utils/i18n.cjs");
|
|
4
|
+
const { applyModerationPolicy } = require("../../services/moderationPolicy.cjs");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
name: "antispam",
|
|
8
|
+
description: {
|
|
9
|
+
en: "Controls anti-spam in the group.",
|
|
10
|
+
ar: "يتحكم في مكافحة الإزعاج في المجموعة.",
|
|
11
|
+
},
|
|
12
|
+
usage: {
|
|
13
|
+
en: "antispam [status]\nantispam <on|off>\nantispam action <WARN|KICK>\nantispam window <seconds>\nantispam count <number>",
|
|
14
|
+
ar: "antispam [status]\nantispam <on|off>\nantispam action <WARN|KICK>\nantispam window <ثوان>\nantispam count <عدد>",
|
|
15
|
+
},
|
|
16
|
+
chat: "group",
|
|
17
|
+
userAdminRequired: true,
|
|
18
|
+
|
|
19
|
+
async execute(sock, msg, args) {
|
|
20
|
+
const groupId = msg.key.remoteJid;
|
|
21
|
+
const subCommand = args[0] ? args[0].toLowerCase() : "status";
|
|
22
|
+
const settings = getGroupSettings(groupId) || {};
|
|
23
|
+
if (!settings.antispam || typeof settings.antispam !== "object") {
|
|
24
|
+
settings.antispam = { enabled: false, time_window: 10, message_count: 5 };
|
|
25
|
+
}
|
|
26
|
+
const spam = settings.antispam;
|
|
27
|
+
|
|
28
|
+
switch (subCommand) {
|
|
29
|
+
case "on":
|
|
30
|
+
spam.enabled = true;
|
|
31
|
+
await sock.sendMessage(groupId, {
|
|
32
|
+
text: tr("✅ Anti-spam is on.", "✅ تم تفعيل مكافحة الإزعاج."),
|
|
33
|
+
});
|
|
34
|
+
break;
|
|
35
|
+
case "off":
|
|
36
|
+
spam.enabled = false;
|
|
37
|
+
await sock.sendMessage(groupId, {
|
|
38
|
+
text: tr("☑️ Anti-spam is off.", "☑️ تم تعطيل مكافحة الإزعاج."),
|
|
39
|
+
});
|
|
40
|
+
break;
|
|
41
|
+
case "action": {
|
|
42
|
+
const action = normalizeFeatureAction(args[1], { allowDelete: false });
|
|
43
|
+
if (!action) {
|
|
44
|
+
return await sock.sendMessage(groupId, {
|
|
45
|
+
text: tr(
|
|
46
|
+
"Invalid action. Available: `WARN`, `KICK`",
|
|
47
|
+
"الإجراء غير صالح. الإجراءات المتاحة: `WARN`, `KICK`",
|
|
48
|
+
),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
applyModerationPolicy(groupId, { features: { antispam: action } });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return await sock.sendMessage(groupId, {
|
|
55
|
+
text: tr(
|
|
56
|
+
error.errors?.[0]?.message || "That action is not allowed.",
|
|
57
|
+
"هذا الإجراء غير مسموح.",
|
|
58
|
+
),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
await sock.sendMessage(groupId, {
|
|
62
|
+
text: tr(`✅ Anti-spam action is now ${action}.`, `✅ تم تعيين إجراء مكافحة الإزعاج إلى ${action}.`),
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
case "window": {
|
|
67
|
+
const seconds = parseInt(args[1], 10);
|
|
68
|
+
if (!Number.isFinite(seconds) || seconds < 1 || seconds > 600) {
|
|
69
|
+
return await sock.sendMessage(groupId, {
|
|
70
|
+
text: tr(
|
|
71
|
+
"Give a window between 1 and 600 seconds.",
|
|
72
|
+
"يرجى تحديد مدة بين 1 و 600 ثانية.",
|
|
73
|
+
),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
spam.time_window = seconds;
|
|
77
|
+
await sock.sendMessage(groupId, {
|
|
78
|
+
text: tr(`✅ Anti-spam window is now ${seconds}s.`, `✅ أصبحت مدة الرصد ${seconds} ثانية.`),
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "count": {
|
|
83
|
+
const count = parseInt(args[1], 10);
|
|
84
|
+
if (!Number.isFinite(count) || count < 2 || count > 100) {
|
|
85
|
+
return await sock.sendMessage(groupId, {
|
|
86
|
+
text: tr(
|
|
87
|
+
"Give a message count between 2 and 100.",
|
|
88
|
+
"يرجى تحديد عدد رسائل بين 2 و 100.",
|
|
89
|
+
),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
spam.message_count = count;
|
|
93
|
+
await sock.sendMessage(groupId, {
|
|
94
|
+
text: tr(`✅ Anti-spam limit is now ${count} messages.`, `✅ أصبح حد الرسائل ${count}.`),
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
default: {
|
|
99
|
+
const state = spam.enabled ? tr("on ✅", "مفعل ✅") : tr("off ☑️", "معطل ☑️");
|
|
100
|
+
const action = featureActionOf(settings, "antispam");
|
|
101
|
+
await sock.sendMessage(groupId, {
|
|
102
|
+
text: tr(
|
|
103
|
+
`*Anti-spam:*\n\nState: ${state}\nWindow: ${spam.time_window ?? 10}s\nCount: ${spam.message_count ?? 5}\nAction: ${action}`,
|
|
104
|
+
`*مكافحة الإزعاج:*\n\nالحالة: ${state}\nالمدة: ${spam.time_window ?? 10}ث\nالعدد: ${spam.message_count ?? 5}\nالإجراء: ${action}`,
|
|
105
|
+
),
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
saveGroupSettings(groupId, settings);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// file: /commands/clearwarns.js
|
|
2
|
-
const { clearUserWarnings } = require("../../utils/storage.cjs");
|
|
3
2
|
const logger = require("../../utils/logger.cjs");
|
|
3
|
+
const { clearMemberModeration, targetFromCommand } = require("../../utils/moderationAction.cjs");
|
|
4
4
|
const { tr } = require("../../utils/i18n.cjs");
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
name: "clearwarns",
|
|
8
8
|
description: {
|
|
9
|
-
en: "Clears all of a member's warnings.",
|
|
10
|
-
ar: "يمسح كل تحذيرات عضو
|
|
9
|
+
en: "Clears all of a member's warnings and dismisses their flag.",
|
|
10
|
+
ar: "يمسح كل تحذيرات عضو معيّن ويلغي تعليمه للمراجعة.",
|
|
11
11
|
},
|
|
12
12
|
usage: {
|
|
13
13
|
en: "clearwarns @member",
|
|
@@ -19,7 +19,8 @@ module.exports = {
|
|
|
19
19
|
async execute(sock, msg) {
|
|
20
20
|
try {
|
|
21
21
|
const groupId = msg.key.remoteJid;
|
|
22
|
-
const
|
|
22
|
+
const target = targetFromCommand(msg);
|
|
23
|
+
const mentionedJid = target?.jid;
|
|
23
24
|
|
|
24
25
|
if (!mentionedJid) {
|
|
25
26
|
return await sock.sendMessage(groupId, {
|
|
@@ -30,8 +31,7 @@ module.exports = {
|
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
clearUserWarnings(groupId, mentionedJid);
|
|
34
|
+
clearMemberModeration(groupId, mentionedJid);
|
|
35
35
|
|
|
36
36
|
const replyText = tr(
|
|
37
37
|
`✅ Cleared every warning for @${mentionedJid.split("@")[0]}.`,
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// file: /commands/demote.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
|
-
|
|
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
|
-
|
|
37
|
-
const
|
|
38
|
+
const targetUser = findGroupParticipantSync(groupMetadata, target.candidates);
|
|
39
|
+
const rosterJid = rosterJidForSync(groupMetadata, target.candidates) || targetJid;
|
|
40
|
+
|
|
38
41
|
if (!targetUser || !targetUser.admin) {
|
|
39
42
|
return await sock.sendMessage(groupId, {
|
|
40
43
|
text: tr(
|
|
@@ -45,7 +48,6 @@ module.exports = {
|
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
// Safety check: Cannot demote the group creator
|
|
49
51
|
if (targetUser.admin === "superadmin") {
|
|
50
52
|
return await sock.sendMessage(groupId, {
|
|
51
53
|
text: tr("The group's creator can't be demoted.", "لا يمكن عزل منشئ المجموعة."),
|
|
@@ -53,11 +55,7 @@ module.exports = {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
try {
|
|
56
|
-
await sock.groupParticipantsUpdate(
|
|
57
|
-
groupId,
|
|
58
|
-
[targetJid],
|
|
59
|
-
"demote", // The action is 'demote'
|
|
60
|
-
);
|
|
58
|
+
await sock.groupParticipantsUpdate(groupId, [rosterJid], "demote");
|
|
61
59
|
await sock.sendMessage(groupId, {
|
|
62
60
|
text: tr(
|
|
63
61
|
`👤 @${targetJid.split("@")[0]} is no longer an admin.`,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { listModerationFlags } = require("../../utils/storage.cjs");
|
|
2
|
+
const logger = require("../../utils/logger.cjs");
|
|
3
|
+
const { tr } = require("../../utils/i18n.cjs");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
name: "flagged",
|
|
7
|
+
description: {
|
|
8
|
+
en: "Lists members waiting for admin review.",
|
|
9
|
+
ar: "يعرض الأعضاء بانتظار مراجعة المشرف.",
|
|
10
|
+
},
|
|
11
|
+
usage: {
|
|
12
|
+
en: "flagged",
|
|
13
|
+
ar: "flagged",
|
|
14
|
+
},
|
|
15
|
+
chat: "group",
|
|
16
|
+
userAdminRequired: true,
|
|
17
|
+
|
|
18
|
+
async execute(sock, msg) {
|
|
19
|
+
const groupId = msg.key.remoteJid;
|
|
20
|
+
try {
|
|
21
|
+
const flags = listModerationFlags(groupId);
|
|
22
|
+
if (!flags.length) {
|
|
23
|
+
return await sock.sendMessage(groupId, {
|
|
24
|
+
text: tr("No members are waiting for review.", "لا يوجد أعضاء بانتظار المراجعة."),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const mentions = flags.map((row) => row.user_id);
|
|
28
|
+
const lines = [
|
|
29
|
+
tr(
|
|
30
|
+
`*Flagged members* (${flags.length})`,
|
|
31
|
+
`*الأعضاء المعلَّمون للمراجعة* (${flags.length})`,
|
|
32
|
+
),
|
|
33
|
+
];
|
|
34
|
+
for (const row of flags) {
|
|
35
|
+
const tag = `@${String(row.user_id).split("@")[0]}`;
|
|
36
|
+
const when = row.flagged_at ? new Date(row.flagged_at).toISOString() : "";
|
|
37
|
+
lines.push(
|
|
38
|
+
tr(
|
|
39
|
+
`• ${tag} — warnings ${row.warn_count}, last: ${row.last_rule || "—"}${when ? `, ${when}` : ""}`,
|
|
40
|
+
`• ${tag} — الإنذارات ${row.warn_count}، آخر مخالفة: ${row.last_rule || "—"}${when ? `، ${when}` : ""}`,
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
await sock.sendMessage(groupId, { text: lines.join("\n"), mentions });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error({ err: error }, "Error in !flagged command");
|
|
47
|
+
await sock.sendMessage(groupId, {
|
|
48
|
+
text: tr("Something went wrong while listing flagged members.", "حدث خطأ أثناء عرض الأعضاء المعلَّمين."),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
isAdminInGroupSync,
|
|
6
6
|
sameUserSync,
|
|
7
7
|
} = require("../../utils/permissions.cjs");
|
|
8
|
+
const { kickGroupMember, targetFromCommand } = require("../../utils/moderationAction.cjs");
|
|
8
9
|
const { tr } = require("../../utils/i18n.cjs");
|
|
9
10
|
|
|
10
11
|
module.exports = {
|
|
@@ -23,17 +24,10 @@ module.exports = {
|
|
|
23
24
|
|
|
24
25
|
async execute(sock, msg, args, body, groupMetadata) {
|
|
25
26
|
const groupId = msg.key.remoteJid;
|
|
26
|
-
|
|
27
|
+
const target = targetFromCommand(msg);
|
|
28
|
+
const targetJid = target?.jid;
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
// 1. Check for mentions
|
|
30
|
-
if (msg.message?.extendedTextMessage?.contextInfo?.mentionedJid?.length > 0) {
|
|
31
|
-
targetJid = msg.message.extendedTextMessage.contextInfo.mentionedJid[0];
|
|
32
|
-
}
|
|
33
|
-
// 2. Check if it's a reply to another message
|
|
34
|
-
else if (msg.message?.extendedTextMessage?.contextInfo?.quotedMessage) {
|
|
35
|
-
targetJid = msg.message.extendedTextMessage.contextInfo.participant;
|
|
36
|
-
} else {
|
|
30
|
+
if (!targetJid) {
|
|
37
31
|
return await sock.sendMessage(groupId, {
|
|
38
32
|
text: tr(
|
|
39
33
|
"Mention the member, or reply to their message, to kick them.",
|
|
@@ -41,23 +35,28 @@ module.exports = {
|
|
|
41
35
|
),
|
|
42
36
|
});
|
|
43
37
|
}
|
|
38
|
+
const targetCandidates = target.candidates;
|
|
44
39
|
|
|
45
40
|
// --- Safety Checks ---
|
|
46
41
|
// Can't kick the bot itself
|
|
47
|
-
if (
|
|
42
|
+
if (
|
|
43
|
+
[sock.user?.id, sock.user?.lid]
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.some((id) => targetCandidates.some((candidate) => sameUserSync(id, candidate)))
|
|
46
|
+
) {
|
|
48
47
|
return await sock.sendMessage(groupId, { text: tr("I can't kick myself.", "لا يمكنني طرد نفسي.") });
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
// Bot owners/admins are privileged across chats and cannot be removed by
|
|
52
51
|
// a group-only admin through an alternate LID/PN representation.
|
|
53
|
-
if (hasBotPrivilegesSync(
|
|
52
|
+
if (targetCandidates.some((candidate) => hasBotPrivilegesSync(candidate))) {
|
|
54
53
|
return await sock.sendMessage(groupId, {
|
|
55
54
|
text: tr("The bot's owner or admins can't be kicked.", "لا يمكن طرد مالك أو مشرف البوت."),
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
// Check if the target is also an admin
|
|
60
|
-
if (isAdminInGroupSync(groupMetadata,
|
|
59
|
+
if (targetCandidates.some((candidate) => isAdminInGroupSync(groupMetadata, candidate))) {
|
|
61
60
|
return await sock.sendMessage(groupId, {
|
|
62
61
|
text: tr("An admin can't kick another admin.", "لا يمكن للمشرف طرد مشرف آخر."),
|
|
63
62
|
});
|
|
@@ -83,8 +82,19 @@ module.exports = {
|
|
|
83
82
|
mentions: [targetJid],
|
|
84
83
|
});
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const result = await kickGroupMember(sock, {
|
|
86
|
+
groupId,
|
|
87
|
+
groupMetadata,
|
|
88
|
+
targetCandidates,
|
|
89
|
+
});
|
|
90
|
+
if (!result.kicked) {
|
|
91
|
+
await sock.sendMessage(groupId, {
|
|
92
|
+
text: tr(
|
|
93
|
+
"Something went wrong while kicking the member. I may not have enough permissions.",
|
|
94
|
+
"حدث خطأ أثناء محاولة طرد العضو. قد تكون صلاحياتي غير كافية.",
|
|
95
|
+
),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
88
98
|
} catch (error) {
|
|
89
99
|
logger.error({ err: error, command: "kick" }, "Error in !kick command");
|
|
90
100
|
await sock.sendMessage(groupId, {
|
|
@@ -4,7 +4,14 @@ const logger = require("../../utils/logger.cjs");
|
|
|
4
4
|
const { isOwnerJidSync, isAdminInGroupSync } = require("../../utils/permissions.cjs");
|
|
5
5
|
const { mediaType } = 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
|
const VALID_TYPES = ["image", "video", "sticker", "audio"];
|
|
10
17
|
|
|
@@ -16,8 +23,8 @@ const command = {
|
|
|
16
23
|
ar: "يتحكم في أنواع الرسائل المسموح بها في المجموعة.",
|
|
17
24
|
},
|
|
18
25
|
usage: {
|
|
19
|
-
en: "media [status]\nmedia <on|off>\nmedia <block|unblock> <image|video|sticker|audio>",
|
|
20
|
-
ar: "media [status]\nmedia <on|off>\nmedia <block|unblock> <image|video|sticker|audio>",
|
|
26
|
+
en: "media [status]\nmedia <on|off>\nmedia action <DELETE|WARN|KICK>\nmedia <block|unblock> <image|video|sticker|audio>",
|
|
27
|
+
ar: "media [status]\nmedia <on|off>\nmedia action <DELETE|WARN|KICK>\nmedia <block|unblock> <image|video|sticker|audio>",
|
|
21
28
|
},
|
|
22
29
|
chat: "group",
|
|
23
30
|
userAdminRequired: true,
|
|
@@ -45,6 +52,31 @@ const command = {
|
|
|
45
52
|
text: tr("☑️ Media control is off.", "☑️ تم تعطيل نظام مراقبة الوسائط."),
|
|
46
53
|
});
|
|
47
54
|
break;
|
|
55
|
+
case "action": {
|
|
56
|
+
const action = normalizeFeatureAction(args[1]);
|
|
57
|
+
if (!action) {
|
|
58
|
+
return await sock.sendMessage(groupId, {
|
|
59
|
+
text: tr(
|
|
60
|
+
"Invalid action. Available: `DELETE`, `WARN`, `KICK`",
|
|
61
|
+
"الإجراء غير صالح. الإجراءات المتاحة: `DELETE`, `WARN`, `KICK`",
|
|
62
|
+
),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
applyModerationPolicy(groupId, { features: { media: action } });
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return await sock.sendMessage(groupId, {
|
|
69
|
+
text: tr(
|
|
70
|
+
error.errors?.[0]?.message || "That action is not allowed.",
|
|
71
|
+
"هذا الإجراء غير مسموح.",
|
|
72
|
+
),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
await sock.sendMessage(groupId, {
|
|
76
|
+
text: tr(`✅ Media action is now ${action}.`, `✅ تم تعيين إجراء الوسائط إلى ${action}.`),
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
48
80
|
case "block": {
|
|
49
81
|
const typeToBlock = args[1] ? args[1].toLowerCase() : "";
|
|
50
82
|
if (!VALID_TYPES.includes(typeToBlock))
|
|
@@ -81,9 +113,10 @@ const command = {
|
|
|
81
113
|
// 'status'
|
|
82
114
|
const state = mediaConfig.enabled ? tr("on ✅", "مفعل ✅") : tr("off ☑️", "معطل ☑️");
|
|
83
115
|
const blocked = mediaConfig.blocked_types.join(", ") || tr("none", "لا يوجد");
|
|
116
|
+
const action = featureActionOf(settings, "media");
|
|
84
117
|
const statusReply = tr(
|
|
85
|
-
`*Media control:*\n\nState: ${state}\nBlocked types: ${blocked}`,
|
|
86
|
-
`*حالة نظام مراقبة الوسائط:*\n\nالحالة: ${state}\nالأنواع الممنوعة: ${blocked}`,
|
|
118
|
+
`*Media control:*\n\nState: ${state}\nAction: ${action}\nBlocked types: ${blocked}`,
|
|
119
|
+
`*حالة نظام مراقبة الوسائط:*\n\nالحالة: ${state}\nالإجراء: ${action}\nالأنواع الممنوعة: ${blocked}`,
|
|
87
120
|
);
|
|
88
121
|
await sock.sendMessage(groupId, { text: statusReply });
|
|
89
122
|
}
|
|
@@ -93,42 +126,45 @@ const command = {
|
|
|
93
126
|
};
|
|
94
127
|
|
|
95
128
|
// --- The Message Handler Logic ---
|
|
129
|
+
function detectMedia(msg, settings) {
|
|
130
|
+
const groupId = msg?.key?.remoteJid;
|
|
131
|
+
if (!groupId?.endsWith("@g.us")) return null;
|
|
132
|
+
const mediaConfig = settings?.media_control;
|
|
133
|
+
if (!mediaConfig?.enabled) return null;
|
|
134
|
+
const blocked = Array.isArray(mediaConfig.blocked_types) ? mediaConfig.blocked_types : [];
|
|
135
|
+
const messageType = mediaType(msg.message);
|
|
136
|
+
if (!messageType || !blocked.includes(messageType)) return null;
|
|
137
|
+
return { rule: "media", reason: `media:${messageType}`, detail: messageType };
|
|
138
|
+
}
|
|
139
|
+
|
|
96
140
|
async function handleMediaControl(sock, msg, _legacyConfig, _normalizeJid) {
|
|
97
141
|
const isGroup = msg.key.remoteJid.endsWith("@g.us");
|
|
98
142
|
if (!isGroup) return false;
|
|
99
143
|
|
|
100
144
|
const groupId = msg.key.remoteJid;
|
|
101
|
-
const settings = getGroupSettings(groupId);
|
|
102
|
-
const mediaConfig = settings.media_control;
|
|
103
|
-
|
|
104
|
-
if (!mediaConfig || !mediaConfig.enabled) return false;
|
|
105
|
-
|
|
145
|
+
const settings = getGroupSettings(groupId) || {};
|
|
106
146
|
const senderId = msg.key.participant || msg.key.remoteJid;
|
|
107
147
|
|
|
108
|
-
// Cache-first: this runs on every group message while media control is on.
|
|
109
148
|
const groupMetadata = await resolveGroupMetadata(sock, groupId);
|
|
110
|
-
const senderIds =
|
|
149
|
+
const senderIds = senderCandidates(msg, sock);
|
|
111
150
|
const isOwner = msg.key.fromMe || senderIds.some(isOwnerJidSync);
|
|
112
151
|
const isSenderAdmin = senderIds.some((id) => isAdminInGroupSync(groupMetadata, id));
|
|
113
|
-
|
|
114
152
|
if (isOwner || isSenderAdmin) return false;
|
|
115
153
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return false; // No action was taken
|
|
154
|
+
const hit = detectMedia(msg, settings);
|
|
155
|
+
if (!hit) return false;
|
|
156
|
+
logger.info(`[Media Control] Deleting ${hit.detail} from ${senderId} in ${groupId}.`);
|
|
157
|
+
const policy = policyFromFeatureAction(featureActionOf(settings, "media"));
|
|
158
|
+
const result = await enforceGroupRule(sock, {
|
|
159
|
+
msg,
|
|
160
|
+
groupMetadata,
|
|
161
|
+
rule: "media",
|
|
162
|
+
detail: hit.detail,
|
|
163
|
+
warningReason: hit.reason,
|
|
164
|
+
...policy,
|
|
165
|
+
targetCandidates: senderIds,
|
|
166
|
+
});
|
|
167
|
+
return Boolean(result.acted);
|
|
131
168
|
}
|
|
132
169
|
|
|
133
|
-
|
|
134
|
-
module.exports = { ...command, handleMediaControl };
|
|
170
|
+
module.exports = { ...command, handleMediaControl, detectMedia };
|