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,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
|
-
|
|
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 === "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:
|
|
34
|
-
|
|
35
|
-
|
|
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 {
|
|
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|
|
|
13
|
-
ar: "setwarn max <عدد>\nsetwarn action <KICK|
|
|
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 (
|
|
27
|
+
if (!Number.isInteger(max) || max < 1 || max > 50) {
|
|
34
28
|
return await sock.sendMessage(groupId, {
|
|
35
29
|
text: tr(
|
|
36
|
-
"Give a
|
|
37
|
-
"يرجى تحديد عدد صحيح
|
|
30
|
+
"Give a whole number from 1 to 50 for the warning limit.",
|
|
31
|
+
"يرجى تحديد عدد صحيح من 1 إلى 50 للحد الأقصى للتحذيرات.",
|
|
38
32
|
),
|
|
39
33
|
});
|
|
40
34
|
}
|
|
41
|
-
|
|
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
|
|
50
|
-
if (action
|
|
42
|
+
const action = normalizeWarnAction(value);
|
|
43
|
+
if (!action) {
|
|
51
44
|
return await sock.sendMessage(groupId, {
|
|
52
45
|
text: tr(
|
|
53
|
-
"Invalid action. Available: `KICK`, `
|
|
54
|
-
"الإجراء غير صالح. الإجراءات المتاحة: `KICK`, `
|
|
46
|
+
"Invalid action. Available: `KICK`, `FLAG`",
|
|
47
|
+
"الإجراء غير صالح. الإجراءات المتاحة: `KICK`, `FLAG`",
|
|
55
48
|
),
|
|
56
49
|
});
|
|
57
50
|
}
|
|
58
|
-
|
|
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|
|
|
69
|
-
"صيغة غير صحيحة. استخدم:\n`!setwarn max <number>`\n`!setwarn action <KICK|
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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, {
|
package/src/commands/group.cjs
CHANGED
|
@@ -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
|
|
119
|
-
const isSenderAdmin = isAdminInGroupSync(groupMetadata,
|
|
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.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const runtimeConfig = require("../config/runtime-config.cjs");
|
|
2
|
+
const { tr } = require("../utils/i18n.cjs");
|
|
3
|
+
const { quotedOf, visibleText } = require("../utils/messageContent.cjs");
|
|
4
|
+
const { formatMarkdownForWhatsApp } = require("../utils/markdownParser.cjs");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
name: "md",
|
|
8
|
+
aliases: ["markdown"],
|
|
9
|
+
description: {
|
|
10
|
+
en: "Converts Markdown from any AI or message into WhatsApp formatting, with tables as labeled bullet lists.",
|
|
11
|
+
ar: "يحوّل ماركداون من أي ذكاء اصطناعي أو رسالة إلى تنسيق واتساب، مع عرض الجداول كقوائم نقطية منظمة.",
|
|
12
|
+
},
|
|
13
|
+
usage: {
|
|
14
|
+
en: "md <markdown text> | reply to a message with md",
|
|
15
|
+
ar: "md <نص ماركداون> | أو رد على رسالة باستخدام md",
|
|
16
|
+
},
|
|
17
|
+
chat: "all",
|
|
18
|
+
|
|
19
|
+
async execute(sock, msg, args, body) {
|
|
20
|
+
const prefix = runtimeConfig.getPrefix();
|
|
21
|
+
// args have been split by the dispatcher. Read the body to retain table
|
|
22
|
+
// rows, code indentation and paragraph breaks, including !md\n<text>.
|
|
23
|
+
const inline =
|
|
24
|
+
typeof body === "string"
|
|
25
|
+
? body
|
|
26
|
+
.slice(prefix.length)
|
|
27
|
+
.trimStart()
|
|
28
|
+
.replace(/^\S+[ \t]*(?:\r?\n)?/, "")
|
|
29
|
+
: (args || []).join(" ");
|
|
30
|
+
const text = inline.trim() ? inline : visibleText(quotedOf(msg));
|
|
31
|
+
return sock.sendMessage(
|
|
32
|
+
msg.key.remoteJid,
|
|
33
|
+
{
|
|
34
|
+
text: text.trim()
|
|
35
|
+
? formatMarkdownForWhatsApp(text)
|
|
36
|
+
: tr(
|
|
37
|
+
`Reply to a Markdown message with \`${prefix}md\`, or paste it after the command.\n\nExample: \`${prefix}md **Bold** and __italic__\`\nTables become labeled bullet lists; code stays unchanged.`,
|
|
38
|
+
`رد على رسالة ماركداون باستخدام \`${prefix}md\`، أو الصق النص بعد الأمر.\n\nمثال: \`${prefix}md **عريض** و __مائل__\`\nتُعرض الجداول كقوائم نقطية منظمة، ويُحفظ محتوى الكود كما هو.`,
|
|
39
|
+
),
|
|
40
|
+
},
|
|
41
|
+
{ quoted: msg },
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
};
|