fca-zoebakaaa 1.0.0

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