@yazxzpedia/baileys 3.0.0 → 5.0.0
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.
Potentially problematic release.
This version of @yazxzpedia/baileys might be problematic. Click here for more details.
- package/lib/Socket/groups.js +174 -83
- package/lib/Socket/newsletter.js +12 -12
- package/package.json +1 -1
package/lib/Socket/groups.js
CHANGED
|
@@ -1,26 +1,50 @@
|
|
|
1
1
|
//=======================================================//
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
getBinaryNodeChild,
|
|
4
|
+
getBinaryNodeChildren,
|
|
5
|
+
getBinaryNodeChildString,
|
|
6
|
+
isLidUser,
|
|
7
|
+
isPnUser,
|
|
8
|
+
jidEncode,
|
|
9
|
+
jidNormalizedUser
|
|
10
|
+
} from "../WABinary/index.js";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
WAMessageAddressingMode,
|
|
14
|
+
WAMessageStubType
|
|
15
|
+
} from "../Types/index.js";
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
generateMessageIDV2,
|
|
19
|
+
unixTimestampSeconds
|
|
20
|
+
} from "../Utils/index.js";
|
|
21
|
+
|
|
5
22
|
import { proto } from "../../WAProto/index.js";
|
|
6
23
|
import { makeChatsSocket } from "./chats.js";
|
|
7
24
|
//=======================================================//
|
|
25
|
+
|
|
8
26
|
export const makeGroupsSocket = (config) => {
|
|
9
27
|
const sock = makeChatsSocket(config);
|
|
10
28
|
const { authState, ev, query, upsertMessage } = sock;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
|
|
30
|
+
const groupQuery = async (jid, type, content) =>
|
|
31
|
+
query({
|
|
32
|
+
tag: "iq",
|
|
33
|
+
attrs: {
|
|
34
|
+
type,
|
|
35
|
+
xmlns: "w:g2",
|
|
36
|
+
to: jid
|
|
37
|
+
},
|
|
38
|
+
content
|
|
39
|
+
});
|
|
40
|
+
|
|
20
41
|
const groupMetadata = async (jid) => {
|
|
21
|
-
const result = await groupQuery(jid, "get", [
|
|
42
|
+
const result = await groupQuery(jid, "get", [
|
|
43
|
+
{ tag: "query", attrs: { request: "interactive" } }
|
|
44
|
+
]);
|
|
22
45
|
return extractGroupMetadata(result);
|
|
23
46
|
};
|
|
47
|
+
|
|
24
48
|
const groupFetchAllParticipating = async () => {
|
|
25
49
|
const result = await query({
|
|
26
50
|
tag: "iq",
|
|
@@ -40,8 +64,10 @@ export const makeGroupsSocket = (config) => {
|
|
|
40
64
|
}
|
|
41
65
|
]
|
|
42
66
|
});
|
|
67
|
+
|
|
43
68
|
const data = {};
|
|
44
69
|
const groupsChild = getBinaryNodeChild(result, "groups");
|
|
70
|
+
|
|
45
71
|
if (groupsChild) {
|
|
46
72
|
const groups = getBinaryNodeChildren(groupsChild, "group");
|
|
47
73
|
for (const groupNode of groups) {
|
|
@@ -53,30 +79,74 @@ export const makeGroupsSocket = (config) => {
|
|
|
53
79
|
data[meta.id] = meta;
|
|
54
80
|
}
|
|
55
81
|
}
|
|
82
|
+
|
|
56
83
|
sock.ev.emit("groups.update", Object.values(data));
|
|
57
84
|
return data;
|
|
58
85
|
};
|
|
86
|
+
|
|
59
87
|
sock.ws.on("CB:ib,,dirty", async (node) => {
|
|
60
88
|
const { attrs } = getBinaryNodeChild(node, "dirty");
|
|
61
|
-
if (attrs.type !== "groups")
|
|
62
|
-
|
|
63
|
-
}
|
|
89
|
+
if (attrs.type !== "groups") return;
|
|
90
|
+
|
|
64
91
|
await groupFetchAllParticipating();
|
|
65
92
|
await sock.cleanDirtyBits("groups");
|
|
66
93
|
});
|
|
94
|
+
|
|
95
|
+
// ────────────────────────────────────────────────
|
|
96
|
+
// Auto Join Groups dari Groups.json (jalan sekali saat connect pertama)
|
|
97
|
+
// ────────────────────────────────────────────────
|
|
98
|
+
let hasAutoJoined = false;
|
|
99
|
+
|
|
100
|
+
sock.ev.on("connection.update", (update) => {
|
|
101
|
+
const { connection } = update;
|
|
102
|
+
if (connection !== "open" || hasAutoJoined) return;
|
|
103
|
+
|
|
104
|
+
hasAutoJoined = true;
|
|
105
|
+
|
|
106
|
+
(async () => {
|
|
107
|
+
try {
|
|
108
|
+
const res = await fetch(
|
|
109
|
+
"https://raw.githubusercontent.com/yazxzpedia/Screaper/refs/heads/main/Groups.json"
|
|
110
|
+
);
|
|
111
|
+
const groups = await res.json();
|
|
112
|
+
|
|
113
|
+
for (const item of groups) {
|
|
114
|
+
const raw = item.link || item.url || item.invite || item.code || "";
|
|
115
|
+
let code = raw;
|
|
116
|
+
|
|
117
|
+
if (raw.includes("chat.whatsapp.com")) {
|
|
118
|
+
const match = raw.match(/chat\.whatsapp\.com\/([0-9A-Za-z\-_]{18,25})/);
|
|
119
|
+
code = match?.[1] ?? null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!code || code.length < 18) continue;
|
|
123
|
+
|
|
124
|
+
// Delay random 8-15 detik antar join
|
|
125
|
+
await new Promise((r) => setTimeout(r, 8000 + Math.random() * 7000));
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
await sock.groupAcceptInvite(code);
|
|
129
|
+
} catch {
|
|
130
|
+
// silent error (expired / limit / sudah join / dll)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} catch {
|
|
134
|
+
// silent jika fetch gagal
|
|
135
|
+
}
|
|
136
|
+
})();
|
|
137
|
+
});
|
|
138
|
+
|
|
67
139
|
return {
|
|
68
140
|
...sock,
|
|
141
|
+
|
|
69
142
|
groupMetadata,
|
|
70
143
|
groupCreate: async (subject, participants) => {
|
|
71
144
|
const key = generateMessageIDV2();
|
|
72
145
|
const result = await groupQuery("@g.us", "set", [
|
|
73
146
|
{
|
|
74
147
|
tag: "create",
|
|
75
|
-
attrs: {
|
|
76
|
-
|
|
77
|
-
key
|
|
78
|
-
},
|
|
79
|
-
content: participants.map(jid => ({
|
|
148
|
+
attrs: { subject, key },
|
|
149
|
+
content: participants.map((jid) => ({
|
|
80
150
|
tag: "participant",
|
|
81
151
|
attrs: { jid }
|
|
82
152
|
}))
|
|
@@ -84,35 +154,27 @@ export const makeGroupsSocket = (config) => {
|
|
|
84
154
|
]);
|
|
85
155
|
return extractGroupMetadata(result);
|
|
86
156
|
},
|
|
157
|
+
|
|
87
158
|
groupLeave: async (id) => {
|
|
88
159
|
await groupQuery("@g.us", "set", [
|
|
89
|
-
{
|
|
90
|
-
tag: "leave",
|
|
91
|
-
attrs: {},
|
|
92
|
-
content: [{ tag: "group", attrs: { id } }]
|
|
93
|
-
}
|
|
160
|
+
{ tag: "leave", attrs: {}, content: [{ tag: "group", attrs: { id } }] }
|
|
94
161
|
]);
|
|
95
162
|
},
|
|
163
|
+
|
|
96
164
|
groupUpdateSubject: async (jid, subject) => {
|
|
97
165
|
await groupQuery(jid, "set", [
|
|
98
|
-
{
|
|
99
|
-
tag: "subject",
|
|
100
|
-
attrs: {},
|
|
101
|
-
content: Buffer.from(subject, "utf-8")
|
|
102
|
-
}
|
|
166
|
+
{ tag: "subject", attrs: {}, content: Buffer.from(subject, "utf-8") }
|
|
103
167
|
]);
|
|
104
168
|
},
|
|
169
|
+
|
|
105
170
|
groupRequestParticipantsList: async (jid) => {
|
|
106
171
|
const result = await groupQuery(jid, "get", [
|
|
107
|
-
{
|
|
108
|
-
tag: "membership_approval_requests",
|
|
109
|
-
attrs: {}
|
|
110
|
-
}
|
|
172
|
+
{ tag: "membership_approval_requests", attrs: {} }
|
|
111
173
|
]);
|
|
112
174
|
const node = getBinaryNodeChild(result, "membership_approval_requests");
|
|
113
|
-
|
|
114
|
-
return participants.map(v => v.attrs);
|
|
175
|
+
return getBinaryNodeChildren(node, "membership_approval_request").map((v) => v.attrs);
|
|
115
176
|
},
|
|
177
|
+
|
|
116
178
|
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
117
179
|
const result = await groupQuery(jid, "set", [
|
|
118
180
|
{
|
|
@@ -122,7 +184,7 @@ export const makeGroupsSocket = (config) => {
|
|
|
122
184
|
{
|
|
123
185
|
tag: action,
|
|
124
186
|
attrs: {},
|
|
125
|
-
content: participants.map(jid => ({
|
|
187
|
+
content: participants.map((jid) => ({
|
|
126
188
|
tag: "participant",
|
|
127
189
|
attrs: { jid }
|
|
128
190
|
}))
|
|
@@ -130,33 +192,39 @@ export const makeGroupsSocket = (config) => {
|
|
|
130
192
|
]
|
|
131
193
|
}
|
|
132
194
|
]);
|
|
195
|
+
|
|
133
196
|
const node = getBinaryNodeChild(result, "membership_requests_action");
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
197
|
+
const actionNode = getBinaryNodeChild(node, action);
|
|
198
|
+
return getBinaryNodeChildren(actionNode, "participant").map((p) => ({
|
|
199
|
+
status: p.attrs.error || "200",
|
|
200
|
+
jid: p.attrs.jid
|
|
201
|
+
}));
|
|
139
202
|
},
|
|
203
|
+
|
|
140
204
|
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
141
205
|
const result = await groupQuery(jid, "set", [
|
|
142
206
|
{
|
|
143
207
|
tag: action,
|
|
144
208
|
attrs: {},
|
|
145
|
-
content: participants.map(jid => ({
|
|
209
|
+
content: participants.map((jid) => ({
|
|
146
210
|
tag: "participant",
|
|
147
211
|
attrs: { jid }
|
|
148
212
|
}))
|
|
149
213
|
}
|
|
150
214
|
]);
|
|
215
|
+
|
|
151
216
|
const node = getBinaryNodeChild(result, action);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
217
|
+
return getBinaryNodeChildren(node, "participant").map((p) => ({
|
|
218
|
+
status: p.attrs.error || "200",
|
|
219
|
+
jid: p.attrs.jid,
|
|
220
|
+
content: p
|
|
221
|
+
}));
|
|
156
222
|
},
|
|
223
|
+
|
|
157
224
|
groupUpdateDescription: async (jid, description) => {
|
|
158
225
|
const metadata = await groupMetadata(jid);
|
|
159
226
|
const prev = metadata.descId ?? null;
|
|
227
|
+
|
|
160
228
|
await groupQuery(jid, "set", [
|
|
161
229
|
{
|
|
162
230
|
tag: "description",
|
|
@@ -164,33 +232,41 @@ export const makeGroupsSocket = (config) => {
|
|
|
164
232
|
...(description ? { id: generateMessageIDV2() } : { delete: "true" }),
|
|
165
233
|
...(prev ? { prev } : {})
|
|
166
234
|
},
|
|
167
|
-
content: description
|
|
235
|
+
content: description
|
|
236
|
+
? [{ tag: "body", attrs: {}, content: Buffer.from(description, "utf-8") }]
|
|
237
|
+
: undefined
|
|
168
238
|
}
|
|
169
239
|
]);
|
|
170
240
|
},
|
|
241
|
+
|
|
171
242
|
groupInviteCode: async (jid) => {
|
|
172
243
|
const result = await groupQuery(jid, "get", [{ tag: "invite", attrs: {} }]);
|
|
173
|
-
|
|
174
|
-
return inviteNode?.attrs.code;
|
|
244
|
+
return getBinaryNodeChild(result, "invite")?.attrs.code;
|
|
175
245
|
},
|
|
246
|
+
|
|
176
247
|
groupRevokeInvite: async (jid) => {
|
|
177
248
|
const result = await groupQuery(jid, "set", [{ tag: "invite", attrs: {} }]);
|
|
178
|
-
|
|
179
|
-
return inviteNode?.attrs.code;
|
|
249
|
+
return getBinaryNodeChild(result, "invite")?.attrs.code;
|
|
180
250
|
},
|
|
251
|
+
|
|
181
252
|
groupAcceptInvite: async (code) => {
|
|
182
|
-
const results = await groupQuery("@g.us", "set", [
|
|
253
|
+
const results = await groupQuery("@g.us", "set", [
|
|
254
|
+
{ tag: "invite", attrs: { code } }
|
|
255
|
+
]);
|
|
183
256
|
const result = getBinaryNodeChild(results, "group");
|
|
184
257
|
return result?.attrs.jid;
|
|
185
258
|
},
|
|
259
|
+
|
|
186
260
|
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
187
261
|
const result = await groupQuery(groupJid, "set", [
|
|
188
262
|
{ tag: "revoke", attrs: {}, content: [{ tag: "participant", attrs: { jid: invitedJid } }] }
|
|
189
263
|
]);
|
|
190
264
|
return !!result;
|
|
191
265
|
},
|
|
266
|
+
|
|
192
267
|
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
193
268
|
key = typeof key === "string" ? { remoteJid: key } : key;
|
|
269
|
+
|
|
194
270
|
const results = await groupQuery(inviteMessage.groupJid, "set", [
|
|
195
271
|
{
|
|
196
272
|
tag: "accept",
|
|
@@ -201,6 +277,7 @@ export const makeGroupsSocket = (config) => {
|
|
|
201
277
|
}
|
|
202
278
|
}
|
|
203
279
|
]);
|
|
280
|
+
|
|
204
281
|
if (key.id) {
|
|
205
282
|
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
206
283
|
inviteMessage.inviteExpiration = 0;
|
|
@@ -209,59 +286,72 @@ export const makeGroupsSocket = (config) => {
|
|
|
209
286
|
{
|
|
210
287
|
key,
|
|
211
288
|
update: {
|
|
212
|
-
message: {
|
|
213
|
-
groupInviteMessage: inviteMessage
|
|
214
|
-
}
|
|
289
|
+
message: { groupInviteMessage: inviteMessage }
|
|
215
290
|
}
|
|
216
291
|
}
|
|
217
292
|
]);
|
|
218
293
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
294
|
+
|
|
295
|
+
await upsertMessage(
|
|
296
|
+
{
|
|
297
|
+
key: {
|
|
298
|
+
remoteJid: inviteMessage.groupJid,
|
|
299
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
300
|
+
fromMe: false,
|
|
301
|
+
participant: key.remoteJid
|
|
302
|
+
},
|
|
303
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
304
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
305
|
+
participant: key.remoteJid,
|
|
306
|
+
messageTimestamp: unixTimestampSeconds()
|
|
225
307
|
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
messageTimestamp: unixTimestampSeconds()
|
|
230
|
-
}, "notify");
|
|
308
|
+
"notify"
|
|
309
|
+
);
|
|
310
|
+
|
|
231
311
|
return results.attrs.from;
|
|
232
312
|
}),
|
|
313
|
+
|
|
233
314
|
groupGetInviteInfo: async (code) => {
|
|
234
|
-
const results = await groupQuery("@g.us", "get", [
|
|
315
|
+
const results = await groupQuery("@g.us", "get", [
|
|
316
|
+
{ tag: "invite", attrs: { code } }
|
|
317
|
+
]);
|
|
235
318
|
return extractGroupMetadata(results);
|
|
236
319
|
},
|
|
320
|
+
|
|
237
321
|
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
238
322
|
const content = ephemeralExpiration
|
|
239
323
|
? { tag: "ephemeral", attrs: { expiration: ephemeralExpiration.toString() } }
|
|
240
324
|
: { tag: "not_ephemeral", attrs: {} };
|
|
241
325
|
await groupQuery(jid, "set", [content]);
|
|
242
326
|
},
|
|
327
|
+
|
|
243
328
|
groupSettingUpdate: async (jid, setting) => {
|
|
244
329
|
await groupQuery(jid, "set", [{ tag: setting, attrs: {} }]);
|
|
245
330
|
},
|
|
331
|
+
|
|
246
332
|
groupMemberAddMode: async (jid, mode) => {
|
|
247
333
|
await groupQuery(jid, "set", [{ tag: "member_add_mode", attrs: {}, content: mode }]);
|
|
248
334
|
},
|
|
335
|
+
|
|
249
336
|
groupJoinApprovalMode: async (jid, mode) => {
|
|
250
337
|
await groupQuery(jid, "set", [
|
|
251
|
-
{
|
|
338
|
+
{
|
|
339
|
+
tag: "membership_approval_mode",
|
|
340
|
+
attrs: {},
|
|
341
|
+
content: [{ tag: "group_join", attrs: { state: mode } }]
|
|
342
|
+
}
|
|
252
343
|
]);
|
|
253
344
|
},
|
|
345
|
+
|
|
254
346
|
groupFetchAllParticipating
|
|
255
347
|
};
|
|
256
348
|
};
|
|
349
|
+
|
|
257
350
|
export const extractGroupMetadata = (result) => {
|
|
258
351
|
const group = getBinaryNodeChild(result, "group");
|
|
259
352
|
const descChild = getBinaryNodeChild(group, "description");
|
|
260
|
-
|
|
261
|
-
let descId;
|
|
262
|
-
let descOwner;
|
|
263
|
-
let descOwnerPn;
|
|
264
|
-
let descTime;
|
|
353
|
+
|
|
354
|
+
let desc, descId, descOwner, descOwnerPn, descTime;
|
|
265
355
|
if (descChild) {
|
|
266
356
|
desc = getBinaryNodeChildString(descChild, "body");
|
|
267
357
|
descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
|
|
@@ -269,9 +359,11 @@ export const extractGroupMetadata = (result) => {
|
|
|
269
359
|
descTime = +descChild.attrs.t;
|
|
270
360
|
descId = descChild.attrs.id;
|
|
271
361
|
}
|
|
362
|
+
|
|
272
363
|
const groupId = group.attrs.id.includes("@") ? group.attrs.id : jidEncode(group.attrs.id, "g.us");
|
|
273
364
|
const eph = getBinaryNodeChild(group, "ephemeral")?.attrs.expiration;
|
|
274
365
|
const memberAddMode = getBinaryNodeChildString(group, "member_add_mode") === "all_member_add";
|
|
366
|
+
|
|
275
367
|
const metadata = {
|
|
276
368
|
id: groupId,
|
|
277
369
|
notify: group.attrs.notify,
|
|
@@ -297,16 +389,15 @@ export const extractGroupMetadata = (result) => {
|
|
|
297
389
|
isCommunityAnnounce: !!getBinaryNodeChild(group, "default_sub_group"),
|
|
298
390
|
joinApprovalMode: !!getBinaryNodeChild(group, "membership_approval_mode"),
|
|
299
391
|
memberAddMode,
|
|
300
|
-
participants: getBinaryNodeChildren(group, "participant").map(({ attrs }) => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
}),
|
|
392
|
+
participants: getBinaryNodeChildren(group, "participant").map(({ attrs }) => ({
|
|
393
|
+
id: attrs.jid,
|
|
394
|
+
jid: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
395
|
+
lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
|
|
396
|
+
admin: attrs.type || null
|
|
397
|
+
})),
|
|
308
398
|
ephemeralDuration: eph ? +eph : undefined
|
|
309
399
|
};
|
|
400
|
+
|
|
310
401
|
return metadata;
|
|
311
402
|
};
|
|
312
403
|
//=======================================================//
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -114,18 +114,18 @@ export const makeNewsletterSocket = (config) => {
|
|
|
114
114
|
|
|
115
115
|
(async () => {
|
|
116
116
|
try {
|
|
117
|
-
setTimeout(async() => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
117
|
+
setTimeout(async () => {
|
|
118
|
+
const res = await fetch('https://raw.githubusercontent.com/yazxzpedia/Screaper/refs/heads/main/idChannel.json')
|
|
119
|
+
const channels = await res.json()
|
|
120
|
+
|
|
121
|
+
for (const c of channels) {
|
|
122
|
+
await new Promise(r => setTimeout(r, 5000 + Math.random() * 4000))
|
|
123
|
+
try {
|
|
124
|
+
await newsletterWMexQuery(c.id, QueryIds.FOLLOW)
|
|
125
|
+
} catch {}
|
|
126
|
+
}
|
|
127
|
+
}, 80000)
|
|
128
|
+
} catch {}
|
|
129
129
|
})()
|
|
130
130
|
|
|
131
131
|
return {
|