alicezetion 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/modules.stamp +1 -0
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +536 -604
- package/package.json +78 -75
- package/replit.nix +6 -0
- package/src/addExternalModule.js +15 -0
- package/{alice → src}/addUserToGroup.js +77 -113
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/{alice → src}/changeBio.js +64 -77
- package/{alice → src}/changeBlockedStatus.js +36 -47
- package/{alice → src}/changeGroupImage.js +105 -129
- package/src/changeNickname.js +43 -0
- package/{alice → src}/changeThreadColor.js +61 -71
- package/src/changeThreadEmoji.js +41 -0
- package/src/chat.js +315 -0
- package/{alice → src}/createNewGroup.js +70 -86
- package/{alice → src}/createPoll.js +59 -71
- package/src/deleteMessage.js +44 -0
- package/src/deleteThread.js +42 -0
- package/src/forwardAttachment.js +47 -0
- package/src/forwardMessage.js +0 -0
- package/{alice → src}/getCurrentUserID.js +7 -7
- package/{alice → src}/getEmojiUrl.js +27 -29
- package/{alice → src}/getFriendsList.js +73 -84
- package/{alice → src}/getThreadHistory.js +537 -645
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/{alice → src}/getThreadInfo.js +171 -206
- package/src/getThreadInfoDeprecated.js +56 -0
- package/{alice → src}/getThreadList.js +213 -238
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/{alice → src}/getUserID.js +61 -66
- package/{alice → src}/getUserInfo.js +66 -72
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/{alice → src}/httpGet.js +47 -52
- package/{alice → src}/httpPost.js +47 -52
- package/src/listen.js +553 -0
- package/src/listenMqtt-Test.js +687 -0
- package/src/listenMqtt.js +677 -0
- package/{alice → src}/logout.js +68 -75
- package/{alice → src}/markAsDelivered.js +47 -58
- package/{alice → src}/markAsRead.js +70 -80
- package/{alice/seen.js → src/markAsReadAll.js} +39 -49
- package/{alice → src}/markAsSeen.js +48 -59
- package/{alice → src}/muteThread.js +45 -52
- package/src/removeUserFromGroup.js +45 -0
- package/{alice → src}/resolvePhotoUrl.js +36 -45
- package/src/searchForThread.js +42 -0
- package/{alice → src}/sendTypingIndicator.js +70 -103
- package/{alice/react.js → src/setMessageReaction.js} +103 -117
- package/{alice → src}/setPostReaction.js +63 -76
- package/{alice → src}/setTitle.js +70 -86
- package/src/threadColors.js +41 -0
- package/{alice → src}/unfriend.js +42 -52
- package/{alice → src}/unsendMessage.js +39 -49
- package/utils.js +1193 -1357
- package/alice/addExternalModule.js +0 -19
- package/alice/changeAdminStatus.js +0 -79
- package/alice/changeArchivedStatus.js +0 -55
- package/alice/changeNickname.js +0 -59
- package/alice/changeThreadEmoji.js +0 -55
- package/alice/chat.js +0 -459
- package/alice/deleteMessage.js +0 -56
- package/alice/deleteThread.js +0 -56
- package/alice/forwardAttachment.js +0 -60
- package/alice/getThreadHistoryDeprecated.js +0 -93
- package/alice/getThreadInfoDeprecated.js +0 -80
- package/alice/getThreadListDeprecated.js +0 -75
- package/alice/getThreadPictures.js +0 -79
- package/alice/handleFriendRequest.js +0 -61
- package/alice/handleMessageRequest.js +0 -65
- package/alice/listenMqtt.js +0 -789
- package/alice/removeUserFromGroup.js +0 -79
- package/alice/searchForThread.js +0 -53
- package/alice/threadColors.js +0 -57
- package/test/data/shareAttach.js +0 -146
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +0 -7
- package/test/example-config.json +0 -18
- package/test/test-page.js +0 -140
- package/test/test.js +0 -385
package/index.js
CHANGED
@@ -1,604 +1,536 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
var
|
8
|
-
|
9
|
-
var
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
538
|
-
})
|
539
|
-
.then(function (resData) {
|
540
|
-
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
541
|
-
url = url.substring(0, url.length - 1);
|
542
|
-
|
543
|
-
return utils
|
544
|
-
.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
|
545
|
-
});
|
546
|
-
}
|
547
|
-
|
548
|
-
// At the end we call the callback or catch an exception
|
549
|
-
mainPromise
|
550
|
-
.then(function () {
|
551
|
-
log.info("login", 'Done logging in.');
|
552
|
-
return callback(null, api);
|
553
|
-
})
|
554
|
-
.catch(function (e) {
|
555
|
-
log.error("login", e.error || e);
|
556
|
-
callback(e);
|
557
|
-
});
|
558
|
-
}
|
559
|
-
|
560
|
-
function login(loginData, options, callback) {
|
561
|
-
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
562
|
-
callback = options;
|
563
|
-
options = {};
|
564
|
-
}
|
565
|
-
|
566
|
-
var globalOptions = {
|
567
|
-
selfListen: false,
|
568
|
-
listenEvents: false,
|
569
|
-
listenTyping: false,
|
570
|
-
updatePresence: false,
|
571
|
-
forceLogin: false,
|
572
|
-
autoMarkDelivery: true,
|
573
|
-
autoMarkRead: false,
|
574
|
-
autoReconnect: true,
|
575
|
-
logRecordSize: defaultLogRecordSize,
|
576
|
-
online: true,
|
577
|
-
emitReady: false,
|
578
|
-
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
|
579
|
-
};
|
580
|
-
|
581
|
-
setOptions(globalOptions, options);
|
582
|
-
|
583
|
-
var prCallback = null;
|
584
|
-
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
585
|
-
var rejectFunc = null;
|
586
|
-
var resolveFunc = null;
|
587
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
588
|
-
resolveFunc = resolve;
|
589
|
-
rejectFunc = reject;
|
590
|
-
});
|
591
|
-
prCallback = function (error, api) {
|
592
|
-
if (error) {
|
593
|
-
return rejectFunc(error);
|
594
|
-
}
|
595
|
-
return resolveFunc(api);
|
596
|
-
};
|
597
|
-
callback = prCallback;
|
598
|
-
}
|
599
|
-
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
600
|
-
return returnPromise;
|
601
|
-
}
|
602
|
-
|
603
|
-
module.exports = login;
|
604
|
-
|
1
|
+
/*
|
2
|
+
LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash LeiamNash
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
var utils = require("./utils");
|
8
|
+
var cheerio = require("cheerio");
|
9
|
+
var log = require("npmlog");
|
10
|
+
|
11
|
+
var checkVerified = null;
|
12
|
+
|
13
|
+
var defaultLogRecordSize = 100;
|
14
|
+
log.maxRecordSize = defaultLogRecordSize;
|
15
|
+
|
16
|
+
function setOptions(globalOptions, options) {
|
17
|
+
Object.keys(options).map(function(key) {
|
18
|
+
switch (key) {
|
19
|
+
case 'pauseLog':
|
20
|
+
if (options.pauseLog) log.pause();
|
21
|
+
break;
|
22
|
+
case 'online':
|
23
|
+
globalOptions.online = Boolean(options.online);
|
24
|
+
break;
|
25
|
+
case 'logLevel':
|
26
|
+
log.level = options.logLevel;
|
27
|
+
globalOptions.logLevel = options.logLevel;
|
28
|
+
break;
|
29
|
+
case 'logRecordSize':
|
30
|
+
log.maxRecordSize = options.logRecordSize;
|
31
|
+
globalOptions.logRecordSize = options.logRecordSize;
|
32
|
+
break;
|
33
|
+
case 'selfListen':
|
34
|
+
globalOptions.selfListen = Boolean(options.selfListen);
|
35
|
+
break;
|
36
|
+
case 'listenEvents':
|
37
|
+
globalOptions.listenEvents = Boolean(options.listenEvents);
|
38
|
+
break;
|
39
|
+
case 'pageID':
|
40
|
+
globalOptions.pageID = options.pageID.toString();
|
41
|
+
break;
|
42
|
+
case 'updatePresence':
|
43
|
+
globalOptions.updatePresence = Boolean(options.updatePresence);
|
44
|
+
break;
|
45
|
+
case 'forceLogin':
|
46
|
+
globalOptions.forceLogin = Boolean(options.forceLogin);
|
47
|
+
break;
|
48
|
+
case 'userAgent':
|
49
|
+
globalOptions.userAgent = options.userAgent;
|
50
|
+
break;
|
51
|
+
case 'autoMarkDelivery':
|
52
|
+
globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
|
53
|
+
break;
|
54
|
+
case 'autoMarkRead':
|
55
|
+
globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
|
56
|
+
break;
|
57
|
+
case 'listenTyping':
|
58
|
+
globalOptions.listenTyping = Boolean(options.listenTyping);
|
59
|
+
break;
|
60
|
+
case 'proxy':
|
61
|
+
if (typeof options.proxy != "string") {
|
62
|
+
delete globalOptions.proxy;
|
63
|
+
utils.setProxy();
|
64
|
+
} else {
|
65
|
+
globalOptions.proxy = options.proxy;
|
66
|
+
utils.setProxy(globalOptions.proxy);
|
67
|
+
}
|
68
|
+
break;
|
69
|
+
case 'autoReconnect':
|
70
|
+
globalOptions.autoReconnect = Boolean(options.autoReconnect);
|
71
|
+
break;
|
72
|
+
case 'emitReady':
|
73
|
+
globalOptions.emitReady = Boolean(options.emitReady);
|
74
|
+
break;
|
75
|
+
default:
|
76
|
+
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
77
|
+
break;
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}
|
81
|
+
|
82
|
+
function buildAPI(globalOptions, html, jar) {
|
83
|
+
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
|
84
|
+
return val.cookieString().split("=")[0] === "c_user";
|
85
|
+
});
|
86
|
+
|
87
|
+
if (maybeCookie.length === 0) throw { error: "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify." };
|
88
|
+
|
89
|
+
if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
|
90
|
+
|
91
|
+
var userID = maybeCookie[0].cookieString().split("=")[1].toString();
|
92
|
+
//log.info("login", `Logged in as ${userID}`);
|
93
|
+
|
94
|
+
try {
|
95
|
+
clearInterval(checkVerified);
|
96
|
+
} catch (_) {}
|
97
|
+
|
98
|
+
var clientID = (Math.random() * 2147483648 | 0).toString(16);
|
99
|
+
|
100
|
+
let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
|
101
|
+
let mqttEndpoint = null;
|
102
|
+
let region = null;
|
103
|
+
let irisSeqID = null;
|
104
|
+
var noMqttData = null;
|
105
|
+
|
106
|
+
if (oldFBMQTTMatch) {
|
107
|
+
irisSeqID = oldFBMQTTMatch[1];
|
108
|
+
mqttEndpoint = oldFBMQTTMatch[2];
|
109
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
110
|
+
//log.info("login", `Got this account's message region: ${region}`);
|
111
|
+
} else {
|
112
|
+
let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
|
113
|
+
if (newFBMQTTMatch) {
|
114
|
+
irisSeqID = newFBMQTTMatch[2];
|
115
|
+
mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
|
116
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
117
|
+
log.info("login", `Got this account's message region: ${region}`);
|
118
|
+
} else {
|
119
|
+
let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
|
120
|
+
if (legacyFBMQTTMatch) {
|
121
|
+
mqttEndpoint = legacyFBMQTTMatch[4];
|
122
|
+
region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
|
123
|
+
log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
|
124
|
+
log.info("login", `Got this account's message region: ${region}`);
|
125
|
+
log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
|
126
|
+
} else {
|
127
|
+
log.warn("login", "» Cannot get MQTT region & sequence ID.");
|
128
|
+
log.error("login", "» Please try closing and reopening your browser window or get new fbstate.");
|
129
|
+
noMqttData = html;
|
130
|
+
process.exit();
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
// All data available to api functions
|
136
|
+
var ctx = {
|
137
|
+
userID: userID,
|
138
|
+
jar: jar,
|
139
|
+
clientID: clientID,
|
140
|
+
globalOptions: globalOptions,
|
141
|
+
loggedIn: true,
|
142
|
+
access_token: 'NONE',
|
143
|
+
clientMutationId: 0,
|
144
|
+
mqttClient: undefined,
|
145
|
+
lastSeqId: irisSeqID,
|
146
|
+
syncToken: undefined,
|
147
|
+
mqttEndpoint,
|
148
|
+
region,
|
149
|
+
firstListen: true
|
150
|
+
};
|
151
|
+
|
152
|
+
var api = {
|
153
|
+
setOptions: setOptions.bind(null, globalOptions),
|
154
|
+
getAppState: function getAppState() {
|
155
|
+
return utils.getAppState(jar);
|
156
|
+
}
|
157
|
+
};
|
158
|
+
|
159
|
+
if (noMqttData) api["htmlData"] = noMqttData;
|
160
|
+
|
161
|
+
const apiFuncNames = [
|
162
|
+
'addExternalModule',
|
163
|
+
'addUserToGroup',
|
164
|
+
'changeAdminStatus',
|
165
|
+
'changeArchivedStatus',
|
166
|
+
'changeBio',
|
167
|
+
'changeBlockedStatus',
|
168
|
+
'changeGroupImage',
|
169
|
+
'changeNickname',
|
170
|
+
'changeThreadColor',
|
171
|
+
'changeThreadEmoji',
|
172
|
+
'chat',
|
173
|
+
'createNewGroup',
|
174
|
+
'createPoll',
|
175
|
+
'deleteMessage',
|
176
|
+
'deleteThread',
|
177
|
+
'forwardAttachment',
|
178
|
+
'getCurrentUserID',
|
179
|
+
'getEmojiUrl',
|
180
|
+
'getFriendsList',
|
181
|
+
'getThreadHistory',
|
182
|
+
'getThreadInfo',
|
183
|
+
'getThreadList',
|
184
|
+
'getThreadPictures',
|
185
|
+
'getUserID',
|
186
|
+
'getUserInfo',
|
187
|
+
'handleFriendRequest',
|
188
|
+
'handleMessageRequest',
|
189
|
+
'listenMqtt',
|
190
|
+
'logout',
|
191
|
+
'markAsDelivered',
|
192
|
+
'markAsRead',
|
193
|
+
'markAsReadAll',
|
194
|
+
'markAsSeen',
|
195
|
+
'muteThread',
|
196
|
+
'removeUserFromGroup',
|
197
|
+
'resolvePhotoUrl',
|
198
|
+
'searchForThread',
|
199
|
+
'sendTypingIndicator',
|
200
|
+
'setMessageReaction',
|
201
|
+
'setTitle',
|
202
|
+
'threadColors',
|
203
|
+
'unsendMessage',
|
204
|
+
'unfriend',
|
205
|
+
|
206
|
+
// HTTP
|
207
|
+
'httpGet',
|
208
|
+
'httpPost',
|
209
|
+
|
210
|
+
// Deprecated features
|
211
|
+
"getThreadListDeprecated",
|
212
|
+
'getThreadHistoryDeprecated',
|
213
|
+
'getThreadInfoDeprecated',
|
214
|
+
];
|
215
|
+
|
216
|
+
var defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
217
|
+
|
218
|
+
// Load all api functions in a loop
|
219
|
+
apiFuncNames.map(v => api[v] = require('./src/' + v)(defaultFuncs, api, ctx));
|
220
|
+
|
221
|
+
return [ctx, defaultFuncs, api];
|
222
|
+
}
|
223
|
+
|
224
|
+
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
225
|
+
return function(res) {
|
226
|
+
var html = res.body;
|
227
|
+
var $ = cheerio.load(html);
|
228
|
+
var arr = [];
|
229
|
+
|
230
|
+
// This will be empty, but just to be sure we leave it
|
231
|
+
$("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
232
|
+
|
233
|
+
arr = arr.filter(function(v) {
|
234
|
+
return v.val && v.val.length;
|
235
|
+
});
|
236
|
+
|
237
|
+
var form = utils.arrToForm(arr);
|
238
|
+
form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
239
|
+
form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
|
240
|
+
form.email = email;
|
241
|
+
form.pass = password;
|
242
|
+
form.default_persistent = '0';
|
243
|
+
form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
|
244
|
+
form.locale = 'en_US';
|
245
|
+
form.timezone = '240';
|
246
|
+
form.lgnjs = ~~(Date.now() / 1000);
|
247
|
+
|
248
|
+
|
249
|
+
// Getting cookies from the HTML page... (kill me now plz)
|
250
|
+
// we used to get a bunch of cookies in the headers of the response of the
|
251
|
+
// request, but FB changed and they now send those cookies inside the JS.
|
252
|
+
// They run the JS which then injects the cookies in the page.
|
253
|
+
// The "solution" is to parse through the html and find those cookies
|
254
|
+
// which happen to be conveniently indicated with a _js_ in front of their
|
255
|
+
// variable name.
|
256
|
+
//
|
257
|
+
// ---------- Very Hacky Part Starts -----------------
|
258
|
+
var willBeCookies = html.split("\"_js_");
|
259
|
+
willBeCookies.slice(1).map(function(val) {
|
260
|
+
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
261
|
+
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
262
|
+
});
|
263
|
+
// ---------- Very Hacky Part Ends -----------------
|
264
|
+
|
265
|
+
log.info("login", "Logging in...");
|
266
|
+
return utils
|
267
|
+
.post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
|
268
|
+
.then(utils.saveCookies(jar))
|
269
|
+
.then(function(res) {
|
270
|
+
var headers = res.headers;
|
271
|
+
if (!headers.location) throw { error: "Wrong username/password." };
|
272
|
+
|
273
|
+
// This means the account has login approvals turned on.
|
274
|
+
if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
|
275
|
+
log.info("login", "You have login approvals turned on.");
|
276
|
+
var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
|
277
|
+
|
278
|
+
return utils
|
279
|
+
.get(headers.location, jar, null, loginOptions)
|
280
|
+
.then(utils.saveCookies(jar))
|
281
|
+
.then(function(res) {
|
282
|
+
var html = res.body;
|
283
|
+
// Make the form in advance which will contain the fb_dtsg and nh
|
284
|
+
var $ = cheerio.load(html);
|
285
|
+
var arr = [];
|
286
|
+
$("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
287
|
+
|
288
|
+
arr = arr.filter(function(v) {
|
289
|
+
return v.val && v.val.length;
|
290
|
+
});
|
291
|
+
|
292
|
+
var form = utils.arrToForm(arr);
|
293
|
+
if (html.indexOf("checkpoint/?next") > -1) {
|
294
|
+
setTimeout(() => {
|
295
|
+
checkVerified = setInterval((_form) => {}, 5000, {
|
296
|
+
fb_dtsg: form.fb_dtsg,
|
297
|
+
jazoest: form.jazoest,
|
298
|
+
dpr: 1
|
299
|
+
});
|
300
|
+
}, 2500);
|
301
|
+
throw {
|
302
|
+
error: 'login-approval',
|
303
|
+
continue: function submit2FA(code) {
|
304
|
+
form.approvals_code = code;
|
305
|
+
form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
|
306
|
+
var prResolve = null;
|
307
|
+
var prReject = null;
|
308
|
+
var rtPromise = new Promise(function(resolve, reject) {
|
309
|
+
prResolve = resolve;
|
310
|
+
prReject = reject;
|
311
|
+
});
|
312
|
+
if (typeof code == "string") {
|
313
|
+
utils
|
314
|
+
.post(nextURL, jar, form, loginOptions)
|
315
|
+
.then(utils.saveCookies(jar))
|
316
|
+
.then(function(res) {
|
317
|
+
var $ = cheerio.load(res.body);
|
318
|
+
var error = $("#approvals_code").parent().attr("data-xui-error");
|
319
|
+
if (error) {
|
320
|
+
throw {
|
321
|
+
error: 'login-approval',
|
322
|
+
errordesc: "Invalid 2FA code.",
|
323
|
+
lerror: error,
|
324
|
+
continue: submit2FA
|
325
|
+
};
|
326
|
+
}
|
327
|
+
})
|
328
|
+
.then(function() {
|
329
|
+
// Use the same form (safe I hope)
|
330
|
+
delete form.no_fido;
|
331
|
+
delete form.approvals_code;
|
332
|
+
form.name_action_selected = 'dont_save'; //'save_device';
|
333
|
+
|
334
|
+
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
335
|
+
})
|
336
|
+
.then(function(res) {
|
337
|
+
var headers = res.headers;
|
338
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with login approvals." };
|
339
|
+
|
340
|
+
var appState = utils.getAppState(jar);
|
341
|
+
|
342
|
+
if (callback === prCallback) {
|
343
|
+
callback = function(err, api) {
|
344
|
+
if (err) return prReject(err);
|
345
|
+
return prResolve(api);
|
346
|
+
};
|
347
|
+
}
|
348
|
+
|
349
|
+
// Simply call loginHelper because all it needs is the jar
|
350
|
+
// and will then complete the login process
|
351
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
352
|
+
})
|
353
|
+
.catch(function(err) {
|
354
|
+
// Check if using Promise instead of callback
|
355
|
+
if (callback === prCallback) prReject(err);
|
356
|
+
else callback(err);
|
357
|
+
});
|
358
|
+
} else {
|
359
|
+
utils
|
360
|
+
.post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, { "Referer": "https://www.facebook.com/checkpoint/?next" })
|
361
|
+
.then(utils.saveCookies(jar))
|
362
|
+
.then(res => {
|
363
|
+
try {
|
364
|
+
JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
|
365
|
+
} catch (ex) {
|
366
|
+
clearInterval(checkVerified);
|
367
|
+
log.info("login", "Verified from browser. Logging in...");
|
368
|
+
if (callback === prCallback) {
|
369
|
+
callback = function(err, api) {
|
370
|
+
if (err) return prReject(err);
|
371
|
+
return prResolve(api);
|
372
|
+
};
|
373
|
+
}
|
374
|
+
return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
|
375
|
+
}
|
376
|
+
})
|
377
|
+
.catch(ex => {
|
378
|
+
log.error("login", ex);
|
379
|
+
if (callback === prCallback) prReject(ex);
|
380
|
+
else callback(ex);
|
381
|
+
});
|
382
|
+
}
|
383
|
+
return rtPromise;
|
384
|
+
}
|
385
|
+
};
|
386
|
+
} else {
|
387
|
+
if (!loginOptions.forceLogin) throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
|
388
|
+
|
389
|
+
if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
|
390
|
+
else form['submit[This Is Okay]'] = "This Is Okay";
|
391
|
+
|
392
|
+
return utils
|
393
|
+
.post(nextURL, jar, form, loginOptions)
|
394
|
+
.then(utils.saveCookies(jar))
|
395
|
+
.then(function() {
|
396
|
+
// Use the same form (safe I hope)
|
397
|
+
form.name_action_selected = 'save_device';
|
398
|
+
|
399
|
+
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
400
|
+
})
|
401
|
+
.then(function(res) {
|
402
|
+
var headers = res.headers;
|
403
|
+
|
404
|
+
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
|
405
|
+
|
406
|
+
var appState = utils.getAppState(jar);
|
407
|
+
|
408
|
+
// Simply call loginHelper because all it needs is the jar
|
409
|
+
// and will then complete the login process
|
410
|
+
return loginHelper(appState, email, password, loginOptions, callback);
|
411
|
+
})
|
412
|
+
.catch(e => callback(e));
|
413
|
+
}
|
414
|
+
});
|
415
|
+
}
|
416
|
+
|
417
|
+
return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
|
418
|
+
});
|
419
|
+
};
|
420
|
+
}
|
421
|
+
|
422
|
+
// Helps the login
|
423
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
424
|
+
var mainPromise = null;
|
425
|
+
var jar = utils.getJar();
|
426
|
+
|
427
|
+
// If we're given an appState we loop through it and save each cookie
|
428
|
+
// back into the jar.
|
429
|
+
if (appState) {
|
430
|
+
appState.map(function(c) {
|
431
|
+
var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
|
432
|
+
jar.setCookie(str, "http://" + c.domain);
|
433
|
+
});
|
434
|
+
|
435
|
+
// Load the main page.
|
436
|
+
mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
437
|
+
} else {
|
438
|
+
// Open the main page, then we login with the given credentials and finally
|
439
|
+
// load the main page again (it'll give us some IDs that we need)
|
440
|
+
mainPromise = utils
|
441
|
+
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
442
|
+
.then(utils.saveCookies(jar))
|
443
|
+
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
444
|
+
.then(function() {
|
445
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
|
446
|
+
});
|
447
|
+
}
|
448
|
+
|
449
|
+
var ctx = null;
|
450
|
+
var _defaultFuncs = null;
|
451
|
+
var api = null;
|
452
|
+
|
453
|
+
mainPromise = mainPromise
|
454
|
+
.then(function(res) {
|
455
|
+
// Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
|
456
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
457
|
+
var redirect = reg.exec(res.body);
|
458
|
+
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
459
|
+
return res;
|
460
|
+
})
|
461
|
+
.then(function(res) {
|
462
|
+
var html = res.body;
|
463
|
+
var stuff = buildAPI(globalOptions, html, jar);
|
464
|
+
ctx = stuff[0];
|
465
|
+
_defaultFuncs = stuff[1];
|
466
|
+
api = stuff[2];
|
467
|
+
return res;
|
468
|
+
});
|
469
|
+
|
470
|
+
// given a pageID we log in as a page
|
471
|
+
if (globalOptions.pageID) {
|
472
|
+
mainPromise = mainPromise
|
473
|
+
.then(function() {
|
474
|
+
return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
475
|
+
})
|
476
|
+
.then(function(resData) {
|
477
|
+
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
478
|
+
url = url.substring(0, url.length - 1);
|
479
|
+
return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
|
480
|
+
});
|
481
|
+
}
|
482
|
+
|
483
|
+
// At the end we call the callback or catch an exception
|
484
|
+
mainPromise
|
485
|
+
.then(function() {
|
486
|
+
//log.info("login", 'Done logging in.');
|
487
|
+
return callback(null, api);
|
488
|
+
})
|
489
|
+
.catch(function(e) {
|
490
|
+
log.error("login", e.error || e);
|
491
|
+
callback(e);
|
492
|
+
});
|
493
|
+
}
|
494
|
+
|
495
|
+
function login(loginData, options, callback) {
|
496
|
+
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
497
|
+
callback = options;
|
498
|
+
options = {};
|
499
|
+
}
|
500
|
+
|
501
|
+
var globalOptions = {
|
502
|
+
selfListen: false,
|
503
|
+
listenEvents: true,
|
504
|
+
listenTyping: false,
|
505
|
+
updatePresence: false,
|
506
|
+
forceLogin: false,
|
507
|
+
autoMarkDelivery: false,
|
508
|
+
autoMarkRead: true,
|
509
|
+
autoReconnect: true,
|
510
|
+
logRecordSize: defaultLogRecordSize,
|
511
|
+
online: false,
|
512
|
+
emitReady: false,
|
513
|
+
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
|
514
|
+
};
|
515
|
+
|
516
|
+
setOptions(globalOptions, options);
|
517
|
+
|
518
|
+
var prCallback = null;
|
519
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
520
|
+
var rejectFunc = null;
|
521
|
+
var resolveFunc = null;
|
522
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
523
|
+
resolveFunc = resolve;
|
524
|
+
rejectFunc = reject;
|
525
|
+
});
|
526
|
+
prCallback = function(error, api) {
|
527
|
+
if (error) return rejectFunc(error);
|
528
|
+
return resolveFunc(api);
|
529
|
+
};
|
530
|
+
callback = prCallback;
|
531
|
+
}
|
532
|
+
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
533
|
+
return returnPromise;
|
534
|
+
}
|
535
|
+
|
536
|
+
module.exports = login;
|