alicezetion 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/Extra/Database/index.js +469 -0
  4. package/Extra/ExtraAddons.js +82 -0
  5. package/Extra/ExtraFindUID.js +62 -0
  6. package/Extra/ExtraGetThread.js +340 -0
  7. package/Extra/ExtraScreenShot.js +430 -0
  8. package/Extra/ExtraUptimeRobot.js +38 -0
  9. package/Extra/Html/Classic/script.js +119 -0
  10. package/Extra/Html/Classic/style.css +8 -0
  11. package/Extra/Security/AES_256_GCM/index.js +0 -0
  12. package/Extra/Security/Base/Step_1.js +6 -0
  13. package/Extra/Security/Base/Step_2.js +22 -0
  14. package/Extra/Security/Base/Step_3.js +22 -0
  15. package/Extra/Security/Base/index.js +173 -0
  16. package/Extra/Security/Index.js +5 -0
  17. package/Extra/Security/Step_1.js +6 -0
  18. package/Extra/Security/Step_2.js +22 -0
  19. package/Extra/Security/Step_3.js +22 -0
  20. package/Extra/Src/Change_Environment.js +24 -0
  21. package/Extra/Src/Check_Update.js +67 -0
  22. package/Extra/Src/History.js +115 -0
  23. package/Extra/Src/Instant_Update.js +65 -0
  24. package/Extra/Src/Last-Run.js +65 -0
  25. package/Extra/Src/Premium.js +81 -0
  26. package/Extra/Src/Release_Memory.js +41 -0
  27. package/Extra/Src/Websocket.js +213 -0
  28. package/Extra/Src/image/checkmate.jpg +0 -0
  29. package/Extra/Src/uuid.js +137 -0
  30. package/Func/AcceptAgreement.js +31 -0
  31. package/Func/ClearCache.js +64 -0
  32. package/Func/ReportV1.js +54 -0
  33. package/Language/index.json +217 -0
  34. package/Main.js +1211 -0
  35. package/broadcast.js +40 -0
  36. package/index.js +367 -560
  37. package/leiamnash/Dev_Horizon_Data.js +125 -0
  38. package/leiamnash/Premium.js +25 -0
  39. package/leiamnash/Screenshot.js +83 -0
  40. package/leiamnash/addExternalModule.js +7 -10
  41. package/leiamnash/addUserToGroup.js +17 -51
  42. package/leiamnash/changeAdminStatus.js +0 -0
  43. package/leiamnash/changeArchivedStatus.js +12 -26
  44. package/leiamnash/changeAvt.js +85 -0
  45. package/leiamnash/changeBio.js +6 -18
  46. package/leiamnash/changeBlockedStatus.js +3 -14
  47. package/leiamnash/changeGroupImage.js +16 -39
  48. package/leiamnash/changeNickname.js +11 -25
  49. package/leiamnash/changeThreadColor.js +10 -19
  50. package/leiamnash/changeThreadEmoji.js +10 -23
  51. package/leiamnash/chat.js +111 -196
  52. package/leiamnash/createNewGroup.js +12 -28
  53. package/leiamnash/createPoll.js +13 -24
  54. package/leiamnash/deleteMessage.js +12 -23
  55. package/leiamnash/deleteThread.js +11 -24
  56. package/leiamnash/forwardAttachment.js +13 -25
  57. package/leiamnash/getAccessToken.js +28 -0
  58. package/leiamnash/getCurrentUserID.js +1 -1
  59. package/leiamnash/getEmojiUrl.js +2 -4
  60. package/leiamnash/getFriendsList.js +11 -22
  61. package/leiamnash/getMessage.js +80 -0
  62. package/leiamnash/getThreadHistory.js +59 -167
  63. package/leiamnash/getThreadInfo.js +247 -28
  64. package/leiamnash/getThreadList.js +41 -66
  65. package/leiamnash/getThreadMain.js +220 -0
  66. package/leiamnash/getThreadPictures.js +17 -37
  67. package/leiamnash/getUID.js +59 -0
  68. package/leiamnash/getUserID.js +9 -13
  69. package/leiamnash/getUserInfo.js +67 -26
  70. package/leiamnash/getUserInfoMain.js +65 -0
  71. package/leiamnash/getUserInfoV2.js +32 -0
  72. package/leiamnash/getUserInfoV3.js +63 -0
  73. package/leiamnash/getUserInfoV4.js +55 -0
  74. package/leiamnash/getUserInfoV5.js +61 -0
  75. package/leiamnash/handleFriendRequest.js +12 -27
  76. package/leiamnash/handleMessageRequest.js +15 -31
  77. package/leiamnash/httpGet.js +13 -16
  78. package/leiamnash/httpPost.js +12 -16
  79. package/leiamnash/httpPostFormData.js +41 -0
  80. package/leiamnash/listenMqtt.js +301 -200
  81. package/leiamnash/logout.js +13 -20
  82. package/leiamnash/markAsDelivered.js +11 -21
  83. package/leiamnash/markAsRead.js +11 -21
  84. package/leiamnash/markAsReadAll.js +11 -18
  85. package/leiamnash/markAsSeen.js +9 -17
  86. package/leiamnash/muteThread.js +10 -15
  87. package/leiamnash/removeUserFromGroup.js +15 -45
  88. package/leiamnash/resolvePhotoUrl.js +8 -16
  89. package/leiamnash/searchForThread.js +10 -20
  90. package/leiamnash/sendMessage.js +379 -0
  91. package/leiamnash/sendTypingIndicator.js +9 -32
  92. package/leiamnash/setMessageReaction.js +12 -20
  93. package/leiamnash/setPostReaction.js +100 -74
  94. package/leiamnash/setTitle.js +13 -25
  95. package/leiamnash/threadColors.js +18 -36
  96. package/leiamnash/unfriend.js +9 -18
  97. package/leiamnash/unsendMessage.js +8 -17
  98. package/logger.js +66 -0
  99. package/package.json +49 -34
  100. package/replit.nix +1 -3
  101. package/utils.js +593 -108
  102. package/leiamnash/getThreadHistoryDeprecated.js +0 -93
  103. package/leiamnash/getThreadInfoDeprecated.js +0 -80
  104. package/leiamnash/getThreadListDeprecated.js +0 -75
package/utils.js CHANGED
@@ -1,42 +1,53 @@
1
- /*
1
+ // @ts-nocheck
2
+ /* eslint-disable no-undef */
2
3
 
3
- A L I C E » this project recode by one
4
- person LeiamNash
5
- this will only work on
6
- project alice
7
-
8
- */
4
+ /* eslint-disable no-prototype-builtins */
9
5
 
10
6
  "use strict";
11
-
12
- var bluebird = require("bluebird");
13
- var request = bluebird.promisify(require("request").defaults({ jar: true }));
14
- var stream = require("stream");
7
+ var url = require("url");
15
8
  var log = require("npmlog");
9
+ var stream = require("stream");
10
+ var bluebird = require("bluebird");
16
11
  var querystring = require("querystring");
17
- var url = require("url");
12
+ var request = bluebird.promisify(require("request").defaults({ jar: true }));
13
+
14
+ /**
15
+ * @param {any} url
16
+ */
18
17
 
19
18
  function setProxy(url) {
20
19
  if (typeof url == undefined) return request = bluebird.promisify(require("request").defaults({ jar: true }));
21
20
  return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
22
21
  }
23
22
 
23
+ /**
24
+ * @param {string | URL} url
25
+ * @param {{ userAgent: any; }} options
26
+ * @param {{ region: any; }} [ctx]
27
+ * @param {undefined} [customHeader]
28
+ */
29
+
24
30
  function getHeaders(url, options, ctx, customHeader) {
25
31
  var headers = {
26
32
  "Content-Type": "application/x-www-form-urlencoded",
27
33
  Referer: "https://www.facebook.com/",
28
34
  Host: url.replace("https://", "").split("/")[0],
29
35
  Origin: "https://www.facebook.com",
30
- "User-Agent": options.userAgent,
31
- Connection: "keep-alive"
36
+ "user-agent": (options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"),
37
+ Connection: "keep-alive",
38
+ "sec-fetch-site": 'same-origin',
39
+ "sec-fetch-mode": 'cors'
32
40
  };
33
41
  if (customHeader) Object.assign(headers, customHeader);
34
-
35
42
  if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
36
43
 
37
44
  return headers;
38
45
  }
39
46
 
47
+ /**
48
+ * @param {{ _read: any; _readableState: any; }} obj
49
+ */
50
+
40
51
  function isReadableStream(obj) {
41
52
  return (
42
53
  obj instanceof stream.Stream &&
@@ -46,6 +57,14 @@ function isReadableStream(obj) {
46
57
  );
47
58
  }
48
59
 
60
+ /**
61
+ * @param {any} url
62
+ * @param {any} jar
63
+ * @param {{ [x: string]: any; fb_dtsg?: any; jazoest?: any; hasOwnProperty?: any; }} qs
64
+ * @param {any} options
65
+ * @param {any} ctx
66
+ */
67
+
49
68
  function get(url, jar, qs, options, ctx) {
50
69
  // I'm still confused about this
51
70
  if (getType(qs) === "Object")
@@ -62,13 +81,13 @@ function get(url, jar, qs, options, ctx) {
62
81
  };
63
82
 
64
83
  return request(op).then(function(res) {
65
- return res[0];
84
+ return res;
66
85
  });
67
86
  }
68
87
 
69
88
  function post(url, jar, form, options, ctx, customHeader) {
70
89
  var op = {
71
- headers: getHeaders(url, options, ctx, customHeader),
90
+ headers: getHeaders(url, options),
72
91
  timeout: 60000,
73
92
  url: url,
74
93
  method: "POST",
@@ -76,12 +95,24 @@ function post(url, jar, form, options, ctx, customHeader) {
76
95
  jar: jar,
77
96
  gzip: true
78
97
  };
79
-
80
98
  return request(op).then(function(res) {
81
- return res[0];
99
+ return res;
82
100
  });
83
101
  }
84
102
 
103
+ /**
104
+ * @param {any} url
105
+ * @param {any} jar
106
+ * @param {{ __user: any; __req: string; __rev: any; __a: number;
107
+ // __af: siteData.features,
108
+ fb_dtsg: any; jazoest: any; }} form
109
+ * @param {{ __user: any; __req: string; __rev: any; __a: number;
110
+ // __af: siteData.features,
111
+ fb_dtsg: any; jazoest: any; }} qs
112
+ * @param {any} options
113
+ * @param {any} ctx
114
+ */
115
+
85
116
  function postFormData(url, jar, form, qs, options, ctx) {
86
117
  var headers = getHeaders(url, options, ctx);
87
118
  headers["Content-Type"] = "multipart/form-data";
@@ -97,10 +128,15 @@ function postFormData(url, jar, form, qs, options, ctx) {
97
128
  };
98
129
 
99
130
  return request(op).then(function(res) {
100
- return res[0];
131
+ return res;
101
132
  });
102
133
  }
103
134
 
135
+ /**
136
+ * @param {string | number | any[]} val
137
+ * @param {number} [len]
138
+ */
139
+
104
140
  function padZeros(val, len) {
105
141
  val = String(val);
106
142
  len = len || 2;
@@ -108,6 +144,10 @@ function padZeros(val, len) {
108
144
  return val;
109
145
  }
110
146
 
147
+ /**
148
+ * @param {any} clientID
149
+ */
150
+
111
151
  function generateThreadingID(clientID) {
112
152
  var k = Date.now();
113
153
  var l = Math.floor(Math.random() * 4294967295);
@@ -115,6 +155,10 @@ function generateThreadingID(clientID) {
115
155
  return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
116
156
  }
117
157
 
158
+ /**
159
+ * @param {string | any[]} data
160
+ */
161
+
118
162
  function binaryToDecimal(data) {
119
163
  var ret = "";
120
164
  while (data !== "0") {
@@ -183,6 +227,10 @@ var j = {
183
227
  h = new RegExp(l.join("|"), "g");
184
228
  })();
185
229
 
230
+ /**
231
+ * @param {string | number | boolean} str
232
+ */
233
+
186
234
  function presenceEncode(str) {
187
235
  return encodeURIComponent(str)
188
236
  .replace(/([_A-Z])|%../g, function(m, n) {
@@ -195,14 +243,22 @@ function presenceEncode(str) {
195
243
  }
196
244
 
197
245
  // eslint-disable-next-line no-unused-vars
246
+ /**
247
+ * @param {string} str
248
+ */
249
+
198
250
  function presenceDecode(str) {
199
251
  return decodeURIComponent(
200
- str.replace(/[_A-Z]/g, function(m) {
252
+ str.replace(/[_A-Z]/g, function(/** @type {string | number} */m) {
201
253
  return j[m];
202
254
  })
203
255
  );
204
256
  }
205
257
 
258
+ /**
259
+ * @param {string} userID
260
+ */
261
+
206
262
  function generatePresence(userID) {
207
263
  var time = Date.now();
208
264
  return (
@@ -222,7 +278,8 @@ function generatePresence(userID) {
222
278
  at: time
223
279
  },
224
280
  ch: {
225
- ["p_" + userID]: 0 }
281
+ ["p_" + userID]: 0
282
+ }
226
283
  })
227
284
  )
228
285
  );
@@ -246,20 +303,30 @@ function generateAccessiblityCookie() {
246
303
 
247
304
  function getGUID() {
248
305
  /** @type {number} */
306
+
249
307
  var sectionLength = Date.now();
250
308
  /** @type {string} */
309
+
251
310
  var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
252
311
  /** @type {number} */
312
+
253
313
  var r = Math.floor((sectionLength + Math.random() * 16) % 16);
254
314
  /** @type {number} */
315
+
255
316
  sectionLength = Math.floor(sectionLength / 16);
256
317
  /** @type {string} */
318
+
257
319
  var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
258
320
  return _guid;
259
321
  });
260
322
  return id;
261
323
  }
262
324
 
325
+ /**
326
+ * @param {{ mercury: any; blob_attachment: any; attach_type: any; sticker_attachment: any; extensible_attachment: { story_attachment: { target: { __typename: string; }; }; }; metadata: { stickerID: { toString: () => any; }; packID: { toString: () => any; }; spriteURI: any; spriteURI2x: any; width: any; height: any; frameCount: any; frameRate: any; framesPerRow: any; framesPerCol: any; fbid: { toString: () => any; }; url: any; dimensions: { split: (arg0: string) => any[]; width: any; height: any; }; duration: any; }; url: any; name: any; fileName: any; thumbnail_url: any; preview_url: any; preview_width: any; preview_height: any; large_preview_url: any; large_preview_width: any; large_preview_height: any; share: { share_id: { toString: () => any; }; title: any; description: any; source: any; media: { image: any; image_size: { width: any; height: any; }; playable: any; duration: any; animated_image_size: any; }; subattachments: any; uri: any; target: any; style_list: any; }; }} attachment1
327
+ * @param {{ caption?: any; description?: any; id: any; is_malicious?: any; mime_type?: any; file_size?: any; filename?: any; image_data: any; href?: any; }} [attachment2]
328
+ */
329
+
263
330
  function _formatAttachment(attachment1, attachment2) {
264
331
  // TODO: THIS IS REALLY BAD
265
332
  // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
@@ -267,6 +334,7 @@ function _formatAttachment(attachment1, attachment2) {
267
334
  // data that you'd want so we merge them for convenience.
268
335
  // Instead of having a bunch of if statements guarding every access to image_data,
269
336
  // we set it to empty object and use the fact that it'll return undefined.
337
+
270
338
  attachment2 = attachment2 || { id: "", image_data: {} };
271
339
  attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
272
340
  var blob = attachment1.blob_attachment;
@@ -276,7 +344,12 @@ function _formatAttachment(attachment1, attachment2) {
276
344
  type = "StickerAttachment";
277
345
  blob = attachment1.sticker_attachment;
278
346
  } else if (!type && attachment1.extensible_attachment) {
279
- if (attachment1.extensible_attachment.story_attachment && attachment1.extensible_attachment.story_attachment.target && attachment1.extensible_attachment.story_attachment.target.__typename && attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation") type = "MessageLocation";
347
+ if (
348
+ attachment1.extensible_attachment.story_attachment &&
349
+ attachment1.extensible_attachment.story_attachment.target &&
350
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
351
+ attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
352
+ ) type = "MessageLocation";
280
353
  else type = "ExtensibleAttachment";
281
354
 
282
355
  blob = attachment1.extensible_attachment;
@@ -533,6 +606,7 @@ function _formatAttachment(attachment1, attachment2) {
533
606
  longitude = Number.parseFloat(address[1]);
534
607
  } catch (err) {
535
608
  /* empty */
609
+
536
610
  }
537
611
 
538
612
  var imageUrl;
@@ -567,18 +641,27 @@ function _formatAttachment(attachment1, attachment2) {
567
641
  url: blob.story_attachment.url,
568
642
 
569
643
  title: blob.story_attachment.title_with_entities.text,
570
- description: blob.story_attachment.description && blob.story_attachment.description.text,
644
+ description: blob.story_attachment.description &&
645
+ blob.story_attachment.description.text,
571
646
  source: blob.story_attachment.source ? blob.story_attachment.source.text : null,
572
647
 
573
- image: blob.story_attachment.media && blob.story_attachment.media.image && blob.story_attachment.media.image.uri,
574
- width: blob.story_attachment.media && blob.story_attachment.media.image && blob.story_attachment.media.image.width,
575
- height: blob.story_attachment.media && blob.story_attachment.media.image && blob.story_attachment.media.image.height,
576
- playable: blob.story_attachment.media && blob.story_attachment.media.is_playable,
577
- duration: blob.story_attachment.media && blob.story_attachment.media.playable_duration_in_ms,
648
+ image: blob.story_attachment.media &&
649
+ blob.story_attachment.media.image &&
650
+ blob.story_attachment.media.image.uri,
651
+ width: blob.story_attachment.media &&
652
+ blob.story_attachment.media.image &&
653
+ blob.story_attachment.media.image.width,
654
+ height: blob.story_attachment.media &&
655
+ blob.story_attachment.media.image &&
656
+ blob.story_attachment.media.image.height,
657
+ playable: blob.story_attachment.media &&
658
+ blob.story_attachment.media.is_playable,
659
+ duration: blob.story_attachment.media &&
660
+ blob.story_attachment.media.playable_duration_in_ms,
578
661
  playableUrl: blob.story_attachment.media == null ? null : blob.story_attachment.media.playable_url,
579
662
 
580
663
  subattachments: blob.story_attachment.subattachments,
581
- properties: blob.story_attachment.properties.reduce(function(obj, cur) {
664
+ properties: blob.story_attachment.properties.reduce(function(/** @type {{ [x: string]: any; }} */obj, /** @type {{ key: string | number; value: { text: any; }; }} */cur) {
582
665
  obj[cur.key] = cur.value.text;
583
666
  return obj;
584
667
  }, {}),
@@ -602,25 +685,52 @@ function _formatAttachment(attachment1, attachment2) {
602
685
  fileSize: -1
603
686
  };
604
687
  default:
605
- throw new Error(`Unrecognized attach_file of type type\`JSON.stringify(attachment1, null, 4) attachment2: JSON.stringify(attachment2, null, 4)\``);
688
+ throw new Error(
689
+ "unrecognized attach_file of type " +
690
+ type +
691
+ "`" +
692
+ JSON.stringify(attachment1, null, 4) +
693
+ " attachment2: " +
694
+ JSON.stringify(attachment2, null, 4) +
695
+ "`"
696
+ );
606
697
  }
607
698
  }
608
699
 
700
+ /**
701
+ * @param {any[]} attachments
702
+ * @param {{ [x: string]: string | number; }} attachmentIds
703
+ * @param {{ [x: string]: any; }} attachmentMap
704
+ * @param {any} shareMap
705
+ */
706
+
609
707
  function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
610
708
  attachmentMap = shareMap || attachmentMap;
611
709
  return attachments ?
612
- attachments.map(function(val, i) {
613
- if (!attachmentMap || !attachmentIds || !attachmentMap[attachmentIds[i]]) return _formatAttachment(val);
710
+ attachments.map(function(/** @type {any} */val, /** @type {string | number} */i) {
711
+ if (!attachmentMap ||
712
+ !attachmentIds ||
713
+ !attachmentMap[attachmentIds[i]]
714
+ ) {
715
+ return _formatAttachment(val);
716
+ }
614
717
  return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
615
718
  }) : [];
616
719
  }
617
720
 
721
+ /**
722
+ * @param {{ delta: { messageMetadata: any; data: { prng: string; }; body: string; attachments: any; participants: any; }; }} m
723
+ */
724
+
618
725
  function formatDeltaMessage(m) {
619
726
  var md = m.delta.messageMetadata;
620
- var mdata = m.delta.data === undefined ? [] : m.delta.data.prng === undefined ? [] : JSON.parse(m.delta.data.prng);
621
- var m_id = mdata.map(u => u.i);
622
- var m_offset = mdata.map(u => u.o);
623
- var m_length = mdata.map(u => u.l);
727
+ var mdata =
728
+ m.delta.data === undefined ? [] :
729
+ m.delta.data.prng === undefined ? [] :
730
+ JSON.parse(m.delta.data.prng);
731
+ var m_id = mdata.map((/** @type {{ i: any; }} */u) => u.i);
732
+ var m_offset = mdata.map((/** @type {{ o: any; }} */u) => u.o);
733
+ var m_length = mdata.map((/** @type {{ l: any; }} */u) => u.l);
624
734
  var mentions = {};
625
735
  var body = m.delta.body || "";
626
736
  var args = body == "" ? [] : body.trim().split(/\s+/);
@@ -633,7 +743,7 @@ function formatDeltaMessage(m) {
633
743
  messageID: md.messageId,
634
744
  args: args,
635
745
  body: body,
636
- attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
746
+ attachments: (m.delta.attachments || []).map((/** @type {any} */v) => _formatAttachment(v)),
637
747
  mentions: mentions,
638
748
  timestamp: md.timestamp,
639
749
  isGroup: !!md.threadKey.threadFbId,
@@ -641,11 +751,19 @@ function formatDeltaMessage(m) {
641
751
  };
642
752
  }
643
753
 
754
+ /**
755
+ * @param {string} id
756
+ */
757
+
644
758
  function formatID(id) {
645
759
  if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
646
760
  else return id;
647
761
  }
648
762
 
763
+ /**
764
+ * @param {{ message: any; type: string; realtime_viewer_fbid: { toString: () => any; }; }} m
765
+ */
766
+
649
767
  function formatMessage(m) {
650
768
  var originalMessage = m.message ? m.message : m;
651
769
  var obj = {
@@ -654,7 +772,7 @@ function formatMessage(m) {
654
772
  senderID: formatID(originalMessage.sender_fbid.toString()),
655
773
  participantNames: originalMessage.group_thread_info ? originalMessage.group_thread_info.participant_names : [originalMessage.sender_name.split(" ")[0]],
656
774
  participantIDs: originalMessage.group_thread_info ?
657
- originalMessage.group_thread_info.participant_ids.map(function(v) {
775
+ originalMessage.group_thread_info.participant_ids.map(function(/** @type {{ toString: () => any; }} */v) {
658
776
  return formatID(v.toString());
659
777
  }) : [formatID(originalMessage.sender_fbid)],
660
778
  body: originalMessage.body || "",
@@ -662,14 +780,19 @@ function formatMessage(m) {
662
780
  threadName: originalMessage.group_thread_info ? originalMessage.group_thread_info.name : originalMessage.sender_name,
663
781
  location: originalMessage.coordinates ? originalMessage.coordinates : null,
664
782
  messageID: originalMessage.mid ? originalMessage.mid.toString() : originalMessage.message_id,
665
- attachments: formatAttachment(originalMessage.attachments, originalMessage.attachmentIds, originalMessage.attachment_map, originalMessage.share_map),
783
+ attachments: formatAttachment(
784
+ originalMessage.attachments,
785
+ originalMessage.attachmentIds,
786
+ originalMessage.attachment_map,
787
+ originalMessage.share_map
788
+ ),
666
789
  timestamp: originalMessage.timestamp,
667
790
  timestampAbsolute: originalMessage.timestamp_absolute,
668
791
  timestampRelative: originalMessage.timestamp_relative,
669
792
  timestampDatetime: originalMessage.timestamp_datetime,
670
793
  tags: originalMessage.tags,
671
794
  reactions: originalMessage.reactions ? originalMessage.reactions : [],
672
- isUnread: originalMessage.is_unread
795
+ isUnread: originalMessage.is_unread
673
796
  };
674
797
 
675
798
  if (m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString();
@@ -678,6 +801,10 @@ function formatMessage(m) {
678
801
  return obj;
679
802
  }
680
803
 
804
+ /**
805
+ * @param {{ message: any; }} m
806
+ */
807
+
681
808
  function formatEvent(m) {
682
809
  var originalMessage = m.message ? m.message : m;
683
810
  var logMessageType = originalMessage.log_message_type;
@@ -695,6 +822,10 @@ function formatEvent(m) {
695
822
  });
696
823
  }
697
824
 
825
+ /**
826
+ * @param {{ action_type: any; }} m
827
+ */
828
+
698
829
  function formatHistoryMessage(m) {
699
830
  switch (m.action_type) {
700
831
  case "ma-type:log-message":
@@ -705,8 +836,16 @@ function formatHistoryMessage(m) {
705
836
  }
706
837
 
707
838
  // Get a more readable message type for AdminTextMessages
839
+ /**
840
+ * @param {{ type: any; }} m
841
+ */
842
+
708
843
  function getAdminTextMessageType(m) {
709
844
  switch (m.type) {
845
+ case "joinable_group_link_mode_change":
846
+ return "log:link-status";
847
+ case "magic_words":
848
+ return "log:magic-words";
710
849
  case "change_thread_theme":
711
850
  return "log:thread-color";
712
851
  case "change_thread_icon":
@@ -722,52 +861,183 @@ function getAdminTextMessageType(m) {
722
861
  case "messenger_call_log":
723
862
  case "participant_joined_group_call":
724
863
  return "log:thread-call";
864
+ case "pin_messages_v2":
865
+ return "log:thread-pinned";
725
866
  }
726
867
  }
727
868
 
869
+ /**
870
+ * @param {string} name
871
+ */
872
+
873
+ function getGenderByPhysicalMethod(name) {
874
+ var GirlName = ["LAN", "HÂN", "LINH", "MAI", "HOA", "THU", "BĂNG", "MỸ", "CHÂU", "THẢO", "THOA", "MẪN", "THÙY", "THỦY", "NGA", "NGÂN", "NGHI", "THƯ", "NGỌC", "BÍCH", "VÂN", "DIỆP", "CHI", "TIÊN", "XUÂN", "GIANG", "NHUNG", "DUNG", "NHƯ", "YẾN", "QUYÊN", "YẾN", "TƯỜNG", "VY", "PHƯƠNG", "LIÊN", "LAN", "HÀ", "MAI", "ĐAN", "HẠ", "QUYÊN", "LY", "HÒA", "OANH", "HƯƠNG", "HẰNG", "QUỲNH", "HẠNH", "NHIÊN", "NHẠN"];
875
+
876
+ var BoyName = ["HƯNG", "HUY", "KHẢI", "KHANG", "KHOA", "KHÔI", "KIÊN", "KIỆT", "LONG", "MINH", "ÂN", "BẢO", "BÌNH", "CƯỜNG", "ĐẠT", "ĐỨC", "DŨNG", "DUY", "HOÀNG", "HÙNG", "HƯNG", "NGHĨA", "NGUYÊN", "THẮNG", "THIỆN", "THỊNH", "TÒA", "TRIẾT", "TRUNG", "TRƯỜNG", "TUẤN", "NHÂN", "VŨ", "VINH", "PHONG", "PHÚC", "QUÂN", "QUANG", "SƠN", "TÀI", "THẮNG", "ĐĂNG", "VĂN", "VĨ", "QUANG", "MẠNH"];
877
+
878
+ var OtherName = ["ANH", "THANH", "TÂM", "DƯƠNG", "AN", "LÂM", "MIÊN", "TÚ", "LÂM", "BẰNG", "KHÁNH", "NHẬT", "VỸ", ".",",","/","%", "&","*","-","+"];
879
+
880
+ try {
881
+ var NameArray = name.split(" ");
882
+ name = NameArray[NameArray.length - 1];
883
+ var Name;
884
+ if (name == " " || name == null) return "UNKNOWN";
885
+ switch (GirlName.includes(name.toUpperCase())) {
886
+ case true: {
887
+ if (!OtherName.includes(name.toUpperCase()) && !BoyName.includes(name.toUpperCase())) Name = "FEMALE";
888
+ else Name = ['FEMALE','MALE'][Math.floor(Math.random() * 2)]; // just temp 🌚
889
+ }
890
+ break;
891
+ case false: {
892
+ if (!OtherName.includes(name.toUpperCase()) && !GirlName.includes(name.toUpperCase())) Name = "MALE";
893
+ else Name = ['FEMALE','MALE'][Math.floor(Math.random() * 2)]; // just temp 🌚
894
+ }
895
+ break;
896
+ }
897
+ }
898
+ catch (e) {
899
+ return "UNKNOWN";
900
+ }
901
+ return Name || "UNKNOWN";
902
+ }
903
+
904
+ /**
905
+ * @param {{ [x: string]: { [x: string]: { [x: string]: any; }; }; class: any; untypedData: any; name: any; addedParticipants: any; leftParticipantFbId: any; messageMetadata: { threadKey: { threadFbId: any; otherUserFbId: any; }; adminText: any; actorFbId: any; }; participants: any; }} m
906
+ */
907
+
728
908
  function formatDeltaEvent(m) {
909
+ var { updateData,getData,hasData } = require('./Extra/ExtraGetThread');
729
910
  var logMessageType;
730
911
  var logMessageData;
731
912
 
732
- // log:thread-color => {theme_color}
733
- // log:user-nickname => {participant_id, nickname}
734
- // log:thread-icon => {thread_icon}
735
- // log:thread-name => {name}
736
- // log:subscribe => {addedParticipants - [Array]}
737
- // log:unsubscribe => {leftParticipantFbId}
738
-
739
- switch (m.class) {
740
- case "AdminTextMessage":
741
- logMessageType = getAdminTextMessageType(m);
913
+ switch (m.class) {
914
+ case "AdminTextMessage":
915
+ logMessageType = getAdminTextMessageType(m);
742
916
  logMessageData = m.untypedData;
743
- break;
744
- case "ThreadName":
745
- logMessageType = "log:thread-name";
917
+ break;
918
+ case "ThreadName":
919
+ logMessageType = "log:thread-name";
746
920
  logMessageData = { name: m.name };
747
- break;
748
- case "ParticipantsAddedToGroupThread":
749
- logMessageType = "log:subscribe";
921
+ break;
922
+ case "ParticipantsAddedToGroupThread":
923
+ logMessageType = "log:subscribe";
750
924
  logMessageData = { addedParticipants: m.addedParticipants };
925
+ break;
926
+ case "ParticipantLeftGroupThread":
927
+ logMessageType = "log:unsubscribe";
928
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
929
+ break;
930
+ case "UserLocation": {
931
+ logMessageType = "log:user-location";
932
+ logMessageData = {
933
+ Image: m.attachments[0].mercury.extensible_attachment.story_attachment.media.image,
934
+ Location: m.attachments[0].mercury.extensible_attachment.story_attachment.target.location_title,
935
+ coordinates: m.attachments[0].mercury.extensible_attachment.story_attachment.target.coordinate,
936
+ url: m.attachments[0].mercury.extensible_attachment.story_attachment.url
937
+ };
938
+ }
939
+ }
940
+ switch (hasData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()))) {
941
+ case true: {
942
+ switch (logMessageType) {
943
+ case "log:thread-color": {
944
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
945
+ x.emoji = (logMessageData.theme_emoji || x.emoji);
946
+ x.color = (logMessageData['theme_color'] || x.color);
947
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
948
+ }
949
+ break;
950
+ case "log:thread-icon": {
951
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
952
+ x.emoji = (logMessageData['thread_icon'] || x.emoji);
953
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
954
+ }
955
+ break;
956
+ case "log:user-nickname": {
957
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
958
+ x.nicknames[logMessageData.participant_id] = (logMessageData.nickname.length == 0 ? x.userInfo.find(i => i.id == String(logMessageData.participant_id)).name : logMessageData.nickname);
959
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
960
+ }
961
+ break;
962
+ case "log:thread-admins": {
963
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
964
+ switch (logMessageData.ADMIN_EVENT) {
965
+ case "add_admin": {
966
+ x.adminIDs.push({ id: logMessageData.TARGET_ID });
967
+ }
968
+ break;
969
+ case "remove_admin": {
970
+ x.adminIDs = x.adminIDs.filter(item => item.id != logMessageData.TARGET_ID);
971
+ }
972
+ break;
973
+ }
974
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
975
+ }
976
+ break;
977
+ case "log:thread-approval-mode": {
978
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
979
+ if (x.approvalMode == true) {
980
+ x.approvalMode = false;
981
+ }
982
+ else {
983
+ x.approvalMode = true;
984
+ }
985
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
986
+ }
987
+ break;
988
+ case "log:thread-name": {
989
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
990
+ x.threadName = (logMessageData.name || formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
991
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
992
+ }
993
+ break;
994
+ case "log:subscribe": {
995
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
996
+ for (let o of logMessageData.addedParticipants) {
997
+ if (x.userInfo.some(i => i.id == o.userFbId)) continue;
998
+ else {
999
+ x.userInfo.push({
1000
+ id: o.userFbId,
1001
+ name: o.fullName,
1002
+ gender: getGenderByPhysicalMethod(o.fullName)
1003
+ });
1004
+ x.participantIDs.push(o.userFbId);
1005
+ }
1006
+ }
1007
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
1008
+ }
1009
+ break;
1010
+ case "log:unsubscribe": {
1011
+ let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
1012
+ x.participantIDs = x.participantIDs.filter(item => item != logMessageData.leftParticipantFbId);
1013
+ x.userInfo = x.userInfo.filter(item => item.id != logMessageData.leftParticipantFbId);
1014
+ if (x.adminIDs.some(i => i.id == logMessageData.leftParticipantFbId)) {
1015
+ x.adminIDs = x.adminIDs.filter(item => item.id != logMessageData.leftParticipantFbId);
1016
+ }
1017
+ updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
1018
+ }
751
1019
  break;
752
- case "ParticipantLeftGroupThread":
753
- logMessageType = "log:unsubscribe";
754
- logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
755
- break;
1020
+ }
756
1021
  }
1022
+ }
757
1023
 
758
- return {
759
- type: "event",
760
- threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
761
- logMessageType: logMessageType,
762
- logMessageData: logMessageData,
763
- logMessageBody: m.messageMetadata.adminText,
764
- author: m.messageMetadata.actorFbId,
765
- participantIDs: m.participants || []
766
- };
1024
+ return {
1025
+ type: "event",
1026
+ threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
1027
+ logMessageType: logMessageType,
1028
+ logMessageData: logMessageData,
1029
+ logMessageBody: m.messageMetadata.adminText,
1030
+ author: m.messageMetadata.actorFbId,
1031
+ participantIDs: m.participants || []
1032
+ };
767
1033
  }
768
1034
 
1035
+ /**
1036
+ * @param {{ st: any; from: { toString: () => any; }; to: any; thread_fbid: any; hasOwnProperty: (arg0: string) => any; from_mobile: any; realtime_viewer_fbid: any; }} event
1037
+ */
1038
+
769
1039
  function formatTyp(event) {
770
- return {
1040
+ return {
771
1041
  isTyping: !!event.st,
772
1042
  from: event.from.toString(),
773
1043
  threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
@@ -779,6 +1049,10 @@ function formatTyp(event) {
779
1049
  };
780
1050
  }
781
1051
 
1052
+ /**
1053
+ * @param {{ threadKey: { otherUserFbId: any; threadFbId: any; }; actorFbId: any; actionTimestampMs: any; }} delta
1054
+ */
1055
+
782
1056
  function formatDeltaReadReceipt(delta) {
783
1057
  // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
784
1058
  // In a group chat actorFbId is used for the reader and threadFbId for the thread.
@@ -790,6 +1064,10 @@ function formatDeltaReadReceipt(delta) {
790
1064
  };
791
1065
  }
792
1066
 
1067
+ /**
1068
+ * @param {{ reader: { toString: () => any; }; time: any; thread_fbid: any; }} event
1069
+ */
1070
+
793
1071
  function formatReadReceipt(event) {
794
1072
  return {
795
1073
  reader: event.reader.toString(),
@@ -799,6 +1077,10 @@ function formatReadReceipt(event) {
799
1077
  };
800
1078
  }
801
1079
 
1080
+ /**
1081
+ * @param {{ chat_ids: any[]; thread_fbids: any[]; timestamp: any; }} event
1082
+ */
1083
+
802
1084
  function formatRead(event) {
803
1085
  return {
804
1086
  threadID: formatID(((event.chat_ids && event.chat_ids[0]) || (event.thread_fbids && event.thread_fbids[0])).toString()),
@@ -807,6 +1089,12 @@ function formatRead(event) {
807
1089
  };
808
1090
  }
809
1091
 
1092
+ /**
1093
+ * @param {string} str
1094
+ * @param {string | any[]} startToken
1095
+ * @param {string} endToken
1096
+ */
1097
+
810
1098
  function getFrom(str, startToken, endToken) {
811
1099
  var start = str.indexOf(startToken) + startToken.length;
812
1100
  if (start < startToken.length) return "";
@@ -817,8 +1105,13 @@ function getFrom(str, startToken, endToken) {
817
1105
  return lastHalf.substring(0, end);
818
1106
  }
819
1107
 
1108
+ /**
1109
+ * @param {string} html
1110
+ */
1111
+
820
1112
  function makeParsable(html) {
821
- let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
1113
+ let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/
1114
+ , "");
822
1115
 
823
1116
  // (What the fuck FB, why windows style newlines?)
824
1117
  // So sometimes FB will send us base multiple objects in the same response.
@@ -835,19 +1128,30 @@ function makeParsable(html) {
835
1128
  return "[" + maybeMultipleObjects.join("},{") + "]";
836
1129
  }
837
1130
 
1131
+ /**
1132
+ * @param {any} form
1133
+ */
1134
+
838
1135
  function arrToForm(form) {
839
1136
  return arrayToObject(form,
840
- function(v) {
1137
+ function(/** @type {{ name: any; }} */v) {
841
1138
  return v.name;
842
1139
  },
843
- function(v) {
1140
+ function(/** @type {{ val: any; }} */v) {
844
1141
  return v.val;
845
1142
  }
846
1143
  );
847
1144
  }
848
1145
 
1146
+ /**
1147
+ * @param {any[]} arr
1148
+ * @param {{ (v: any): any; (arg0: any): string | number; }} getKey
1149
+ * @param {{ (v: any): any; (arg0: any): any; }} getValue
1150
+ */
1151
+
849
1152
  function arrayToObject(arr, getKey, getValue) {
850
- return arr.reduce(function(acc, val) {
1153
+ return arr.reduce(function(/** @type {{ [x: string]: any; }} */
1154
+ acc, /** @type {any} */val) {
851
1155
  acc[getKey(val)] = getValue(val);
852
1156
  return acc;
853
1157
  }, {});
@@ -862,6 +1166,12 @@ function generateTimestampRelative() {
862
1166
  return d.getHours() + ":" + padZeros(d.getMinutes());
863
1167
  }
864
1168
 
1169
+ /**
1170
+ * @param {any} html
1171
+ * @param {any} userID
1172
+ * @param {{ fb_dtsg: any; ttstamp: any; globalOptions: any; }} ctx
1173
+ */
1174
+
865
1175
  function makeDefaults(html, userID, ctx) {
866
1176
  var reqCounter = 1;
867
1177
  var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
@@ -885,6 +1195,10 @@ function makeDefaults(html, userID, ctx) {
885
1195
  for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
886
1196
  var revision = getFrom(html, 'revision":', ",");
887
1197
 
1198
+ /**
1199
+ * @param {{ [x: string]: any; hasOwnProperty: (arg0: string) => any; }} obj
1200
+ */
1201
+
888
1202
  function mergeWithDefaults(obj) {
889
1203
  // @TODO This is missing a key called __dyn.
890
1204
  // After some investigation it seems like __dyn is some sort of set that FB
@@ -925,14 +1239,36 @@ function makeDefaults(html, userID, ctx) {
925
1239
  return newObj;
926
1240
  }
927
1241
 
1242
+ /**
1243
+ * @param {any} url
1244
+ * @param {any} jar
1245
+ * @param {any} form
1246
+ * @param {any} ctxx
1247
+ */
1248
+
928
1249
  function postWithDefaults(url, jar, form, ctxx) {
929
1250
  return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx);
930
1251
  }
931
1252
 
1253
+ /**
1254
+ * @param {any} url
1255
+ * @param {any} jar
1256
+ * @param {any} qs
1257
+ * @param {any} ctxx
1258
+ */
1259
+
932
1260
  function getWithDefaults(url, jar, qs, ctxx) {
933
1261
  return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
934
1262
  }
935
1263
 
1264
+ /**
1265
+ * @param {any} url
1266
+ * @param {any} jar
1267
+ * @param {any} form
1268
+ * @param {any} qs
1269
+ * @param {any} ctxx
1270
+ */
1271
+
936
1272
  function postFormDataWithDefault(url, jar, form, qs, ctxx) {
937
1273
  return postFormData(url, jar, mergeWithDefaults(form), mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
938
1274
  }
@@ -944,9 +1280,15 @@ function makeDefaults(html, userID, ctx) {
944
1280
  };
945
1281
  }
946
1282
 
1283
+ /**
1284
+ * @param {{ jar: { setCookie: (arg0: string, arg1: string) => void; }; fb_dtsg: string; ttstamp: string; }} ctx
1285
+ * @param {{ postFormData: (arg0: string, arg1: any, arg2: any, arg3: {}) => any; post: (arg0: string, arg1: any, arg2: any) => any; get: (arg0: any, arg1: any) => Promise<any>; }} defaultFuncs
1286
+ * @param {string | number} [retryCount]
1287
+ */
1288
+
947
1289
  function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
948
1290
  if (retryCount == undefined) retryCount = 0;
949
- return function(data) {
1291
+ return function(/** @type {{ body: string; statusCode: string | number; request: { uri: { protocol: string; hostname: string; pathname: string; }; headers: { [x: string]: string; }; formData: any; method: string; }; }} */data) {
950
1292
  return bluebird.try(function() {
951
1293
  log.verbose("parseAndCheckLogin", data.body);
952
1294
  if (data.statusCode >= 500 && data.statusCode < 600) {
@@ -961,8 +1303,13 @@ function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
961
1303
  var retryTime = Math.floor(Math.random() * 5000);
962
1304
  log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
963
1305
  var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
964
- if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {})).then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
965
- else return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData)).then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1306
+ if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
1307
+ return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
1308
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1309
+ } else {
1310
+ return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
1311
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1312
+ }
966
1313
  }
967
1314
  if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
968
1315
 
@@ -1004,19 +1351,34 @@ function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
1004
1351
  }
1005
1352
  }
1006
1353
 
1007
- if (res.error === 1357001) throw { error: "Not logged in." };
1008
- return res;
1354
+ if (res.error === 1357001) {
1355
+ if (global.Fca.Require.FastConfig.AutoLogin) {
1356
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
1357
+ return global.Fca.Action('AutoLogin');
1358
+ });
1359
+ }
1360
+ else if (!global.Fca.Require.FastConfig.AutoLogin) {
1361
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
1362
+ }
1363
+ return;
1364
+ }
1365
+ else return res;
1009
1366
  });
1010
1367
  };
1011
1368
  }
1012
1369
 
1370
+ /**
1371
+ * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
1372
+ */
1373
+
1013
1374
  function saveCookies(jar) {
1014
- return function(res) {
1375
+ return function(/** @type {{ headers: { [x: string]: any[]; }; }} */res) {
1015
1376
  var cookies = res.headers["set-cookie"] || [];
1016
- cookies.forEach(function(c) {
1017
- if (c.indexOf(".facebook.com") > -1) jar.setCookie(c, "https://www.facebook.com");
1018
- var c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1019
- jar.setCookie(c2, "https://www.messenger.com");
1377
+ cookies.forEach(function(/** @type {string} */c) {
1378
+ if (c.indexOf(".facebook.com") > -1) { // yo wtf is this?
1379
+ jar.setCookie(c, "https://www.facebook.com");
1380
+ jar.setCookie(c.replace(/domain=\.facebook\.com/, "domain=.messenger.com"), "https://www.messenger.com");
1381
+ }
1020
1382
  });
1021
1383
  return res;
1022
1384
  };
@@ -1038,22 +1400,35 @@ var NUM_TO_MONTH = [
1038
1400
  ];
1039
1401
  var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1040
1402
 
1403
+ /**
1404
+ * @param {{ getUTCDate: () => any; getUTCHours: () => any; getUTCMinutes: () => any; getUTCSeconds: () => any; getUTCDay: () => string | number; getUTCMonth: () => string | number; getUTCFullYear: () => string; }} date
1405
+ */
1406
+
1041
1407
  function formatDate(date) {
1042
1408
  var d = date.getUTCDate();
1043
- d = d >= 10 ? d : `0${d}`;
1409
+ d = d >= 10 ? d : "0" + d;
1044
1410
  var h = date.getUTCHours();
1045
- h = h >= 10 ? h : `0${h}`;
1411
+ h = h >= 10 ? h : "0" + h;
1046
1412
  var m = date.getUTCMinutes();
1047
- m = m >= 10 ? m : `0${m}`;
1413
+ m = m >= 10 ? m : "0" + m;
1048
1414
  var s = date.getUTCSeconds();
1049
- s = s >= 10 ? s : `0${s}`;
1050
- return `${NUM_TO_DAY[date.getUTCDay()]}, ${d} ${NUM_TO_MONTH[date.getUTCMonth()]} ${date.getUTCFullYear()} ${h}:${m}:${s} GMT`;
1415
+ s = s >= 10 ? s : "0" + s;
1416
+ return (NUM_TO_DAY[date.getUTCDay()] + ", " + d + " " + NUM_TO_MONTH[date.getUTCMonth()] + " " + date.getUTCFullYear() + " " + h + ":" + m + ":" + s + " GMT");
1051
1417
  }
1052
1418
 
1419
+ /**
1420
+ * @param {string[]} arr
1421
+ * @param {string} url
1422
+ */
1423
+
1053
1424
  function formatCookie(arr, url) {
1054
1425
  return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com";
1055
1426
  }
1056
1427
 
1428
+ /**
1429
+ * @param {{ thread_fbid: { toString: () => any; }; participants: any[]; name: any; custom_nickname: any; snippet: any; snippet_attachments: any; snippet_sender: any; unread_count: any; message_count: any; image_src: any; timestamp: any; mute_until: any; is_canonical_user: any; is_canonical: any; is_subscribed: any; folder: any; is_archived: any; recipients_loadable: any; has_email_participant: any; read_only: any; can_reply: any; cannot_reply_reason: any; last_message_timestamp: any; last_read_timestamp: any; last_message_type: any; custom_like_icon: any; custom_color: any; admin_ids: any; thread_type: any; }} data
1430
+ */
1431
+
1057
1432
  function formatThread(data) {
1058
1433
  return {
1059
1434
  threadID: formatID(data.thread_fbid.toString()),
@@ -1068,7 +1443,6 @@ function formatThread(data) {
1068
1443
  messageCount: data.message_count,
1069
1444
  imageSrc: data.image_src,
1070
1445
  timestamp: data.timestamp,
1071
- serverTimestamp: data.server_timestamp, // what is this?
1072
1446
  muteUntil: data.mute_until,
1073
1447
  isCanonicalUser: data.is_canonical_user,
1074
1448
  isCanonical: data.is_canonical,
@@ -1090,10 +1464,19 @@ function formatThread(data) {
1090
1464
  };
1091
1465
  }
1092
1466
 
1467
+ /**
1468
+ * @param {any} obj
1469
+ */
1470
+
1093
1471
  function getType(obj) {
1094
1472
  return Object.prototype.toString.call(obj).slice(8, -1);
1095
1473
  }
1096
1474
 
1475
+ /**
1476
+ * @param {{ lat: number; p: any; }} presence
1477
+ * @param {any} userID
1478
+ */
1479
+
1097
1480
  function formatProxyPresence(presence, userID) {
1098
1481
  if (presence.lat === undefined || presence.p === undefined) return null;
1099
1482
  return {
@@ -1104,6 +1487,11 @@ function formatProxyPresence(presence, userID) {
1104
1487
  };
1105
1488
  }
1106
1489
 
1490
+ /**
1491
+ * @param {{ la: number; a: any; }} presence
1492
+ * @param {any} userID
1493
+ */
1494
+
1107
1495
  function formatPresence(presence, userID) {
1108
1496
  return {
1109
1497
  type: "presence",
@@ -1113,10 +1501,19 @@ function formatPresence(presence, userID) {
1113
1501
  };
1114
1502
  }
1115
1503
 
1504
+ /**
1505
+ * @param {any} payload
1506
+ */
1507
+
1116
1508
  function decodeClientPayload(payload) {
1117
1509
  /*
1118
1510
  Special function which Client using to "encode" clients JSON payload
1119
1511
  */
1512
+
1513
+ /**
1514
+ * @param {string | any[]} array
1515
+ */
1516
+
1120
1517
  function Utf8ArrayToStr(array) {
1121
1518
  var out, i, len, c;
1122
1519
  var char2, char3;
@@ -1142,7 +1539,7 @@ function decodeClientPayload(payload) {
1142
1539
  out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
1143
1540
  break;
1144
1541
  case 14:
1145
- char2 = array[i++];
1542
+ char2 = array[i++];
1146
1543
  char3 = array[i++];
1147
1544
  out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
1148
1545
  break;
@@ -1153,25 +1550,113 @@ function decodeClientPayload(payload) {
1153
1550
  return JSON.parse(Utf8ArrayToStr(payload));
1154
1551
  }
1155
1552
 
1156
- function getAppState(jar) {
1157
- return jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1553
+ /**
1554
+ * @param {{ getCookies: (arg0: string) => string | any[]; }} jar
1555
+ */
1556
+
1557
+ function getAppState(jar, Encode) {
1558
+ var prettyMilliseconds = require('pretty-ms');
1559
+ var getText = globalThis.Fca.getText;
1560
+ var Security = require("./Extra/Security/Base");
1561
+ var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1562
+ var logger = require('./logger'),languageFile = require('./Language/index.json');
1563
+ var Language = languageFile.find(i => i.Language == globalThis.Fca.Require.FastConfig.Language).Folder.Index;
1564
+ var data;
1565
+ switch (require(process.cwd() + "/alice/database/alicization.json").EncryptFeature) {
1566
+ case true: {
1567
+ if (Encode == undefined) Encode = true;
1568
+ if (process.env['FBKEY'] != undefined && Encode) {
1569
+ logger.Normal(Language.EncryptSuccess);
1570
+ data = Security(JSON.stringify(appstate),process.env['FBKEY'],"Encrypt");
1571
+ }
1572
+ else return appstate;
1573
+ }
1574
+ break;
1575
+ case false: {
1576
+ data = appstate;
1577
+ }
1578
+ break;
1579
+ default: {
1580
+ logger.Normal(getText(Language.IsNotABoolean,require(process.cwd() + "/alice/database/alicization.json").EncryptFeature));
1581
+ data = appstate;
1582
+ }
1583
+ }
1584
+ if(!globalThis.Fca.Setting.get('getAppState')) {
1585
+ logger.Normal(getText(Language.ProcessDone,`${prettyMilliseconds(Date.now() - globalThis.Fca.startTime)}`),function() { globalThis.Fca.Setting.set('getAppState',true); });
1586
+ }
1587
+ return data;
1588
+ }
1589
+
1590
+ function getData_Path(Obj , Arr, Stt) {
1591
+ //default stt = 0
1592
+ if (Arr.length === 0 && Obj != undefined) {
1593
+ return Obj; //object
1594
+ }
1595
+ else if (Obj == undefined) {
1596
+ return Stt;
1597
+ }
1598
+ const head = Arr[0];
1599
+ if (head == undefined) {
1600
+ return Stt;
1601
+ }
1602
+ const tail = Arr.slice(1);
1603
+ return getData_Path(Obj[head], tail, Stt++);
1604
+ }
1605
+
1606
+
1607
+ function setData_Path(obj, path, value) {
1608
+ if (!path.length) {
1609
+ return obj;
1610
+ }
1611
+ const currentKey = path[0];
1612
+ let currentObj = obj[currentKey];
1613
+
1614
+ if (!currentObj) {
1615
+ obj[currentKey] = value;
1616
+ currentObj = obj[currentKey];
1617
+ }
1618
+ path.shift();
1619
+ if (!path.length) {
1620
+ currentObj = value;
1621
+ } else {
1622
+ currentObj = setData_Path(currentObj, path, value);
1623
+ }
1624
+
1625
+ return obj;
1626
+ }
1627
+
1628
+ function getPaths(obj, parentPath = []) {
1629
+ let paths = [];
1630
+ for (let prop in obj) {
1631
+ if (typeof obj[prop] === "object") {
1632
+ paths = paths.concat(getPaths(obj[prop], [...parentPath, prop]));
1633
+ } else {
1634
+ paths.push([...parentPath, prop]);
1635
+ }
1636
+ }
1637
+ return paths;
1158
1638
  }
1639
+
1159
1640
  module.exports = {
1160
- isReadableStream,
1161
- get,
1162
- post,
1163
- postFormData,
1164
- generateThreadingID,
1165
- generateOfflineThreadingID,
1166
- getGUID,
1167
- getFrom,
1168
- makeParsable,
1169
- arrToForm,
1170
- getSignatureID,
1641
+ isReadableStream:isReadableStream,
1642
+ get:get,
1643
+ post:post,
1644
+ postFormData:postFormData,
1645
+ generateThreadingID:generateThreadingID,
1646
+ generateOfflineThreadingID:generateOfflineThreadingID,
1647
+ getGUID:getGUID,
1648
+ getFrom:getFrom,
1649
+ makeParsable:makeParsable,
1650
+ arrToForm:arrToForm,
1651
+ getSignatureID:getSignatureID,
1171
1652
  getJar: request.jar,
1172
- generateTimestampRelative,
1173
- makeDefaults,
1174
- parseAndCheckLogin,
1653
+ generateTimestampRelative:generateTimestampRelative,
1654
+ makeDefaults:makeDefaults,
1655
+ parseAndCheckLogin:parseAndCheckLogin,
1656
+ getGender: getGenderByPhysicalMethod,
1657
+ getData_Path,
1658
+ setData_Path,
1659
+ getPaths,
1175
1660
  saveCookies,
1176
1661
  getType,
1177
1662
  _formatAttachment,