node-ainzfb-new 1.4.4

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