team-atf 0.0.1-security → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of team-atf might be problematic. Click here for more details.

Files changed (98) hide show
  1. package/.gitattributes +2 -0
  2. package/Extra/Database/index.js +360 -0
  3. package/Extra/ExtraAddons.js +78 -0
  4. package/Extra/ExtraFindUID.js +60 -0
  5. package/Extra/ExtraGetThread.js +118 -0
  6. package/Extra/ExtraScreenShot.js +430 -0
  7. package/Extra/ExtraUptimeRobot.js +26 -0
  8. package/Extra/Html/Classic/script.js +119 -0
  9. package/Extra/Html/Classic/style.css +8 -0
  10. package/Extra/Security/Index.js +146 -0
  11. package/Extra/Security/Step_1.js +11 -0
  12. package/Extra/Security/Step_2.js +20 -0
  13. package/Extra/Security/Step_3.js +20 -0
  14. package/Extra/Src/History.js +115 -0
  15. package/Extra/Src/Last-Run.js +65 -0
  16. package/Extra/Src/Premium.js +84 -0
  17. package/Extra/Src/uuid.js +137 -0
  18. package/Func/AcceptAgreement.js +32 -0
  19. package/Func/ClearCache.js +64 -0
  20. package/Func/ReportV1.js +54 -0
  21. package/LICENSE +24 -0
  22. package/Language/index.json +88 -0
  23. package/README.md +3 -5
  24. package/SECURITY.md +17 -0
  25. package/broadcast.js +38 -0
  26. package/index.js +1357 -0
  27. package/logger.js +65 -0
  28. package/package.json +88 -3
  29. package/src/Dev_Horizon_Data.js +125 -0
  30. package/src/Premium.js +30 -0
  31. package/src/Screenshot.js +85 -0
  32. package/src/addExternalModule.js +16 -0
  33. package/src/addUserToGroup.js +79 -0
  34. package/src/changeAdminStatus.js +79 -0
  35. package/src/changeArchivedStatus.js +41 -0
  36. package/src/changeAvt.js +85 -0
  37. package/src/changeBio.js +65 -0
  38. package/src/changeBlockedStatus.js +36 -0
  39. package/src/changeGroupImage.js +106 -0
  40. package/src/changeNickname.js +45 -0
  41. package/src/changeThreadColor.js +62 -0
  42. package/src/changeThreadEmoji.js +42 -0
  43. package/src/createNewGroup.js +70 -0
  44. package/src/createPoll.js +60 -0
  45. package/src/deleteMessage.js +45 -0
  46. package/src/deleteThread.js +43 -0
  47. package/src/forwardAttachment.js +48 -0
  48. package/src/getAccessToken.js +32 -0
  49. package/src/getCurrentUserID.js +7 -0
  50. package/src/getEmojiUrl.js +27 -0
  51. package/src/getFriendsList.js +73 -0
  52. package/src/getMessage.js +80 -0
  53. package/src/getThreadHistory.js +537 -0
  54. package/src/getThreadInfo.js +348 -0
  55. package/src/getThreadList.js +213 -0
  56. package/src/getThreadMain.js +220 -0
  57. package/src/getThreadPictures.js +59 -0
  58. package/src/getUID.js +59 -0
  59. package/src/getUserID.js +62 -0
  60. package/src/getUserInfo.js +129 -0
  61. package/src/getUserInfoMain.js +65 -0
  62. package/src/getUserInfoV2.js +36 -0
  63. package/src/getUserInfoV3.js +63 -0
  64. package/src/getUserInfoV4.js +55 -0
  65. package/src/getUserInfoV5.js +61 -0
  66. package/src/handleFriendRequest.js +46 -0
  67. package/src/handleMessageRequest.js +49 -0
  68. package/src/httpGet.js +49 -0
  69. package/src/httpPost.js +48 -0
  70. package/src/httpPostFormData.js +41 -0
  71. package/src/listenMqtt.js +702 -0
  72. package/src/logout.js +68 -0
  73. package/src/markAsDelivered.js +48 -0
  74. package/src/markAsRead.js +70 -0
  75. package/src/markAsReadAll.js +43 -0
  76. package/src/markAsSeen.js +51 -0
  77. package/src/muteThread.js +47 -0
  78. package/src/removeUserFromGroup.js +49 -0
  79. package/src/resolvePhotoUrl.js +37 -0
  80. package/src/searchForThread.js +43 -0
  81. package/src/sendMessage.js +334 -0
  82. package/src/sendTypingIndicator.js +80 -0
  83. package/src/setMessageReaction.js +109 -0
  84. package/src/setPostReaction.js +102 -0
  85. package/src/setTitle.js +74 -0
  86. package/src/threadColors.js +39 -0
  87. package/src/unfriend.js +43 -0
  88. package/src/unsendMessage.js +40 -0
  89. package/test/data/shareAttach.js +146 -0
  90. package/test/data/something.mov +0 -0
  91. package/test/data/test.png +0 -0
  92. package/test/data/test.txt +7 -0
  93. package/test/env/.env +0 -0
  94. package/test/example-config.json +18 -0
  95. package/test/test-page.js +140 -0
  96. package/test/test.js +385 -0
  97. package/test/testv2.js +3 -0
  98. package/utils.js +1648 -0
package/index.js ADDED
@@ -0,0 +1,1357 @@
1
+ 'use strict';
2
+
3
+
4
+
5
+ /!-[ Global Set ]-!/
6
+
7
+ global.Fca = new Object({
8
+ isThread: new Array(),
9
+ isUser: new Array(),
10
+ startTime: Date.now(),
11
+ Setting: new Map(),
12
+ Version: require('./package.json').version,
13
+ Require: new Object({
14
+ fs: require("fs"),
15
+ Fetch: require('got'),
16
+ log: require("npmlog"),
17
+ utils: require("./utils"),
18
+ logger: require('./logger'),
19
+ languageFile: require('./Language/index.json'),
20
+ Database: require("./Extra/Database"),
21
+ Security: require('./Extra/Src/uuid')
22
+ }),
23
+ getText: function(/** @type {any[]} */...Data) {
24
+ var Main = (Data.splice(0,1)).toString();
25
+ for (let i = 0; i < Data.length; i++) Main = Main.replace(RegExp(`%${i + 1}`, 'g'), Data[i]);
26
+ return Main;
27
+ },
28
+ Data: new Object({
29
+ ObjFastConfig: {
30
+ "Language": "en",
31
+ "PreKey": "",
32
+ "AutoUpdate": false,
33
+ "MainColor": "#9900FF",
34
+ "MainName": "[ FCA-CHAND ]",
35
+ "Logo": true,
36
+ "Uptime": true,
37
+ "Config": "default",
38
+ "Login2Fa": false,
39
+ "AutoLogin": false,
40
+ "BroadCast": true,
41
+ "AuthString": "SD4S XQ32 O2JA WXB3 FUX2 OPJ7 Q7JZ 4R6Z | https://i.imgur.com/RAg3rvw.png Please remove this !, Recommend If You Using getUserInfoV2",
42
+ "EncryptFeature": true,
43
+ "ResetDataLogin": false,
44
+ "AutoRestartMinutes": 0,
45
+ "HTML": {
46
+ "HTML": true,
47
+ "UserName": "Guest",
48
+ "MusicLink": "https://drive.google.com/uc?id=1zlAALlxk1TnO7jXtEP_O6yvemtzA2ukA&export=download"
49
+ }
50
+ },
51
+ CountTime: function() {
52
+ var fs = global.Fca.Require.fs;
53
+ if (fs.existsSync(__dirname + '/CountTime.json')) {
54
+ try {
55
+ var data = Number(fs.readFileSync(__dirname + '/CountTime.json', 'utf8')),
56
+ hours = Math.floor(data / (60 * 60));
57
+ }
58
+ catch (e) {
59
+ fs.writeFileSync(__dirname + '/CountTime.json', 0);
60
+ hours = 0;
61
+ }
62
+ }
63
+ else {
64
+ hours = 0;
65
+ }
66
+ return `${hours} Hours`;
67
+ }
68
+ }),
69
+ AutoLogin: async function () {
70
+ var Database = global.Fca.Require.Database;
71
+ var logger = global.Fca.Require.logger;
72
+ var Email = (await global.Fca.Require.Database.get('Account')).replace(RegExp('"', 'g'), ''); //hmm IDK
73
+ var PassWord = (await global.Fca.Require.Database.get('Password')).replace(RegExp('"', 'g'), '');
74
+ login({ email: Email, password: PassWord},async (error, api) => {
75
+ if (error) {
76
+ logger.Error(JSON.stringify(error,null,2), function() { logger.Error("AutoLogin Failed!", function() { process.exit(0); }) });
77
+ }
78
+ try {
79
+ await Database.set("TempState", api.getAppState());
80
+ }
81
+ catch(e) {
82
+ logger.Warning(global.Fca.Require.Language.Index.ErrDatabase);
83
+ logger.Error();
84
+ process.exit(0);
85
+ }
86
+ process.exit(1);
87
+ });
88
+ }
89
+ });
90
+
91
+ /!-[ Check File To Run Process ]-!/
92
+
93
+ let Boolean_Fca = ["AutoUpdate","Uptime","BroadCast","EncryptFeature","AutoLogin","ResetDataLogin","Login2Fa","Logo"];
94
+ let String_Fca = ["MainName","PreKey","Language","AuthString","Config"]
95
+ let Number_Fca = ["AutoRestartMinutes"];
96
+ let All_Variable = Boolean_Fca.concat(String_Fca,Number_Fca);
97
+
98
+ try {
99
+ if (!global.Fca.Require.fs.existsSync(process.cwd() + '/TeamAtfChand.json')) {
100
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/TeamAtfChand.json", JSON.stringify(global.Fca.Data.ObjFastConfig, null, "\t"));
101
+ process.exit(1);
102
+ }
103
+
104
+ try {
105
+ var DataLanguageSetting = require(process.cwd() + "/TeamAtfChand.json");
106
+ }
107
+ catch (e) {
108
+ global.Fca.Require.logger.Error('Detect Your TeamAtfChand Settings Invalid!, Carry out default restoration');
109
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/TeamAtfChand.json", JSON.stringify(global.Fca.Data.ObjFastConfig, null, "\t"));
110
+ process.exit(1)
111
+ }
112
+ if (global.Fca.Require.fs.existsSync(process.cwd() + '/TeamAtfChand.json')) {
113
+ try {
114
+ if (DataLanguageSetting.Logo != undefined) {
115
+ delete DataLanguageSetting.Logo
116
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/TeamAtfChand.json", JSON.stringify(DataLanguageSetting, null, "\t"));
117
+ }
118
+ }
119
+ catch (e) {
120
+ console.log(e);
121
+ }
122
+ if (!global.Fca.Require.languageFile.some((/** @type {{ Language: string; }} */i) => i.Language == DataLanguageSetting.Language)) {
123
+ global.Fca.Require.logger.Warning("Not Support Language: " + DataLanguageSetting.Language + " Only 'en' and 'vi'");
124
+ process.exit(0);
125
+ }
126
+ var Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == DataLanguageSetting.Language).Folder.Index;
127
+ global.Fca.Require.Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == DataLanguageSetting.Language).Folder;
128
+ } else process.exit(1);
129
+ for (let i in DataLanguageSetting) {
130
+ if (Boolean_Fca.includes(i)) {
131
+ if (global.Fca.Require.utils.getType(DataLanguageSetting[i]) != "Boolean") return logger.Error(i + " Is Not A Boolean, Need To Be true Or false !", function() { process.exit(0) });
132
+ else continue;
133
+ }
134
+ else if (String_Fca.includes(i)) {
135
+ if (global.Fca.Require.utils.getType(DataLanguageSetting[i]) != "String") return logger.Error(i + " Is Not A String, Need To Be String!", function() { process.exit(0) });
136
+ else continue;
137
+ }
138
+ else if (Number_Fca.includes(i)) {
139
+ if (global.Fca.Require.utils.getType(DataLanguageSetting[i]) != "Number") return logger.Error(i + " Is Not A Number, Need To Be Number !", function() { process.exit(0) });
140
+ else continue;
141
+ }
142
+ }
143
+ for (let i of All_Variable) {
144
+ if (!DataLanguageSetting[All_Variable[i]] == undefined) {
145
+ DataLanguageSetting[All_Variable[i]] = global.Fca.Data.ObjFastConfig[All_Variable[i]];
146
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/TeamAtfChand.json", JSON.stringify(DataLanguageSetting, null, "\t"));
147
+ }
148
+ else continue;
149
+ }
150
+ global.Fca.Require.FastConfig = DataLanguageSetting;
151
+ }
152
+ catch (e) {
153
+ console.log(e);
154
+ global.Fca.Require.logger.Error();
155
+ }
156
+
157
+ /!-[ Require config and use ]-!/
158
+
159
+ if (global.Fca.Require.FastConfig.Config != 'default') {
160
+ //do ssth
161
+ }
162
+
163
+ /!-[ Require All Package Need Use ]-!/
164
+
165
+ var utils = global.Fca.Require.utils,
166
+ logger = global.Fca.Require.logger,
167
+ fs = global.Fca.Require.fs,
168
+ getText = global.Fca.getText,
169
+ log = global.Fca.Require.log,
170
+ Fetch = global.Fca.Require.Fetch,
171
+ express = require("express")(),
172
+ { join, resolve } = require('path'),
173
+ cheerio = require("cheerio"),
174
+ StateCrypt = {},
175
+ { readFileSync } = require('fs-extra'),
176
+ Database = require("./Extra/Database"),
177
+ readline = require("readline"),
178
+ chalk = require("chalk"),
179
+ figlet = require("figlet"),
180
+ os = require("os"),
181
+ Security = require("./Extra/Security/Index");
182
+
183
+ /!-[ Set Variable For Process ]-!/
184
+
185
+ log.maxRecordSize = 100;
186
+ var checkVerified = null;
187
+ var Boolean_Option = ['online','selfListen','listenEvents','updatePresence','forceLogin','autoMarkDelivery','autoMarkRead','listenTyping','autoReconnect','emitReady'];
188
+
189
+ /!-[ Set And Check Template HTML ]-!/
190
+
191
+ var css = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'style.css'));
192
+ var js = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'script.js'));
193
+
194
+ /!-[ Function Generate HTML Template ]-!/
195
+
196
+ /**
197
+ * It returns a string of HTML code.
198
+ * @param UserName - The username of the user
199
+ * @param Type - The type of user, either "Free" or "Premium"
200
+ * @param link - The link to the music you want to play
201
+ * @returns A HTML file
202
+ */
203
+
204
+ function ClassicHTML(UserName,Type,link) {
205
+ return `<!DOCTYPE html>
206
+ <html lang="en" >
207
+ <head>
208
+ <meta charset="UTF-8">
209
+ <title>Horizon</title>
210
+ <link rel="stylesheet" href="./style.css">
211
+ </head>
212
+ <body>
213
+ <center>
214
+ <marquee><b>waiting for u :d</b></marquee>
215
+ <h2>Horizon User Infomation</h2>
216
+ <h3>UserName: ${UserName} | Type: ${Type}</h3>
217
+ <canvas id="myCanvas"></canvas>
218
+ <script src="./script.js"></script>
219
+ <footer class="footer">
220
+ <div id="music">
221
+ <audio autoplay="false" controls="true" loop="true" src="${link}" __idm_id__="5070849">Your browser does not support the audio element.</audio>
222
+ <br><b>Session ID:</b> ${global.Fca.Require.Security.create().uuid}<br>
223
+ <br>Thanks For Using <b>team.atf</b> - From <b>Chand</b> <3<br>
224
+ </div>
225
+ </footer>
226
+ </div>
227
+ </center>
228
+ </html>
229
+ </body>`
230
+ //lazy to change
231
+ }
232
+
233
+ /!-[ Stating Http Infomation ]-!/
234
+
235
+ express.set('DFP', (process.env.PORT || process.env.port || 1932));
236
+ express.use(function(req, res, next) {
237
+ switch (req.url.split('?')[0]) {
238
+ case '/script.js': {
239
+ res.writeHead(200, { 'Content-Type': 'text/javascript' });
240
+ res.write(js);
241
+ break;
242
+ }
243
+ case '/style.css': {
244
+ res.writeHead(200, { 'Content-Type': 'text/css' });
245
+ res.write(css);
246
+ break;
247
+ }
248
+ // case '/History': {
249
+ // if (req.query.PassWord == process.env.REPL_OWNER) {
250
+ // res.writeHead(200, { 'Content-Type': 'application/json charset=utf-8' });
251
+ // res.write(JSON.stringify(console.history,null,2),'utf8');
252
+ // res.end();
253
+ // }
254
+ // else res.json({
255
+ // Status: false,
256
+ // Error: "Thiếu Params ?PassWord=PassWordCuaBan =))"
257
+ // });
258
+ // break;
259
+ // }
260
+ default: {
261
+ res.writeHead(200, "OK", { "Content-Type": "text/html" });
262
+ res.write(ClassicHTML(global.Fca.Require.FastConfig.HTML.UserName, global.Fca.Data.PremText.includes("Premium") ? "Premium": "Free", global.Fca.Require.FastConfig.HTML.MusicLink));
263
+ }
264
+ }
265
+ res.end();
266
+ })
267
+
268
+ global.Fca.Require.Web = express;
269
+
270
+ /!-[ Function setOptions ]-!/
271
+
272
+ /**
273
+ * @param {{ [x: string]: boolean; selfListen?: boolean; listenEvents?: boolean; listenTyping?: boolean; updatePresence?: boolean; forceLogin?: boolean; autoMarkDelivery?: boolean; autoMarkRead?: boolean; autoReconnect?: boolean; logRecordSize: any; online?: boolean; emitReady?: boolean; userAgent: any; logLevel?: any; pageID?: any; proxy?: any; }} globalOptions
274
+ * @param {{ [x: string]: any; logLevel?: any; forceLogin?: boolean; userAgent?: any; pauseLog?: any; logRecordSize?: any; pageID?: any; proxy?: any; }} options
275
+ */
276
+
277
+ function setOptions(globalOptions, options) {
278
+ Object.keys(options).map(function(key) {
279
+ switch (Boolean_Option.includes(key)) {
280
+ case true: {
281
+ globalOptions[key] = Boolean(options[key]);
282
+ break;
283
+ }
284
+ case false: {
285
+ switch (key) {
286
+ case 'pauseLog': {
287
+ if (options.pauseLog) log.pause();
288
+ else log.resume();
289
+ break;
290
+ }
291
+ case 'logLevel': {
292
+ log.level = options.logLevel;
293
+ globalOptions.logLevel = options.logLevel;
294
+ break;
295
+ }
296
+ case 'logRecordSize': {
297
+ log.maxRecordSize = options.logRecordSize;
298
+ globalOptions.logRecordSize = options.logRecordSize;
299
+ break;
300
+ }
301
+ case 'pageID': {
302
+ globalOptions.pageID = options.pageID.toString();
303
+ break;
304
+ }
305
+ case 'userAgent': {
306
+ globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36');
307
+ break;
308
+ }
309
+ case 'proxy': {
310
+ if (typeof options.proxy != "string") {
311
+ delete globalOptions.proxy;
312
+ utils.setProxy();
313
+ } else {
314
+ globalOptions.proxy = options.proxy;
315
+ utils.setProxy(globalOptions.proxy);
316
+ }
317
+ break;
318
+ }
319
+ default: {
320
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
321
+ break;
322
+ }
323
+ }
324
+ break;
325
+ }
326
+ }
327
+ });
328
+ }
329
+
330
+ /!-[ Function BuildAPI ]-!/
331
+
332
+ /**
333
+ * @param {any} globalOptions
334
+ * @param {string} html
335
+ * @param {{ getCookies: (arg0: string) => any[]; }} jar
336
+ */
337
+
338
+ function buildAPI(globalOptions, html, jar) {
339
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(/** @type {{ cookieString: () => string; }} */val) { return val.cookieString().split("=")[0] === "c_user"; });
340
+
341
+ if (maybeCookie.length === 0) {
342
+ switch (global.Fca.Require.FastConfig.AutoLogin) {
343
+ case true: {
344
+ global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
345
+ return global.Fca.AutoLogin();
346
+ });
347
+ break;
348
+ }
349
+ case false: {
350
+ throw { error: global.Fca.Require.Language.Index.ErrAppState };
351
+
352
+ }
353
+ }
354
+ }
355
+
356
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", Language.CheckPointLevelI);
357
+
358
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
359
+ process.env['UID'] = logger.Normal(getText(Language.UID,userID), userID);
360
+
361
+ try {
362
+ clearInterval(checkVerified);
363
+ } catch (e) {
364
+ console.log(e);
365
+ }
366
+
367
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
368
+
369
+ var CHECK_MQTT = {
370
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
371
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
372
+ legacyFBMQTTMatch: html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/)
373
+ }
374
+
375
+ let Slot = Object.keys(CHECK_MQTT);
376
+
377
+ var mqttEndpoint,region,irisSeqID;
378
+ Object.keys(CHECK_MQTT).map(function(MQTT) {
379
+ if (CHECK_MQTT[MQTT] && !region) {
380
+ switch (Slot.indexOf(MQTT)) {
381
+ case 0: {
382
+ irisSeqID = CHECK_MQTT[MQTT][1];
383
+ mqttEndpoint = CHECK_MQTT[MQTT][2];
384
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
385
+ return;
386
+ }
387
+ case 1: {
388
+ irisSeqID = CHECK_MQTT[MQTT][2];
389
+ mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
390
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
391
+ return;
392
+ }
393
+ case 2: {
394
+ mqttEndpoint = CHECK_MQTT[MQTT][4];
395
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
396
+ return;
397
+ }
398
+ }
399
+ return;
400
+ }
401
+ });
402
+
403
+ var ctx = {
404
+ userID: userID,
405
+ jar: jar,
406
+ clientID: clientID,
407
+ globalOptions: globalOptions,
408
+ loggedIn: true,
409
+ access_token: 'NONE',
410
+ clientMutationId: 0,
411
+ mqttClient: undefined,
412
+ lastSeqId: irisSeqID,
413
+ syncToken: undefined,
414
+ mqttEndpoint: mqttEndpoint,
415
+ region: region,
416
+ firstListen: true
417
+ };
418
+
419
+ var api = {
420
+ setOptions: setOptions.bind(null, globalOptions),
421
+ getAppState: function getAppState() {
422
+ return utils.getAppState(jar);
423
+ }
424
+ };
425
+
426
+ if (region && mqttEndpoint) {
427
+ //do sth
428
+ }
429
+ else {
430
+ log.warn("login", getText(Language.NoAreaData));
431
+ api["htmlData"] = html;
432
+ }
433
+
434
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
435
+
436
+ fs.readdirSync(__dirname + "/src").filter((/** @type {string} */File) => File.endsWith(".js") && !File.includes('Dev_')).map((/** @type {string} */File) => api[File.split('.').slice(0, -1).join('.')] = require('./src/' + File)(defaultFuncs, api, ctx));
437
+
438
+ return {
439
+ ctx,
440
+ defaultFuncs,
441
+ api
442
+ };
443
+ }
444
+
445
+ /!-[ Function makeLogin ]-!/
446
+
447
+ /**
448
+ * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
449
+ * @param {any} email
450
+ * @param {any} password
451
+ * @param {{ forceLogin: any; }} loginOptions
452
+ * @param {(err: any, api: any) => any} callback
453
+ * @param {any} prCallback
454
+ */
455
+
456
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
457
+ return function(/** @type {{ body: any; }} */res) {
458
+ var html = res.body,$ = cheerio.load(html),arr = [];
459
+
460
+ $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
461
+
462
+ arr = arr.filter(function(v) {
463
+ return v.val && v.val.length;
464
+ });
465
+
466
+ var form = utils.arrToForm(arr);
467
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
468
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
469
+ form.email = email;
470
+ form.pass = password;
471
+ form.default_persistent = '0';
472
+ form.locale = 'en_US';
473
+ form.timezone = '240';
474
+ form.lgnjs = ~~(Date.now() / 1000);
475
+
476
+ html.split("\"_js_").slice(1).map((/** @type {any} */val) => {
477
+ jar.setCookie(utils.formatCookie(JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]"), "facebook"),"https://www.facebook.com")
478
+ });
479
+
480
+ logger.Normal(Language.OnLogin);
481
+ return utils
482
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
483
+ .then(utils.saveCookies(jar))
484
+ .then(function(/** @type {{ headers: any; }} */res) {
485
+ var headers = res.headers;
486
+ if (!headers.location) throw { error: Language.InvaildAccount };
487
+
488
+ // This means the account has login approvals turned on.
489
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
490
+ logger.Warning(Language.TwoAuth);
491
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
492
+
493
+ return utils
494
+ .get(headers.location, jar, null, loginOptions)
495
+ .then(utils.saveCookies(jar))
496
+ .then(async function(/** @type {{ body: any; }} */res) {
497
+ if (!await Database.get('ThroughAcc')) {
498
+ await Database.set('ThroughAcc', email);
499
+ }
500
+ else {
501
+ if (String((await Database.get('ThroughAcc'))).replace(RegExp('"','g'), '') != String(email).replace(RegExp('"','g'), '')) {
502
+ await Database.set('ThroughAcc', email);
503
+ if (await Database.get('Through2Fa')) {
504
+ await Database.delete('Through2Fa');
505
+ }
506
+ }
507
+ }
508
+ var html = res.body,$ = cheerio.load(html), arr = [];
509
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
510
+ arr = arr.filter(v => { return v.val && v.val.length });
511
+ var form = utils.arrToForm(arr);
512
+ if (html.indexOf("checkpoint/?next") > -1) {
513
+ setTimeout(() => {
514
+ checkVerified = setInterval((_form) => {}, 5000, {
515
+ fb_dtsg: form.fb_dtsg,
516
+ jazoest: form.jazoest,
517
+ dpr: 1
518
+ });
519
+ }, 2500);
520
+ switch (global.Fca.Require.FastConfig.Login2Fa) {
521
+ case true: {
522
+ try {
523
+ const question = question => {
524
+ const rl = readline.createInterface({
525
+ input: process.stdin,
526
+ output: process.stdout
527
+ });
528
+ return new Promise(resolve => {
529
+ rl.question(question, answer => {
530
+ rl.close();
531
+ return resolve(answer);
532
+ });
533
+ });
534
+ };
535
+ async function EnterSecurityCode() {
536
+ try {
537
+ var Through2Fa = await Database.get('Through2Fa');
538
+ if (Through2Fa) {
539
+ Through2Fa.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
540
+ let str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
541
+ jar.setCookie(str, "http://" + c.domain);
542
+ })
543
+ var from2 = utils.arrToForm(arr);
544
+ from2.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
545
+ from2.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
546
+ from2.email = email;
547
+ from2.pass = password;
548
+ from2.default_persistent = '0';
549
+ from2.locale = 'en_US';
550
+ from2.timezone = '240';
551
+ from2.lgnjs = ~~(Date.now() / 1000);
552
+ return utils
553
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, from2, loginOptions)
554
+ .then(utils.saveCookies(jar))
555
+ .then(function(/** @type {{ headers: any; }} */res) {
556
+ var headers = res.headers;
557
+ if (!headers['set-cookie'][0].includes('deleted')) {
558
+ logger.Warning(Language.ErrThroughCookies, async function() {
559
+ await Database.delete('Through2Fa');
560
+ });
561
+ process.exit(1);
562
+ }
563
+ if (headers.location && headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
564
+ return utils
565
+ .get(headers.location, jar, null, loginOptions)
566
+ .then(utils.saveCookies(jar))
567
+ .then(function(/** @type {{ body: any; }} */res) {
568
+ var html = res.body,$ = cheerio.load(html), arr = [];
569
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
570
+ arr = arr.filter(v => { return v.val && v.val.length });
571
+ var from2 = utils.arrToForm(arr);
572
+
573
+ if (html.indexOf("checkpoint/?next") > -1) {
574
+ setTimeout(() => {
575
+ checkVerified = setInterval((_form) => {}, 5000, {
576
+ fb_dtsg: from2.fb_dtsg,
577
+ jazoest: from2.jazoest,
578
+ dpr: 1
579
+ });
580
+ }, 2500);
581
+ if (!res.headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
582
+ try {
583
+ delete from2.name_action_selected;
584
+ from2['submit[Continue]'] = $("#checkpointSubmitButton").html();
585
+ return utils
586
+ .post(nextURL, jar, from2, loginOptions)
587
+ .then(utils.saveCookies(jar))
588
+ .then(function() {
589
+ from2['submit[This was me]'] = "This was me";
590
+ return utils.post(nextURL, jar, from2, loginOptions).then(utils.saveCookies(jar));
591
+ })
592
+ .then(function() {
593
+ delete from2['submit[This was me]'];
594
+ from2.name_action_selected = 'save_device';
595
+ from2['submit[Continue]'] = $("#checkpointSubmitButton").html();
596
+ return utils.post(nextURL, jar, from2, loginOptions).then(utils.saveCookies(jar));
597
+ })
598
+ .then(async function(/** @type {{ headers: any; body: string | string[]; }} */res) {
599
+ var headers = res.headers;
600
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
601
+ var appState = utils.getAppState(jar,false);
602
+ await Database.set('Through2Fa', appState);
603
+ return loginHelper(appState, email, password, loginOptions, callback);
604
+ })
605
+ .catch((/** @type {any} */e) => callback(e));
606
+ }
607
+ catch (e) {
608
+ console.log(e)
609
+ }
610
+ }
611
+ }
612
+ })
613
+ }
614
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
615
+ }).catch((/** @type {any} */e) => console.log(e));
616
+ }
617
+ }
618
+ catch (e) {
619
+ await Database.delete('Through2Fa');
620
+ }
621
+ var code = await question(Language.EnterSecurityCode);
622
+ try {
623
+ form.approvals_code = code;
624
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
625
+ var prResolve,prReject;
626
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
627
+ if (typeof code == "string") { //always strings
628
+ utils
629
+ .post(nextURL, jar, form, loginOptions)
630
+ .then(utils.saveCookies(jar))
631
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
632
+ var $ = cheerio.load(res.body);
633
+ var error = $("#approvals_code").parent().attr("data-xui-error");
634
+ if (error) {
635
+ logger.Warning(Language.InvaildTwoAuthCode,function() { EnterSecurityCode(); }); //bruh loop
636
+ };
637
+ })
638
+ .then(function() {
639
+ delete form.no_fido;delete form.approvals_code;
640
+ form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
641
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
642
+ })
643
+ .then(async function(/** @type {{ headers: any; body: string | string[]; }} */res) {
644
+ var headers = res.headers;
645
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
646
+ try {
647
+ delete form.name_action_selected;
648
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
649
+ return utils
650
+ .post(nextURL, jar, form, loginOptions)
651
+ .then(utils.saveCookies(jar))
652
+ .then(function() {
653
+ form['submit[This was me]'] = "This was me";
654
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
655
+ })
656
+ .then(function() {
657
+ delete form['submit[This was me]'];
658
+ form.name_action_selected = 'save_device';
659
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
660
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
661
+ })
662
+ .then(async function(/** @type {{ headers: any; body: string | string[]; }} */res) {
663
+ var headers = res.headers;
664
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
665
+ var appState = utils.getAppState(jar,false);
666
+ await Database.set('Through2Fa', appState);
667
+ return loginHelper(appState, email, password, loginOptions, callback);
668
+ })
669
+ .catch((/** @type {any} */e) => callback(e));
670
+ }
671
+ catch (e) {
672
+ console.log(e)
673
+ }
674
+ }
675
+ var appState = utils.getAppState(jar,false);
676
+ if (callback === prCallback) {
677
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
678
+ if (err) return prReject(err);
679
+ return prResolve(api);
680
+ };
681
+ }
682
+ await Database.set('Through2Fa', appState);
683
+ return loginHelper(appState, email, password, loginOptions, callback);
684
+ })
685
+ .catch(function(/** @type {any} */err) {
686
+ if (callback === prCallback) prReject(err);
687
+ else callback(err);
688
+ });
689
+ } else {
690
+ utils
691
+ .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" })
692
+ .then(utils.saveCookies(jar))
693
+ .then(async function(/** @type {{ body: string; }} */res) {
694
+ try {
695
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
696
+ } catch (ex) {
697
+ clearInterval(checkVerified);
698
+ logger.Warning(Language.VerifiedCheck);
699
+ if (callback === prCallback) {
700
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
701
+ if (err) return prReject(err);
702
+ return prResolve(api);
703
+ };
704
+ }
705
+ let appState = utils.getAppState(jar,false);
706
+ return loginHelper(appState, email, password, loginOptions, callback);
707
+ }
708
+ })
709
+ .catch((/** @type {any} */ex) => {
710
+ log.error("login", ex);
711
+ if (callback === prCallback) prReject(ex);
712
+ else callback(ex);
713
+ });
714
+ }
715
+ return rtPromise;
716
+ }
717
+ catch (e) {
718
+ logger.Error(e)
719
+ logger.Error()
720
+ process.exit(0)
721
+ }
722
+ }
723
+ await EnterSecurityCode()
724
+ }
725
+ catch (e) {
726
+ logger.Error(e)
727
+ logger.Error();
728
+ process.exit(0);
729
+ }
730
+ }
731
+ break;
732
+ case false: {
733
+ throw {
734
+ error: 'login-approval',
735
+ continue: function submit2FA(/** @type {any} */code) {
736
+ form.approvals_code = code;
737
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
738
+ var prResolve,prReject;
739
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
740
+ if (typeof code == "string") {
741
+ utils
742
+ .post(nextURL, jar, form, loginOptions)
743
+ .then(utils.saveCookies(jar))
744
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
745
+ var $ = cheerio.load(res.body);
746
+ var error = $("#approvals_code").parent().attr("data-xui-error");
747
+ if (error) {
748
+ throw {
749
+ error: 'login-approval',
750
+ errordesc: Language.InvaildTwoAuthCode,
751
+ lerror: error,
752
+ continue: submit2FA
753
+ };
754
+ }
755
+ })
756
+ .then(function() {
757
+ delete form.no_fido;delete form.approvals_code;
758
+ form.name_action_selected = 'dont_save'; //'save_device' || 'dont_save;
759
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
760
+ })
761
+ .then(function(/** @type {{ headers: any; body: string | string[]; }} */res) {
762
+ var headers = res.headers;
763
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: Language.ApprovalsErr };
764
+ var appState = utils.getAppState(jar,false);
765
+ if (callback === prCallback) {
766
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
767
+ if (err) return prReject(err);
768
+ return prResolve(api);
769
+ };
770
+ }
771
+ return loginHelper(appState, email, password, loginOptions, callback);
772
+ })
773
+ .catch(function(/** @type {any} */err) {
774
+ if (callback === prCallback) prReject(err);
775
+ else callback(err);
776
+ });
777
+ } else {
778
+ utils
779
+ .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" })
780
+ .then(utils.saveCookies(jar))
781
+ .then((/** @type {{ body: string; }} */res) => {
782
+ try {
783
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
784
+ } catch (ex) {
785
+ clearInterval(checkVerified);
786
+ logger.Warning(Language.VerifiedCheck);
787
+ if (callback === prCallback) {
788
+ callback = function(/** @type {any} */err, /** @type {any} */api) {
789
+ if (err) return prReject(err);
790
+ return prResolve(api);
791
+ };
792
+ }
793
+ return loginHelper(utils.getAppState(jar,false), email, password, loginOptions, callback);
794
+ }
795
+ })
796
+ .catch((/** @type {any} */ex) => {
797
+ log.error("login", ex);
798
+ if (callback === prCallback) prReject(ex);
799
+ else callback(ex);
800
+ });
801
+ }
802
+ return rtPromise;
803
+ }
804
+ };
805
+ }
806
+ }
807
+ } else {
808
+ if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
809
+
810
+ if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
811
+ else form['submit[This Is Okay]'] = "This Is Okay";
812
+
813
+ return utils
814
+ .post(nextURL, jar, form, loginOptions)
815
+ .then(utils.saveCookies(jar))
816
+ .then(function() {
817
+ form.name_action_selected = 'dont_save';
818
+
819
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
820
+ })
821
+ .then(function(/** @type {{ headers: any; body: string | string[]; }} */res) {
822
+ var headers = res.headers;
823
+
824
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
825
+
826
+ var appState = utils.getAppState(jar,false);
827
+
828
+ return loginHelper(appState, email, password, loginOptions, callback);
829
+ })
830
+ .catch((/** @type {any} */e) => callback(e));
831
+ }
832
+ });
833
+ }
834
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
835
+ });
836
+ };
837
+ }
838
+
839
+ /!-[ Function backup ]-!/
840
+
841
+ /**
842
+ * @param {string} data
843
+ * @param {any} globalOptions
844
+ * @param {any} callback
845
+ * @param {any} prCallback
846
+ */
847
+
848
+ function backup(data,globalOptions, callback, prCallback) {
849
+ try {
850
+ var appstate;
851
+ try {
852
+ appstate = JSON.parse(data)
853
+ }
854
+ catch(e) {
855
+ appstate = data;
856
+ }
857
+ logger.Warning(Language.BackupNoti);
858
+ try {
859
+ loginHelper(appstate,null,null,globalOptions, callback, prCallback)
860
+ }
861
+ catch (e) {
862
+ logger.Error(Language.ErrBackup);
863
+ process.exit(0);
864
+ }
865
+ }
866
+ catch (e) {
867
+ return logger.Error();
868
+ }
869
+ }
870
+
871
+ /!-[ async function loginHelper ]-!/
872
+
873
+ /**
874
+ * @param {string | any[]} appState
875
+ * @param {any} email
876
+ * @param {any} password
877
+ * @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
878
+ * @param {(arg0: any, arg1: undefined) => void} callback
879
+ * @param {(error: any, api: any) => any} [prCallback]
880
+ */
881
+
882
+ async function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
883
+ var mainPromise = null;
884
+ var jar = utils.getJar();
885
+
886
+ if (fs.existsSync('./backupappstate.json')) {
887
+ fs.unlinkSync('./backupappstate.json');
888
+ }
889
+
890
+ try {
891
+ if (appState) {
892
+ logger.Normal(Language.OnProcess);
893
+ switch (await Database.has("FBKEY")) {
894
+ case true: {
895
+ process.env.FBKEY = await Database.get("FBKEY");
896
+ }
897
+ break;
898
+ case false: {
899
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
900
+ process.env['FBKEY'] = SecurityKey;
901
+ await Database.set('FBKEY', SecurityKey);
902
+ }
903
+ break;
904
+ default: {
905
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
906
+ process.env['FBKEY'] = SecurityKey;
907
+ await Database.set('FBKEY', SecurityKey);
908
+ }
909
+ }
910
+ try {
911
+ switch (global.Fca.Require.FastConfig.EncryptFeature) {
912
+ case true: {
913
+ appState = JSON.parse(JSON.stringify(appState, null, "\t"));
914
+ switch (utils.getType(appState)) {
915
+ case "Array": {
916
+ switch (utils.getType(appState[0])) {
917
+ case "Object": {
918
+ logger.Normal(Language.NotReadyToDecrypt);
919
+ }
920
+ break;
921
+ case "String": {
922
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
923
+ logger.Normal(Language.DecryptSuccess);
924
+ }
925
+ }
926
+ }
927
+ break;
928
+ case "Object": {
929
+ try {
930
+ appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
931
+ logger.Normal(Language.DecryptSuccess);
932
+ }
933
+ catch (e) {
934
+ if (process.env.Backup != undefined && process.env.Backup) {
935
+ await backup(process.env.Backup,globalOptions, callback, prCallback);
936
+ }
937
+ else {
938
+ try {
939
+ if (await Database.has('Backup')) {
940
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
941
+ }
942
+ else {
943
+ logger.Normal(Language.ErrBackup);
944
+ process.exit(0);
945
+ }
946
+ }
947
+ catch (e) {
948
+ logger.Warning(Language.ErrBackup);
949
+ logger.Error();
950
+ process.exit(0);
951
+ }
952
+ }
953
+ logger.Warning(Language.DecryptFailed);
954
+ return logger.Error();
955
+ }
956
+ }
957
+ break;
958
+ case "String": {
959
+ try {
960
+ appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
961
+ logger.Normal(Language.DecryptSuccess);
962
+ }
963
+ catch (e) {
964
+ if (process.env.Backup != undefined && process.env.Backup) {
965
+ await backup(process.env.Backup,globalOptions, callback, prCallback);
966
+ }
967
+ else {
968
+ try {
969
+ if (await Database.has('Backup')) {
970
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
971
+ }
972
+ else {
973
+ logger.Normal(Language.ErrBackup);
974
+ process.exit(0);
975
+ }
976
+ }
977
+ catch (e) {
978
+ logger.Warning(Language.ErrBackup);
979
+ logger.Error();
980
+ process.exit(0);
981
+ }
982
+ }
983
+ logger.Warning(Language.DecryptFailed);
984
+ return logger.Error();
985
+ }
986
+ }
987
+ break;
988
+ default: {
989
+ logger.Warning(Language.InvaildAppState);
990
+ process.exit(0)
991
+ }
992
+ }
993
+ }
994
+ break;
995
+ case false: {
996
+ switch (utils.getType(appState)) {
997
+ case "Array": {
998
+ logger.Normal(Language.EncryptStateOff);
999
+ }
1000
+ break;
1001
+ case "Object": {
1002
+ logger.Normal(Language.EncryptStateOff);
1003
+ try {
1004
+ appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
1005
+ logger.Normal(Language.DecryptSuccess);
1006
+ }
1007
+ catch (e) {
1008
+ if (process.env.Backup != undefined && process.env.Backup) {
1009
+ await backup(process.env.Backup,globalOptions, callback, prCallback);
1010
+ }
1011
+ else {
1012
+ try {
1013
+ if (await Database.has('Backup')) {
1014
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
1015
+ }
1016
+ else {
1017
+ logger.Warning(Language.ErrBackup);
1018
+ process.exit(0);
1019
+ }
1020
+ }
1021
+ catch (e) {
1022
+ logger.Warning(Language.ErrBackup);
1023
+ logger.Error();
1024
+ process.exit(0);
1025
+ }
1026
+ }
1027
+ logger.Warning(Language.DecryptFailed);
1028
+ return logger.Error();
1029
+ }
1030
+ }
1031
+ break;
1032
+ default: {
1033
+ logger.Warning(Language.InvaildAppState);
1034
+ process.exit(0)
1035
+ }
1036
+ }
1037
+ }
1038
+ break;
1039
+ default: {
1040
+ logger.Warning(getText(Language.IsNotABoolean,global.Fca.Require.FastConfig.EncryptFeature))
1041
+ process.exit(0);
1042
+ }
1043
+ }
1044
+ }
1045
+ catch (e) {
1046
+ console.log(e);
1047
+ }
1048
+
1049
+ try {
1050
+ appState = JSON.parse(appState);
1051
+ }
1052
+ catch (e) {
1053
+ try {
1054
+ appState = appState;
1055
+ }
1056
+ catch (e) {
1057
+ return logger.Error();
1058
+ }
1059
+ }
1060
+ try {
1061
+ global.Fca.Data.AppState = appState;
1062
+ appState.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
1063
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
1064
+ jar.setCookie(str, "http://" + c.domain);
1065
+ });
1066
+ process.env.Backup = appState;
1067
+ await Database.set('Backup', appState);
1068
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
1069
+ } catch (e) {
1070
+ console.log(e)
1071
+ if (process.env.Backup != undefined && process.env.Backup) {
1072
+ return await backup(process.env.Backup,globalOptions, callback, prCallback);
1073
+ }
1074
+ try {
1075
+ if (await Database.has('Backup')) {
1076
+ return await backup(await Database.get('Backup'),globalOptions, callback, prCallback);
1077
+ }
1078
+ else {
1079
+ logger.Warning(Language.ErrBackup);
1080
+ process.exit(0);
1081
+ }
1082
+ }
1083
+ catch (e) {
1084
+ logger.Warning(Language.ErrBackup);
1085
+ process.exit(0);
1086
+ }
1087
+ return logger.Warning(Language.ErrBackup); // unreachable 👑
1088
+ }
1089
+ } else {
1090
+ mainPromise = utils
1091
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
1092
+ .then(utils.saveCookies(jar))
1093
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
1094
+ .then(function() {
1095
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
1096
+ });
1097
+ }
1098
+ } catch (e) {
1099
+ console.log(e);
1100
+ }
1101
+ var ctx,api;
1102
+ mainPromise = mainPromise
1103
+ .then(function(/** @type {{ body: string; }} */res) {
1104
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/,redirect = reg.exec(res.body);
1105
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1106
+ return res;
1107
+ })
1108
+ .then(function(/** @type {{ body: any; }} */res) {
1109
+ var html = res.body,Obj = buildAPI(globalOptions, html, jar);
1110
+ ctx = Obj.ctx;
1111
+ api = Obj.api;
1112
+ process.env.api = Obj.api;
1113
+ return res;
1114
+ });
1115
+ if (globalOptions.pageID) {
1116
+ mainPromise = mainPromise
1117
+ .then(function() {
1118
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
1119
+ })
1120
+ .then(function(/** @type {{ body: any; }} */resData) {
1121
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
1122
+ url = url.substring(0, url.length - 1);
1123
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
1124
+ });
1125
+ }
1126
+ mainPromise
1127
+ .then(function() {
1128
+ const { execSync } = require('child_process');
1129
+ Fetch('https://raw.githubusercontent.com/corazoncary/fca/main/package.json').then(async (/** @type {{ body: { toString: () => string; }; }} */res) => {
1130
+ const localVersion = global.Fca.Version;
1131
+ if (Number(localVersion.replace(/\./g,"")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g,"")) ) {
1132
+ log.warn("[ FCA-CHAND ] •",getText(Language.NewVersionFound,global.Fca.Version,JSON.parse(res.body.toString()).version));
1133
+ if (global.Fca.Require.FastConfig.AutoUpdate == true) {
1134
+ log.warn("[ FCA-CHAND ] •",Language.AutoUpdate);
1135
+ try {
1136
+ execSync('npm install team.atf@latest', { stdio: 'inherit' });
1137
+ logger.Success(Language.UpdateSuccess)
1138
+ logger.Normal(Language.RestartAfterUpdate);
1139
+ await new Promise(resolve => setTimeout(resolve,5*1000));
1140
+ console.clear();process.exit(1);
1141
+ }
1142
+ catch (err) {
1143
+ log.warn('Error Update: ' + err);
1144
+ logger.Normal(Language.UpdateFailed);
1145
+ try {
1146
+ const fs = require('fs-extra')
1147
+ try {
1148
+ logger.Error('succeess Package');
1149
+ execSync('npm cache clean --force', { stdio: 'ignore'})
1150
+ await new Promise(resolve => setTimeout(resolve, 2*1000))
1151
+ fs.removeSync('../team.atf');
1152
+ // why stdio is not studio :v
1153
+ await new Promise(resolve => setTimeout(resolve, 2*1000))
1154
+ execSync('npm i team.atf@latest', { stdio: 'inherit'})
1155
+ logger.Success("success Restart");
1156
+ process.exit(1);
1157
+ }
1158
+ catch (e) {
1159
+ logger.Warning("Đã Bị Lỗi Hãy Nhập Vào Console Mã Sau Đây Để Fix !");
1160
+ logger.Warning("rmdir -rf ./node_modules/team.atf && npm i team.atf@latest && npm start");
1161
+ logger.Warning("Hãy Copy Hết Những Chữ Trên, Cần Làm Đúng 100% Nếu Ko File Bạn Sẽ Bay Màu ✨")
1162
+ process.exit(0);
1163
+ }
1164
+ }
1165
+ catch (e) {
1166
+ logger.Error(Language.NotiAfterUseToolFail)
1167
+ logger.Warning("rmdir ./node_modules after type npm i && npm start");
1168
+ process.exit(0);
1169
+ }
1170
+ }
1171
+ }
1172
+ }
1173
+ else {
1174
+ logger.Normal(getText(Language.LocalVersion,localVersion));
1175
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
1176
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
1177
+ require('./Extra/ExtraUptimeRobot')();
1178
+ DataLanguageSetting.HTML.HTML==true? global.Fca.Require.Web.listen(global.Fca.Require.Web.get('DFP')) : global.Fca.Require.Web = null;
1179
+ callback(null, api);
1180
+ };
1181
+ }).catch(async function(e) {
1182
+ console.log(e)
1183
+ logger.Warning(Language.AutoCheckUpdateFailure)
1184
+ logger.Normal(getText(Language.LocalVersion,global.Fca.Version));
1185
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
1186
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
1187
+ require('./Extra/ExtraUptimeRobot')();
1188
+ DataLanguageSetting.HTML.HTML==true? global.Fca.Require.Web.listen(global.Fca.Require.Web.get('DFP')) : global.Fca.Require.Web = null;
1189
+ callback(null, api);
1190
+ });
1191
+ }).catch(function(/** @type {{ error: any; }} */e) {
1192
+ log.error("login", e.error || e);
1193
+ callback(e);
1194
+ });
1195
+ }
1196
+
1197
+ /**
1198
+ * It asks the user for their account and password, and then saves it to the database.
1199
+ */
1200
+
1201
+ function setUserNameAndPassWord() {
1202
+ let rl = readline.createInterface({
1203
+ input: process.stdin,
1204
+ output: process.stdout
1205
+ });
1206
+ let localbrand2 = global.Fca.Version
1207
+ console.clear();
1208
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1209
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1210
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1211
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(localbrand2) + '\n');
1212
+ try {
1213
+ rl.question(Language.TypeAccount, (Account) => {
1214
+ if (!Account.includes("@") && global.Fca.Require.utils.getType(parseInt(Account)) != "Number") return logger.Normal(Language.TypeAccountError, function () { process.exit(1) }); //Very Human
1215
+ else rl.question(Language.TypePassword,async function (Password) {
1216
+ rl.close();
1217
+ try {
1218
+ await Database.set("Account", Account);
1219
+ await Database.set("Password", Password);
1220
+ }
1221
+ catch (e) {
1222
+ logger.Warning(Language.ErrDataBase);
1223
+ logger.Error();
1224
+ process.exit(0);
1225
+ }
1226
+ if (global.Fca.Require.FastConfig.ResetDataLogin) {
1227
+ global.Fca.Require.FastConfig.ResetDataLogin = false;
1228
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/TeamAtfChand.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1229
+ }
1230
+ logger.Success(Language.SuccessSetData);
1231
+ process.exit(1);
1232
+ });
1233
+ })
1234
+ }
1235
+ catch (e) {
1236
+ logger.Error(e)
1237
+ }
1238
+ }
1239
+
1240
+ /**
1241
+ * @param {{ email: any; password: any; appState: any; }} loginData
1242
+ * @param {{}} options
1243
+ * @param {(error: any, api: any) => any} callback
1244
+ */
1245
+
1246
+ function login(loginData, options, callback) {
1247
+
1248
+ if (utils.getType(loginData) == "Array") {
1249
+ if (loginData.length == 3) {
1250
+ options = loginData[1];
1251
+ callback = loginData[2];
1252
+ loginData = loginData[0]
1253
+ }
1254
+ else if (loginData.length == 2) {
1255
+ options = loginData[1];
1256
+ loginData = loginData[0]
1257
+ }
1258
+ else {
1259
+ loginData = loginData[0]
1260
+ }
1261
+ }
1262
+
1263
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1264
+ callback = options;
1265
+ options = {};
1266
+ }
1267
+
1268
+ var globalOptions = {
1269
+ selfListen: true,
1270
+ listenEvents: true,
1271
+ listenTyping: true,
1272
+ updatePresence: false,
1273
+ forceLogin: false,
1274
+ autoMarkDelivery: true,
1275
+ autoMarkRead: true,
1276
+ autoReconnect: true,
1277
+ logRecordSize: 100,
1278
+ online: true,
1279
+ emitReady: false,
1280
+ 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"
1281
+ };
1282
+
1283
+ if (loginData.email && loginData.password) {
1284
+ setOptions(globalOptions, {
1285
+ logLevel: "silent",
1286
+ forceLogin: true,
1287
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"
1288
+ });
1289
+ }
1290
+ else if (loginData.appState) {
1291
+ setOptions(globalOptions, options);
1292
+ }
1293
+
1294
+ var prCallback = null;
1295
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1296
+ var rejectFunc = null;
1297
+ var resolveFunc = null;
1298
+ var returnPromise = new Promise(function(resolve, reject) {
1299
+ resolveFunc = resolve;
1300
+ rejectFunc = reject;
1301
+ });
1302
+ prCallback = function(/** @type {any} */error, /** @type {any} */api) {
1303
+ if (error) return rejectFunc(error);
1304
+ return resolveFunc(api);
1305
+ };
1306
+ callback = prCallback;
1307
+ }
1308
+
1309
+ (async function() {
1310
+ var Premium = require("./Extra/Src/Premium");
1311
+ global.Fca.Data.PremText = await Premium(global.Fca.Require.Security.create().uuid) || "Bạn Đang Sài Phiên Bản: Free !";
1312
+ if (!loginData.email && !loginData.password) {
1313
+ switch (global.Fca.Require.FastConfig.AutoLogin) {
1314
+ case true: {
1315
+ if (global.Fca.Require.FastConfig.ResetDataLogin) return setUserNameAndPassWord();
1316
+ else {
1317
+ try {
1318
+ if (await Database.get("TempState")) {
1319
+ try {
1320
+ loginData.appState = JSON.parse(await Database.get("TempState"));
1321
+ }
1322
+ catch (_) {
1323
+ loginData.appState = await Database.get("TempState");
1324
+ }
1325
+ await Database.delete("TempState");
1326
+ }
1327
+ }
1328
+ catch (e) {
1329
+ console.log(e)
1330
+ await Database.delete("TempState");
1331
+ logger.Warning(Language.ErrDataBase);
1332
+ logger.Error();
1333
+ process.exit(0);
1334
+ }
1335
+ try {
1336
+ if (await Database.has('Account') && await Database.has('Password')) return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1337
+ else return setUserNameAndPassWord();
1338
+ }
1339
+ catch (e) {
1340
+ console.log(e)
1341
+ logger.Warning(Language.ErrDataBase);
1342
+ logger.Error();
1343
+ process.exit(0);
1344
+ }
1345
+ }
1346
+ }
1347
+ case false: {
1348
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1349
+ }
1350
+ }
1351
+ }
1352
+ else loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1353
+ })()
1354
+ return returnPromise;
1355
+ }
1356
+
1357
+ module.exports = login;