alicezetion 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/.travis.yml +6 -0
  4. package/index.js +182 -495
  5. package/package.json +10 -8
  6. package/replit.nix +4 -6
  7. package/src/addExternalModule.js +15 -0
  8. package/{leiamnash → src}/addUserToGroup.js +16 -52
  9. package/src/changeAdminStatus.js +47 -0
  10. package/src/changeArchivedStatus.js +41 -0
  11. package/{leiamnash → src}/changeBio.js +6 -19
  12. package/{leiamnash → src}/changeBlockedStatus.js +3 -14
  13. package/{leiamnash → src}/changeGroupImage.js +16 -40
  14. package/src/changeNickname.js +43 -0
  15. package/{leiamnash → src}/changeThreadColor.js +10 -20
  16. package/src/changeThreadEmoji.js +41 -0
  17. package/src/chat.js +315 -0
  18. package/{leiamnash → src}/createNewGroup.js +12 -28
  19. package/{leiamnash → src}/createPoll.js +13 -25
  20. package/src/deleteMessage.js +44 -0
  21. package/src/deleteThread.js +42 -0
  22. package/src/forwardAttachment.js +47 -0
  23. package/src/forwardMessage.js +0 -0
  24. package/{leiamnash → src}/getCurrentUserID.js +1 -1
  25. package/{leiamnash → src}/getEmojiUrl.js +2 -4
  26. package/{leiamnash → src}/getFriendsList.js +10 -21
  27. package/{leiamnash → src}/getThreadHistory.js +58 -166
  28. package/{leiamnash → src}/getThreadHistoryDeprecated.js +20 -42
  29. package/src/getThreadInfo.js +171 -0
  30. package/src/getThreadInfoDeprecated.js +56 -0
  31. package/{leiamnash → src}/getThreadList.js +41 -66
  32. package/src/getThreadListDeprecated.js +46 -0
  33. package/src/getThreadPictures.js +59 -0
  34. package/{leiamnash → src}/getUserID.js +9 -14
  35. package/{leiamnash → src}/getUserInfo.js +12 -18
  36. package/src/handleFriendRequest.js +46 -0
  37. package/src/handleMessageRequest.js +47 -0
  38. package/{leiamnash → src}/httpGet.js +12 -17
  39. package/{leiamnash → src}/httpPost.js +12 -17
  40. package/src/listen.js +553 -0
  41. package/src/listenMqtt-Test.js +687 -0
  42. package/src/listenMqtt.js +677 -0
  43. package/{leiamnash → src}/logout.js +13 -20
  44. package/{leiamnash → src}/markAsDelivered.js +11 -22
  45. package/{leiamnash → src}/markAsRead.js +11 -21
  46. package/{leiamnash → src}/markAsReadAll.js +10 -20
  47. package/{leiamnash → src}/markAsSeen.js +7 -18
  48. package/{leiamnash → src}/muteThread.js +11 -18
  49. package/src/removeUserFromGroup.js +45 -0
  50. package/{leiamnash → src}/resolvePhotoUrl.js +8 -17
  51. package/{leiamnash → src}/searchForThread.js +10 -21
  52. package/src/sendMessage.js +315 -0
  53. package/{leiamnash → src}/sendTypingIndicator.js +14 -47
  54. package/{leiamnash → src}/setMessageReaction.js +12 -26
  55. package/{leiamnash → src}/setPostReaction.js +13 -26
  56. package/{leiamnash → src}/setTitle.js +13 -29
  57. package/src/threadColors.js +41 -0
  58. package/{leiamnash → src}/unfriend.js +9 -19
  59. package/{leiamnash → src}/unsendMessage.js +9 -19
  60. package/test/data/shareAttach.js +146 -0
  61. package/test/data/something.mov +0 -0
  62. package/test/data/test.png +0 -0
  63. package/test/data/test.txt +7 -0
  64. package/test/example-config.json +18 -0
  65. package/test/test-page.js +140 -0
  66. package/test/test.js +385 -0
  67. package/utils.js +1021 -1238
  68. package/leiamnash/addExternalModule.js +0 -19
  69. package/leiamnash/changeAdminStatus.js +0 -79
  70. package/leiamnash/changeApprovalMode.js +0 -80
  71. package/leiamnash/changeArchivedStatus.js +0 -55
  72. package/leiamnash/changeNickname.js +0 -59
  73. package/leiamnash/changeThreadEmoji.js +0 -55
  74. package/leiamnash/chat.js +0 -447
  75. package/leiamnash/deleteMessage.js +0 -56
  76. package/leiamnash/deleteThread.js +0 -56
  77. package/leiamnash/forwardAttachment.js +0 -60
  78. package/leiamnash/getThreadInfo.js +0 -212
  79. package/leiamnash/getThreadInfoDeprecated.js +0 -80
  80. package/leiamnash/getThreadListDeprecated.js +0 -75
  81. package/leiamnash/getThreadPictures.js +0 -79
  82. package/leiamnash/handleFriendRequest.js +0 -61
  83. package/leiamnash/handleMessageRequest.js +0 -65
  84. package/leiamnash/listenMqtt.js +0 -1129
  85. package/leiamnash/removeUserFromGroup.js +0 -79
  86. package/leiamnash/threadColors.js +0 -57
package/index.js CHANGED
@@ -12,50 +12,48 @@ log.maxRecordSize = defaultLogRecordSize;
12
12
  function setOptions(globalOptions, options) {
13
13
  Object.keys(options).map(function(key) {
14
14
  switch (key) {
15
- case "pauseLog":
15
+ case 'pauseLog':
16
16
  if (options.pauseLog) log.pause();
17
17
  break;
18
- case "online":
18
+ case 'online':
19
19
  globalOptions.online = Boolean(options.online);
20
20
  break;
21
- case "logLevel":
21
+ case 'logLevel':
22
22
  log.level = options.logLevel;
23
23
  globalOptions.logLevel = options.logLevel;
24
24
  break;
25
- case "logRecordSize":
25
+ case 'logRecordSize':
26
26
  log.maxRecordSize = options.logRecordSize;
27
27
  globalOptions.logRecordSize = options.logRecordSize;
28
28
  break;
29
- case "selfListen":
29
+ case 'selfListen':
30
30
  globalOptions.selfListen = Boolean(options.selfListen);
31
31
  break;
32
- case "listenEvents":
32
+ case 'listenEvents':
33
33
  globalOptions.listenEvents = Boolean(options.listenEvents);
34
34
  break;
35
- case "pageID":
35
+ case 'pageID':
36
36
  globalOptions.pageID = options.pageID.toString();
37
37
  break;
38
- case "updatePresence":
38
+ case 'updatePresence':
39
39
  globalOptions.updatePresence = Boolean(options.updatePresence);
40
40
  break;
41
- case "forceLogin":
41
+ case 'forceLogin':
42
42
  globalOptions.forceLogin = Boolean(options.forceLogin);
43
43
  break;
44
- case "userAgent":
44
+ case 'userAgent':
45
45
  globalOptions.userAgent = options.userAgent;
46
46
  break;
47
- case "autoMarkDelivery":
48
- globalOptions.autoMarkDelivery = Boolean(
49
- options.autoMarkDelivery
50
- );
47
+ case 'autoMarkDelivery':
48
+ globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
51
49
  break;
52
- case "autoMarkRead":
50
+ case 'autoMarkRead':
53
51
  globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
54
52
  break;
55
- case "listenTyping":
53
+ case 'listenTyping':
56
54
  globalOptions.listenTyping = Boolean(options.listenTyping);
57
55
  break;
58
- case "proxy":
56
+ case 'proxy':
59
57
  if (typeof options.proxy != "string") {
60
58
  delete globalOptions.proxy;
61
59
  utils.setProxy();
@@ -64,58 +62,38 @@ function setOptions(globalOptions, options) {
64
62
  utils.setProxy(globalOptions.proxy);
65
63
  }
66
64
  break;
67
- case "autoReconnect":
65
+ case 'autoReconnect':
68
66
  globalOptions.autoReconnect = Boolean(options.autoReconnect);
69
67
  break;
70
- case "emitReady":
68
+ case 'emitReady':
71
69
  globalOptions.emitReady = Boolean(options.emitReady);
72
70
  break;
73
71
  default:
74
- log.warn(
75
- "setOptions",
76
- "Unrecognized option given to setOptions: " + key
77
- );
72
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
78
73
  break;
79
74
  }
80
75
  });
81
76
  }
82
77
 
83
78
  function buildAPI(globalOptions, html, jar) {
84
- var maybeCookie = jar
85
- .getCookies("https://www.facebook.com")
86
- .filter(function(val) {
87
- return val.cookieString().split("=")[0] === "c_user";
88
- });
79
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
80
+ return val.cookieString().split("=")[0] === "c_user";
81
+ });
89
82
 
90
- if (maybeCookie.length === 0) {
91
- throw {
92
- error:
93
- "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.",
94
- };
95
- }
83
+ 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." };
96
84
 
97
- if (html.indexOf("/checkpoint/block/?next") > -1) {
98
- log.warn(
99
- "login",
100
- "Checkpoint detected. Please log in with a browser to verify."
101
- );
102
- }
85
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
103
86
 
104
- var userID = maybeCookie[0]
105
- .cookieString()
106
- .split("=")[1]
107
- .toString();
87
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
108
88
  //log.info("login", `Logged in as ${userID}`);
109
89
 
110
90
  try {
111
91
  clearInterval(checkVerified);
112
92
  } catch (_) {}
113
93
 
114
- var clientID = ((Math.random() * 2147483648) | 0).toString(16);
94
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
115
95
 
116
- let oldFBMQTTMatch = html.match(
117
- /irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/
118
- );
96
+ let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
119
97
  let mqttEndpoint = null;
120
98
  let region = null;
121
99
  let irisSeqID = null;
@@ -125,42 +103,27 @@ function buildAPI(globalOptions, html, jar) {
125
103
  irisSeqID = oldFBMQTTMatch[1];
126
104
  mqttEndpoint = oldFBMQTTMatch[2];
127
105
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
128
- // log.info("login", `Got this account's message region: ${region}`);
106
+ //log.info("login", `Got this account's message region: ${region}`);
129
107
  } else {
130
- let newFBMQTTMatch = html.match(
131
- /{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/
132
- );
108
+ let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
133
109
  if (newFBMQTTMatch) {
134
110
  irisSeqID = newFBMQTTMatch[2];
135
111
  mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
136
- region = new URL(mqttEndpoint).searchParams
137
- .get("region")
138
- .toUpperCase();
139
- // log.info("login", `Got this account's message region: ${region}`);
112
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
113
+ // log.info("login", `Got this account's message region: ${region}`);
140
114
  } else {
141
- let legacyFBMQTTMatch = html.match(
142
- /(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/
143
- );
115
+ let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
144
116
  if (legacyFBMQTTMatch) {
145
117
  mqttEndpoint = legacyFBMQTTMatch[4];
146
- region = new URL(mqttEndpoint).searchParams
147
- .get("region")
148
- .toUpperCase();
149
- /* log.warn(
150
- "login",
151
- `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`
152
- );
153
- log.info(
154
- "login",
155
- `Got this account's message region: ${region}`
156
- );
157
- log.info(
158
- "login",
159
- `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`
160
- );*/
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]}`);*/
161
122
  } else {
162
- // log.warn("login", "Cannot get MQTT region & sequence ID.");
123
+ /*log.warn("login", "» Cannot get MQTT region & sequence ID.");
124
+ log.error("login", "» Please try closing and reopening your browser window or get new fbstate.");*/
163
125
  noMqttData = html;
126
+ process.exit();
164
127
  }
165
128
  }
166
129
  }
@@ -172,92 +135,85 @@ function buildAPI(globalOptions, html, jar) {
172
135
  clientID: clientID,
173
136
  globalOptions: globalOptions,
174
137
  loggedIn: true,
175
- access_token: "NONE",
138
+ access_token: 'NONE',
176
139
  clientMutationId: 0,
177
140
  mqttClient: undefined,
178
141
  lastSeqId: irisSeqID,
179
142
  syncToken: undefined,
180
143
  mqttEndpoint,
181
144
  region,
182
- firstListen: true,
145
+ firstListen: true
183
146
  };
184
147
 
185
148
  var api = {
186
149
  setOptions: setOptions.bind(null, globalOptions),
187
150
  getAppState: function getAppState() {
188
151
  return utils.getAppState(jar);
189
- },
152
+ }
190
153
  };
191
154
 
192
- if (noMqttData) {
193
- api["htmlData"] = noMqttData;
194
- }
155
+ if (noMqttData) api["htmlData"] = noMqttData;
195
156
 
196
157
  const apiFuncNames = [
197
- "addExternalModule",
198
- "addUserToGroup",
199
- "changeAdminStatus",
200
- "changeApprovalMode",
201
- "changeArchivedStatus",
202
- "changeBio",
203
- "changeBlockedStatus",
204
- "changeGroupImage",
205
- "changeNickname",
206
- "changeThreadColor",
207
- "changeThreadEmoji",
208
- "createNewGroup",
209
- "createPoll",
210
- "deleteMessage",
211
- "deleteThread",
212
- "forwardAttachment",
213
- "getCurrentUserID",
214
- "getEmojiUrl",
215
- "getFriendsList",
216
- "getThreadHistory",
217
- "getThreadInfo",
218
- "getThreadList",
219
- "getThreadPictures",
220
- "getUserID",
221
- "getUserInfo",
222
- "handleMessageRequest",
223
- "listenMqtt",
224
- "logout",
225
- "markAsDelivered",
226
- "markAsRead",
227
- "markAsReadAll",
228
- "markAsSeen",
229
- "muteThread",
230
- "removeUserFromGroup",
231
- "resolvePhotoUrl",
232
- "searchForThread",
233
- "chat",
234
- "sendTypingIndicator",
235
- "setMessageReaction",
236
- "setTitle",
237
- "threadColors",
238
- "unsendMessage",
239
- "unfriend",
158
+ 'addExternalModule',
159
+ 'addUserToGroup',
160
+ 'changeAdminStatus',
161
+ 'changeArchivedStatus',
162
+ 'changeBio',
163
+ 'changeBlockedStatus',
164
+ 'changeGroupImage',
165
+ 'changeNickname',
166
+ 'chat',
167
+ 'changeThreadColor',
168
+ 'changeThreadEmoji',
169
+ 'createNewGroup',
170
+ 'createPoll',
171
+ 'deleteMessage',
172
+ 'deleteThread',
173
+ 'forwardAttachment',
174
+ 'getCurrentUserID',
175
+ 'getEmojiUrl',
176
+ 'getFriendsList',
177
+ 'getThreadHistory',
178
+ 'getThreadInfo',
179
+ 'getThreadList',
180
+ 'getThreadPictures',
181
+ 'getUserID',
182
+ 'getUserInfo',
183
+ 'handleFriendRequest',
184
+ 'handleMessageRequest',
185
+ 'listenMqtt',
186
+ 'logout',
187
+ 'markAsDelivered',
188
+ 'markAsRead',
189
+ 'markAsReadAll',
190
+ 'markAsSeen',
191
+ 'muteThread',
192
+ 'removeUserFromGroup',
193
+ 'resolvePhotoUrl',
194
+ 'searchForThread',
195
+ 'sendMessage',
196
+ 'sendTypingIndicator',
197
+ 'setMessageReaction',
198
+ 'setTitle',
199
+ 'threadColors',
200
+ 'unsendMessage',
201
+ 'unfriend',
240
202
 
241
203
  // HTTP
242
- "httpGet",
243
- "httpPost",
204
+ 'httpGet',
205
+ 'httpPost',
244
206
 
245
207
  // Deprecated features
246
208
  "getThreadListDeprecated",
247
- "getThreadHistoryDeprecated",
248
- "getThreadInfoDeprecated",
209
+ 'getThreadHistoryDeprecated',
210
+ 'getThreadInfoDeprecated',
249
211
  ];
250
212
 
251
213
  var defaultFuncs = utils.makeDefaults(html, userID, ctx);
252
214
 
253
215
  // Load all api functions in a loop
254
- apiFuncNames.map(function(v) {
255
- api[v] = require("./leiamnash/" + v)(defaultFuncs, api, ctx);
256
- });
257
-
258
- //Removing original `listen` that uses pull.
259
- //Map it to listenMqtt instead for backward compatibly.
260
- api.listen = api.listenMqtt;
216
+ apiFuncNames.map(v => api[v] = require('./src/' + v)(defaultFuncs, api, ctx));
261
217
 
262
218
  return [ctx, defaultFuncs, api];
263
219
  }
@@ -269,27 +225,24 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
269
225
  var arr = [];
270
226
 
271
227
  // This will be empty, but just to be sure we leave it
272
- $("#login_form input").map(function(i, v) {
273
- arr.push({ val: $(v).val(), name: $(v).attr("name") });
274
- });
228
+ $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
275
229
 
276
230
  arr = arr.filter(function(v) {
277
231
  return v.val && v.val.length;
278
232
  });
279
233
 
280
234
  var form = utils.arrToForm(arr);
281
- form.lsd = utils.getFrom(html, '["LSD",[],{"token":"', '"}');
282
- form.lgndim = Buffer.from(
283
- '{"w":1440,"h":900,"aw":1440,"ah":834,"c":24}'
284
- ).toString("base64");
235
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
236
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
285
237
  form.email = email;
286
238
  form.pass = password;
287
- form.default_persistent = "0";
288
- form.lgnrnd = utils.getFrom(html, 'name="lgnrnd" value="', '"');
289
- form.locale = "en_US";
290
- form.timezone = "240";
239
+ form.default_persistent = '0';
240
+ form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
241
+ form.locale = 'en_US';
242
+ form.timezone = '240';
291
243
  form.lgnjs = ~~(Date.now() / 1000);
292
244
 
245
+
293
246
  // Getting cookies from the HTML page... (kill me now plz)
294
247
  // we used to get a bunch of cookies in the headers of the response of the
295
248
  // request, but FB changed and they now send those cookies inside the JS.
@@ -299,42 +252,25 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
299
252
  // variable name.
300
253
  //
301
254
  // ---------- Very Hacky Part Starts -----------------
302
- var willBeCookies = html.split('"_js_');
255
+ var willBeCookies = html.split("\"_js_");
303
256
  willBeCookies.slice(1).map(function(val) {
304
- var cookieData = JSON.parse(
305
- '["' + utils.getFrom(val, "", "]") + "]"
306
- );
307
- jar.setCookie(
308
- utils.formatCookie(cookieData, "facebook"),
309
- "https://www.facebook.com"
310
- );
257
+ var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
258
+ jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
311
259
  });
312
260
  // ---------- Very Hacky Part Ends -----------------
313
261
 
314
- // log.info("login", "Logging in...");
262
+ //log.info("login", "Logging in...");
315
263
  return utils
316
- .post(
317
- "https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110",
318
- jar,
319
- form,
320
- loginOptions
321
- )
264
+ .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
322
265
  .then(utils.saveCookies(jar))
323
266
  .then(function(res) {
324
267
  var headers = res.headers;
325
- if (!headers.location) {
326
- throw { error: "Wrong username/password." };
327
- }
268
+ if (!headers.location) throw { error: "Wrong username/password." };
328
269
 
329
270
  // This means the account has login approvals turned on.
330
- if (
331
- headers.location.indexOf(
332
- "https://www.facebook.com/checkpoint/"
333
- ) > -1
334
- ) {
271
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
335
272
  log.info("login", "You have login approvals turned on.");
336
- var nextURL =
337
- "https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php";
273
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
338
274
 
339
275
  return utils
340
276
  .get(headers.location, jar, null, loginOptions)
@@ -344,12 +280,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
344
280
  // Make the form in advance which will contain the fb_dtsg and nh
345
281
  var $ = cheerio.load(html);
346
282
  var arr = [];
347
- $("form input").map(function(i, v) {
348
- arr.push({
349
- val: $(v).val(),
350
- name: $(v).attr("name"),
351
- });
352
- });
283
+ $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
353
284
 
354
285
  arr = arr.filter(function(v) {
355
286
  return v.val && v.val.length;
@@ -358,76 +289,36 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
358
289
  var form = utils.arrToForm(arr);
359
290
  if (html.indexOf("checkpoint/?next") > -1) {
360
291
  setTimeout(() => {
361
- checkVerified = setInterval(
362
- (_form) => {
363
- /* utils
364
- .post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
365
- "Referer": "https://www.facebook.com/checkpoint/?next"
366
- })
367
- .then(utils.saveCookies(jar))
368
- .then(res => {
369
- try {
370
- JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
371
- } catch (ex) {
372
- clearInterval(checkVerified);
373
- log.info("login", "Verified from browser. Logging in...");
374
- return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
375
- }
376
- })
377
- .catch(ex => {
378
- log.error("login", ex);
379
- }); */
380
- },
381
- 5000,
382
- {
383
- fb_dtsg: form.fb_dtsg,
384
- jazoest: form.jazoest,
385
- dpr: 1,
386
- }
387
- );
292
+ checkVerified = setInterval((_form) => {}, 5000, {
293
+ fb_dtsg: form.fb_dtsg,
294
+ jazoest: form.jazoest,
295
+ dpr: 1
296
+ });
388
297
  }, 2500);
389
298
  throw {
390
- error: "login-approval",
299
+ error: 'login-approval',
391
300
  continue: function submit2FA(code) {
392
301
  form.approvals_code = code;
393
- form["submit[Continue]"] = $(
394
- "#checkpointSubmitButton"
395
- ).html(); //'Continue';
302
+ form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
396
303
  var prResolve = null;
397
304
  var prReject = null;
398
- var rtPromise = new Promise(function(
399
- resolve,
400
- reject
401
- ) {
305
+ var rtPromise = new Promise(function(resolve, reject) {
402
306
  prResolve = resolve;
403
307
  prReject = reject;
404
308
  });
405
309
  if (typeof code == "string") {
406
310
  utils
407
- .post(
408
- nextURL,
409
- jar,
410
- form,
411
- loginOptions
412
- )
311
+ .post(nextURL, jar, form, loginOptions)
413
312
  .then(utils.saveCookies(jar))
414
313
  .then(function(res) {
415
- var $ = cheerio.load(
416
- res.body
417
- );
418
- var error = $(
419
- "#approvals_code"
420
- )
421
- .parent()
422
- .attr("data-xui-error");
314
+ var $ = cheerio.load(res.body);
315
+ var error = $("#approvals_code").parent().attr("data-xui-error");
423
316
  if (error) {
424
317
  throw {
425
- error:
426
- "login-approval",
427
- errordesc:
428
- "Invalid 2FA code.",
318
+ error: 'login-approval',
319
+ errordesc: "Invalid 2FA code.",
429
320
  lerror: error,
430
- continue: submit2FA,
321
+ continue: submit2FA
431
322
  };
432
323
  }
433
324
  })
@@ -435,235 +326,98 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
435
326
  // Use the same form (safe I hope)
436
327
  delete form.no_fido;
437
328
  delete form.approvals_code;
438
- form.name_action_selected =
439
- "dont_save"; //'save_device';
440
-
441
- return utils
442
- .post(
443
- nextURL,
444
- jar,
445
- form,
446
- loginOptions
447
- )
448
- .then(
449
- utils.saveCookies(
450
- jar
451
- )
452
- );
329
+ form.name_action_selected = 'dont_save'; //'save_device';
330
+
331
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
453
332
  })
454
333
  .then(function(res) {
455
334
  var headers = res.headers;
456
- if (
457
- !headers.location &&
458
- res.body.indexOf(
459
- "Review Recent Login"
460
- ) > -1
461
- ) {
462
- throw {
463
- error:
464
- "Something went wrong with login approvals.",
465
- };
466
- }
335
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with login approvals." };
467
336
 
468
- var appState = utils.getAppState(
469
- jar
470
- );
471
-
472
- if (
473
- callback === prCallback
474
- ) {
475
- callback = function(
476
- err,
477
- api
478
- ) {
479
- if (err) {
480
- return prReject(
481
- err
482
- );
483
- }
484
- return prResolve(
485
- api
486
- );
337
+ var appState = utils.getAppState(jar);
338
+
339
+ if (callback === prCallback) {
340
+ callback = function(err, api) {
341
+ if (err) return prReject(err);
342
+ return prResolve(api);
487
343
  };
488
344
  }
489
345
 
490
346
  // Simply call loginHelper because all it needs is the jar
491
347
  // and will then complete the login process
492
- return loginHelper(
493
- appState,
494
- email,
495
- password,
496
- loginOptions,
497
- callback
498
- );
348
+ return loginHelper(appState, email, password, loginOptions, callback);
499
349
  })
500
350
  .catch(function(err) {
501
351
  // Check if using Promise instead of callback
502
- if (
503
- callback === prCallback
504
- ) {
505
- prReject(err);
506
- } else {
507
- callback(err);
508
- }
352
+ if (callback === prCallback) prReject(err);
353
+ else callback(err);
509
354
  });
510
355
  } else {
511
356
  utils
512
- .post(
513
- "https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php",
514
- jar,
515
- form,
516
- loginOptions,
517
- null,
518
- {
519
- Referer:
520
- "https://www.facebook.com/checkpoint/?next",
521
- }
522
- )
357
+ .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" })
523
358
  .then(utils.saveCookies(jar))
524
- .then((res) => {
359
+ .then(res => {
525
360
  try {
526
- JSON.parse(
527
- res.body.replace(
528
- /for\s*\(\s*;\s*;\s*\)\s*;\s*/,
529
- ""
530
- )
531
- );
361
+ JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
532
362
  } catch (ex) {
533
- clearInterval(
534
- checkVerified
535
- );
536
- /* log.info(
537
- "login",
538
- "Verified from browser. Logging in..."
539
- );*/
540
- if (
541
- callback ===
542
- prCallback
543
- ) {
544
- callback = function(
545
- err,
546
- api
547
- ) {
548
- if (err) {
549
- return prReject(
550
- err
551
- );
552
- }
553
- return prResolve(
554
- api
555
- );
363
+ clearInterval(checkVerified);
364
+ log.info("login", "Verified from browser. Logging in...");
365
+ if (callback === prCallback) {
366
+ callback = function(err, api) {
367
+ if (err) return prReject(err);
368
+ return prResolve(api);
556
369
  };
557
370
  }
558
- return loginHelper(
559
- utils.getAppState(
560
- jar
561
- ),
562
- email,
563
- password,
564
- loginOptions,
565
- callback
566
- );
371
+ return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
567
372
  }
568
373
  })
569
- .catch((ex) => {
374
+ .catch(ex => {
570
375
  log.error("login", ex);
571
- if (
572
- callback === prCallback
573
- ) {
574
- prReject(ex);
575
- } else {
576
- callback(ex);
577
- }
376
+ if (callback === prCallback) prReject(ex);
377
+ else callback(ex);
578
378
  });
579
379
  }
580
380
  return rtPromise;
581
- },
381
+ }
582
382
  };
583
383
  } else {
584
- if (!loginOptions.forceLogin) {
585
- throw {
586
- error:
587
- "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again.",
588
- };
589
- }
590
- if (
591
- html.indexOf("Suspicious Login Attempt") >
592
- -1
593
- ) {
594
- form["submit[This was me]"] = "This was me";
595
- } else {
596
- form["submit[This Is Okay]"] =
597
- "This Is Okay";
598
- }
384
+ if (!loginOptions.forceLogin) throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
385
+
386
+ if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
387
+ else form['submit[This Is Okay]'] = "This Is Okay";
599
388
 
600
389
  return utils
601
390
  .post(nextURL, jar, form, loginOptions)
602
391
  .then(utils.saveCookies(jar))
603
392
  .then(function() {
604
393
  // Use the same form (safe I hope)
605
- form.name_action_selected =
606
- "save_device";
607
-
608
- return utils
609
- .post(
610
- nextURL,
611
- jar,
612
- form,
613
- loginOptions
614
- )
615
- .then(utils.saveCookies(jar));
394
+ form.name_action_selected = 'save_device';
395
+
396
+ return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
616
397
  })
617
398
  .then(function(res) {
618
399
  var headers = res.headers;
619
400
 
620
- if (
621
- !headers.location &&
622
- res.body.indexOf(
623
- "Review Recent Login"
624
- ) > -1
625
- ) {
626
- throw {
627
- error:
628
- "Something went wrong with review recent login.",
629
- };
630
- }
401
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
631
402
 
632
403
  var appState = utils.getAppState(jar);
633
404
 
634
405
  // Simply call loginHelper because all it needs is the jar
635
406
  // and will then complete the login process
636
- return loginHelper(
637
- appState,
638
- email,
639
- password,
640
- loginOptions,
641
- callback
642
- );
407
+ return loginHelper(appState, email, password, loginOptions, callback);
643
408
  })
644
- .catch(function(e) {
645
- callback(e);
646
- });
409
+ .catch(e => callback(e));
647
410
  }
648
411
  });
649
412
  }
650
413
 
651
- return utils
652
- .get("https://www.facebook.com/", jar, null, loginOptions)
653
- .then(utils.saveCookies(jar));
414
+ return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
654
415
  });
655
416
  };
656
417
  }
657
418
 
658
419
  // Helps the login
659
- function loginHelper(
660
- appState,
661
- email,
662
- password,
663
- globalOptions,
664
- callback,
665
- prCallback
666
- ) {
420
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
667
421
  var mainPromise = null;
668
422
  var jar = utils.getJar();
669
423
 
@@ -671,48 +425,21 @@ function loginHelper(
671
425
  // back into the jar.
672
426
  if (appState) {
673
427
  appState.map(function(c) {
674
- var str =
675
- c.key +
676
- "=" +
677
- c.value +
678
- "; expires=" +
679
- c.expires +
680
- "; domain=" +
681
- c.domain +
682
- "; path=" +
683
- c.path +
684
- ";";
428
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
685
429
  jar.setCookie(str, "http://" + c.domain);
686
430
  });
687
431
 
688
432
  // Load the main page.
689
- mainPromise = utils
690
- .get("https://www.facebook.com/", jar, null, globalOptions, {
691
- noRef: true,
692
- })
693
- .then(utils.saveCookies(jar));
433
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
694
434
  } else {
695
435
  // Open the main page, then we login with the given credentials and finally
696
436
  // load the main page again (it'll give us some IDs that we need)
697
437
  mainPromise = utils
698
- .get("https://www.facebook.com/", null, null, globalOptions, {
699
- noRef: true,
700
- })
438
+ .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
701
439
  .then(utils.saveCookies(jar))
702
- .then(
703
- makeLogin(
704
- jar,
705
- email,
706
- password,
707
- globalOptions,
708
- callback,
709
- prCallback
710
- )
711
- )
440
+ .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
712
441
  .then(function() {
713
- return utils
714
- .get("https://www.facebook.com/", jar, null, globalOptions)
715
- .then(utils.saveCookies(jar));
442
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
716
443
  });
717
444
  }
718
445
 
@@ -725,11 +452,7 @@ function loginHelper(
725
452
  // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
726
453
  var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
727
454
  var redirect = reg.exec(res.body);
728
- if (redirect && redirect[1]) {
729
- return utils
730
- .get(redirect[1], jar, null, globalOptions)
731
- .then(utils.saveCookies(jar));
732
- }
455
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
733
456
  return res;
734
457
  })
735
458
  .then(function(res) {
@@ -745,52 +468,29 @@ function loginHelper(
745
468
  if (globalOptions.pageID) {
746
469
  mainPromise = mainPromise
747
470
  .then(function() {
748
- return utils.get(
749
- "https://www.facebook.com/" +
750
- ctx.globalOptions.pageID +
751
- "/messages/?section=messages&subsection=inbox",
752
- ctx.jar,
753
- null,
754
- globalOptions
755
- );
471
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
756
472
  })
757
473
  .then(function(resData) {
758
- var url = utils
759
- .getFrom(
760
- resData.body,
761
- 'window.location.replace("https:\\/\\/www.facebook.com\\',
762
- '");'
763
- )
764
- .split("\\")
765
- .join("");
474
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
766
475
  url = url.substring(0, url.length - 1);
767
-
768
- return utils.get(
769
- "https://www.facebook.com" + url,
770
- ctx.jar,
771
- null,
772
- globalOptions
773
- );
476
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
774
477
  });
775
478
  }
776
479
 
777
480
  // At the end we call the callback or catch an exception
778
481
  mainPromise
779
482
  .then(function() {
780
- //log.info("login", "Done logging in.");
483
+ //log.info("login", 'Done logging in.');
781
484
  return callback(null, api);
782
485
  })
783
486
  .catch(function(e) {
784
- //log.error("login", e.error || e);
487
+ log.error("login", e.error || e);
785
488
  callback(e);
786
489
  });
787
490
  }
788
491
 
789
492
  function login(loginData, options, callback) {
790
- if (
791
- utils.getType(options) === "Function" ||
792
- utils.getType(options) === "AsyncFunction"
793
- ) {
493
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
794
494
  callback = options;
795
495
  options = {};
796
496
  }
@@ -801,23 +501,19 @@ function login(loginData, options, callback) {
801
501
  listenTyping: false,
802
502
  updatePresence: false,
803
503
  forceLogin: false,
804
- autoMarkDelivery: true,
805
- autoMarkRead: false,
504
+ autoMarkDelivery: false,
505
+ autoMarkRead: true,
806
506
  autoReconnect: true,
807
507
  logRecordSize: defaultLogRecordSize,
808
- online: true,
508
+ online: false,
809
509
  emitReady: false,
810
- userAgent:
811
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18",
510
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
812
511
  };
813
512
 
814
- setOptions(globalOptions, options || {});
513
+ setOptions(globalOptions, options);
815
514
 
816
515
  var prCallback = null;
817
- if (
818
- utils.getType(callback) !== "Function" &&
819
- utils.getType(callback) !== "AsyncFunction"
820
- ) {
516
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
821
517
  var rejectFunc = null;
822
518
  var resolveFunc = null;
823
519
  var returnPromise = new Promise(function(resolve, reject) {
@@ -825,22 +521,13 @@ function login(loginData, options, callback) {
825
521
  rejectFunc = reject;
826
522
  });
827
523
  prCallback = function(error, api) {
828
- if (error) {
829
- return rejectFunc(error);
830
- }
524
+ if (error) return rejectFunc(error);
831
525
  return resolveFunc(api);
832
526
  };
833
527
  callback = prCallback;
834
528
  }
835
- loginHelper(
836
- loginData.appState,
837
- loginData.email,
838
- loginData.password,
839
- globalOptions,
840
- callback,
841
- prCallback
842
- );
529
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
843
530
  return returnPromise;
844
531
  }
845
532
 
846
- module.exports = login;
533
+ module.exports = login;