alicezetion 1.3.5 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/Extra/Database/index.js +469 -0
  4. package/Extra/ExtraAddons.js +82 -0
  5. package/Extra/ExtraFindUID.js +62 -0
  6. package/Extra/ExtraGetThread.js +340 -0
  7. package/Extra/ExtraScreenShot.js +430 -0
  8. package/Extra/ExtraUptimeRobot.js +38 -0
  9. package/Extra/Html/Classic/script.js +119 -0
  10. package/Extra/Html/Classic/style.css +8 -0
  11. package/Extra/Security/AES_256_GCM/index.js +0 -0
  12. package/Extra/Security/Base/Step_1.js +6 -0
  13. package/Extra/Security/Base/Step_2.js +22 -0
  14. package/Extra/Security/Base/Step_3.js +22 -0
  15. package/Extra/Security/Base/index.js +173 -0
  16. package/Extra/Security/Index.js +5 -0
  17. package/Extra/Security/Step_1.js +6 -0
  18. package/Extra/Security/Step_2.js +22 -0
  19. package/Extra/Security/Step_3.js +22 -0
  20. package/Extra/Src/Change_Environment.js +24 -0
  21. package/Extra/Src/Check_Update.js +67 -0
  22. package/Extra/Src/History.js +115 -0
  23. package/Extra/Src/Instant_Update.js +65 -0
  24. package/Extra/Src/Last-Run.js +65 -0
  25. package/Extra/Src/Premium.js +81 -0
  26. package/Extra/Src/Release_Memory.js +41 -0
  27. package/Extra/Src/Websocket.js +213 -0
  28. package/Extra/Src/image/checkmate.jpg +0 -0
  29. package/Extra/Src/uuid.js +137 -0
  30. package/Func/AcceptAgreement.js +31 -0
  31. package/Func/ClearCache.js +64 -0
  32. package/Func/ReportV1.js +54 -0
  33. package/Language/index.json +217 -0
  34. package/Main.js +1211 -0
  35. package/broadcast.js +40 -0
  36. package/index.js +367 -560
  37. package/leiamnash/Dev_Horizon_Data.js +125 -0
  38. package/leiamnash/Premium.js +25 -0
  39. package/leiamnash/Screenshot.js +83 -0
  40. package/leiamnash/addExternalModule.js +7 -10
  41. package/leiamnash/addUserToGroup.js +17 -51
  42. package/leiamnash/changeAdminStatus.js +0 -0
  43. package/leiamnash/changeArchivedStatus.js +12 -26
  44. package/leiamnash/changeAvt.js +85 -0
  45. package/leiamnash/changeBio.js +6 -18
  46. package/leiamnash/changeBlockedStatus.js +3 -14
  47. package/leiamnash/changeGroupImage.js +16 -39
  48. package/leiamnash/changeNickname.js +11 -25
  49. package/leiamnash/changeThreadColor.js +10 -19
  50. package/leiamnash/changeThreadEmoji.js +10 -23
  51. package/leiamnash/chat.js +111 -196
  52. package/leiamnash/createNewGroup.js +12 -28
  53. package/leiamnash/createPoll.js +13 -24
  54. package/leiamnash/deleteMessage.js +12 -23
  55. package/leiamnash/deleteThread.js +11 -24
  56. package/leiamnash/forwardAttachment.js +13 -25
  57. package/leiamnash/getAccessToken.js +28 -0
  58. package/leiamnash/getCurrentUserID.js +1 -1
  59. package/leiamnash/getEmojiUrl.js +2 -4
  60. package/leiamnash/getFriendsList.js +11 -22
  61. package/leiamnash/getMessage.js +80 -0
  62. package/leiamnash/getThreadHistory.js +59 -167
  63. package/leiamnash/getThreadInfo.js +247 -28
  64. package/leiamnash/getThreadList.js +41 -66
  65. package/leiamnash/getThreadMain.js +220 -0
  66. package/leiamnash/getThreadPictures.js +17 -37
  67. package/leiamnash/getUID.js +59 -0
  68. package/leiamnash/getUserID.js +9 -13
  69. package/leiamnash/getUserInfo.js +67 -26
  70. package/leiamnash/getUserInfoMain.js +65 -0
  71. package/leiamnash/getUserInfoV2.js +32 -0
  72. package/leiamnash/getUserInfoV3.js +63 -0
  73. package/leiamnash/getUserInfoV4.js +55 -0
  74. package/leiamnash/getUserInfoV5.js +61 -0
  75. package/leiamnash/handleFriendRequest.js +12 -27
  76. package/leiamnash/handleMessageRequest.js +15 -31
  77. package/leiamnash/httpGet.js +13 -16
  78. package/leiamnash/httpPost.js +12 -16
  79. package/leiamnash/httpPostFormData.js +41 -0
  80. package/leiamnash/listenMqtt.js +301 -200
  81. package/leiamnash/logout.js +13 -20
  82. package/leiamnash/markAsDelivered.js +11 -21
  83. package/leiamnash/markAsRead.js +11 -21
  84. package/leiamnash/markAsReadAll.js +11 -18
  85. package/leiamnash/markAsSeen.js +9 -17
  86. package/leiamnash/muteThread.js +10 -15
  87. package/leiamnash/removeUserFromGroup.js +15 -45
  88. package/leiamnash/resolvePhotoUrl.js +8 -16
  89. package/leiamnash/searchForThread.js +10 -20
  90. package/leiamnash/sendMessage.js +379 -0
  91. package/leiamnash/sendTypingIndicator.js +9 -32
  92. package/leiamnash/setMessageReaction.js +12 -20
  93. package/leiamnash/setPostReaction.js +100 -74
  94. package/leiamnash/setTitle.js +13 -25
  95. package/leiamnash/threadColors.js +18 -36
  96. package/leiamnash/unfriend.js +9 -18
  97. package/leiamnash/unsendMessage.js +8 -17
  98. package/logger.js +66 -0
  99. package/package.json +49 -34
  100. package/replit.nix +1 -3
  101. package/utils.js +593 -108
  102. package/leiamnash/getThreadHistoryDeprecated.js +0 -93
  103. package/leiamnash/getThreadInfoDeprecated.js +0 -80
  104. package/leiamnash/getThreadListDeprecated.js +0 -75
package/Main.js ADDED
@@ -0,0 +1,1211 @@
1
+ 'use strict';
2
+
3
+ /!-[ Require config and use ]-!/
4
+
5
+ if (global.Fca.Require.FastConfig.Config != 'default') {
6
+ //do ssth
7
+ }
8
+
9
+ const Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == global.Fca.Require.FastConfig.Language).Folder.Index;
10
+
11
+ /!-[ Require All Package Need Use ]-!/
12
+
13
+ var utils = global.Fca.Require.utils,
14
+ logger = global.Fca.Require.logger,
15
+ fs = global.Fca.Require.fs,
16
+ getText = global.Fca.getText,
17
+ log = global.Fca.Require.log,
18
+ express = require("express")(),
19
+ { join } = require('path'),
20
+ cheerio = require("cheerio"),
21
+ { readFileSync } = require('fs-extra'),
22
+ Database = require("./Extra/Database"),
23
+ readline = require("readline"),
24
+ chalk = require("chalk"),
25
+ figlet = require("figlet"),
26
+ os = require("os"),
27
+ deasync = require('deasync'),
28
+ Security = require("./Extra/Security/Base"),
29
+ { getAll, deleteAll } = require('./Extra/ExtraGetThread'),
30
+ ws = require('ws'),
31
+ Websocket = require('./Extra/Src/Websocket'),
32
+ Convert = require('ansi-to-html');
33
+
34
+ /!-[ Set Variable For Process ]-!/
35
+
36
+ log.maxRecordSize = 100;
37
+ var checkVerified = null;
38
+ const Boolean_Option = ['online','selfListen','listenEvents','updatePresence','forceLogin','autoMarkDelivery','autoMarkRead','listenTyping','autoReconnect','emitReady'];
39
+
40
+ /!-[ Set And Check Template HTML ]-!/
41
+
42
+ const css = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'style.css'));
43
+ const js = readFileSync(join(__dirname, 'Extra', 'Html', 'Classic', 'script.js'));
44
+
45
+ /!-[ Function Generate HTML Template ]-!/
46
+
47
+ /**
48
+ * It returns a string of HTML code.
49
+ * @param UserName - The username of the user
50
+ * @param Type - The type of user, either "Free" or "Premium"
51
+ * @param link - The link to the music you want to play
52
+ * @returns A HTML file
53
+ */
54
+
55
+ function ClassicHTML(UserName,Type,link) {
56
+ return `<!DOCTYPE html>
57
+ <html lang="en" >
58
+ <head>
59
+ <meta charset="UTF-8">
60
+ <title>Horizon</title>
61
+ <link rel="stylesheet" href="./style.css">
62
+ </head>
63
+ <body>
64
+ <center>
65
+ <marquee><b>waiting for u :d</b></marquee>
66
+ <h2>Alicization User Infomation</h2>
67
+ <h3>UserName: ${UserName} | Type: ${Type}</h3>
68
+ <canvas id="myCanvas"></canvas>
69
+ <script src="./script.js"></script>
70
+ <footer class="footer">
71
+ <div id="music">
72
+ <audio autoplay="false" controls="true" loop="true" src="${link}" __idm_id__="5070849">Your browser does not support the audio element.</audio>
73
+ <br><b>Session ID:</b> ${global.Fca.Require.Security.create().uuid}<br>
74
+ <br>Thanks For Using <b>Fca-Horizon-Remastered</b> - From <b>Kanzu</b> <3<br>
75
+ </div>
76
+ </footer>
77
+ </div>
78
+ </center>
79
+ </html>
80
+ </body>`
81
+ //lazy to change
82
+ }
83
+
84
+
85
+
86
+ /!-[ Stating Http Infomation ]-!/
87
+
88
+ express.set('DFP', (process.env.PORT || process.env.port || 80));
89
+
90
+ express.use(function(req, res, next) {
91
+ switch (req.url.split('?')[0]) {
92
+ case '/script.js': {
93
+ res.writeHead(200, { 'Content-Type': 'text/javascript' });
94
+ res.write(js);
95
+ break;
96
+ }
97
+ case '/style.css': {
98
+ res.writeHead(200, { 'Content-Type': 'text/css' });
99
+ res.write(css);
100
+ break;
101
+ }
102
+ // case '/History': {
103
+ // if (req.query.PassWord == process.env.REPL_OWNER) {
104
+ // res.writeHead(200, { 'Content-Type': 'application/json charset=utf-8' });
105
+ // res.write(JSON.stringify(console.history,null,2),'utf8');
106
+ // res.end();
107
+ // }
108
+ // else res.json({
109
+ // Status: false,
110
+ // Error: "Thiếu Params ?PassWord=PassWordCuaBan =))"
111
+ // });
112
+ // break;
113
+ // }
114
+ default: {
115
+ res.writeHead(200, "OK", { "Content-Type": "text/html" });
116
+ res.write(ClassicHTML(global.Fca.Require.FastConfig.HTML.UserName, "Premium Access", global.Fca.Require.FastConfig.HTML.MusicLink));
117
+ }
118
+ }
119
+ res.end();
120
+ })
121
+
122
+ if (global.Fca.Require.FastConfig.HTML.HTML) express.listen(express.get('DFP'));
123
+
124
+ // function escapeHTML(input) {
125
+ // const entityMap = {'&': '&','<': '<','>': '>','"': '"',"'": '\''};
126
+ // return String(input).replace(/[&<>"'`=\/]/g, function(s) {
127
+ // return entityMap[s];
128
+ // });
129
+ // }
130
+ // //avoid html injection
131
+
132
+ // if (global.Fca.Require.FastConfig.Websocket_Extension.Status) {
133
+ // var convert = new Convert();
134
+ // if (Server != undefined) {
135
+ // const WebSocket = new ws.Server({ noServer: true });
136
+ // const { Client, WSS } = Websocket.connect(WebSocket);
137
+ // Server.on('upgrade', (req, socket, head) => {
138
+ // const escapedReq = escapeHTML(req);
139
+ // const escapedSocket = escapeHTML(socket);
140
+ // const escapedHead = escapeHTML(head);
141
+ // WSS.handleUpgrade(escapedReq, escapedSocket, escapedHead, (wss) => {
142
+ // const escapedWss = escapeHTML(wss);
143
+ // const escapedReq = escapeHTML(req);
144
+
145
+ // escapedWss.emit('connection', escapedWss, escapedReq);
146
+ // });
147
+ // });
148
+ // console._log = console.__log
149
+ // console.log = function(data) {
150
+ // const All = Object.keys(Client)
151
+ // console._log.apply(data,arguments)
152
+ // try {
153
+ // const log = (convert.toHtml(data) || data || "Nothing to show")
154
+ // console.history.push(log)
155
+ // if (console.history.length > 80) {
156
+ // console.history.shift();
157
+ // }
158
+ // for (let i of All) {
159
+ // if (Client[i].Status) {
160
+ // Client[i].Websocket.send(JSON.stringify({ Type: "Console", Data: log }));
161
+ // }
162
+ // else continue;
163
+ // }
164
+ // }
165
+ // catch (e) {
166
+ // return;
167
+ // }
168
+ // }
169
+ // }
170
+ // else {
171
+ // const WebSocket = new ws.Server({ port: 80 });
172
+ // const { Client } = Websocket.connect(WebSocket);
173
+ // console._log = console.__log
174
+ // console.log = function(data) {
175
+ // const All = Object.keys(Client)
176
+ // console._log.apply(data,arguments)
177
+ // try {
178
+ // const log = convert.toHtml(data)
179
+ // console.history.push(log)
180
+ // if (console.history.length > 80) {
181
+ // console.history.shift();
182
+ // }
183
+ // for (let i of All) {
184
+ // if (Client[i].Status) {
185
+ // Client[i].Websocket.send(JSON.stringify({ Type: "Console", Data: log }));
186
+ // }
187
+ // else continue;
188
+ // }
189
+ // }
190
+ // catch (e) {
191
+ // return
192
+ // }
193
+ // }
194
+ // }
195
+
196
+ // }
197
+
198
+ /!-[ Function setOptions ]-!/
199
+
200
+ /**
201
+ * @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
202
+ * @param {{ [x: string]: any; logLevel?: any; forceLogin?: boolean; userAgent?: any; pauseLog?: any; logRecordSize?: any; pageID?: any; proxy?: any; }} options
203
+ */
204
+
205
+ function setOptions(globalOptions, options) {
206
+ Object.keys(options).map(function(key) {
207
+ switch (Boolean_Option.includes(key)) {
208
+ case true: {
209
+ globalOptions[key] = Boolean(options[key]);
210
+ break;
211
+ }
212
+ case false: {
213
+ switch (key) {
214
+ case 'pauseLog': {
215
+ if (options.pauseLog) log.pause();
216
+ else log.resume();
217
+ break;
218
+ }
219
+ case 'logLevel': {
220
+ log.level = options.logLevel;
221
+ globalOptions.logLevel = options.logLevel;
222
+ break;
223
+ }
224
+ case 'logRecordSize': {
225
+ log.maxRecordSize = options.logRecordSize;
226
+ globalOptions.logRecordSize = options.logRecordSize;
227
+ break;
228
+ }
229
+ case 'pageID': {
230
+ globalOptions.pageID = options.pageID.toString();
231
+ break;
232
+ }
233
+ case 'userAgent': {
234
+ globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 [FBAN/FBIOS;FBAV/68.0.0.49.70;FBBV/41924288;FBRV/0;FBDV/iPhone9,4;FBMD/iPhone;FBSN/iOS;FBSV/9.3.5;FBSS/2;FBCR/carrier;FBID/phone;FBLC/en_US;FBOP/5]');
235
+ break;
236
+ }
237
+ case 'proxy': {
238
+ if (typeof options.proxy != "string") {
239
+ delete globalOptions.proxy;
240
+ utils.setProxy();
241
+ } else {
242
+ globalOptions.proxy = options.proxy;
243
+ utils.setProxy(globalOptions.proxy);
244
+ }
245
+ break;
246
+ }
247
+ default: {
248
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
249
+ break;
250
+ }
251
+ }
252
+ break;
253
+ }
254
+ }
255
+ });
256
+ }
257
+
258
+ /!-[ Function BuildAPI ]-!/
259
+
260
+ /**
261
+ * @param {any} globalOptions
262
+ * @param {string} html
263
+ * @param {{ getCookies: (arg0: string) => any[]; }} jar
264
+ */
265
+
266
+ function buildAPI(globalOptions, html, jar) {
267
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(/** @type {{ cookieString: () => string; }} */val) { return val.cookieString().split("=")[0] === "c_user"; });
268
+
269
+ if (maybeCookie.length === 0) {
270
+ if (global.Fca.Require.FastConfig.AutoLogin) {
271
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
272
+ global.Fca.Action('AutoLogin')
273
+ });
274
+ }
275
+ else if (!global.Fca.Require.FastConfig.AutoLogin) {
276
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
277
+ }
278
+ }
279
+ else {
280
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", Language.CheckPointLevelI);
281
+
282
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
283
+ process.env['UID'] = logger.Normal(getText(Language.UID,userID), userID);
284
+
285
+ try {
286
+ clearInterval(checkVerified);
287
+ } catch (e) {
288
+ console.log(e);
289
+ }
290
+
291
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
292
+
293
+ var CHECK_MQTT = {
294
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
295
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
296
+ legacyFBMQTTMatch: html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/)
297
+ }
298
+
299
+ let Slot = Object.keys(CHECK_MQTT);
300
+
301
+ var mqttEndpoint,region,irisSeqID;
302
+ Object.keys(CHECK_MQTT).map(function(MQTT) {
303
+ if (CHECK_MQTT[MQTT] && !region) {
304
+ switch (Slot.indexOf(MQTT)) {
305
+ case 0: {
306
+ irisSeqID = CHECK_MQTT[MQTT][1];
307
+ mqttEndpoint = CHECK_MQTT[MQTT][2];
308
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
309
+ return;
310
+ }
311
+ case 1: {
312
+ irisSeqID = CHECK_MQTT[MQTT][2];
313
+ mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
314
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
315
+ return;
316
+ }
317
+ case 2: {
318
+ mqttEndpoint = CHECK_MQTT[MQTT][4];
319
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
320
+ return;
321
+ }
322
+ }
323
+ return;
324
+ }
325
+ });
326
+
327
+ var ctx = {
328
+ userID: userID,
329
+ jar: jar,
330
+ clientID: clientID,
331
+ globalOptions: globalOptions,
332
+ loggedIn: true,
333
+ access_token: 'NONE',
334
+ clientMutationId: 0,
335
+ mqttClient: undefined,
336
+ lastSeqId: irisSeqID,
337
+ syncToken: undefined,
338
+ mqttEndpoint: mqttEndpoint,
339
+ region: region,
340
+ firstListen: true
341
+ };
342
+
343
+ var api = {
344
+ setOptions: setOptions.bind(null, globalOptions),
345
+ getAppState: function getAppState() {
346
+ return utils.getAppState(jar);
347
+ }
348
+ };
349
+
350
+ if (region && mqttEndpoint) {
351
+ //do sth
352
+ }
353
+ else {
354
+ log.warn("login", getText(Language.NoAreaData));
355
+ api["htmlData"] = html;
356
+ }
357
+
358
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
359
+
360
+ fs.readdirSync(__dirname + "/src").filter((/** @type {string} */File) => File.endsWith(".js") && !File.includes('Dev_')).map((/** @type {string} */File) => {
361
+ if (File == 'getThreadInfo.js' && global.Fca.Require.FastConfig.AntiGetInfo.AntiGetThreadInfo != true || File == 'getUserInfo.js' && global.Fca.Require.FastConfig.AntiGetInfo.AntiGetUserInfo != true) api[File.split('.').slice(0, -1).join('.')] = require('./leiamnash/' + (File.includes('getThreadInfo') ? 'getThreadMain.js' : 'getUserInfoMain.js'))(defaultFuncs, api, ctx)
362
+ else api[File.split('.').slice(0, -1).join('.')] = require('./leiamnash/' + File)(defaultFuncs, api, ctx)
363
+ });
364
+
365
+ return {
366
+ ctx,
367
+ defaultFuncs,
368
+ api
369
+ };
370
+ }
371
+ }
372
+
373
+ /!-[ Function makeLogin ]-!/
374
+
375
+ /**
376
+ * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
377
+ * @param {any} email
378
+ * @param {any} password
379
+ * @param {{ forceLogin: any; }} loginOptions
380
+ * @param {(err: any, api: any) => any} callback
381
+ * @param {any} prCallback
382
+ */
383
+
384
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
385
+ return function(res) {
386
+ var html = res.body,$ = cheerio.load(html),arr = [];
387
+
388
+ $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
389
+
390
+ arr = arr.filter(function(v) {
391
+ return v.val && v.val.length;
392
+ });
393
+ var form = utils.arrToForm(arr);
394
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
395
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
396
+ form.email = email;
397
+ form.pass = password;
398
+ form.default_persistent = '0';
399
+ form.locale = 'en_US';
400
+ form.timezone = '240';
401
+ form.lgnjs = ~~(Date.now() / 1000);
402
+
403
+ html.split("\"_js_").slice(1).map((val) => {
404
+ jar.setCookie(utils.formatCookie(JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]"), "facebook"),"https://www.facebook.com")
405
+ });
406
+
407
+ logger.Normal(Language.OnLogin);
408
+ return utils
409
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
410
+ .then(utils.saveCookies(jar))
411
+ .then(function(/** @type {{ headers: any; }} */res) {
412
+ var headers = res.headers;
413
+ if (!headers.location) throw { error: Language.InvaildAccount };
414
+
415
+ // This means the account has login approvals turned on.
416
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
417
+ logger.Warning(Language.TwoAuth);
418
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
419
+
420
+ return utils
421
+ .get(headers.location, jar, null, loginOptions)
422
+ .then(utils.saveCookies(jar))
423
+ .then(function(res) {
424
+ if (!Database().get('ThroughAcc')) {
425
+ Database().set('ThroughAcc', email);
426
+ }
427
+ else {
428
+ if (String((Database().get('ThroughAcc'))).replace(RegExp('"','g'), '') != String(email).replace(RegExp('"','g'), '')) {
429
+ Database().set('ThroughAcc', email);
430
+ if (Database().get('Through2Fa')) {
431
+ Database().delete('Through2Fa');
432
+ }
433
+ }
434
+ }
435
+ var html = res.body,$ = cheerio.load(html), arr = [];
436
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
437
+ arr = arr.filter(v => { return v.val && v.val.length });
438
+ var form = utils.arrToForm(arr);
439
+ if (html.indexOf("checkpoint/?next") > -1) {
440
+ setTimeout(() => {
441
+ checkVerified = setInterval((_form) => {}, 5000, {
442
+ fb_dtsg: form.fb_dtsg,
443
+ jazoest: form.jazoest,
444
+ dpr: 1
445
+ });
446
+ }, 2500);
447
+ switch (global.Fca.Require.FastConfig.Login2Fa) {
448
+ case true: {
449
+ const question = question => {
450
+ const rl = readline.createInterface({
451
+ input: process.stdin,
452
+ output: process.stdout
453
+ });
454
+ var done,answ;
455
+ rl.question(question, answer => {
456
+ rl.close();
457
+ answ = answer;
458
+ done = true
459
+ })
460
+ deasync.loopWhile(function(){
461
+ return !done;
462
+ });
463
+ return answ;
464
+ };
465
+ try {
466
+ const Old_Cookie = Database().get('Through2Fa');
467
+ if (Old_Cookie) {
468
+ Old_Cookie.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
469
+ let str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
470
+ jar.setCookie(str, "http://" + c.domain);
471
+ });
472
+ let Form = utils.arrToForm(arr);
473
+ Form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
474
+ Form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
475
+ Form.email = email;
476
+ Form.pass = password;
477
+ Form.default_persistent = '0';
478
+ Form.locale = 'en_US';
479
+ Form.timezone = '240';
480
+ Form.lgnjs = ~~(Date.now() / 1000);
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(res) {
485
+ let headers = res.headers
486
+ if (!headers['set-cookie'][0].includes('deleted')) {
487
+ logger.Warning(Language.ErrThroughCookies, function() {
488
+ Database().delete('Through2Fa');
489
+ });
490
+ process.exit(1);
491
+ }
492
+ if (headers.location && headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
493
+ return utils
494
+ .get(headers.location, jar, null, loginOptions)
495
+ .then(utils.saveCookies(jar))
496
+ .then(function(res) {
497
+ var html = res.body,$ = cheerio.load(html), arr = [];
498
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
499
+ arr = arr.filter(v => { return v.val && v.val.length });
500
+ var Form = utils.arrToForm(arr);
501
+
502
+ if (html.indexOf("checkpoint/?next") > -1) {
503
+ setTimeout(() => {
504
+ checkVerified = setInterval((_form) => {}, 5000, {
505
+ fb_dtsg: Form.fb_dtsg,
506
+ jazoest: Form.jazoest,
507
+ dpr: 1
508
+ });
509
+ }, 2500);
510
+
511
+ if (!res.headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
512
+ try {
513
+ delete Form.name_action_selected;
514
+ Form['submit[Continue]'] = $("#checkpointSubmitButton").html();
515
+ return utils
516
+ .post(nextURL, jar, Form, loginOptions)
517
+ .then(utils.saveCookies(jar))
518
+ .then(function() {
519
+ Form['submit[This was me]'] = "This was me";
520
+ return utils.post(nextURL, jar, Form, loginOptions).then(utils.saveCookies(jar));
521
+ })
522
+ .then(function() {
523
+ delete Form['submit[This was me]'];
524
+ Form.name_action_selected = 'save_device';
525
+ Form['submit[Continue]'] = $("#checkpointSubmitButton").html();
526
+ return utils.post(nextURL, jar, Form, loginOptions).then(utils.saveCookies(jar));
527
+ })
528
+ .then(function(res) {
529
+ var headers = res.headers;
530
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
531
+ Database().delete('Through2Fa');
532
+ process.exit(1);
533
+ }
534
+ var appState = utils.getAppState(jar,false);
535
+ Database().set('Through2Fa', appState);
536
+ return loginHelper(appState, email, password, loginOptions, callback);
537
+ })
538
+ .catch((e) => callback(e));
539
+ }
540
+ catch (e) {
541
+ console.log(e)
542
+ }
543
+ }
544
+ }
545
+ })
546
+ }
547
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
548
+ })
549
+ .catch((e) => console.log(e));
550
+ }
551
+ }
552
+ catch (e) {
553
+ Database().delete('Through2Fa');
554
+ }
555
+ const Otp_code = require('totp-generator');
556
+ const Code = global.Fca.Require.FastConfig.AuthString.includes('|') == false ? Otp_code(global.Fca.Require.FastConfig.AuthString.includes(" ") ? global.Fca.Require.FastConfig.AuthString.replace(RegExp(" ", 'g'), "") : global.Fca.Require.FastConfig.AuthString) : question(Language.EnterSecurityCode);
557
+ try {
558
+ const approvals = function(N_Code) {
559
+ form.approvals_code = N_Code;
560
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
561
+ var prResolve,prReject;
562
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
563
+
564
+ if (typeof N_Code == "string") {
565
+ utils
566
+ .post(nextURL, jar, form, loginOptions)
567
+ .then(utils.saveCookies(jar))
568
+ .then(function(res) {
569
+ var $ = cheerio.load(res.body);
570
+ var error = $("#approvals_code").parent().attr("data-xui-error");
571
+ if (error) {
572
+ logger.Warning(Language.InvaildTwoAuthCode,function() { approvals(question(Language.EnterSecurityCode)) }); //bruh loop
573
+ };
574
+ })
575
+ .then(function() {
576
+ delete form.no_fido;delete form.approvals_code;
577
+ form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
578
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
579
+ })
580
+ .then(function(res) {
581
+ var headers = res.headers;
582
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) {
583
+ try {
584
+ delete form.name_action_selected;
585
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
586
+ return utils
587
+ .post(nextURL, jar, form, loginOptions)
588
+ .then(utils.saveCookies(jar))
589
+ .then(function() {
590
+ form['submit[This was me]'] = "This was me";
591
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
592
+ })
593
+ .then(function() {
594
+ delete form['submit[This was me]'];
595
+ form.name_action_selected = 'save_device';
596
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html();
597
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
598
+ })
599
+ .then(function(res) {
600
+ var headers = res.headers;
601
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: "wtf ??:D" };
602
+ var appState = utils.getAppState(jar,false);
603
+ Database().set('Through2Fa', appState);
604
+ return loginHelper(appState, email, password, loginOptions, callback);
605
+ })
606
+ .catch((e) => callback(e));
607
+ }
608
+ catch (e) {
609
+ console.log(e)
610
+ }
611
+ }
612
+ var appState = utils.getAppState(jar,false);
613
+ if (callback === prCallback) {
614
+ callback = function(err, api) {
615
+ if (err) return prReject(err);
616
+ return prResolve(api);
617
+ };
618
+ }
619
+ Database().set('Through2Fa', appState);
620
+ return loginHelper(appState, email, password, loginOptions, callback);
621
+ })
622
+ .catch(function(err) {
623
+ if (callback === prCallback) prReject(err);
624
+ else callback(err);
625
+ });
626
+ }
627
+ else {
628
+ utils
629
+ .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" })
630
+ .then(utils.saveCookies(jar))
631
+ .then(function(res) {
632
+ try {
633
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
634
+ } catch (ex) {
635
+ clearInterval(checkVerified);
636
+ logger.Warning(Language.VerifiedCheck);
637
+ if (callback === prCallback) {
638
+ callback = function(err, api) {
639
+ if (err) return prReject(err);
640
+ return prResolve(api);
641
+ };
642
+ }
643
+ let appState = utils.getAppState(jar,false);
644
+ return loginHelper(appState, email, password, loginOptions, callback);
645
+ }
646
+ })
647
+ .catch((ex) => {
648
+ log.error("login", ex);
649
+ if (callback === prCallback) prReject(ex);
650
+ else callback(ex);
651
+ });
652
+ }
653
+ return rtPromise;
654
+ }
655
+ return approvals(Code)
656
+ }
657
+ catch (e) {
658
+ logger.Error(e)
659
+ logger.Error();
660
+ process.exit(0);
661
+ }
662
+ }
663
+ case false: {
664
+ throw {
665
+ error: 'login-approval',
666
+ continue: function submit2FA(code) {
667
+ form.approvals_code = code;
668
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
669
+ var prResolve,prReject;
670
+ var rtPromise = new Promise((resolve, reject) => { prResolve = resolve; prReject = reject; });
671
+ if (typeof code == "string") {
672
+ utils
673
+ .post(nextURL, jar, form, loginOptions)
674
+ .then(utils.saveCookies(jar))
675
+ .then(function(/** @type {{ body: string | Buffer; }} */res) {
676
+ var $ = cheerio.load(res.body);
677
+ var error = $("#approvals_code").parent().attr("data-xui-error");
678
+ if (error) {
679
+ throw {
680
+ error: 'login-approval',
681
+ errordesc: Language.InvaildTwoAuthCode,
682
+ lerror: error,
683
+ continue: submit2FA
684
+ };
685
+ }
686
+ })
687
+ .then(function() {
688
+ delete form.no_fido;delete form.approvals_code;
689
+ form.name_action_selected = 'dont_save'; //'save_device' || 'dont_save;
690
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
691
+ })
692
+ .then(function(res) {
693
+ var headers = res.headers;
694
+ if (!headers.location && res.headers['set-cookie'][0].includes('checkpoint')) throw { error: Language.ApprovalsErr };
695
+ var appState = utils.getAppState(jar,false);
696
+ if (callback === prCallback) {
697
+ callback = function(err, api) {
698
+ if (err) return prReject(err);
699
+ return prResolve(api);
700
+ };
701
+ }
702
+ return loginHelper(appState, email, password, loginOptions, callback);
703
+ })
704
+ .catch(function(err) {
705
+ if (callback === prCallback) prReject(err);
706
+ else callback(err);
707
+ });
708
+ } else {
709
+ utils
710
+ .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" })
711
+ .then(utils.saveCookies(jar))
712
+ .then((res) => {
713
+ try {
714
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
715
+ } catch (ex) {
716
+ clearInterval(checkVerified);
717
+ logger.Warning(Language.VerifiedCheck);
718
+ if (callback === prCallback) {
719
+ callback = function(err, api) {
720
+ if (err) return prReject(err);
721
+ return prResolve(api);
722
+ };
723
+ }
724
+ return loginHelper(utils.getAppState(jar,false), email, password, loginOptions, callback);
725
+ }
726
+ })
727
+ .catch((ex) => {
728
+ log.error("login", ex);
729
+ if (callback === prCallback) prReject(ex);
730
+ else callback(ex);
731
+ });
732
+ }
733
+ return rtPromise;
734
+ }
735
+ };
736
+ }
737
+ }
738
+ } else {
739
+ if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
740
+
741
+ if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
742
+ else form['submit[This Is Okay]'] = "This Is Okay";
743
+
744
+ return utils
745
+ .post(nextURL, jar, form, loginOptions)
746
+ .then(utils.saveCookies(jar))
747
+ .then(function() {
748
+ form.name_action_selected = 'dont_save';
749
+
750
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
751
+ })
752
+ .then(function(res) {
753
+ var headers = res.headers;
754
+
755
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
756
+
757
+ var appState = utils.getAppState(jar,false);
758
+
759
+ return loginHelper(appState, email, password, loginOptions, callback);
760
+ })
761
+ .catch((e) => callback(e));
762
+ }
763
+ });
764
+ }
765
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
766
+ });
767
+ };
768
+ }
769
+
770
+ /!-[ Function backup ]-!/
771
+
772
+ /**
773
+ * @param {string} data
774
+ * @param {any} globalOptions
775
+ * @param {any} callback
776
+ * @param {any} prCallback
777
+ */
778
+
779
+ function backup(data,globalOptions, callback, prCallback) {
780
+ try {
781
+ var appstate;
782
+ try {
783
+ appstate = JSON.parse(data)
784
+ }
785
+ catch(e) {
786
+ appstate = data;
787
+ }
788
+ logger.Warning(Language.BackupNoti);
789
+ try {
790
+ loginHelper(appstate,null,null,globalOptions, callback, prCallback)
791
+ }
792
+ catch (e) {
793
+ logger.Error(Language.ErrBackup);
794
+ process.exit(0);
795
+ }
796
+ }
797
+ catch (e) {
798
+ return logger.Error();
799
+ }
800
+ }
801
+
802
+ /!-[ function loginHelper ]-!/
803
+
804
+ /**
805
+ * @param {string | any[]} appState
806
+ * @param {any} email
807
+ * @param {any} password
808
+ * @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
809
+ * @param {(arg0: any, arg1: undefined) => void} callback
810
+ * @param {(error: any, api: any) => any} [prCallback]
811
+ */
812
+
813
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
814
+ var mainPromise = null;
815
+ var jar = utils.getJar();
816
+
817
+ try {
818
+ if (appState) {
819
+ logger.Normal(Language.OnProcess);
820
+ switch (Database().has("FBKEY")) {
821
+ case true: {
822
+ process.env.FBKEY = Database().get("FBKEY");
823
+ }
824
+ break;
825
+ case false: {
826
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
827
+ process.env['FBKEY'] = SecurityKey;
828
+ Database().set('FBKEY', SecurityKey);
829
+ }
830
+ break;
831
+ default: {
832
+ const SecurityKey = global.Fca.Require.Security.create().apiKey;
833
+ process.env['FBKEY'] = SecurityKey;
834
+ Database().set('FBKEY', SecurityKey);
835
+ }
836
+ }
837
+ try {
838
+ switch (global.Fca.Require.FastConfig.EncryptFeature) {
839
+ case true: {
840
+ appState = JSON.parse(JSON.stringify(appState, null, "\t"));
841
+ switch (utils.getType(appState)) {
842
+ case "Array": {
843
+ switch (utils.getType(appState[0])) {
844
+ case "Object": {
845
+ logger.Normal(Language.NotReadyToDecrypt);
846
+ }
847
+ break;
848
+ case "String": {
849
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
850
+ logger.Normal(Language.DecryptSuccess);
851
+ }
852
+ break;
853
+ default: {
854
+ logger.Warning(Language.InvaildAppState);
855
+ process.exit(0)
856
+ }
857
+ }
858
+ }
859
+ break;
860
+ default: {
861
+ logger.Warning(Language.InvaildAppState);
862
+ process.exit(0)
863
+ }
864
+ }
865
+ }
866
+ break;
867
+ case false: {
868
+ switch (utils.getType(appState)) {
869
+ case "Array": {
870
+ switch (utils.getType(appState[0])) {
871
+ case "Object": {
872
+ logger.Normal(Language.EncryptStateOff);
873
+ }
874
+ break;
875
+ case "String": {
876
+ appState = Security(appState,process.env['FBKEY'],'Decrypt');
877
+ logger.Normal(Language.EncryptStateOff);
878
+ logger.Normal(Language.DecryptSuccess);
879
+ }
880
+ break;
881
+ default: {
882
+ logger.Warning(Language.InvaildAppState);
883
+ process.exit(0)
884
+ }
885
+ }
886
+ }
887
+ break;
888
+ default: {
889
+ logger.Warning(Language.InvaildAppState);
890
+ process.exit(0)
891
+ }
892
+ }
893
+ }
894
+ break;
895
+ default: {
896
+ logger.Warning(getText(Language.IsNotABoolean,global.Fca.Require.FastConfig.EncryptFeature))
897
+ process.exit(0);
898
+ }
899
+ }
900
+ }
901
+ catch (e) {
902
+ console.log(e);
903
+ }
904
+
905
+ try {
906
+ appState = JSON.parse(appState);
907
+ }
908
+ catch (e) {
909
+ try {
910
+ appState = appState;
911
+ }
912
+ catch (e) {
913
+ return logger.Error();
914
+ }
915
+ }
916
+ try {
917
+ global.Fca.Data.AppState = appState;
918
+ appState.map(function(/** @type {{ key: string; value: string; expires: string; domain: string; path: string; }} */c) {
919
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
920
+ jar.setCookie(str, "http://" + c.domain);
921
+ });
922
+ Database().set('Backup', appState);
923
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
924
+ }
925
+ catch (e) {
926
+ try {
927
+ if (Database().has('Backup')) {
928
+ return backup(Database().get('Backup'),globalOptions, callback, prCallback);
929
+ }
930
+ else {
931
+ logger.Warning(Language.ErrBackup);
932
+ process.exit(0);
933
+ }
934
+ }
935
+ catch (e) {
936
+ logger.Warning(Language.ErrBackup);
937
+ process.exit(0);
938
+ }
939
+ }
940
+ }
941
+
942
+ else {
943
+ mainPromise = utils
944
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
945
+ .then(utils.saveCookies(jar))
946
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
947
+ .then(function() {
948
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
949
+ });
950
+ }
951
+ } catch (e) {
952
+ console.log(e);
953
+ }
954
+
955
+
956
+ var ctx,api;
957
+ mainPromise = mainPromise
958
+ .then(function(res) {
959
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/,redirect = reg.exec(res.body);
960
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
961
+ return res;
962
+ })
963
+ .then(function(res) {
964
+ var html = res.body,Obj = buildAPI(globalOptions, html, jar);
965
+ ctx = Obj.ctx;
966
+ api = Obj.api;
967
+ process.env.api = Obj.api;
968
+ return res;
969
+ });
970
+ if (globalOptions.pageID) {
971
+ mainPromise = mainPromise
972
+ .then(function() {
973
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
974
+ })
975
+ .then(function(resData) {
976
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
977
+ url = url.substring(0, url.length - 1);
978
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
979
+ });
980
+ }
981
+ mainPromise
982
+ .then(async() => {
983
+ logger.Normal(getText(Language.LocalVersion,global.Fca.Version));
984
+ logger.Normal(getText(Language.CountTime,global.Fca.Data.CountTime()))
985
+ logger.Normal(Language.WishMessage[Math.floor(Math.random()*Language.WishMessage.length)]);
986
+ require('./Extra/ExtraUptimeRobot')();
987
+ callback(null, api);
988
+ }).catch(function(/** @type {{ error: any; }} */e) {
989
+ log.error("login", e.error || e);
990
+ callback(e);
991
+ });
992
+ }
993
+
994
+ /**
995
+ * It asks the user for their account and password, and then saves it to the database.
996
+ */
997
+
998
+ function setUserNameAndPassWord() {
999
+ let rl = readline.createInterface({
1000
+ input: process.stdin,
1001
+ output: process.stdout
1002
+ });
1003
+
1004
+ console.clear();
1005
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1006
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1007
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1008
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(global.Fca.Version) + '\n');
1009
+ try {
1010
+ rl.question(Language.TypeAccount, (Account) => {
1011
+ if (!Account.includes("@") && global.Fca.Require.utils.getType(parseInt(Account)) != "Number") return logger.Normal(Language.TypeAccountError, function () { process.exit(1) }); //Very Human
1012
+ else rl.question(Language.TypePassword, function (Password) {
1013
+ rl.close();
1014
+ try {
1015
+ Database().set("Account", Account);
1016
+ Database().set("Password", Password);
1017
+ }
1018
+ catch (e) {
1019
+ logger.Warning(Language.ErrDataBase);
1020
+ logger.Error();
1021
+ process.exit(0);
1022
+ }
1023
+ if (global.Fca.Require.FastConfig.ResetDataLogin) {
1024
+ global.Fca.Require.FastConfig.ResetDataLogin = false;
1025
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/alice/database/alicization.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1026
+ }
1027
+ logger.Success(Language.SuccessSetData);
1028
+ process.exit(1);
1029
+ });
1030
+ })
1031
+ }
1032
+ catch (e) {
1033
+ logger.Error(e)
1034
+ }
1035
+ }
1036
+
1037
+ /**
1038
+ * @param {{ email: any; password: any; appState: any; }} loginData
1039
+ * @param {{}} options
1040
+ * @param {(error: any, api: any) => any} callback
1041
+ */
1042
+
1043
+ function login(loginData, options, callback) {
1044
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
1045
+ callback = options;
1046
+ options = {};
1047
+ }
1048
+
1049
+ var globalOptions = {
1050
+ selfListen: false,
1051
+ listenEvents: true,
1052
+ listenTyping: false,
1053
+ updatePresence: false,
1054
+ forceLogin: false,
1055
+ autoMarkDelivery: false,
1056
+ autoMarkRead: false,
1057
+ autoReconnect: true,
1058
+ logRecordSize: 100,
1059
+ online: false,
1060
+ emitReady: false,
1061
+ 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"
1062
+ };
1063
+
1064
+ var prCallback = null;
1065
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
1066
+ var rejectFunc = null;
1067
+ var resolveFunc = null;
1068
+ var returnPromise = new Promise(function(resolve, reject) {
1069
+ resolveFunc = resolve;
1070
+ rejectFunc = reject;
1071
+ });
1072
+ prCallback = function(error, api) {
1073
+ if (error) return rejectFunc(error);
1074
+ return resolveFunc(api);
1075
+ };
1076
+ callback = prCallback;
1077
+ }
1078
+
1079
+ if (loginData.email && loginData.password) {
1080
+ setOptions(globalOptions, {
1081
+ logLevel: "silent",
1082
+ forceLogin: true,
1083
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"
1084
+ });
1085
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1086
+ }
1087
+ else if (loginData.appState) {
1088
+ setOptions(globalOptions, options);
1089
+ let All = (getAll()).filter(i => i.data.messageCount !== undefined);
1090
+ if (All.length >= 1) {
1091
+ deleteAll(All.map(obj => obj.data.threadID));
1092
+ }
1093
+
1094
+ if (global.Fca.Require.FastConfig.Websocket_Extension.Status) {
1095
+ const UserName = Database().get('Ws_UserName');
1096
+ const PassWord = Database().get("Ws_PassWord");
1097
+ if (!UserName || !PassWord || global.Fca.Require.FastConfig.Websocket_Extension.ResetData) {
1098
+ const question = question => {
1099
+ const rl = readline.createInterface({
1100
+ input: process.stdin,
1101
+ output: process.stdout
1102
+ });
1103
+ var done,answ;
1104
+ rl.question(question, answer => {
1105
+ rl.close();
1106
+ answ = answer;
1107
+ done = true
1108
+ })
1109
+ deasync.loopWhile(function(){
1110
+ return !done;
1111
+ });
1112
+ return answ;
1113
+ };
1114
+ console.clear();
1115
+ console.log(figlet.textSync('Horizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }));
1116
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Operating System: " + chalk.bold.red(os.type()));
1117
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Machine Version: " + chalk.bold.red(os.version()));
1118
+ console.log(chalk.bold.hex('#9900FF')("[</>]") + chalk.bold.yellow(' => ') + "Fca Version: " + chalk.bold.red(global.Fca.Version) + '\n');
1119
+ const UserName = question(Language.Ws_TypeUserName);
1120
+ const PassWord = question(Language.Ws_TypePassWord);
1121
+ if (!UserName || !PassWord) {
1122
+ logger.Warning("Dangerous action detected! Proceeding to automatically disable websocket_extension.");
1123
+ global.Fca.Require.FastConfig.Websocket_Extension.Status = false;
1124
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
1125
+ }
1126
+ else {
1127
+ try {
1128
+ Database().set('Ws_UserName', UserName);
1129
+ Database().set('Ws_PassWord', PassWord);
1130
+ logger.Success(Language.Ws_Success, function() {
1131
+ const speakeasy = require('speakeasy');
1132
+ const secret = (speakeasy.generateSecret({ length: 20 }));
1133
+ logger.Warning(getText(Language.Ws_2Fa, secret.base32))
1134
+ Database().set('Ws_2Fa', secret.base32);
1135
+ if (global.Fca.Require.FastConfig.Websocket_Extension.ResetData) {
1136
+ global.Fca.Require.FastConfig.Websocket_Extension.ResetData = false;
1137
+ global.Fca.Require.fs.writeFileSync(process.cwd() + '/alice/database/alicization.json', JSON.stringify(global.Fca.Require.FastConfig, null, 4));
1138
+ }
1139
+ question("Enter To Continue!");
1140
+ const ask = function() {
1141
+ const TFa_Check = question(Language.Ws_2Fa_Check)
1142
+ if (TFa_Check != speakeasy.totp({
1143
+ secret: secret.base32,
1144
+ encoding: 'base32'
1145
+ })) {
1146
+ logger.Warning("Incorrect code, please enter again")
1147
+ ask();
1148
+ }
1149
+ else {
1150
+ logger.Success("Success!");
1151
+ process.exit(1);
1152
+ }
1153
+ }
1154
+ return ask();
1155
+ });
1156
+ }
1157
+ catch (e) {
1158
+ console.log(e)
1159
+ logger.Warning("Error, auto turn off Websocket_extension");
1160
+ global.Fca.Require.FastConfig.Websocket_Extension.Status = false;
1161
+ global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
1162
+ process.exit(1);
1163
+ }
1164
+ }
1165
+ }
1166
+ }
1167
+
1168
+ switch (global.Fca.Require.FastConfig.AutoLogin) {
1169
+ case true: {
1170
+ if (global.Fca.Require.FastConfig.ResetDataLogin) return setUserNameAndPassWord();
1171
+ else {
1172
+ try {
1173
+ const TempState = Database().get("TempState")
1174
+ if (TempState) {
1175
+ try {
1176
+ loginData.appState = JSON.parse(TempState);
1177
+ }
1178
+ catch (_) {
1179
+ loginData.appState = TempState;
1180
+ }
1181
+ Database().delete("TempState");
1182
+ }
1183
+ }
1184
+ catch (e) {
1185
+ console.log(e)
1186
+ Database().delete("TempState");
1187
+ logger.Warning(Language.ErrDataBase);
1188
+ logger.Error();
1189
+ process.exit(0);
1190
+ }
1191
+ try {
1192
+ if (Database().has('Account') && Database().has('Password')) return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1193
+ else return setUserNameAndPassWord();
1194
+ }
1195
+ catch (e) {
1196
+ console.log(e)
1197
+ logger.Warning(Language.ErrDataBase);
1198
+ logger.Error();
1199
+ process.exit(0);
1200
+ }
1201
+ }
1202
+ }
1203
+ case false: {
1204
+ return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
1205
+ }
1206
+ }
1207
+ }
1208
+ return returnPromise;
1209
+ }
1210
+
1211
+ module.exports = login;