alicezetion 1.5.3 → 1.5.4

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 +601 -386
  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,601 @@
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
- }
164
-
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
- }
181
- }
182
- }
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
- }
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
- };
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
+ }
74
+
75
+ function buildAPI(globalOptions, html, jar) {
76
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) {
77
+ return val.cookieString().split("=")[0] === "c_user";
78
+ });
79
+
80
+ if (maybeCookie.length === 0) {
81
+ 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." };
82
+ }
83
+
84
+ if (html.indexOf("/checkpoint/block/?next") > -1) {
85
+ log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
86
+ }
87
+
88
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
89
+ try {
90
+ clearInterval(checkVerified);
91
+ } catch (_) { }
92
+
93
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
94
+
95
+
96
+ let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
97
+ let mqttEndpoint = null;
98
+ let region = null;
99
+ let irisSeqID = null;
100
+ var noMqttData = null;
101
+
102
+ if (oldFBMQTTMatch) {
103
+ irisSeqID = oldFBMQTTMatch[1];
104
+ mqttEndpoint = oldFBMQTTMatch[2];
105
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
106
+ //log.info("login", `Got this account's message region: ${region}`);
107
+ } else {
108
+ let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
109
+ if (newFBMQTTMatch) {
110
+ irisSeqID = newFBMQTTMatch[2];
111
+ mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
112
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
113
+ // log.info("login", `Got this account's message region: ${region}`);
114
+ } else {
115
+ let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
116
+ if (legacyFBMQTTMatch) {
117
+ mqttEndpoint = legacyFBMQTTMatch[4];
118
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
119
+ /* log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
120
+ log.info("login", `Got this account's message region: ${region}`);
121
+ log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);*/
122
+ } else {
123
+ log.warn("login", "Cannot get MQTT region & sequence ID.");
124
+ noMqttData = html;
125
+ }
126
+ }
127
+ }
128
+
129
+ // All data available to api functions
130
+ var ctx = {
131
+ userID: userID,
132
+ jar: jar,
133
+ clientID: clientID,
134
+ globalOptions: globalOptions,
135
+ loggedIn: true,
136
+ access_token: 'NONE',
137
+ clientMutationId: 0,
138
+ mqttClient: undefined,
139
+ lastSeqId: irisSeqID,
140
+ syncToken: undefined,
141
+ mqttEndpoint,
142
+ region,
143
+ firstListen: true
144
+ };
145
+
146
+ var api = {
147
+ setOptions: setOptions.bind(null, globalOptions),
148
+ getAppState: function getAppState() {
149
+ return utils.getAppState(jar);
150
+ }
151
+ };
152
+
153
+ if (noMqttData) {
154
+ api["htmlData"] = noMqttData;
155
+ }
156
+
157
+ const apiFuncNames = [
158
+ 'addExternalModule',
159
+ 'addUserToGroup',
160
+ 'changeAdminStatus',
161
+ 'changeArchivedStatus',
162
+ 'changeBio',
163
+ 'changeBlockedStatus',
164
+ 'changeGroupImage',
165
+ 'changeNickname',
166
+ 'changeThreadColor',
167
+ 'changeThreadEmoji',
168
+ 'createNewGroup',
169
+ 'createPoll',
170
+ 'deleteMessage',
171
+ 'deleteThread',
172
+ 'forwardAttachment',
173
+ 'getCurrentUserID',
174
+ 'getEmojiUrl',
175
+ 'getFriendsList',
176
+ 'getThreadHistory',
177
+ 'getThreadInfo',
178
+ 'getThreadList',
179
+ 'getThreadPictures',
180
+ 'getUserID',
181
+ 'getUserInfo',
182
+ 'handleMessageRequest',
183
+ 'listenMqtt',
184
+ 'logout',
185
+ 'markAsDelivered',
186
+ 'markAsRead',
187
+ 'markAsReadAll',
188
+ 'markAsSeen',
189
+ 'muteThread',
190
+ 'removeUserFromGroup',
191
+ 'resolvePhotoUrl',
192
+ 'searchForThread',
193
+ 'chat',
194
+ 'sendTypingIndicator',
195
+ 'setMessageReaction',
196
+ 'setTitle',
197
+ 'threadColors',
198
+ 'unsendMessage',
199
+
200
+ // HTTP
201
+ 'httpGet',
202
+ 'httpPost',
203
+
204
+ // Deprecated features
205
+ "getThreadListDeprecated",
206
+ 'getThreadHistoryDeprecated',
207
+ 'getThreadInfoDeprecated',
208
+ ];
209
+
210
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
211
+
212
+ // Load all api functions in a loop
213
+ apiFuncNames.map(function (v) {
214
+ api[v] = require('./leiamnash/' + v)(defaultFuncs, api, ctx);
215
+ });
216
+
217
+ //Removing original `listen` that uses pull.
218
+ //Map it to listenMqtt instead for backward compatibly.
219
+ api.listen = api.listenMqtt;
220
+
221
+ return [ctx, defaultFuncs, api];
222
+ }
223
+
224
+ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
225
+ return function (res) {
226
+ var html = res.body;
227
+ var $ = cheerio.load(html);
228
+ var arr = [];
229
+
230
+ // This will be empty, but just to be sure we leave it
231
+ $("#login_form input").map(function (i, v) {
232
+ arr.push({ val: $(v).val(), name: $(v).attr("name") });
233
+ });
234
+
235
+ arr = arr.filter(function (v) {
236
+ return v.val && v.val.length;
237
+ });
238
+
239
+ var form = utils.arrToForm(arr);
240
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
241
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
242
+ form.email = email;
243
+ form.pass = password;
244
+ form.default_persistent = '0';
245
+ form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
246
+ form.locale = 'en_US';
247
+ form.timezone = '240';
248
+ form.lgnjs = ~~(Date.now() / 1000);
249
+
250
+
251
+ // Getting cookies from the HTML page... (kill me now plz)
252
+ // we used to get a bunch of cookies in the headers of the response of the
253
+ // request, but FB changed and they now send those cookies inside the JS.
254
+ // They run the JS which then injects the cookies in the page.
255
+ // The "solution" is to parse through the html and find those cookies
256
+ // which happen to be conveniently indicated with a _js_ in front of their
257
+ // variable name.
258
+ //
259
+ // ---------- Very Hacky Part Starts -----------------
260
+ var willBeCookies = html.split("\"_js_");
261
+ willBeCookies.slice(1).map(function (val) {
262
+ var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
263
+ jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
264
+ });
265
+ // ---------- Very Hacky Part Ends -----------------
266
+
267
+ // log.info("login", "Logging in...");
268
+ return utils
269
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
270
+ .then(utils.saveCookies(jar))
271
+ .then(function (res) {
272
+ var headers = res.headers;
273
+ if (!headers.location) {
274
+ throw { error: "Wrong username/password." };
275
+ }
276
+
277
+ // This means the account has login approvals turned on.
278
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
279
+ log.info("login", "You have login approvals turned on.");
280
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
281
+
282
+ return utils
283
+ .get(headers.location, jar, null, loginOptions)
284
+ .then(utils.saveCookies(jar))
285
+ .then(function (res) {
286
+ var html = res.body;
287
+ // Make the form in advance which will contain the fb_dtsg and nh
288
+ var $ = cheerio.load(html);
289
+ var arr = [];
290
+ $("form input").map(function (i, v) {
291
+ arr.push({ val: $(v).val(), name: $(v).attr("name") });
292
+ });
293
+
294
+ arr = arr.filter(function (v) {
295
+ return v.val && v.val.length;
296
+ });
297
+
298
+ var form = utils.arrToForm(arr);
299
+ if (html.indexOf("checkpoint/?next") > -1) {
300
+ setTimeout(() => {
301
+ checkVerified = setInterval((_form) => {
302
+ /* utils
303
+ .post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
304
+ "Referer": "https://www.facebook.com/checkpoint/?next"
305
+ })
306
+ .then(utils.saveCookies(jar))
307
+ .then(res => {
308
+ try {
309
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
310
+ } catch (ex) {
311
+ clearInterval(checkVerified);
312
+ log.info("login", "Verified from browser. Logging in...");
313
+ return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
314
+ }
315
+ })
316
+ .catch(ex => {
317
+ log.error("login", ex);
318
+ }); */
319
+ }, 5000, {
320
+ fb_dtsg: form.fb_dtsg,
321
+ jazoest: form.jazoest,
322
+ dpr: 1
323
+ });
324
+ }, 2500);
325
+ throw {
326
+ error: 'login-approval',
327
+ continue: function submit2FA(code) {
328
+ form.approvals_code = code;
329
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
330
+ var prResolve = null;
331
+ var prReject = null;
332
+ var rtPromise = new Promise(function (resolve, reject) {
333
+ prResolve = resolve;
334
+ prReject = reject;
335
+ });
336
+ if (typeof code == "string") {
337
+ utils
338
+ .post(nextURL, jar, form, loginOptions)
339
+ .then(utils.saveCookies(jar))
340
+ .then(function (res) {
341
+ var $ = cheerio.load(res.body);
342
+ var error = $("#approvals_code").parent().attr("data-xui-error");
343
+ if (error) {
344
+ throw {
345
+ error: 'login-approval',
346
+ errordesc: "Invalid 2FA code.",
347
+ lerror: error,
348
+ continue: submit2FA
349
+ };
350
+ }
351
+ })
352
+ .then(function () {
353
+ // Use the same form (safe I hope)
354
+ delete form.no_fido;
355
+ delete form.approvals_code;
356
+ form.name_action_selected = 'dont_save'; //'save_device';
357
+
358
+ return utils
359
+ .post(nextURL, jar, form, loginOptions)
360
+ .then(utils.saveCookies(jar));
361
+ })
362
+ .then(function (res) {
363
+ var headers = res.headers;
364
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
365
+ throw { error: "Something went wrong with login approvals." };
366
+ }
367
+
368
+ var appState = utils.getAppState(jar);
369
+
370
+ if (callback === prCallback) {
371
+ callback = function (err, api) {
372
+ if (err) {
373
+ return prReject(err);
374
+ }
375
+ return prResolve(api);
376
+ };
377
+ }
378
+
379
+ // Simply call loginHelper because all it needs is the jar
380
+ // and will then complete the login process
381
+ return loginHelper(appState, email, password, loginOptions, callback);
382
+ })
383
+ .catch(function (err) {
384
+ // Check if using Promise instead of callback
385
+ if (callback === prCallback) {
386
+ prReject(err);
387
+ } else {
388
+ callback(err);
389
+ }
390
+ });
391
+ } else {
392
+ utils
393
+ .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, {
394
+ "Referer": "https://www.facebook.com/checkpoint/?next"
395
+ })
396
+ .then(utils.saveCookies(jar))
397
+ .then(res => {
398
+ try {
399
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
400
+ } catch (ex) {
401
+ clearInterval(checkVerified);
402
+ //log.info("login", "Verified from browser. Logging in...");
403
+ if (callback === prCallback) {
404
+ callback = function (err, api) {
405
+ if (err) {
406
+ return prReject(err);
407
+ }
408
+ return prResolve(api);
409
+ };
410
+ }
411
+ return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
412
+ }
413
+ })
414
+ .catch(ex => {
415
+ log.error("login", ex);
416
+ if (callback === prCallback) {
417
+ prReject(ex);
418
+ } else {
419
+ callback(ex);
420
+ }
421
+ });
422
+ }
423
+ return rtPromise;
424
+ }
425
+ };
426
+ } else {
427
+ if (!loginOptions.forceLogin) {
428
+ throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
429
+ }
430
+ if (html.indexOf("Suspicious Login Attempt") > -1) {
431
+ form['submit[This was me]'] = "This was me";
432
+ } else {
433
+ form['submit[This Is Okay]'] = "This Is Okay";
434
+ }
435
+
436
+ return utils
437
+ .post(nextURL, jar, form, loginOptions)
438
+ .then(utils.saveCookies(jar))
439
+ .then(function () {
440
+ // Use the same form (safe I hope)
441
+ form.name_action_selected = 'save_device';
442
+
443
+ return utils
444
+ .post(nextURL, jar, form, loginOptions)
445
+ .then(utils.saveCookies(jar));
446
+ })
447
+ .then(function (res) {
448
+ var headers = res.headers;
449
+
450
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
451
+ throw { error: "Something went wrong with review recent login." };
452
+ }
453
+
454
+ var appState = utils.getAppState(jar);
455
+
456
+ // Simply call loginHelper because all it needs is the jar
457
+ // and will then complete the login process
458
+ return loginHelper(appState, email, password, loginOptions, callback);
459
+ })
460
+ .catch(function (e) {
461
+ callback(e);
462
+ });
463
+ }
464
+ });
465
+ }
466
+
467
+ return utils
468
+ .get('https://www.facebook.com/', jar, null, loginOptions)
469
+ .then(utils.saveCookies(jar));
470
+ });
471
+ };
472
+ }
473
+
474
+ // Helps the login
475
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
476
+ var mainPromise = null;
477
+ var jar = utils.getJar();
478
+
479
+ // If we're given an appState we loop through it and save each cookie
480
+ // back into the jar.
481
+ if (appState) {
482
+ appState.map(function (c) {
483
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
484
+ jar.setCookie(str, "http://" + c.domain);
485
+ });
486
+
487
+ // Load the main page.
488
+ mainPromise = utils
489
+ .get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
490
+ .then(utils.saveCookies(jar));
491
+ } else {
492
+ // Open the main page, then we login with the given credentials and finally
493
+ // load the main page again (it'll give us some IDs that we need)
494
+ mainPromise = utils
495
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
496
+ .then(utils.saveCookies(jar))
497
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
498
+ .then(function () {
499
+ return utils
500
+ .get('https://www.facebook.com/', jar, null, globalOptions)
501
+ .then(utils.saveCookies(jar));
502
+ });
503
+ }
504
+
505
+ var ctx = null;
506
+ var _defaultFuncs = null;
507
+ var api = null;
508
+
509
+ mainPromise = mainPromise
510
+ .then(function (res) {
511
+ // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
512
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
513
+ var redirect = reg.exec(res.body);
514
+ if (redirect && redirect[1]) {
515
+ return utils
516
+ .get(redirect[1], jar, null, globalOptions)
517
+ .then(utils.saveCookies(jar));
518
+ }
519
+ return res;
520
+ })
521
+ .then(function (res) {
522
+ var html = res.body;
523
+ var stuff = buildAPI(globalOptions, html, jar);
524
+ ctx = stuff[0];
525
+ _defaultFuncs = stuff[1];
526
+ api = stuff[2];
527
+ return res;
528
+ });
529
+
530
+ // given a pageID we log in as a page
531
+ if (globalOptions.pageID) {
532
+ mainPromise = mainPromise
533
+ .then(function () {
534
+ return utils
535
+ .get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
536
+ })
537
+ .then(function (resData) {
538
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
539
+ url = url.substring(0, url.length - 1);
540
+
541
+ return utils
542
+ .get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
543
+ });
544
+ }
545
+
546
+ // At the end we call the callback or catch an exception
547
+ mainPromise
548
+ .then(function () {
549
+ // log.info("login", 'Done logging in.');
550
+ return callback(null, api);
551
+ })
552
+ .catch(function (e) {
553
+ log.error("login", e.error || e);
554
+ callback(e);
555
+ });
556
+ }
557
+
558
+ function login(loginData, options, callback) {
559
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
560
+ callback = options;
561
+ options = {};
562
+ }
563
+
564
+ var globalOptions = {
565
+ selfListen: false,
566
+ listenEvents: false,
567
+ listenTyping: false,
568
+ updatePresence: false,
569
+ forceLogin: false,
570
+ autoMarkDelivery: true,
571
+ autoMarkRead: false,
572
+ autoReconnect: true,
573
+ logRecordSize: defaultLogRecordSize,
574
+ online: true,
575
+ emitReady: false,
576
+ 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]"
577
+ };
578
+
579
+ setOptions(globalOptions, options);
580
+
581
+ var prCallback = null;
582
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
583
+ var rejectFunc = null;
584
+ var resolveFunc = null;
585
+ var returnPromise = new Promise(function (resolve, reject) {
586
+ resolveFunc = resolve;
587
+ rejectFunc = reject;
588
+ });
589
+ prCallback = function (error, api) {
590
+ if (error) {
591
+ return rejectFunc(error);
592
+ }
593
+ return resolveFunc(api);
594
+ };
595
+ callback = prCallback;
596
+ }
597
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
598
+ return returnPromise;
599
+ }
600
+
601
+ module.exports = login;