alicezetion 1.5.3 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/index.js +576 -382
  4. package/leiamnash/addExternalModule.js +19 -16
  5. package/leiamnash/addUserToGroup.js +113 -79
  6. package/leiamnash/changeAdminStatus.js +79 -79
  7. package/leiamnash/changeArchivedStatus.js +55 -41
  8. package/leiamnash/changeBio.js +77 -65
  9. package/leiamnash/changeBlockedStatus.js +47 -36
  10. package/leiamnash/changeGroupImage.js +129 -106
  11. package/leiamnash/changeNickname.js +59 -45
  12. package/leiamnash/changeThreadColor.js +71 -62
  13. package/leiamnash/changeThreadEmoji.js +55 -42
  14. package/leiamnash/chat.js +459 -374
  15. package/leiamnash/createNewGroup.js +86 -70
  16. package/leiamnash/createPoll.js +71 -60
  17. package/leiamnash/deleteMessage.js +56 -45
  18. package/leiamnash/deleteThread.js +56 -43
  19. package/leiamnash/forwardAttachment.js +60 -48
  20. package/leiamnash/getCurrentUserID.js +7 -7
  21. package/leiamnash/getEmojiUrl.js +29 -27
  22. package/leiamnash/getFriendsList.js +84 -73
  23. package/leiamnash/getThreadHistory.js +645 -537
  24. package/leiamnash/getThreadHistoryDeprecated.js +93 -0
  25. package/leiamnash/getThreadInfo.js +206 -425
  26. package/leiamnash/getThreadInfoDeprecated.js +80 -0
  27. package/leiamnash/getThreadList.js +238 -213
  28. package/leiamnash/getThreadListDeprecated.js +75 -0
  29. package/leiamnash/getThreadPictures.js +79 -59
  30. package/leiamnash/getUserID.js +66 -62
  31. package/leiamnash/getUserInfo.js +72 -113
  32. package/leiamnash/handleFriendRequest.js +61 -46
  33. package/leiamnash/handleMessageRequest.js +65 -49
  34. package/leiamnash/httpGet.js +52 -49
  35. package/leiamnash/httpPost.js +52 -48
  36. package/leiamnash/listenMqtt.js +789 -787
  37. package/leiamnash/logout.js +75 -68
  38. package/leiamnash/markAsDelivered.js +58 -48
  39. package/leiamnash/markAsRead.js +80 -70
  40. package/leiamnash/markAsReadAll.js +49 -42
  41. package/leiamnash/markAsSeen.js +59 -51
  42. package/leiamnash/muteThread.js +52 -47
  43. package/leiamnash/removeUserFromGroup.js +79 -49
  44. package/leiamnash/resolvePhotoUrl.js +45 -37
  45. package/leiamnash/searchForThread.js +53 -43
  46. package/leiamnash/sendTypingIndicator.js +103 -80
  47. package/leiamnash/setMessageReaction.js +117 -109
  48. package/leiamnash/setPostReaction.js +76 -102
  49. package/leiamnash/setTitle.js +86 -74
  50. package/leiamnash/threadColors.js +57 -39
  51. package/leiamnash/unfriend.js +52 -43
  52. package/leiamnash/unsendMessage.js +49 -40
  53. package/package.json +72 -90
  54. package/utils.js +1356 -1684
  55. package/Extra/Database/index.js +0 -469
  56. package/Extra/ExtraAddons.js +0 -82
  57. package/Extra/ExtraFindUID.js +0 -62
  58. package/Extra/ExtraGetThread.js +0 -340
  59. package/Extra/ExtraScreenShot.js +0 -430
  60. package/Extra/ExtraUptimeRobot.js +0 -38
  61. package/Extra/Html/Classic/script.js +0 -119
  62. package/Extra/Html/Classic/style.css +0 -8
  63. package/Extra/Security/AES_256_GCM/index.js +0 -0
  64. package/Extra/Security/Base/Step_1.js +0 -6
  65. package/Extra/Security/Base/Step_2.js +0 -22
  66. package/Extra/Security/Base/Step_3.js +0 -22
  67. package/Extra/Security/Base/index.js +0 -174
  68. package/Extra/Security/Index.js +0 -5
  69. package/Extra/Security/Step_1.js +0 -6
  70. package/Extra/Security/Step_2.js +0 -22
  71. package/Extra/Security/Step_3.js +0 -22
  72. package/Extra/Src/Change_Environment.js +0 -24
  73. package/Extra/Src/Check_Update.js +0 -67
  74. package/Extra/Src/History.js +0 -115
  75. package/Extra/Src/Instant_Update.js +0 -65
  76. package/Extra/Src/Last-Run.js +0 -65
  77. package/Extra/Src/Premium.js +0 -81
  78. package/Extra/Src/Release_Memory.js +0 -41
  79. package/Extra/Src/Websocket.js +0 -213
  80. package/Extra/Src/image/checkmate.jpg +0 -0
  81. package/Extra/Src/uuid.js +0 -137
  82. package/Func/AcceptAgreement.js +0 -31
  83. package/Func/ClearCache.js +0 -64
  84. package/Func/ReportV1.js +0 -54
  85. package/Language/index.json +0 -217
  86. package/Main.js +0 -1270
  87. package/broadcast.js +0 -40
  88. package/leiamnash/Dev_Horizon_Data.js +0 -125
  89. package/leiamnash/Premium.js +0 -25
  90. package/leiamnash/Screenshot.js +0 -83
  91. package/leiamnash/changeAvt.js +0 -85
  92. package/leiamnash/getAccessToken.js +0 -28
  93. package/leiamnash/getMessage.js +0 -80
  94. package/leiamnash/getThreadMain.js +0 -220
  95. package/leiamnash/getUID.js +0 -59
  96. package/leiamnash/getUserInfoMain.js +0 -65
  97. package/leiamnash/getUserInfoV2.js +0 -32
  98. package/leiamnash/getUserInfoV3.js +0 -63
  99. package/leiamnash/getUserInfoV4.js +0 -55
  100. package/leiamnash/getUserInfoV5.js +0 -61
  101. package/leiamnash/httpPostFormData.js +0 -41
  102. package/leiamnash/sendMessage.js +0 -379
  103. package/logger.js +0 -66
package/index.js CHANGED
@@ -1,386 +1,580 @@
1
- 'use strict';
2
- /* eslint-disable linebreak-style */
3
- const utils = require('./utils');
4
- global.Fca = new Object({
5
- isThread: new Array(),
6
- isUser: new Array(),
7
- startTime: Date.now(),
8
- Setting: new Map(),
9
- Version: require('./package.json').version,
10
- Require: new Object({
11
- fs: require("fs"),
12
- Fetch: require('got'),
13
- log: require("npmlog"),
14
- utils: require("./utils.js"),
15
- logger: require('./logger.js'),
16
- languageFile: require('./Language/index.json'),
17
- Security: require('./Extra/Src/uuid.js')
18
- }),
19
- getText: function(/** @type {any[]} */...Data) {
20
- var Main = (Data.splice(0,1)).toString();
21
- for (let i = 0; i < Data.length; i++) Main = Main.replace(RegExp(`%${i + 1}`, 'g'), Data[i]);
22
- return Main;
23
- },
24
- Data: new Object({
25
- ObjFastConfig: {
26
- "Language": "vi",
27
- "PreKey": "",
28
- "AutoUpdate": true,
29
- "MainColor": "#9900FF",
30
- "MainName": "[ FCA-HZI ]",
31
- "Uptime": false,
32
- "Config": "default",
33
- "DevMode": false,
34
- "Login2Fa": false,
35
- "AutoLogin": false,
36
- "BroadCast": true,
37
- "AuthString": "SD4S XQ32 O2JA WXB3 FUX2 OPJ7 Q7JZ 4R6Z | https://i.imgur.com/RAg3rvw.png Please remove this !, Recommend If You Using getUserInfoV2",
38
- "EncryptFeature": true,
39
- "ResetDataLogin": false,
40
- "AutoInstallNode": false,
41
- "AntiSendAppState": true,
42
- "AutoRestartMinutes": 0,
43
- "RestartMQTT_Minutes": 0,
44
- "Websocket_Extension": {
45
- "Status": false,
46
- "ResetData": false,
47
- "AppState_Path": "appstate.json"
48
- },
49
- "HTML": {
50
- "HTML": true,
51
- "UserName": "Guest",
52
- "MusicLink": "https://drive.google.com/uc?id=1zlAALlxk1TnO7jXtEP_O6yvemtzA2ukA&export=download"
53
- },
54
- "AntiGetInfo": {
55
- "Database_Type": "default", //json or default
56
- "AntiGetThreadInfo": true,
57
- "AntiGetUserInfo": true
58
- },
59
- "Stable_Version": {
60
- "Accept": false,
61
- "Version": ""
62
- }
63
- },
64
- CountTime: function() {
65
- var fs = global.Fca.Require.fs;
66
- if (fs.existsSync(__dirname + '/CountTime.json')) {
67
- try {
68
- var data = Number(fs.readFileSync(__dirname + '/CountTime.json', 'utf8')),
69
- hours = Math.floor(data / (60 * 60));
70
- }
71
- catch (e) {
72
- fs.writeFileSync(__dirname + '/CountTime.json', 0);
73
- hours = 0;
74
- }
75
- }
76
- else {
77
- hours = 0;
78
- }
79
- return `${hours} Hours`;
80
- }
81
- }),
82
- Action: function(Type) {
83
- switch (Type) {
84
- case "AutoLogin": {
85
- var Database = require('./Extra/Database');
86
- var logger = global.Fca.Require.logger;
87
- var Email = (Database().get('Account')).replace(RegExp('"', 'g'), ''); //hmm IDK
88
- var PassWord = (Database().get('Password')).replace(RegExp('"', 'g'), '');
89
- require('./Main')({ email: Email, password: PassWord},async (error, api) => {
90
- if (error) {
91
- logger.Error(JSON.stringify(error,null,2), function() { logger.Error("AutoLogin Failed!", function() { process.exit(0); }) });
92
- }
93
- try {
94
- Database().set("TempState", Database().get('Through2Fa'));
95
- }
96
- catch(e) {
97
- logger.Warning(global.Fca.Require.Language.Index.ErrDatabase);
98
- logger.Error();
99
- process.exit(0);
100
- }
101
- process.exit(1);
102
- });
103
- }
104
- break;
105
- default: {
106
- require('npmlog').Error("Invalid Message!");
107
- };
108
- }
109
- }
110
- });
111
-
112
- try {
113
- let Boolean_Fca = ["AntiSendAppState","AutoUpdate","Uptime","BroadCast","EncryptFeature","AutoLogin","ResetDataLogin","Login2Fa", "DevMode","AutoInstallNode"];
114
- let String_Fca = ["MainName","PreKey","Language","AuthString","Config"]
115
- let Number_Fca = ["AutoRestartMinutes","RestartMQTT_Minutes"];
116
- let Object_Fca = ["HTML","Stable_Version","AntiGetInfo","Websocket_Extension"];
117
- let All_Variable = Boolean_Fca.concat(String_Fca,Number_Fca,Object_Fca);
118
-
119
-
120
- if (!global.Fca.Require.fs.existsSync(process.cwd() + '/alice/database/alicization.json')) {
121
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(global.Fca.Data.ObjFastConfig, null, "\t"));
122
- process.exit(1);
123
- }
124
-
125
- try {
126
- var Data_Setting = require(process.cwd() + "/alice/database/alicization.json");
127
- }
128
- catch (e) {
129
- global.Fca.Require.logger.Error('Detect Your alicization Settings Invalid!, Carry out default restoration');
130
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(global.Fca.Data.ObjFastConfig, null, "\t"));
131
- process.exit(1)
132
- }
133
- if (global.Fca.Require.fs.existsSync(process.cwd() + '/alice/database/alicization.json')) {
134
-
135
- for (let i of All_Variable) {
136
- if (Data_Setting[i] == undefined) {
137
- Data_Setting[i] = global.Fca.Data.ObjFastConfig[i];
138
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(Data_Setting, null, "\t"));
139
- }
140
- else continue;
141
- } //Check Variable
142
-
143
- for (let i in Data_Setting) {
144
- if (Boolean_Fca.includes(i)) {
145
- if (global.Fca.Require.utils.getType(Data_Setting[i]) != "Boolean") logger.Error(i + " Is Not A Boolean, Need To Be true Or false !", function() { process.exit(0) });
146
- else continue;
147
- }
148
- else if (String_Fca.includes(i)) {
149
- if (global.Fca.Require.utils.getType(Data_Setting[i]) != "String") logger.Error(i + " Is Not A String, Need To Be String!", function() { process.exit(0) });
150
- else continue;
151
- }
152
- else if (Number_Fca.includes(i)) {
153
- if (global.Fca.Require.utils.getType(Data_Setting[i]) != "Number") logger.Error(i + " Is Not A Number, Need To Be Number !", function() { process.exit(0) });
154
- else continue;
155
- }
156
- else if (Object_Fca.includes(i)) {
157
- if (global.Fca.Require.utils.getType(Data_Setting[i]) != "Object") {
158
- Data_Setting[i] = global.Fca.Data.ObjFastConfig[i];
159
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(Data_Setting, null, "\t"));
160
- }
161
- else continue;
162
- }
163
- }
1
+ "use strict";
2
+
3
+ var utils = require("./utils");
4
+ var cheerio = require("cheerio");
5
+ var log = require("npmlog");
6
+
7
+ var checkVerified = null;
8
+
9
+ var defaultLogRecordSize = 100;
10
+ log.maxRecordSize = defaultLogRecordSize;
11
+
12
+ function setOptions(globalOptions, options) {
13
+ Object.keys(options).map(function (key) {
14
+ switch (key) {
15
+ case 'online':
16
+ globalOptions.online = Boolean(options.online);
17
+ break;
18
+ case 'logLevel':
19
+ log.level = options.logLevel;
20
+ globalOptions.logLevel = options.logLevel;
21
+ break;
22
+ case 'logRecordSize':
23
+ log.maxRecordSize = options.logRecordSize;
24
+ globalOptions.logRecordSize = options.logRecordSize;
25
+ break;
26
+ case 'selfListen':
27
+ globalOptions.selfListen = Boolean(options.selfListen);
28
+ break;
29
+ case 'listenEvents':
30
+ globalOptions.listenEvents = Boolean(options.listenEvents);
31
+ break;
32
+ case 'pageID':
33
+ globalOptions.pageID = options.pageID.toString();
34
+ break;
35
+ case 'updatePresence':
36
+ globalOptions.updatePresence = Boolean(options.updatePresence);
37
+ break;
38
+ case 'forceLogin':
39
+ globalOptions.forceLogin = Boolean(options.forceLogin);
40
+ break;
41
+ case 'userAgent':
42
+ globalOptions.userAgent = options.userAgent;
43
+ break;
44
+ case 'autoMarkDelivery':
45
+ globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
46
+ break;
47
+ case 'autoMarkRead':
48
+ globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
49
+ break;
50
+ case 'listenTyping':
51
+ globalOptions.listenTyping = Boolean(options.listenTyping);
52
+ break;
53
+ case 'proxy':
54
+ if (typeof options.proxy != "string") {
55
+ delete globalOptions.proxy;
56
+ utils.setProxy();
57
+ } else {
58
+ globalOptions.proxy = options.proxy;
59
+ utils.setProxy(globalOptions.proxy);
60
+ }
61
+ break;
62
+ case 'autoReconnect':
63
+ globalOptions.autoReconnect = Boolean(options.autoReconnect);
64
+ break;
65
+ case 'emitReady':
66
+ globalOptions.emitReady = Boolean(options.emitReady);
67
+ break;
68
+ default:
69
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
70
+ break;
71
+ }
72
+ });
73
+ }
164
74
 
165
- for (let i of Object_Fca) {
166
- const All_Paths = utils.getPaths(global.Fca.Data.ObjFastConfig[i]);
167
- const Mission = { Main_Path: i, Data_Path: All_Paths }
168
- for (let i of Mission.Data_Path) {
169
- if (Data_Setting[Mission.Main_Path] == undefined) {
170
- Data_Setting[Mission.Main_Path] = global.Fca.Data.ObjFastConfig[Mission.Main_Path];
171
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(Data_Setting, null, "\t"));
172
- }
173
- const User_Data = (utils.getData_Path(Data_Setting[Mission.Main_Path], i, 0))
174
- const User_Data_Type = utils.getType(User_Data);
175
- if (User_Data_Type == "Number") {
176
- const Mission_Path = User_Data == 0 ? i : i.slice(0, User_Data);
177
- const Mission_Obj = utils.getData_Path(global.Fca.Data.ObjFastConfig[Mission.Main_Path], Mission_Path, 0);
178
- Data_Setting[Mission.Main_Path] = utils.setData_Path(Data_Setting[Mission.Main_Path], Mission_Path, Mission_Obj)
179
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(Data_Setting, null, "\t"));
180
- }
75
+ function buildAPI(globalOptions, html, jar) {
76
+ try {
77
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
78
+ return val.cookieString().split("=")[0] === "c_user";
79
+ });
80
+ if (maybeCookie.length === 0) throw { error: "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify." };
81
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
82
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
83
+ clearInterval(checkVerified);
84
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
85
+ let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
86
+ let mqttEndpoint = null;
87
+ let region = null;
88
+ let irisSeqID = null;
89
+ var noMqttData = null;
90
+ if (oldFBMQTTMatch) {
91
+ irisSeqID = oldFBMQTTMatch[1];
92
+ mqttEndpoint = oldFBMQTTMatch[2];
93
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
94
+ } else {
95
+ let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
96
+ if (newFBMQTTMatch) {
97
+ irisSeqID = newFBMQTTMatch[2];
98
+ mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
99
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
100
+ } else {
101
+ let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
102
+ if (legacyFBMQTTMatch) {
103
+ mqttEndpoint = legacyFBMQTTMatch[4];
104
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
105
+ } else {
106
+ noMqttData = html;
107
+ process.exit();
181
108
  }
182
109
  }
183
-
184
- if (!global.Fca.Require.languageFile.some((/** @type {{ Language: string; }} */i) => i.Language == Data_Setting.Language)) {
185
- global.Fca.Require.logger.Warning("Not Support Language: " + Data_Setting.Language + " Only 'en' and 'vi'");
186
- process.exit(0);
187
- }
188
- global.Fca.Require.Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == Data_Setting.Language).Folder;
189
- } else process.exit(1);
190
- global.Fca.Require.FastConfig = Data_Setting;
191
- }
192
- catch (e) {
193
- console.log(e);
194
- global.Fca.Require.logger.Error();
195
- }
196
-
197
- // if (global.Fca.Require.FastConfig.Websocket_Extension.Status) {
198
- // console.history = new Array();
199
- // var Convert = require('ansi-to-html');
200
- // var convert = new Convert();
201
- // console.__log = console.log;
202
- // console.log = function (data) {
203
- // const log = convert.toHtml(data)
204
- // console.history.push(log)
205
- // console.__log.apply(console,arguments)
206
- // if (console.history.length > 80) {
207
- // console.history.shift();
208
- // }
209
- // }
210
- // }
211
-
212
- module.exports = function(loginData, options, callback) {
213
- const Language = global.Fca.Require.languageFile.find((/** @type {{ Language: string; }} */i) => i.Language == global.Fca.Require.FastConfig.Language).Folder.Index;
214
- const login = require('./Main');
215
- const fs = require('fs');
216
- const got = require('got');
217
- const log = require('npmlog');
218
- const { execSync } = require('child_process');
219
- const Database = require('./Extra/Database');
220
-
221
- if (global.Fca.Require.FastConfig.DevMode) {
222
- require('./Extra/Src/Release_Memory');
223
110
  }
224
-
225
- return got.get('https://github.com/KanzuXHorizon/Global_Horizon/raw/main/InstantAction.json').then(async function(res) {
226
- if (global.Fca.Require.FastConfig.AutoInstallNode) {
227
- switch (fs.existsSync(process.cwd() + "/replit.nix") && process.env["REPL_ID"] != undefined) {
228
- case true: {
229
- await require('./Extra/Src/Change_Environment.js')();
230
- break;
231
- }
232
- case false: {
233
- const NodeVersion = execSync('node -v').toString().replace(/(\r\n|\n|\r)/gm, "");
234
- if (!NodeVersion.includes("v14") && !NodeVersion.includes("v16") && !Database(true).has('SkipReplitNix')) {
235
- log.warn("[ Alicization ] •",global.Fca.getText(Language.NodeVersionNotSupported, NodeVersion));
236
- await new Promise(resolve => setTimeout(resolve, 3000));
237
- try {
238
- switch (process.platform) {
239
- case "win32": {
240
- try {
241
- //check if user using nvm
242
- if (fs.existsSync(process.env.APPDATA + "/nvm/nvm.exe")) {
243
- log.warn("[ Alicization ] •", Language.UsingNVM);
244
- process.exit(0);
245
- }
246
- //download NodeJS v14 for Windows and slient install
247
- await got('https://nodejs.org/dist/v14.17.0/node-v14.17.0-x64.msi').pipe(fs.createWriteStream(process.cwd() + "/node-v14.17.0-x64.msi"));
248
- log.info("[ Alicization ] •", Language.DownloadingNode);
249
- await new Promise(resolve => setTimeout(resolve, 3000));
250
- execSync('msiexec /i node-v14.17.0-x64.msi /qn');
251
- log.info("[ Alicization ] •", Language.NodeDownloadingComplete);
252
- await new Promise(resolve => setTimeout(resolve, 3000));
253
- log.info("[ Alicization ] •", Language.RestartRequire);
254
- Database(true).set("NeedRebuild", true);
255
- process.exit(0);
256
- }
257
- catch (e) {
258
- log.error("[ Alicization ] •",Language.ErrNodeDownload);
259
- process.exit(0);
260
- }
261
- }
262
- case "linux": {
263
-
264
- try {
265
- if (process.env["REPL_ID"] != undefined) {
266
- log.warn("[ Alicization ] •", "Look like you are using Replit, and didn't have replit.nix file in your project, i don't know how to help you, hmm i will help you pass this step, but you need to install NodeJS v14 by yourself, and restart your repl");
267
- Database(true).set('SkipReplitNix', true);
268
- await new Promise(resolve => setTimeout(resolve, 3000));
269
- process.exit(1);
270
- }
271
- //check if user using nvm
272
- if (fs.existsSync(process.env.HOME + "/.nvm/nvm.sh")) {
273
- log.warn("[ Alicization ] •", Language.UsingNVM);
274
- process.exit(0);
275
- }
276
- //download NodeJS v14 for Linux and slient install
277
- await got('https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz').pipe(fs.createWriteStream(process.cwd() + "/node-v14.17.0-linux-x64.tar.xz"));
278
- log.info("[ Alicization ] •", Language.DownloadingNode);
279
- await new Promise(resolve => setTimeout(resolve, 3000));
280
- execSync('tar -xf node-v14.17.0-linux-x64.tar.xz');
281
- execSync('cd node-v14.17.0-linux-x64');
282
- execSync('sudo cp -R * /usr/local/');
283
- log.info("[ Alicization ] •", Language.NodeDownloadingComplete);
284
- await new Promise(resolve => setTimeout(resolve, 3000));
285
- log.info("[ Alicization ] •",Language.RestartingN);
286
- Database(true).set("NeedRebuild", true);
287
- process.exit(1);
288
- }
289
- catch (e) {
290
- log.error("[ Alicization ] •",Language.ErrNodeDownload);
291
- process.exit(0);
292
- }
293
- }
294
- case "darwin": {
295
- try {
296
- //check if user using nvm
297
- if (fs.existsSync(process.env.HOME + "/.nvm/nvm.sh")) {
298
- log.warn("[ Alicization ] •", Language.UsingNVM);
299
- process.exit(0);
300
- }
301
- //download NodeJS v14 for MacOS and slient install
302
- await got('https://nodejs.org/dist/v14.17.0/node-v14.17.0-darwin-x64.tar.gz').pipe(fs.createWriteStream(process.cwd() + "/node-v14.17.0-darwin-x64.tar.gz"));
303
- log.info("[ Alicization ] •", Language.DownloadingNode);
304
- await new Promise(resolve => setTimeout(resolve, 3000));
305
- execSync('tar -xf node-v14.17.0-darwin-x64.tar.gz');
306
- execSync('cd node-v14.17.0-darwin-x64');
307
- execSync('sudo cp -R * /usr/local/');
308
- log.info("[ Alicization ] •", Language.NodeDownloadingComplete);
309
- await new Promise(resolve => setTimeout(resolve, 3000));
310
- log.info("[ Alicization ] •",Language.RestartingN);
311
- Database(true).set("NeedRebuild", true);
312
- process.exit(1);
313
- }
314
- catch (e) {
315
- log.error("[ Alicization ] •",Language.ErrNodeDownload);
316
- process.exit(0);
317
- }
318
- }
319
- }
320
- }
321
- catch (e) {
322
- console.log(e);
323
- log.error("[ Alicization ] •","NodeJS v14 Installation Failed, Please Try Again and Contact fb.com/Lazic.Kanzu!");
324
- process.exit(0);
325
- }
326
- }
327
- }
328
- }
329
- }
330
- if ((Database(true).get("NeedRebuild")) == true) {
331
- Database(true).set("NeedRebuild", false);
332
- log.info("[ Alicization ] ",Language.Rebuilding);
333
- await new Promise(resolve => setTimeout(resolve, 3000));
334
- try {
335
- execSync('npm rebuild', {stdio: 'inherit'});
336
- }
337
- catch (e) {
338
- console.log(e);
339
- log.error("[ Alicization ] •",Language.ErrRebuilding);
340
- }
341
- log.info("[ Alicization ] •",Language.SuccessRebuilding);
342
- await new Promise(resolve => setTimeout(resolve, 3000));
343
- log.info("[ Alicization ] •",Language.RestartingN);
344
- process.exit(1);
345
- }
346
-
347
- let Data = JSON.parse(res.body);
348
- if (global.Fca.Require.FastConfig.Stable_Version.Accept == true) {
349
- if (Data.Stable_Version.Valid_Version.includes(global.Fca.Require.FastConfig.Stable_Version.Version)) {
350
- let TimeStamp = Database(true).get('Check_Update');
351
- if (TimeStamp == null || TimeStamp == undefined || Date.now() - TimeStamp > 300000) {
352
- var Check_Update = require('./Extra/Src/Check_Update.js');
353
- await Check_Update(global.Fca.Require.FastConfig.Stable_Version.Version);
354
- }
355
- }
356
- else {
357
- log.warn("[ Alicization ] •", "Error Stable Version, Please Check Your Stable Version in alicization.json, Automatically turn off Stable Version!");
358
- global.Fca.Require.FastConfig.Stable_Version.Accept = false;
359
- global.Fca.Require.fs.writeFileSync(process.cwd() + "/alice/database/alicization.json", JSON.stringify(global.Fca.Require.FastConfig, null, "\t"));
360
- process.exit(1);
361
- }
362
- }
363
- else {
364
- if (Data.HasProblem == true || Data.ForceUpdate == true) {
365
- let TimeStamp = Database(true).get('Instant_Update');
366
- if (TimeStamp == null || TimeStamp == undefined || Date.now() - TimeStamp > 500) {
367
- var Instant_Update = require('./Extra/Src/Instant_Update.js');
368
- await Instant_Update()
369
- }
370
- }
371
- else {
372
- let TimeStamp = Database(true).get('Check_Update');
373
- if (TimeStamp == null || TimeStamp == undefined || Date.now() - TimeStamp > 300000) {
374
- var Check_Update = require('./Extra/Src/Check_Update.js');
375
- await Check_Update()
376
- }
377
- }
378
- }
379
- return login(loginData, options, callback);
380
- }).catch(function(err) {
381
- console.log(err)
382
- log.error("[ Alicization ] •",Language.UnableToConnect);
383
- log.warn("[ Alicization ] •", "offline mode activated");
384
- return login(loginData, options, callback);
385
- });
386
- };
111
+ } catch (err) {}
112
+
113
+ var ctx = {
114
+ userID: userID,
115
+ jar: jar,
116
+ clientID: clientID,
117
+ globalOptions: globalOptions,
118
+ loggedIn: true,
119
+ access_token: 'NONE',
120
+ clientMutationId: 0,
121
+ mqttClient: undefined,
122
+ lastSeqId: irisSeqID,
123
+ syncToken: undefined,
124
+ mqttEndpoint,
125
+ region,
126
+ firstListen: true
127
+ };
128
+
129
+ var api = {
130
+ setOptions: setOptions.bind(null, globalOptions),
131
+ getAppState: function getAppState() {
132
+ return utils.getAppState(jar);
133
+ }
134
+ };
135
+
136
+ if (noMqttData) {
137
+ api["htmlData"] = noMqttData;
138
+ }
139
+
140
+ const apiFuncNames = [
141
+ 'addExternalModule',
142
+ 'addUserToGroup',
143
+ 'changeAdminStatus',
144
+ 'changeArchivedStatus',
145
+ 'changeBio',
146
+ 'changeBlockedStatus',
147
+ 'changeGroupImage',
148
+ 'changeNickname',
149
+ 'changeThreadColor',
150
+ 'changeThreadEmoji',
151
+ 'createNewGroup',
152
+ 'createPoll',
153
+ 'deleteMessage',
154
+ 'deleteThread',
155
+ 'forwardAttachment',
156
+ 'getCurrentUserID',
157
+ 'getEmojiUrl',
158
+ 'getFriendsList',
159
+ 'getThreadHistory',
160
+ 'getThreadInfo',
161
+ 'getThreadList',
162
+ 'getThreadPictures',
163
+ 'getUserID',
164
+ 'getUserInfo',
165
+ 'handleMessageRequest',
166
+ 'listenMqtt',
167
+ 'logout',
168
+ 'markAsDelivered',
169
+ 'markAsRead',
170
+ 'markAsReadAll',
171
+ 'markAsSeen',
172
+ 'muteThread',
173
+ 'removeUserFromGroup',
174
+ 'resolvePhotoUrl',
175
+ 'searchForThread',
176
+ 'chat',
177
+ 'sendTypingIndicator',
178
+ 'setMessageReaction',
179
+ 'setTitle',
180
+ 'threadColors',
181
+ 'unsendMessage',
182
+
183
+ // HTTP
184
+ 'httpGet',
185
+ 'httpPost',
186
+
187
+ // Deprecated features
188
+ "getThreadListDeprecated",
189
+ 'getThreadHistoryDeprecated',
190
+ 'getThreadInfoDeprecated',
191
+ ];
192
+
193
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
194
+
195
+ // Load all api functions in a loop
196
+ apiFuncNames.map(function (v) {
197
+ api[v] = require('./leiamnash/' + v)(defaultFuncs, api, ctx);
198
+ });
199
+
200
+ return [ctx, defaultFuncs, api];
201
+ }
202
+
203
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
204
+ return function (res) {
205
+ var html = res.body;
206
+ var $ = cheerio.load(html);
207
+ var arr = [];
208
+
209
+ // This will be empty, but just to be sure we leave it
210
+ $("#login_form input").map(function (i, v) {
211
+ arr.push({ val: $(v).val(), name: $(v).attr("name") });
212
+ });
213
+
214
+ arr = arr.filter(function (v) {
215
+ return v.val && v.val.length;
216
+ });
217
+
218
+ var form = utils.arrToForm(arr);
219
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
220
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
221
+ form.email = email;
222
+ form.pass = password;
223
+ form.default_persistent = '0';
224
+ form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
225
+ form.locale = 'en_US';
226
+ form.timezone = '240';
227
+ form.lgnjs = ~~(Date.now() / 1000);
228
+
229
+
230
+ // Getting cookies from the HTML page... (kill me now plz)
231
+ // we used to get a bunch of cookies in the headers of the response of the
232
+ // request, but FB changed and they now send those cookies inside the JS.
233
+ // They run the JS which then injects the cookies in the page.
234
+ // The "solution" is to parse through the html and find those cookies
235
+ // which happen to be conveniently indicated with a _js_ in front of their
236
+ // variable name.
237
+ //
238
+ // ---------- Very Hacky Part Starts -----------------
239
+ var willBeCookies = html.split("\"_js_");
240
+ willBeCookies.slice(1).map(function (val) {
241
+ var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
242
+ jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
243
+ });
244
+ // ---------- Very Hacky Part Ends -----------------
245
+
246
+ // log.info("login", "Logging in...");
247
+ return utils
248
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
249
+ .then(utils.saveCookies(jar))
250
+ .then(function (res) {
251
+ var headers = res.headers;
252
+ if (!headers.location) {
253
+ throw { error: "Wrong username/password." };
254
+ }
255
+
256
+ // This means the account has login approvals turned on.
257
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
258
+ log.info("login", "You have login approvals turned on.");
259
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
260
+
261
+ return utils
262
+ .get(headers.location, jar, null, loginOptions)
263
+ .then(utils.saveCookies(jar))
264
+ .then(function (res) {
265
+ var html = res.body;
266
+ // Make the form in advance which will contain the fb_dtsg and nh
267
+ var $ = cheerio.load(html);
268
+ var arr = [];
269
+ $("form input").map(function (i, v) {
270
+ arr.push({ val: $(v).val(), name: $(v).attr("name") });
271
+ });
272
+
273
+ arr = arr.filter(function (v) {
274
+ return v.val && v.val.length;
275
+ });
276
+
277
+ var form = utils.arrToForm(arr);
278
+ if (html.indexOf("checkpoint/?next") > -1) {
279
+ setTimeout(() => {
280
+ checkVerified = setInterval((_form) => {
281
+ /* utils
282
+ .post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
283
+ "Referer": "https://www.facebook.com/checkpoint/?next"
284
+ })
285
+ .then(utils.saveCookies(jar))
286
+ .then(res => {
287
+ try {
288
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
289
+ } catch (ex) {
290
+ clearInterval(checkVerified);
291
+ log.info("login", "Verified from browser. Logging in...");
292
+ return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
293
+ }
294
+ })
295
+ .catch(ex => {
296
+ log.error("login", ex);
297
+ }); */
298
+ }, 5000, {
299
+ fb_dtsg: form.fb_dtsg,
300
+ jazoest: form.jazoest,
301
+ dpr: 1
302
+ });
303
+ }, 2500);
304
+ throw {
305
+ error: 'login-approval',
306
+ continue: function submit2FA(code) {
307
+ form.approvals_code = code;
308
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
309
+ var prResolve = null;
310
+ var prReject = null;
311
+ var rtPromise = new Promise(function (resolve, reject) {
312
+ prResolve = resolve;
313
+ prReject = reject;
314
+ });
315
+ if (typeof code == "string") {
316
+ utils
317
+ .post(nextURL, jar, form, loginOptions)
318
+ .then(utils.saveCookies(jar))
319
+ .then(function (res) {
320
+ var $ = cheerio.load(res.body);
321
+ var error = $("#approvals_code").parent().attr("data-xui-error");
322
+ if (error) {
323
+ throw {
324
+ error: 'login-approval',
325
+ errordesc: "Invalid 2FA code.",
326
+ lerror: error,
327
+ continue: submit2FA
328
+ };
329
+ }
330
+ })
331
+ .then(function () {
332
+ // Use the same form (safe I hope)
333
+ delete form.no_fido;
334
+ delete form.approvals_code;
335
+ form.name_action_selected = 'dont_save'; //'save_device';
336
+
337
+ return utils
338
+ .post(nextURL, jar, form, loginOptions)
339
+ .then(utils.saveCookies(jar));
340
+ })
341
+ .then(function (res) {
342
+ var headers = res.headers;
343
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
344
+ throw { error: "Something went wrong with login approvals." };
345
+ }
346
+
347
+ var appState = utils.getAppState(jar);
348
+
349
+ if (callback === prCallback) {
350
+ callback = function (err, api) {
351
+ if (err) {
352
+ return prReject(err);
353
+ }
354
+ return prResolve(api);
355
+ };
356
+ }
357
+
358
+ // Simply call loginHelper because all it needs is the jar
359
+ // and will then complete the login process
360
+ return loginHelper(appState, email, password, loginOptions, callback);
361
+ })
362
+ .catch(function (err) {
363
+ // Check if using Promise instead of callback
364
+ if (callback === prCallback) {
365
+ prReject(err);
366
+ } else {
367
+ callback(err);
368
+ }
369
+ });
370
+ } else {
371
+ utils
372
+ .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, {
373
+ "Referer": "https://www.facebook.com/checkpoint/?next"
374
+ })
375
+ .then(utils.saveCookies(jar))
376
+ .then(res => {
377
+ try {
378
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
379
+ } catch (ex) {
380
+ clearInterval(checkVerified);
381
+ //log.info("login", "Verified from browser. Logging in...");
382
+ if (callback === prCallback) {
383
+ callback = function (err, api) {
384
+ if (err) {
385
+ return prReject(err);
386
+ }
387
+ return prResolve(api);
388
+ };
389
+ }
390
+ return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
391
+ }
392
+ })
393
+ .catch(ex => {
394
+ log.error("login", ex);
395
+ if (callback === prCallback) {
396
+ prReject(ex);
397
+ } else {
398
+ callback(ex);
399
+ }
400
+ });
401
+ }
402
+ return rtPromise;
403
+ }
404
+ };
405
+ } else {
406
+ if (!loginOptions.forceLogin) {
407
+ throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
408
+ }
409
+ if (html.indexOf("Suspicious Login Attempt") > -1) {
410
+ form['submit[This was me]'] = "This was me";
411
+ } else {
412
+ form['submit[This Is Okay]'] = "This Is Okay";
413
+ }
414
+
415
+ return utils
416
+ .post(nextURL, jar, form, loginOptions)
417
+ .then(utils.saveCookies(jar))
418
+ .then(function () {
419
+ // Use the same form (safe I hope)
420
+ form.name_action_selected = 'save_device';
421
+
422
+ return utils
423
+ .post(nextURL, jar, form, loginOptions)
424
+ .then(utils.saveCookies(jar));
425
+ })
426
+ .then(function (res) {
427
+ var headers = res.headers;
428
+
429
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
430
+ throw { error: "Something went wrong with review recent login." };
431
+ }
432
+
433
+ var appState = utils.getAppState(jar);
434
+
435
+ // Simply call loginHelper because all it needs is the jar
436
+ // and will then complete the login process
437
+ return loginHelper(appState, email, password, loginOptions, callback);
438
+ })
439
+ .catch(function (e) {
440
+ callback(e);
441
+ });
442
+ }
443
+ });
444
+ }
445
+
446
+ return utils
447
+ .get('https://www.facebook.com/', jar, null, loginOptions)
448
+ .then(utils.saveCookies(jar));
449
+ });
450
+ };
451
+ }
452
+
453
+ // Helps the login
454
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
455
+ var mainPromise = null;
456
+ var jar = utils.getJar();
457
+
458
+ // If we're given an appState we loop through it and save each cookie
459
+ // back into the jar.
460
+ if (appState) {
461
+ appState.map(function (c) {
462
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
463
+ jar.setCookie(str, "http://" + c.domain);
464
+ });
465
+
466
+ // Load the main page.
467
+ mainPromise = utils
468
+ .get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
469
+ .then(utils.saveCookies(jar));
470
+ } else {
471
+ // Open the main page, then we login with the given credentials and finally
472
+ // load the main page again (it'll give us some IDs that we need)
473
+ mainPromise = utils
474
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
475
+ .then(utils.saveCookies(jar))
476
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
477
+ .then(function () {
478
+ return utils
479
+ .get('https://www.facebook.com/', jar, null, globalOptions)
480
+ .then(utils.saveCookies(jar));
481
+ });
482
+ }
483
+
484
+ var ctx = null;
485
+ var _defaultFuncs = null;
486
+ var api = null;
487
+
488
+ mainPromise = mainPromise
489
+ .then(function (res) {
490
+ // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
491
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
492
+ var redirect = reg.exec(res.body);
493
+ if (redirect && redirect[1]) {
494
+ return utils
495
+ .get(redirect[1], jar, null, globalOptions)
496
+ .then(utils.saveCookies(jar));
497
+ }
498
+ return res;
499
+ })
500
+ .then(function (res) {
501
+ var html = res.body;
502
+ var stuff = buildAPI(globalOptions, html, jar);
503
+ ctx = stuff[0];
504
+ _defaultFuncs = stuff[1];
505
+ api = stuff[2];
506
+ return res;
507
+ });
508
+
509
+ // given a pageID we log in as a page
510
+ if (globalOptions.pageID) {
511
+ mainPromise = mainPromise
512
+ .then(function () {
513
+ return utils
514
+ .get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
515
+ })
516
+ .then(function (resData) {
517
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
518
+ url = url.substring(0, url.length - 1);
519
+
520
+ return utils
521
+ .get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
522
+ });
523
+ }
524
+
525
+ // At the end we call the callback or catch an exception
526
+ mainPromise
527
+ .then(function () {
528
+ // log.info("login", 'Done logging in.');
529
+ return callback(null, api);
530
+ })
531
+ .catch(function (e) {
532
+ log.error("login", e.error || e);
533
+ callback(e);
534
+ });
535
+ }
536
+
537
+ function login(loginData, options, callback) {
538
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
539
+ callback = options;
540
+ options = {};
541
+ }
542
+
543
+ var globalOptions = {
544
+ selfListen: false,
545
+ listenEvents: false,
546
+ listenTyping: false,
547
+ updatePresence: false,
548
+ forceLogin: false,
549
+ autoMarkDelivery: true,
550
+ autoMarkRead: false,
551
+ autoReconnect: true,
552
+ logRecordSize: defaultLogRecordSize,
553
+ online: true,
554
+ emitReady: false,
555
+ 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]"
556
+ };
557
+
558
+ setOptions(globalOptions, options);
559
+
560
+ var prCallback = null;
561
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
562
+ var rejectFunc = null;
563
+ var resolveFunc = null;
564
+ var returnPromise = new Promise(function (resolve, reject) {
565
+ resolveFunc = resolve;
566
+ rejectFunc = reject;
567
+ });
568
+ prCallback = function (error, api) {
569
+ if (error) {
570
+ return rejectFunc(error);
571
+ }
572
+ return resolveFunc(api);
573
+ };
574
+ callback = prCallback;
575
+ }
576
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
577
+ return returnPromise;
578
+ }
579
+
580
+ module.exports = login;