fca-priyansh 16.0.0 → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/Extra/Balancer.js +49 -0
  2. package/Extra/Bypass/956/index.js +234 -0
  3. package/Extra/Bypass/test/aaaa.json +170 -0
  4. package/Extra/Bypass/test/index.js +188 -0
  5. package/Extra/Database/index.js +249 -140
  6. package/Extra/ExtraAddons.js +35 -33
  7. package/Extra/ExtraFindUID.js +3 -1
  8. package/Extra/ExtraGetThread.js +303 -56
  9. package/Extra/ExtraUptimeRobot.js +15 -3
  10. package/Extra/Html/Classic/script.js +3 -3
  11. package/Extra/Security/AES_256_GCM/index.js +0 -0
  12. package/Extra/Security/Base/Step_1.js +6 -0
  13. package/Extra/Security/Base/Step_2.js +22 -0
  14. package/Extra/Security/Base/Step_3.js +22 -0
  15. package/Extra/Security/Base/index.js +191 -0
  16. package/Extra/Security/Index.js +5 -146
  17. package/Extra/Security/Step_1.js +4 -9
  18. package/Extra/Security/Step_2.js +2 -0
  19. package/Extra/Security/Step_3.js +4 -2
  20. package/Extra/Src/Change_Environment.js +1 -1
  21. package/Extra/Src/Check_Update.js +67 -0
  22. package/Extra/Src/History.js +2 -2
  23. package/Extra/Src/Instant_Update.js +65 -0
  24. package/Extra/Src/Premium.js +35 -38
  25. package/Extra/Src/Release_Memory.js +160 -0
  26. package/Extra/Src/Websocket.js +213 -0
  27. package/Extra/Src/image/checkmate.jpg +0 -0
  28. package/Extra/Src/test.js +28 -0
  29. package/Extra/Src/uuid.js +1 -1
  30. package/Func/AcceptAgreement.js +4 -5
  31. package/Func/ClearCache.js +7 -7
  32. package/Func/ReportV1.js +5 -5
  33. package/LICENSE +1 -4
  34. package/Language/index.json +59 -8
  35. package/Main.js +1290 -0
  36. package/README.md +198 -1
  37. package/broadcast.js +43 -37
  38. package/index.js +303 -1704
  39. package/logger.js +4 -4
  40. package/package.json +16 -11
  41. package/src/Dev_Horizon_Data.js +3 -3
  42. package/src/Dev_getThreadInfoOLD.js +422 -0
  43. package/src/Dev_shareTest2.js +68 -0
  44. package/src/Dev_shareTest3.js +71 -0
  45. package/src/Premium.js +8 -13
  46. package/src/Screenshot.js +4 -6
  47. package/src/editMessage.js +53 -0
  48. package/src/getAccessToken.js +0 -4
  49. package/src/getFriendsList.js +1 -1
  50. package/src/getMessage.js +26 -3
  51. package/src/getThreadHistory.js +1 -1
  52. package/src/getThreadInfo.js +237 -161
  53. package/src/getThreadInfoOLD.js +422 -0
  54. package/src/getThreadMain.js +1 -1
  55. package/src/getUID.js +3 -3
  56. package/src/getUserInfo.js +56 -73
  57. package/src/getUserInfoMain.js +2 -2
  58. package/src/getUserInfoV2.js +0 -4
  59. package/src/getUserInfoV3.js +3 -3
  60. package/src/getUserInfoV4.js +5 -5
  61. package/src/getUserInfoV5.js +4 -4
  62. package/src/listenMqtt.js +905 -625
  63. package/src/listenMqttV1.js +846 -0
  64. package/src/sendMessage.js +54 -2
  65. package/src/sendMqttMessage.js +71 -0
  66. package/src/setPostReaction.js +3 -3
  67. package/src/shareContact.js +55 -0
  68. package/src/shareLink.js +58 -0
  69. package/src/unsendMessage.js +28 -20
  70. package/src/unsendMqttMessage.js +66 -0
  71. package/utils.js +1567 -138
  72. package/.gitattributes +0 -2
  73. package/gitattributes +0 -2
  74. package/gitignore.txt +0 -10
package/Main.js ADDED
@@ -0,0 +1,1290 @@
1
+ 'use strict';
2
+
3
+ //-[ Require config and use ]-!/
4
+
5
+ if (global.Fca.Require.Priyansh.Config != 'default') {
6
+ //do ssth
7
+ }
8
+
9
+ const Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == global.Fca.Require.Priyansh.Language).Folder.Index;
10
+
11
+ //-[ Require All Package Need Use ]-!/
12
+
13
+ var utils = global.Fca.Require.utils,
14
+ logger = global.Fca.Require.logger,
15
+ fs = global.Fca.Require.fs,
16
+ getText = global.Fca.getText,
17
+ log = global.Fca.Require.log,
18
+ express = require("express")(),
19
+ { join } = require('path'),
20
+ cheerio = require("cheerio"),
21
+ { readFileSync, writeFileSync } = require('fs-extra'),
22
+ Database = require("./Extra/Database"),
23
+ readline = require("readline"),
24
+ chalk = require("chalk"),
25
+ figlet = require("figlet"),
26
+ os = require("os"),
27
+ deasync = require('deasync'),
28
+ Security = require("./Extra/Security/Base"),
29
+ { getAll, deleteAll } = require('./Extra/ExtraGetThread'),
30
+ ws = require('ws'),
31
+ Websocket = require('./Extra/Src/Websocket'),
32
+ Convert = require('ansi-to-html');
33
+
34
+ //-[ Set Variable For Process ]-!/
35
+
36
+ log.maxRecordSize = 100;
37
+ var checkVerified = null;
38
+ const Boolean_Option = ['online','selfListen','listenEvents','updatePresence','forceLogin','autoMarkDelivery','autoMarkRead','listenTyping','autoReconnect','emitReady'];
39
+
40
+ function setOptions(globalOptions, options) {
41
+ Object.keys(options).map(function(key) {
42
+ switch (Boolean_Option.includes(key)) {
43
+ case true: {
44
+ globalOptions[key] = Boolean(options[key]);
45
+ break;
46
+ }
47
+ case false: {
48
+ switch (key) {
49
+ case 'pauseLog': {
50
+ if (options.pauseLog) log.pause();
51
+ else log.resume();
52
+ break;
53
+ }
54
+ case 'logLevel': {
55
+ log.level = options.logLevel;
56
+ globalOptions.logLevel = options.logLevel;
57
+ break;
58
+ }
59
+ case 'logRecordSize': {
60
+ log.maxRecordSize = options.logRecordSize;
61
+ globalOptions.logRecordSize = options.logRecordSize;
62
+ break;
63
+ }
64
+ case 'pageID': {
65
+ globalOptions.pageID = options.pageID.toString();
66
+ break;
67
+ }
68
+ case 'userAgent': {
69
+ globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36');
70
+ break;
71
+ }
72
+ case 'proxy': {
73
+ if (typeof options.proxy != "string") {
74
+ delete globalOptions.proxy;
75
+ utils.setProxy();
76
+ } else {
77
+ globalOptions.proxy = options.proxy;
78
+ utils.setProxy(globalOptions.proxy);
79
+ }
80
+ break;
81
+ }
82
+ default: {
83
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
84
+ break;
85
+ }
86
+ }
87
+ break;
88
+ }
89
+ }
90
+ });
91
+ }
92
+
93
+ function BypassAutomationNotification(resp, jar, globalOptions, appstate,ID) {
94
+ global.Fca.BypassAutomationNotification = BypassAutomationNotification
95
+ try {
96
+ let UID;
97
+ if (ID) UID = ID
98
+ else {
99
+ UID = (appstate.find(i => i.key == 'c_user') || appstate.find(i => i.key == 'i_user'))
100
+ UID = UID.value;
101
+ }
102
+ if (resp !== undefined) {
103
+ if (resp.request.uri && resp.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
104
+ if (resp.request.uri.href.includes('601051028565049')) {
105
+ const fb_dtsg = utils.getFrom(resp.body, '["DTSGInitData",[],{"token":"', '","');
106
+ const jazoest = utils.getFrom(resp.body, 'jazoest=', '",');
107
+ const lsd = utils.getFrom(resp.body, "[\"LSD\",[],{\"token\":\"", "\"}");
108
+
109
+ const FormBypass = {
110
+ av: UID,
111
+ fb_dtsg, jazoest, lsd,
112
+ fb_api_caller_class: "RelayModern",
113
+ fb_api_req_friendly_name: "FBScrapingWarningMutation",
114
+ variables: JSON.stringify({}),
115
+ server_timestamps: true,
116
+ doc_id: 6339492849481770
117
+ }
118
+ return utils.post("https://www.facebook.com/api/graphql/", jar, FormBypass, globalOptions)
119
+ .then(utils.saveCookies(jar)).then(function(res) {
120
+ global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.Bypass_AutoNoti);
121
+ return process.exit(1);
122
+ });
123
+ }
124
+ else {
125
+ return resp;
126
+ }
127
+ }
128
+ else {
129
+ return resp
130
+ }
131
+ }
132
+ else {
133
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(function(res) {
134
+ if (res.request.uri && res.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
135
+ if (res.request.uri.href.includes('601051028565049')) return { Status: true, Body: res.body }
136
+ else return { Status: false, Body: res.body }
137
+ }
138
+ else return { Status: false, Body: res.body }
139
+ }).then(function(res) {
140
+ if (res.Status === true) {
141
+ const fb_dtsg = utils.getFrom(res.Body, '["DTSGInitData",[],{"token":"', '","');
142
+ const jazoest = utils.getFrom(res.Body, 'jazoest=', '",');
143
+ const lsd = utils.getFrom(res.Body, "[\"LSD\",[],{\"token\":\"", "\"}");
144
+
145
+ const FormBypass = {
146
+ av: UID,
147
+ fb_dtsg, jazoest, lsd,
148
+ fb_api_caller_class: "RelayModern",
149
+ fb_api_req_friendly_name: "FBScrapingWarningMutation",
150
+ variables: JSON.stringify({}),
151
+ server_timestamps: true,
152
+ doc_id: 6339492849481770
153
+ }
154
+ return utils.post("https://www.facebook.com/api/graphql/", jar, FormBypass, globalOptions).then(utils.saveCookies(jar))
155
+ .then(res => {
156
+ global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.Bypass_AutoNoti);
157
+ return res
158
+ })
159
+ }
160
+ else return res;
161
+
162
+ })
163
+ .then(function(res) {
164
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar))
165
+ })
166
+ .then(function(res) {
167
+ return process.exit(1)
168
+ })
169
+ }
170
+ }
171
+ catch (e) {
172
+ console.log(e)
173
+ }
174
+ }
175
+
176
+ //-[ Function BuildAPI ]-!/
177
+
178
+ /**
179
+ * @param {any} globalOptions
180
+ * @param {string} html
181
+ * @param {{ getCookies: (arg0: string) => any[]; }} jar
182
+ */
183
+
184
+ function buildAPI(globalOptions, html, jar, bypass_region) {
185
+ //new feat
186
+ const fb_dtsg = utils.getFroms(html, '["DTSGInitData",[],{"token":"', '","')[0]; //nhăm nhăm nhăm nhăm
187
+
188
+ //check tiktik
189
+ var userID;
190
+ var cookie = jar.getCookies("https://www.facebook.com");
191
+ //.log(cookie)
192
+ var maybeUser = cookie.filter(function(val) { return val.cookieString().split("=")[0] === "c_user"; });
193
+ var maybeTiktik = cookie.filter(function(val) { return val.cookieString().split("=")[0] === "i_user"; });
194
+ if (maybeUser.length === 0 && maybeTiktik.length === 0) {
195
+ if (global.Fca.Require.Priyansh.AutoLogin) {
196
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
197
+ global.Fca.Action('AutoLogin')
198
+ });
199
+ }
200
+ else if (!global.Fca.Require.Priyansh.AutoLogin) {
201
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
202
+ }
203
+ }
204
+ else {
205
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", Language.CheckPointLevelI);
206
+
207
+ if (maybeTiktik[0] && maybeTiktik[0].cookieString().includes('i_user')) {
208
+ userID = maybeTiktik[0].cookieString().split("=")[1].toString();
209
+
210
+ }
211
+ else userID = maybeUser[0].cookieString().split("=")[1].toString();
212
+ process.env['UID'] = logger.Normal(getText(Language.UID,userID), userID);
213
+
214
+ try {
215
+ clearInterval(checkVerified);
216
+ } catch (e) {
217
+ console.log(e);
218
+ }
219
+
220
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
221
+
222
+ var CHECK_MQTT = {
223
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
224
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
225
+ legacyFBMQTTMatch: html.match(/\["MqttWebConfig",\[\],{"fbid":"(.*?)","appID":219994525426954,"endpoint":"(.*?)","pollingEndpoint":"(.*?)"/)
226
+ }
227
+
228
+ // tổng hợp danh sách region never die của Kanzu =))
229
+ /**
230
+ * PRN = Pacific Northwest Region (Khu vực Tây Bắc Thái Bình Dương)
231
+ * VLL = Valley Region
232
+ * ASH = Ashburn Region
233
+ * DFW = Dallas/Fort Worth Region
234
+ * LLA = Los Angeles Region
235
+ * FRA = Frankfurt
236
+ * SIN = Singapore
237
+ * NRT = Tokyo (Japan)
238
+ * HKG = Hong Kong
239
+ * SYD = Sydney
240
+ */
241
+
242
+ let Slot = Object.keys(CHECK_MQTT);
243
+ var mqttEndpoint,region,irisSeqID;
244
+ Object.keys(CHECK_MQTT).map(function(MQTT) {
245
+ if (CHECK_MQTT[MQTT] && !region) {
246
+ switch (Slot.indexOf(MQTT)) {
247
+ case 0: {
248
+ irisSeqID = CHECK_MQTT[MQTT][1];
249
+ mqttEndpoint = CHECK_MQTT[MQTT][2].replace(/\\\//g, "/");
250
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
251
+ return;
252
+ }
253
+ case 1: {
254
+ irisSeqID = CHECK_MQTT[MQTT][2];
255
+ mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
256
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
257
+ return;
258
+ }
259
+ case 2: {
260
+ mqttEndpoint = CHECK_MQTT[MQTT][2].replace(/\\\//g, "/"); //is important lmao f?
261
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
262
+ return;
263
+ }
264
+ }
265
+ return;
266
+ }
267
+ });
268
+
269
+ const regions = [
270
+ {
271
+ code: "PRN",
272
+ name: "Pacific Northwest Region",
273
+ location: "Khu vực Tây Bắc Thái Bình Dương"
274
+ },
275
+ {
276
+ code: "VLL",
277
+ name: "Valley Region",
278
+ location: "Valley"
279
+ },
280
+ {
281
+ code: "ASH",
282
+ name: "Ashburn Region",
283
+ location: "Ashburn"
284
+ },
285
+ {
286
+ code: "DFW",
287
+ name: "Dallas/Fort Worth Region",
288
+ location: "Dallas/Fort Worth"
289
+ },
290
+ {
291
+ code: "LLA",
292
+ name: "Los Angeles Region",
293
+ location: "Los Angeles"
294
+ },
295
+ {
296
+ code: "FRA",
297
+ name: "Frankfurt",
298
+ location: "Frankfurt"
299
+ },
300
+ {
301
+ code: "SIN",
302
+ name: "Singapore",
303
+ location: "Singapore"
304
+ },
305
+ {
306
+ code: "NRT",
307
+ name: "Tokyo",
308
+ location: "Japan"
309
+ },
310
+ {
311
+ code: "HKG",
312
+ name: "Hong Kong",
313
+ location: "Hong Kong"
314
+ },
315
+ {
316
+ code: "SYD",
317
+ name: "Sydney",
318
+ location: "Sydney"
319
+ },
320
+ {
321
+ code: "PNB",
322
+ name: "Pacific Northwest - Beta",
323
+ location: "Pacific Northwest "
324
+ }
325
+ ];
326
+
327
+ if (!region) {
328
+ region = ['prn',"pnb","vll","hkg","sin"][Math.random()*5|0];
329
+
330
+ }
331
+ if (!mqttEndpoint) {
332
+ mqttEndpoint = "wss://edge-chat.facebook.com/chat?region=" + region;
333
+ }
334
+
335
+ const Location = regions.find(r => r.code === region.toUpperCase());
336
+ logger.Normal(getText(Language.Area,(Location == undefined ? region.toUpperCase() : Location.name)));
337
+
338
+ var ctx = {
339
+ userID: userID,
340
+ jar: jar,
341
+ clientID: clientID,
342
+ globalOptions: globalOptions,
343
+ loggedIn: true,
344
+ access_token: 'NONE',
345
+ clientMutationId: 0,
346
+ mqttClient: undefined,
347
+ lastSeqId: irisSeqID,
348
+ syncToken: undefined,
349
+ mqttEndpoint: mqttEndpoint,
350
+ region: region,
351
+ firstListen: true,
352
+ req_ID: 0,
353
+ callback_Task: {},
354
+ fb_dtsg //i love u
355
+ };
356
+
357
+ var api = {
358
+ setOptions: setOptions.bind(null, globalOptions),
359
+ getAppState: function getAppState() {
360
+ return utils.getAppState(jar);
361
+ }
362
+ };
363
+ if (region && mqttEndpoint) {
364
+ //do sth
365
+ }
366
+ else {
367
+ if (bypass_region) {
368
+ logger.Normal(Language.NoAreaDataBypass);
369
+ }
370
+ else {
371
+ log.warn("login", getText(Language.NoAreaData));
372
+ api["htmlData"] = html;
373
+ }
374
+ }
375
+
376
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
377
+
378
+ fs.readdirSync(__dirname + "/src").filter((/** @type {string} */File) => File.endsWith(".js") && !File.includes('Dev_')).map((/** @type {string} */File) => {
379
+ if (File == 'getThreadInfo.js' && global.Fca.Require.Priyansh.AntiGetInfo.AntiGetThreadInfo != true || File == 'getUserInfo.js' && global.Fca.Require.Priyansh.AntiGetInfo.AntiGetUserInfo != true) api[File.split('.').slice(0, -1).join('.')] = require('./src/' + (File.includes('getThreadInfo') ? 'getThreadMain.js' : 'getUserInfoMain.js'))(defaultFuncs, api, ctx)
380
+ else api[File.split('.').slice(0, -1).join('.')] = require('./src/' + File)(defaultFuncs, api, ctx)
381
+ });
382
+
383
+ return {
384
+ ctx,
385
+ defaultFuncs,
386
+ api
387
+ };
388
+ }
389
+ }
390
+
391
+ //-[ Function makeLogin ]-!/
392
+
393
+ /**
394
+ * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
395
+ * @param {any} email
396
+ * @param {any} password
397
+ * @param {{ forceLogin: any; }} loginOptions
398
+ * @param {(err: any, api: any) => any} callback
399
+ * @param {any} prCallback
400
+ */
401
+
402
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
403
+ return function(res) {
404
+ var html = res.body,$ = cheerio.load(html),arr = [];
405
+
406
+ $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
407
+
408
+ arr = arr.filter(function(v) {
409
+ return v.val && v.val.length;
410
+ });
411
+ var form = utils.arrToForm(arr);
412
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
413
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
414
+ form.email = email;
415
+ form.pass = password;
416
+ form.default_persistent = '0';
417
+ form.locale = 'en_US';
418
+ form.timezone = '240';
419
+ form.lgnjs = ~~(Date.now() / 1000);
420
+
421
+ html.split("\"_js_").slice(1).map((val) => {
422
+ jar.setCookie(utils.formatCookie(JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]"), "facebook"),"https://www.facebook.com")
423
+ });
424
+
425
+ logger.Normal(Language.OnLogin);
426
+ return utils
427
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
428
+ .then(utils.saveCookies(jar))
429
+ .then(function(/** @type {{ headers: any; }} */res) {
430
+ var headers = res.headers;
431
+ if (!headers.location) throw { error: Language.InvaildAccount };
432
+
433
+ // This means the account has login approvals turned on.
434
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
435
+ logger.Warning(Language.TwoAuth);
436
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
437
+
438
+ return utils
439
+ .get(headers.location, jar, null, loginOptions)
440
+ .then(utils.saveCookies(jar))
441
+ .then(function(res) {
442
+ if (!Database().get('ThroughAcc')) {
443
+ Database().set('ThroughAcc', email);
444
+ }
445
+ else {
446
+ if (String((Database().get('ThroughAcc'))).replace(RegExp('"','g'), '') != String(email).replace(RegExp('"','g'), '')) {
447
+ Database().set('ThroughAcc', email);
448
+ if (Database().get('Through2Fa')) {
449
+ Database().delete('Through2Fa');
450
+ }
451
+ }
452
+ }
453
+ var html = res.body,$ = cheerio.load(html), arr = [];
454
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
455
+ arr = arr.filter(v => { return v.val && v.val.length });
456
+ var form = utils.arrToForm(arr);
457
+ if (html.indexOf("checkpoint/?next") > -1) {
458
+ setTimeout(() => {
459
+ checkVerified = setInterval((_form) => {}, 5000, {
460
+ fb_dtsg: form.fb_dtsg,
461
+ jazoest: form.jazoest,
462
+ dpr: 1
463
+ });
464
+ }, 2500);
465
+ switch (global.Fca.Require.Priyansh.Login2Fa) {
466
+ case true: {
467
+ const question = question => {
468
+ const rl = readline.createInterface({
469
+ input: process.stdin,
470
+ output: process.stdout
471
+ });
472
+ var done,answ;
473
+ rl.question(question, answer => {
474
+ rl.close();
475
+ answ = answer;
476
+ done = true
477
+ })
478
+ deasync.loopWhile(function(){
479
+ return !done;
480
+ });
481
+ return answ;
482
+ };
483
+ try {
484
+ const Old_Cookie = Database().get('Through2Fa');
485
+ if (Old_Cookie) {
486
+ Old_Cookie.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
487
+ let str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
488
+ jar.setCookie(str, "http://" + c.domain);
489
+ });
490
+ let Form = utils.arrToForm(arr);
491
+ Form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
492
+ Form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
493
+ Form.email = email;
494
+ Form.pass = password;
495
+ Form.default_persistent = '0';
496
+ Form.locale = 'en_US';
497
+ Form.timezone = '240';
498
+ Form.lgnjs = ~~(Date.now() / 1000);
499
+ return utils
500
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, Form, loginOptions)
501
+ .then(utils.saveCookies(jar))
502
+ .then(function(res) {
503
+ let headers = res.headers
504
+ if (!headers['set-cookie'][0].includes('deleted')) {
505
+ logger.Warning(Language.ErrThroughCookies, function() {
506
+ Database().delete('Through2Fa');
507
+ });
508
+ process.exit(1);
509
+ }
510
+ if (headers.location && headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
511
+ return utils
512
+ .get(headers.location, jar, null, loginOptions)
513
+ .then(utils.saveCookies(jar))
514
+ .then(function(res) {
515
+ var html = res.body,$ = cheerio.load(html), arr = [];
516
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
517
+ arr = arr.filter(v => { return v.val && v.val.length });
518
+ var Form = utils.arrToForm(arr);
519
+
520
+ if (html.indexOf("checkpoint/?next") > -1) {
521
+ setTimeout(() => {
522
+ checkVerified = setInterval((_form) => {}, 5000, {
523
+ fb_dtsg: Form.fb_dtsg,
524
+ jazoest: Form.jazoest,
525
+ dpr: 1
526
+ });
527
+ }, 2500);
528
+
529
+ if (!res.headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
530
+ try {
531
+ delete Form.name_action_selected;
532
+ Form['submit[Continue]'] = $("#checkpointSubmitButton").html();
533
+ return utils
534
+ .post(nextURL, jar, Form, loginOptions)
535
+ .then(utils.saveCookies(jar))
536
+ .then(function() {
537
+ Form['submit[This was me]'] = "This was me";
538
+ return utils.post(nextURL, jar, Form, loginOptions).then(utils.saveCookies(jar));
539
+ })
540
+ .then(function() {
541
+ delete Form['submit[This was me]'];
542
+ Form.name_action_selected = 'save_device';
543
+ Form['submit[Continue]'] = $("#checkpointSubmitButton").html();
544
+ return utils.post(nextURL, jar, Form, loginOptions).then(utils.saveCookies(jar));
545
+ })
546
+ .then(function(res) {
547
+ var headers = res.headers;
548
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
549
+ Database().delete('Through2Fa');
550
+ process.exit(1);
551
+ }
552
+ var appState = utils.getAppState(jar,false);
553
+ Database().set('Through2Fa', appState);
554
+ return loginHelper(appState, email, password, loginOptions, callback);
555
+ })
556
+ .catch((e) => callback(e));
557
+ }
558
+ catch (e) {
559
+ console.log(e)
560
+ }
561
+ }
562
+ }
563
+ })
564
+ }
565
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
566
+ })
567
+ .catch((e) => console.log(e));
568
+ }
569
+ }
570
+ catch (e) {
571
+ Database().delete('Through2Fa');
572
+ }
573
+ const Otp_code = require('totp-generator');
574
+ const Code = global.Fca.Require.Priyansh.AuthString.includes('|') == false ? Otp_code(global.Fca.Require.Priyansh.AuthString.includes(" ") ? global.Fca.Require.Priyansh.AuthString.replace(RegExp(" ", 'g'), "") : global.Fca.Require.Priyansh.AuthString) : question(Language.EnterSecurityCode);
575
+ try {
576
+ const approvals = function(N_Code) {
577
+ form.approvals_code = N_Code;
578
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
579
+ var prResolve,prReject;
580
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
581
+
582
+ if (typeof N_Code == "string") {
583
+ utils
584
+ .post(nextURL, jar, form, loginOptions)
585
+ .then(utils.saveCookies(jar))
586
+ .then(function(res) {
587
+ var $ = cheerio.load(res.body);
588
+ var error = $("#approvals_code").parent().attr("data-xui-error");
589
+ if (error) {
590
+ logger.Warning(Language.InvaildTwoAuthCode,function() { approvals(question(Language.EnterSecurityCode)) }); //bruh loop
591
+ };
592
+ })
593
+ .then(function() {
594
+ delete form.no_fido;delete form.approvals_code;
595
+ form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
596
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
597
+ })
598
+ .then(function(res) {
599
+ var headers = res.headers;
600
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
601
+ try {
602
+ delete form.name_action_selected;
603
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
604
+ return utils
605
+ .post(nextURL, jar, form, loginOptions)
606
+ .then(utils.saveCookies(jar))
607
+ .then(function() {
608
+ form['submit[This was me]'] = "This was me";
609
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
610
+ })
611
+ .then(function() {
612
+ delete form['submit[This was me]'];
613
+ form.name_action_selected = 'save_device';
614
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
615
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
616
+ })
617
+ .then(function(res) {
618
+ var headers = res.headers;
619
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
620
+ var appState = utils.getAppState(jar,false);
621
+ Database().set('Through2Fa', appState);
622
+ return loginHelper(appState, email, password, loginOptions, callback);
623
+ })
624
+ .catch((e) => callback(e));
625
+ }
626
+ catch (e) {
627
+ console.log(e)
628
+ }
629
+ }
630
+ var appState = utils.getAppState(jar,false);
631
+ if (callback === prCallback) {
632
+ callback = function(err, api) {
633
+ if (err) return prReject(err);
634
+ return prResolve(api);
635
+ };
636
+ }
637
+ Database().set('Through2Fa', appState);
638
+ return loginHelper(appState, email, password, loginOptions, callback);
639
+ })
640
+ .catch(function(err) {
641
+ if (callback === prCallback) prReject(err);
642
+ else callback(err);
643
+ });
644
+ }
645
+ else {
646
+ utils
647
+ .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" })
648
+ .then(utils.saveCookies(jar))
649
+ .then(function(res) {
650
+ try {
651
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
652
+ } catch (ex) {
653
+ clearInterval(checkVerified);
654
+ logger.Warning(Language.VerifiedCheck);
655
+ if (callback === prCallback) {
656
+ callback = function(err, api) {
657
+ if (err) return prReject(err);
658
+ return prResolve(api);
659
+ };
660
+ }
661
+ let appState = utils.getAppState(jar,false);
662
+ return loginHelper(appState, email, password, loginOptions, callback);
663
+ }
664
+ })
665
+ .catch((ex) => {
666
+ log.error("login", ex);
667
+ if (callback === prCallback) prReject(ex);
668
+ else callback(ex);
669
+ });
670
+ }
671
+ return rtPromise;
672
+ }
673
+ return approvals(Code)
674
+ }
675
+ catch (e) {
676
+ logger.Error(e)
677
+ logger.Error();
678
+ process.exit(0);
679
+ }
680
+ }
681
+ case false: {
682
+ throw {
683
+ error: 'login-approval',
684
+ continue: function submit2FA(code) {
685
+ form.approvals_code = code;
686
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
687
+ var prResolve,prReject;
688
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
689
+ if (typeof code == "string") {
690
+ utils
691
+ .post(nextURL, jar, form, loginOptions)
692
+ .then(utils.saveCookies(jar))
693
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
694
+ var $ = cheerio.load(res.body);
695
+ var error = $("#approvals_code").parent().attr("data-xui-error");
696
+ if (error) {
697
+ throw {
698
+ error: 'login-approval',
699
+ errordesc: Language.InvaildTwoAuthCode,
700
+ lerror: error,
701
+ continue: submit2FA
702
+ };
703
+ }
704
+ })
705
+ .then(function() {
706
+ delete form.no_fido;delete form.approvals_code;
707
+ form.name_action_selected = 'dont_save'; //'save_device' || 'dont_save;
708
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
709
+ })
710
+ .then(function(res) {
711
+ var headers = res.headers;
712
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: Language.ApprovalsErr };
713
+ var appState = utils.getAppState(jar,false);
714
+ if (callback === prCallback) {
715
+ callback = function(err, api) {
716
+ if (err) return prReject(err);
717
+ return prResolve(api);
718
+ };
719
+ }
720
+ return loginHelper(appState, email, password, loginOptions, callback);
721
+ })
722
+ .catch(function(err) {
723
+ if (callback === prCallback) prReject(err);
724
+ else callback(err);
725
+ });
726
+ } else {
727
+ utils
728
+ .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" })
729
+ .then(utils.saveCookies(jar))
730
+ .then((res) => {
731
+ try {
732
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
733
+ } catch (ex) {
734
+ clearInterval(checkVerified);
735
+ logger.Warning(Language.VerifiedCheck);
736
+ if (callback === prCallback) {
737
+ callback = function(err, api) {
738
+ if (err) return prReject(err);
739
+ return prResolve(api);
740
+ };
741
+ }
742
+ return loginHelper(utils.getAppState(jar,false), email, password, loginOptions, callback);
743
+ }
744
+ })
745
+ .catch((ex) => {
746
+ log.error("login", ex);
747
+ if (callback === prCallback) prReject(ex);
748
+ else callback(ex);
749
+ });
750
+ }
751
+ return rtPromise;
752
+ }
753
+ };
754
+ }
755
+ }
756
+ } else {
757
+ if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
758
+
759
+ if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
760
+ else form['submit[This Is Okay]'] = "This Is Okay";
761
+
762
+ return utils
763
+ .post(nextURL, jar, form, loginOptions)
764
+ .then(utils.saveCookies(jar))
765
+ .then(function() {
766
+ form.name_action_selected = 'dont_save';
767
+
768
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
769
+ })
770
+ .then(function(res) {
771
+ var headers = res.headers;
772
+
773
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
774
+
775
+ var appState = utils.getAppState(jar,false);
776
+
777
+ return loginHelper(appState, email, password, loginOptions, callback);
778
+ })
779
+ .catch((e) => callback(e));
780
+ }
781
+ });
782
+ }
783
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
784
+ });
785
+ };
786
+ }
787
+
788
+ //-[ Function backup ]-!/
789
+
790
+ /**
791
+ * @param {string} data
792
+ * @param {any} globalOptions
793
+ * @param {any} callback
794
+ * @param {any} prCallback
795
+ */
796
+
797
+ function backup(data,globalOptions, callback, prCallback) {
798
+ try {
799
+ var appstate;
800
+ try {
801
+ appstate = JSON.parse(data)
802
+ }
803
+ catch(e) {
804
+ appstate = data;
805
+ }
806
+ logger.Warning(Language.BackupNoti);
807
+ try {
808
+ loginHelper(appstate,null,null,globalOptions, callback, prCallback)
809
+ }
810
+ catch (e) {
811
+ logger.Error(Language.ErrBackup);
812
+ process.exit(0);
813
+ }
814
+ }
815
+ catch (e) {
816
+ return logger.Error();
817
+ }
818
+ }
819
+
820
+ //-[ function loginHelper ]-!/
821
+
822
+ /**
823
+ * @param {string | any[]} appState
824
+ * @param {any} email
825
+ * @param {any} password
826
+ * @param {{ selfListen?: boolean; listenEvents?: boolean; listenTyping?: boolean; updatePresence?: boolean; forceLogin?: boolean; autoMarkDelivery?: boolean; autoMarkRead?: boolean; autoReconnect?: boolean; logRecordSize?: number; online?: boolean; emitReady?: boolean; userAgent?: string; pageID?: any; }} globalOptions
827
+ * @param {(arg0: any, arg1: undefined) => void} callback
828
+ * @param {(error: any, api: any) => any} [prCallback]
829
+ */
830
+
831
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
832
+ var mainPromise = null;
833
+ var jar = utils.getJar();
834
+
835
+ try {
836
+ if (appState) {
837
+ logger.Normal(Language.OnProcess);
838
+ switch (Database().has("FBKEY")) {
839
+ case true: {
840
+ process.env.FBKEY = Database().get("FBKEY");
841
+ }
842
+ break;
843
+ case false: {
844
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
845
+ process.env['FBKEY'] = SecurityKey;
846
+ Database().set('FBKEY', SecurityKey);
847
+ }
848
+ break;
849
+ default: {
850
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
851
+ process.env['FBKEY'] = SecurityKey;
852
+ Database().set('FBKEY', SecurityKey);
853
+ }
854
+ }
855
+ try {
856
+ switch (global.Fca.Require.Priyansh.EncryptFeature) {
857
+ case true: {
858
+ appState = JSON.parse(JSON.stringify(appState, null, "\t"));
859
+ switch (utils.getType(appState)) {
860
+ case "Array": {
861
+ switch (utils.getType(appState[0])) {
862
+ case "Object": {
863
+ logger.Normal(Language.NotReadyToDecrypt);
864
+ }
865
+ break;
866
+ case "String": {
867
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
868
+ logger.Normal(Language.DecryptSuccess);
869
+ }
870
+ break;
871
+ default: {
872
+ logger.Warning(Language.InvaildAppState);
873
+ process.exit(0)
874
+ }
875
+ }
876
+ }
877
+ break;
878
+ default: {
879
+ logger.Warning(Language.InvaildAppState);
880
+ process.exit(0)
881
+ }
882
+ }
883
+ }
884
+ break;
885
+ case false: {
886
+ switch (utils.getType(appState)) {
887
+ case "Array": {
888
+ switch (utils.getType(appState[0])) {
889
+ case "Object": {
890
+ logger.Normal(Language.EncryptStateOff);
891
+ }
892
+ break;
893
+ case "String": {
894
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
895
+ logger.Normal(Language.EncryptStateOff);
896
+ logger.Normal(Language.DecryptSuccess);
897
+ }
898
+ break;
899
+ default: {
900
+ logger.Warning(Language.InvaildAppState);
901
+ process.exit(0)
902
+ }
903
+ }
904
+ }
905
+ break;
906
+ default: {
907
+ logger.Warning(Language.InvaildAppState);
908
+ process.exit(0)
909
+ }
910
+ }
911
+ }
912
+ break;
913
+ default: {
914
+ logger.Warning(getText(Language.IsNotABoolean,global.Fca.Require.Priyansh.EncryptFeature))
915
+ process.exit(0);
916
+ }
917
+ }
918
+ }
919
+ catch (e) {
920
+ console.log(e);
921
+ }
922
+
923
+ try {
924
+ appState = JSON.parse(appState);
925
+ }
926
+ catch (e) {
927
+ try {
928
+ appState = appState;
929
+ }
930
+ catch (e) {
931
+ return logger.Error();
932
+ }
933
+ }
934
+ try {
935
+ global.Fca.Data.AppState = appState;
936
+ appState.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
937
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
938
+ jar.setCookie(str, "http://" + c.domain);
939
+ });
940
+ Database().set('Backup', appState);
941
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
942
+ }
943
+ catch (e) {
944
+ try {
945
+ if (Database().has('Backup')) {
946
+ return backup(Database().get('Backup'),globalOptions, callback, prCallback);
947
+ }
948
+ else {
949
+ logger.Warning(Language.ErrBackup);
950
+ process.exit(0);
951
+ }
952
+ }
953
+ catch (e) {
954
+ logger.Warning(Language.ErrBackup);
955
+ process.exit(0);
956
+ }
957
+ }
958
+ }
959
+
960
+ else {
961
+ mainPromise = utils
962
+ .get("https://www.facebook.com/Lazic.Kanzu", null, null, globalOptions, { noRef: true }) // for fixing
963
+ .then(utils.saveCookies(jar))
964
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
965
+ .then(function() {
966
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
967
+ });
968
+ }
969
+ } catch (e) {
970
+ console.log(e);
971
+ }
972
+
973
+ function CheckAndFixErr(res, fastSwitch) {
974
+ if (fastSwitch) return res;
975
+ let reg_antierr = /7431627028261359627/gs; // =))))))
976
+ if (reg_antierr.test(res.body)) {
977
+ const Data = JSON.stringify(res.body);
978
+ const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
979
+ if (Dt_Check == undefined) return res
980
+ const fid = Dt_Check.split("\\\\")[0];//fix sau
981
+ if (Dt_Check == undefined || Dt_Check == "") return res
982
+ const final_fid = fid.split(`\\`)[0];
983
+ if (final_fid == undefined || final_fid == '') return res;
984
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
985
+ bypass_region_err = true;
986
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
987
+ }
988
+ else return res
989
+ }
990
+
991
+ function Redirect(res,fastSwitch) {
992
+ if (fastSwitch) return res;
993
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
994
+ redirect = reg.exec(res.body);
995
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions)
996
+ return res;
997
+ }
998
+
999
+ let redirect = [1, "https://m.facebook.com/"];
1000
+ let bypass_region_err = false;
1001
+ var ctx,api;
1002
+ mainPromise = mainPromise
1003
+ .then(res => Redirect(res))
1004
+ .then(res => CheckAndFixErr(res))
1005
+ //fix via login with defaut UA return WWW.facebook.com not m.facebook.com
1006
+ .then(function(res) {
1007
+ if (global.OnAutoLoginProcess) return res;
1008
+ else {
1009
+ let Regex_Via = /MPageLoadClientMetrics/gs; //default for normal account, can easily get region, without this u can't get region in some case but u can run normal
1010
+ if (!Regex_Via.test(res.body)) {
1011
+ //www.facebook.com
1012
+ globalOptions.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.2849.68";
1013
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
1014
+ }
1015
+ else return res
1016
+ }
1017
+ })
1018
+ .then(res => BypassAutomationNotification(res, jar, globalOptions, appState))
1019
+ .then(res => Redirect(res, global.OnAutoLoginProcess))
1020
+ .then(res => CheckAndFixErr(res, global.OnAutoLoginProcess))
1021
+ // .then(res => {
1022
+ // return utils.get('https://www.facebook.com/', jar, null, globalOptions, {}).then(utils.saveCookies(jar));
1023
+ // })
1024
+ // .then(function(res) {
1025
+ // let reg_old_web = /Switch Default Site/gs;
1026
+ // if (reg_old_web.test(res.body)) {
1027
+ // let Data_Resp = JSON.stringify(res.body);
1028
+ // const link = Data_Resp.split('settings/site')[1].split("\"")[0].replace('\\', '')
1029
+ // const redirect_link2 = redirect[1] + "settings/site" + utils.cleanHTML(link)
1030
+ // console.log(redirect_link2)
1031
+ // return utils.get("https://www.facebook.com/", jar, null, globalOptions).then(utils.saveCookies(jar)); // try ag
1032
+ // }
1033
+ // else return res;
1034
+ // })
1035
+ // .then(function(res) {
1036
+ // var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
1037
+ // redirect = reg.exec(res.body);
1038
+ // if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1039
+ // return res;
1040
+ // })
1041
+ .then(function(res){
1042
+ var html = res.body,Obj = buildAPI(globalOptions, html, jar,bypass_region_err);
1043
+ ctx = Obj.ctx;
1044
+ api = Obj.api;
1045
+ return res;
1046
+ });
1047
+ if (globalOptions.pageID) {
1048
+ mainPromise = mainPromise
1049
+ .then(function() {
1050
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
1051
+ })
1052
+ .then(function(resData) {
1053
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
1054
+ url = url.substring(0, url.length - 1);
1055
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
1056
+ });
1057
+ }
1058
+ mainPromise
1059
+ .then(async() => {
1060
+ logger.Normal(getText(Language.LocalVersion,global.Fca.Version));
1061
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
1062
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
1063
+ require('./Extra/ExtraUptimeRobot')();
1064
+ callback(null, api);
1065
+ }).catch(function(/** @type {{ error: any; }} */e) {
1066
+ log.error("login", e.error || e);
1067
+ callback(e);
1068
+ });
1069
+ }
1070
+
1071
+
1072
+ /**
1073
+ * It asks the user for their account and password, and then saves it to the database.
1074
+ */
1075
+
1076
+ function setUserNameAndPassWord() {
1077
+ let rl = readline.createInterface({
1078
+ input: process.stdin,
1079
+ output: process.stdout
1080
+ });
1081
+
1082
+ console.clear();
1083
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1084
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1085
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1086
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(global.Fca.Version) + '\n');
1087
+ try {
1088
+ rl.question(Language.TypeAccount, (Account) => {
1089
+ if (!Account.includes("@") && global.Fca.Require.utils.getType(parseInt(Account)) != "Number") return logger.Normal(Language.TypeAccountError, function () { process.exit(1) }); //Very Human
1090
+ else rl.question(Language.TypePassword, function (Password) {
1091
+ rl.close();
1092
+ try {
1093
+ Database().set("Account", Account);
1094
+ Database().set("Password", Password);
1095
+ }
1096
+ catch (e) {
1097
+ logger.Warning(Language.ErrDataBase);
1098
+ logger.Error();
1099
+ process.exit(0);
1100
+ }
1101
+ if (global.Fca.Require.Priyansh.ResetDataLogin) {
1102
+ global.Fca.Require.Priyansh.ResetDataLogin = false;
1103
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/PriyanshFca.json', JSON.stringify(global.Fca.Require.Priyansh, null, 4));
1104
+ }
1105
+ logger.Success(Language.SuccessSetData);
1106
+ process.exit(1);
1107
+ });
1108
+ })
1109
+ }
1110
+ catch (e) {
1111
+ logger.Error(e)
1112
+ }
1113
+ }
1114
+
1115
+ /**
1116
+ * @param {{ email: any; password: any; appState: any; }} loginData
1117
+ * @param {{}} options
1118
+ * @param {(error: any, api: any) => any} callback
1119
+ */
1120
+
1121
+ function login(loginData, options, callback) {
1122
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1123
+ callback = options;
1124
+ options = {};
1125
+ }
1126
+
1127
+ var globalOptions = {
1128
+ selfListen: false,
1129
+ listenEvents: true,
1130
+ listenTyping: false,
1131
+ updatePresence: false,
1132
+ forceLogin: false,
1133
+ autoMarkDelivery: false,
1134
+ autoMarkRead: false,
1135
+ autoReconnect: true,
1136
+ logRecordSize: 100,
1137
+ online: false,
1138
+ emitReady: false,
1139
+ 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"
1140
+ };
1141
+
1142
+ var prCallback = null;
1143
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1144
+ var rejectFunc = null;
1145
+ var resolveFunc = null;
1146
+ var returnPromise = new Promise(function(resolve, reject) {
1147
+ resolveFunc = resolve;
1148
+ rejectFunc = reject;
1149
+ });
1150
+ prCallback = function(error, api) {
1151
+ if (error) return rejectFunc(error);
1152
+ return resolveFunc(api);
1153
+ };
1154
+ callback = prCallback;
1155
+ }
1156
+
1157
+ if (loginData.email && loginData.password) {
1158
+ setOptions(globalOptions, {
1159
+ logLevel: "silent",
1160
+ forceLogin: true,
1161
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"
1162
+ });
1163
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1164
+ }
1165
+ else if (loginData.appState) {
1166
+ setOptions(globalOptions, options);
1167
+ let All = (getAll()).filter(i => i.data !== null);
1168
+ All = All.filter(i => i.data.messageCount !== undefined)
1169
+ if (All.length >= 1) {
1170
+ deleteAll(All.map(obj => obj.data.threadID));
1171
+ }
1172
+ /*
1173
+ if (global.Fca.Require.FastConfig.Websocket_Extension.Status) {
1174
+ const UserName = Database().get('Ws_UserName');
1175
+ const PassWord = Database().get("Ws_PassWord");
1176
+ if (!UserName || !PassWord || global.Fca.Require.FastConfig.Websocket_Extension.ResetData) {
1177
+ const question = question => {
1178
+ const rl = readline.createInterface({
1179
+ input: process.stdin,
1180
+ output: process.stdout
1181
+ });
1182
+ var done,answ;
1183
+ rl.question(question, answer => {
1184
+ rl.close();
1185
+ answ = answer;
1186
+ done = true
1187
+ })
1188
+ deasync.loopWhile(function(){
1189
+ return !done;
1190
+ });
1191
+ return answ;
1192
+ };
1193
+ console.clear();
1194
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1195
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1196
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1197
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(global.Fca.Version) + '\n');
1198
+ const UserName = question(Language.Ws_TypeUserName);
1199
+ const PassWord = question(Language.Ws_TypePassWord);
1200
+ if (!UserName || !PassWord) {
1201
+ logger.Warning("Dangerous action detected! Proceeding to automatically disable websocket_extension.");
1202
+ global.Fca.Require.FastConfig.Websocket_Extension.Status = false;
1203
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/PriyanshFca.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
1204
+ }
1205
+ else {
1206
+ try {
1207
+ Database().set('Ws_UserName', UserName);
1208
+ Database().set('Ws_PassWord', PassWord);
1209
+ logger.Success(Language.Ws_Success, function() {
1210
+ const speakeasy = require('speakeasy');
1211
+ const secret = (speakeasy.generateSecret({ length: 20 }));
1212
+ logger.Warning(getText(Language.Ws_2Fa, secret.base32))
1213
+ Database().set('Ws_2Fa', secret.base32);
1214
+ if (global.Fca.Require.FastConfig.Websocket_Extension.ResetData) {
1215
+ global.Fca.Require.FastConfig.Websocket_Extension.ResetData = false;
1216
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/PriyanshFca.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1217
+ }
1218
+ question("Enter To Continue!");
1219
+ const ask = function() {
1220
+ const TFa_Check = question(Language.Ws_2Fa_Check)
1221
+ if (TFa_Check != speakeasy.totp({
1222
+ secret: secret.base32,
1223
+ encoding: 'base32'
1224
+ })) {
1225
+ logger.Warning("Mã Không Đúng vui lòng nhập lại(Incorrect code, please enter again.)")
1226
+ ask();
1227
+ }
1228
+ else {
1229
+ logger.Success("Success!");
1230
+ process.exit(1);
1231
+ }
1232
+ }
1233
+ return ask();
1234
+ });
1235
+ }
1236
+ catch (e) {
1237
+ console.log(e)
1238
+ logger.Warning("Error, auto turn off Websocket_extension");
1239
+ global.Fca.Require.FastConfig.Websocket_Extension.Status = false;
1240
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/PriyanshFca.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
1241
+ process.exit(1);
1242
+ }
1243
+ }
1244
+ }
1245
+ }
1246
+ **/
1247
+ switch (global.Fca.Require.Priyansh.AutoLogin) {
1248
+ case true: {
1249
+ if (global.Fca.Require.Priyansh.ResetDataLogin) return setUserNameAndPassWord();
1250
+ else {
1251
+ try {
1252
+ const TempState = Database().get("TempState")
1253
+ if (TempState) {
1254
+ try {
1255
+ loginData.appState = JSON.parse(TempState);
1256
+ }
1257
+ catch (_) {
1258
+ loginData.appState = TempState;
1259
+ }
1260
+ Database().delete("TempState");
1261
+ }
1262
+ }
1263
+ catch (e) {
1264
+ console.log(e)
1265
+ Database().delete("TempState");
1266
+ logger.Warning(Language.ErrDataBase);
1267
+ logger.Error();
1268
+ process.exit(0);
1269
+ }
1270
+ try {
1271
+ if (Database().has('Account') && Database().has('Password')) return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1272
+ else return setUserNameAndPassWord();
1273
+ }
1274
+ catch (e) {
1275
+ console.log(e)
1276
+ logger.Warning(Language.ErrDataBase);
1277
+ logger.Error();
1278
+ process.exit(0);
1279
+ }
1280
+ }
1281
+ }
1282
+ case false: {
1283
+ return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1284
+ }
1285
+ }
1286
+ }
1287
+ return returnPromise;
1288
+ }
1289
+
1290
+ module.exports = login;