davexbaileys 2.5.17 → 2.5.18
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/lib/Socket/groups.js +46 -19
- package/package.json +1 -1
package/lib/Socket/groups.js
CHANGED
|
@@ -10,30 +10,57 @@ const WABinary_1 = require("../WABinary");
|
|
|
10
10
|
const chats_1 = require("./chats");
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Extract all group JIDs (@g.us) mentioned in a message's contextInfo.mentionedJid list.
|
|
14
|
+
*
|
|
15
|
+
* WHAT "antiGroupMention" means in WhatsApp bots:
|
|
16
|
+
* When someone sends a message and @-tags a GROUP (not a person), WhatsApp puts that
|
|
17
|
+
* group's JID (ending in @g.us) inside contextInfo.mentionedJid.
|
|
18
|
+
* "Anti group mention" = detect & action messages where someone is tagging/promoting
|
|
19
|
+
* ANOTHER GROUP inside your group — e.g. sharing group invite links or pinging rival groups.
|
|
20
|
+
* It is NOT about messages coming FROM a group; it is about messages that CONTAIN a @group mention.
|
|
21
|
+
*
|
|
22
|
+
* HOW it works (official Baileys source — Utils/messages.js):
|
|
23
|
+
* key.contextInfo.mentionedJid = message.mentions;
|
|
24
|
+
* Each entry is either a user JID (@s.whatsapp.net) or a group JID (@g.us).
|
|
25
|
+
*
|
|
26
|
+
* FIX (v2.5.18): previous version used `getAllMentioned(ctx) || getAllMentioned(next)`.
|
|
27
|
+
* An empty array [] is truthy in JS, so the || chain ALWAYS stopped at the first call
|
|
28
|
+
* even when that message type didn't exist. Now we chain on contextInfo objects (which
|
|
29
|
+
* are undefined when absent = falsy) so the || correctly falls through.
|
|
30
|
+
*
|
|
31
|
+
* @param message - WebMessageInfo object (sock.ev.on('messages.upsert') message)
|
|
32
|
+
* @returns array of group JIDs (@g.us) mentioned — empty array means no group mentions
|
|
18
33
|
*/
|
|
19
34
|
const getGroupMentions = (message) => {
|
|
20
|
-
|
|
21
|
-
const getAllMentioned = (contextInfo) => {
|
|
22
|
-
return (contextInfo === null || contextInfo === void 0 ? void 0 : contextInfo.mentionedJid) || [];
|
|
23
|
-
};
|
|
24
|
-
const msg = message === null || message === void 0 ? void 0 : message.message;
|
|
35
|
+
const msg = (message === null || message === void 0 ? void 0 : message.message) || null;
|
|
25
36
|
if (!msg) return [];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
// Chain on contextInfo OBJECTS (undefined = falsy → || falls through correctly)
|
|
38
|
+
const contextInfo =
|
|
39
|
+
msg.extendedTextMessage?.contextInfo ||
|
|
40
|
+
msg.imageMessage?.contextInfo ||
|
|
41
|
+
msg.videoMessage?.contextInfo ||
|
|
42
|
+
msg.documentMessage?.contextInfo ||
|
|
43
|
+
msg.audioMessage?.contextInfo ||
|
|
44
|
+
msg.stickerMessage?.contextInfo ||
|
|
45
|
+
null;
|
|
46
|
+
const mentionedJids = (contextInfo === null || contextInfo === void 0 ? void 0 : contextInfo.mentionedJid) || [];
|
|
47
|
+
return mentionedJids.filter(jid => typeof jid === 'string' && jid.endsWith('@g.us'));
|
|
33
48
|
};
|
|
34
49
|
/**
|
|
35
|
-
* Returns true if the message
|
|
36
|
-
* Use
|
|
50
|
+
* Returns true if the message @-mentions any group JID (@g.us).
|
|
51
|
+
* Use to enforce "anti group mention" — remove or warn members who tag other groups
|
|
52
|
+
* inside your group to prevent spam or promotion of rival groups.
|
|
53
|
+
*
|
|
54
|
+
* Usage:
|
|
55
|
+
* sock.ev.on('messages.upsert', async ({ messages }) => {
|
|
56
|
+
* for (const msg of messages) {
|
|
57
|
+
* if (isAntiGroupMention(msg)) {
|
|
58
|
+
* const groups = getGroupMentions(msg); // array of @g.us JIDs they tagged
|
|
59
|
+
* await sock.sendMessage(msg.key.remoteJid, { text: 'No group mentions allowed!' });
|
|
60
|
+
* await sock.groupParticipantsUpdate(msg.key.remoteJid, [msg.key.participant], 'remove');
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
37
64
|
*/
|
|
38
65
|
const isAntiGroupMention = (message) => {
|
|
39
66
|
return getGroupMentions(message).length > 0;
|
package/package.json
CHANGED