alicezetion 1.8.4 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/modules.stamp +1 -0
  3. package/.cache/replit/nix/env.json +1 -1
  4. package/index.js +375 -210
  5. package/leiamnash/addExternalModule.js +15 -0
  6. package/leiamnash/addUserToGroup.js +77 -0
  7. package/leiamnash/changeAdminStatus.js +47 -0
  8. package/leiamnash/changeArchivedStatus.js +41 -0
  9. package/leiamnash/changeAvatar.js +127 -0
  10. package/leiamnash/changeBio.js +64 -0
  11. package/leiamnash/changeBlockedStatus.js +36 -0
  12. package/leiamnash/changeGroupImage.js +105 -0
  13. package/leiamnash/changeNickname.js +43 -0
  14. package/leiamnash/changeThreadColor.js +61 -0
  15. package/leiamnash/changeThreadEmoji.js +41 -0
  16. package/{src → leiamnash}/chat.js +3 -28
  17. package/leiamnash/createNewGroup.js +70 -0
  18. package/leiamnash/createPoll.js +59 -0
  19. package/leiamnash/deleteMessage.js +44 -0
  20. package/leiamnash/deleteThread.js +42 -0
  21. package/leiamnash/forwardAttachment.js +47 -0
  22. package/leiamnash/forwardMessage.js +0 -0
  23. package/leiamnash/getCurrentUserID.js +7 -0
  24. package/leiamnash/getEmojiUrl.js +27 -0
  25. package/leiamnash/getFriendsList.js +73 -0
  26. package/leiamnash/getInfoVideo.js +134 -0
  27. package/leiamnash/getThreadHistory.js +537 -0
  28. package/leiamnash/getThreadHistoryDeprecated.js +71 -0
  29. package/{src → leiamnash}/getThreadInfo.js +54 -70
  30. package/leiamnash/getThreadInfoDeprecated.js +56 -0
  31. package/leiamnash/getThreadList.js +213 -0
  32. package/leiamnash/getThreadListDeprecated.js +46 -0
  33. package/leiamnash/getThreadPictures.js +59 -0
  34. package/leiamnash/getUserID.js +61 -0
  35. package/leiamnash/getUserInfo.js +66 -0
  36. package/leiamnash/handleFriendRequest.js +46 -0
  37. package/leiamnash/handleMessageRequest.js +47 -0
  38. package/leiamnash/httpGet.js +47 -0
  39. package/leiamnash/httpPost.js +47 -0
  40. package/leiamnash/httpPostFormData.js +42 -0
  41. package/{src → leiamnash}/listenMqtt.js +6 -16
  42. package/leiamnash/logout.js +68 -0
  43. package/leiamnash/markAsDelivered.js +47 -0
  44. package/leiamnash/markAsRead.js +70 -0
  45. package/leiamnash/markAsReadAll.js +40 -0
  46. package/leiamnash/markAsSeen.js +48 -0
  47. package/leiamnash/muteThread.js +45 -0
  48. package/leiamnash/react.js +109 -0
  49. package/{src → leiamnash}/refreshFb_dtsg.js +1 -1
  50. package/leiamnash/removeUserFromGroup.js +45 -0
  51. package/leiamnash/resolvePhotoUrl.js +36 -0
  52. package/leiamnash/searchForThread.js +42 -0
  53. package/leiamnash/seen.js +40 -0
  54. package/leiamnash/sendMessage.js +315 -0
  55. package/leiamnash/sendTypingIndicator.js +70 -0
  56. package/leiamnash/setMessageReaction.js +103 -0
  57. package/leiamnash/setPostReaction.js +63 -0
  58. package/leiamnash/setTitle.js +70 -0
  59. package/leiamnash/threadColors.js +41 -0
  60. package/leiamnash/unfriend.js +42 -0
  61. package/leiamnash/unsendMessage.js +39 -0
  62. package/leiamnash/uploadAttachment.js +96 -0
  63. package/package.json +3 -6
  64. package/replit.nix +4 -4
  65. package/utils.js +176 -135
  66. package/src/addExternalModule.js +0 -17
  67. package/src/addUserToGroup.js +0 -113
  68. package/src/changeAdminStatus.js +0 -79
  69. package/src/changeArchivedStatus.js +0 -55
  70. package/src/changeAvatar.js +0 -93
  71. package/src/changeBio.js +0 -77
  72. package/src/changeBlockedStatus.js +0 -47
  73. package/src/changeCover.js +0 -73
  74. package/src/changeGroupImage.js +0 -132
  75. package/src/changeName.js +0 -79
  76. package/src/changeNickname.js +0 -59
  77. package/src/changeThreadColor.js +0 -65
  78. package/src/changeThreadEmoji.js +0 -55
  79. package/src/createNewGroup.js +0 -86
  80. package/src/createPoll.js +0 -71
  81. package/src/data/getThreadInfo.json +0 -1
  82. package/src/deleteMessage.js +0 -56
  83. package/src/deleteThread.js +0 -56
  84. package/src/forwardAttachment.js +0 -60
  85. package/src/getAccess.js +0 -112
  86. package/src/getAvatarUser.js +0 -78
  87. package/src/getCurrentUserID.js +0 -7
  88. package/src/getEmojiUrl.js +0 -29
  89. package/src/getFriendsList.js +0 -83
  90. package/src/getThreadHistory.js +0 -666
  91. package/src/getThreadList.js +0 -237
  92. package/src/getThreadPictures.js +0 -79
  93. package/src/getUserID.js +0 -66
  94. package/src/getUserInfo.js +0 -163
  95. package/src/handleFriendRequest.js +0 -61
  96. package/src/handleMessageRequest.js +0 -65
  97. package/src/httpGet.js +0 -57
  98. package/src/httpPost.js +0 -57
  99. package/src/httpPostFormData.js +0 -63
  100. package/src/listenNotification.js +0 -88
  101. package/src/logout.js +0 -275
  102. package/src/markAsDelivered.js +0 -58
  103. package/src/markAsRead.js +0 -80
  104. package/src/markAsReadAll.js +0 -50
  105. package/src/markAsSeen.js +0 -59
  106. package/src/muteThread.js +0 -52
  107. package/src/react.js +0 -117
  108. package/src/removeUserFromGroup.js +0 -79
  109. package/src/resolvePhotoUrl.js +0 -45
  110. package/src/searchForThread.js +0 -53
  111. package/src/searchStickers.js +0 -52
  112. package/src/seen.js +0 -50
  113. package/src/sendMessage.js +0 -477
  114. package/src/sendMessageMqtt.js +0 -316
  115. package/src/sendTypingIndicator.js +0 -103
  116. package/src/setMessageReaction.js +0 -117
  117. package/src/setPostReaction.js +0 -109
  118. package/src/setTitle.js +0 -86
  119. package/src/threadColors.js +0 -131
  120. package/src/unfriend.js +0 -52
  121. package/src/unsendMessage.js +0 -49
  122. /package/{src → leiamnash}/getMessage.js +0 -0
package/utils.js CHANGED
@@ -1,23 +1,40 @@
1
+ /* eslint-disable no-prototype-builtins */
1
2
  "use strict";
2
3
 
3
- let request = require("request").defaults({ jar: true });
4
+ const bluebird = require("bluebird");
5
+ let request = bluebird.promisify(require("request").defaults({ jar: true, proxy: process.env.FB_PROXY }));
4
6
  const stream = require("stream");
5
7
  const log = require("npmlog");
6
8
  const querystring = require("querystring");
7
9
  const url = require("url");
8
10
 
9
- function setProxy(proxy) {
10
- if (typeof proxy == 'string')
11
- request = require("request").defaults({ jar: true, proxy });
12
- else request = request;
13
- return;
11
+ class CustomError extends Error {
12
+ constructor(obj) {
13
+ if (typeof obj === 'string')
14
+ obj = { message: obj };
15
+ if (typeof obj !== 'object' || obj === null)
16
+ throw new TypeError('Object required');
17
+ obj.message ? super(obj.message) : super();
18
+ Object.assign(this, obj);
19
+ }
20
+ }
21
+
22
+ function setProxy(url) {
23
+ if (typeof url == "undefined")
24
+ return request = bluebird.promisify(require("request").defaults({
25
+ jar: true
26
+ }));
27
+ return request = bluebird.promisify(require("request").defaults({
28
+ jar: true,
29
+ proxy: url
30
+ }));
14
31
  }
15
32
 
16
33
  function getHeaders(url, options, ctx, customHeader) {
17
- var headers = {
34
+ const headers = {
18
35
  "Content-Type": "application/x-www-form-urlencoded",
19
36
  Referer: "https://www.facebook.com/",
20
- Host: new URL(url).hostname,
37
+ Host: url.replace("https://", "").split("/")[0],
21
38
  Origin: "https://www.facebook.com",
22
39
  "User-Agent": options.userAgent,
23
40
  Connection: "keep-alive",
@@ -26,10 +43,9 @@ function getHeaders(url, options, ctx, customHeader) {
26
43
  if (customHeader) {
27
44
  Object.assign(headers, customHeader);
28
45
  }
29
- if (customHeader && customHeader.noRef)
30
- delete headers.Referer;
31
- if (ctx && ctx.region)
32
- headers["X-MSGR-Region"] = ctx.region;
46
+ if (ctx && ctx.region) {
47
+ headers["X-MSGR-Region"] = ctx.region;
48
+ }
33
49
 
34
50
  return headers;
35
51
  }
@@ -43,7 +59,7 @@ function isReadableStream(obj) {
43
59
  );
44
60
  }
45
61
 
46
- function get(url, jar, qs, options, ctx, customHeader) {
62
+ function get(url, jar, qs, options, ctx) {
47
63
  // I'm still confused about this
48
64
  if (getType(qs) === "Object") {
49
65
  for (const prop in qs) {
@@ -53,7 +69,7 @@ function get(url, jar, qs, options, ctx, customHeader) {
53
69
  }
54
70
  }
55
71
  const op = {
56
- headers: getHeaders(url, options, ctx, customHeader),
72
+ headers: getHeaders(url, options, ctx),
57
73
  timeout: 60000,
58
74
  qs: qs,
59
75
  url: url,
@@ -62,39 +78,31 @@ function get(url, jar, qs, options, ctx, customHeader) {
62
78
  gzip: true
63
79
  };
64
80
 
65
- var callback;
66
- var returnPromise = new Promise(function (resolve, reject) {
67
- callback = (error, data) => error != null ? reject(error) : resolve(data);
68
- });
69
- request(op, callback);
70
-
71
- return returnPromise;
81
+ return request(op).then(function (res) {
82
+ return Array.isArray(res) ? res[0] : res;
83
+ });
72
84
  }
73
85
 
74
86
  function post(url, jar, form, options, ctx, customHeader) {
75
- var op = {
76
- headers: getHeaders(url, options, ctx, customHeader),
77
- timeout: 60000,
87
+ const op = {
88
+ headers: getHeaders(url, options, ctx, customHeader),
89
+ timeout: 60000,
78
90
  url: url,
79
91
  method: "POST",
80
92
  form: form,
81
93
  jar: jar,
82
94
  gzip: true
83
- }
84
-
85
- var callback;
86
- var returnPromise = new Promise(function (resolve, reject) {
87
- callback = (error, data) => error != null ? reject(error) : resolve(data);
88
- });
89
- request(op, callback);
95
+ };
90
96
 
91
- return returnPromise;
97
+ return request(op).then(function (res) {
98
+ return Array.isArray(res) ? res[0] : res;
99
+ });
92
100
  }
93
101
 
94
102
  function postFormData(url, jar, form, qs, options, ctx) {
95
- var headers = getHeaders(url, options, ctx);
103
+ const headers = getHeaders(url, options, ctx);
96
104
  headers["Content-Type"] = "multipart/form-data";
97
- var op = {
105
+ const op = {
98
106
  headers: headers,
99
107
  timeout: 60000,
100
108
  url: url,
@@ -105,13 +113,9 @@ function postFormData(url, jar, form, qs, options, ctx) {
105
113
  gzip: true
106
114
  };
107
115
 
108
- var callback;
109
- var returnPromise = new Promise(function (resolve, reject) {
110
- callback = (error, data) => error != null ? reject(error) : resolve(data);
111
- });
112
- request(op, callback);
113
-
114
- return returnPromise;
116
+ return request(op).then(function (res) {
117
+ return Array.isArray(res) ? res[0] : res;
118
+ });
115
119
  }
116
120
 
117
121
  function padZeros(val, len) {
@@ -748,7 +752,6 @@ function formatDeltaMessage(m) {
748
752
  m_offset[i] + m_length[i]
749
753
  );
750
754
  }
751
-
752
755
  return {
753
756
  type: "message",
754
757
  senderID: formatID(md.actorFbId.toString()),
@@ -761,7 +764,7 @@ function formatDeltaMessage(m) {
761
764
  mentions: mentions,
762
765
  timestamp: md.timestamp,
763
766
  isGroup: !!md.threadKey.threadFbId,
764
- participantIDs: m.delta.participants
767
+ participantIDs: m.delta.participants || (md.cid ? md.cid.canonicalParticipantFbids : []) || []
765
768
  };
766
769
  }
767
770
 
@@ -857,10 +860,6 @@ function formatHistoryMessage(m) {
857
860
  // Get a more readable message type for AdminTextMessages
858
861
  function getAdminTextMessageType(type) {
859
862
  switch (type) {
860
- case 'unpin_messages_v2':
861
- return 'log:unpin-message';
862
- case 'pin_messages_v2':
863
- return 'log:pin-message';
864
863
  case "change_thread_theme":
865
864
  return "log:thread-color";
866
865
  case "change_thread_icon":
@@ -935,7 +934,7 @@ function formatDeltaEvent(m) {
935
934
  logMessageBody: m.messageMetadata.adminText,
936
935
  timestamp: m.messageMetadata.timestamp,
937
936
  author: m.messageMetadata.actorFbId,
938
- participantIDs: m.participants
937
+ participantIDs: (m.participants || []).map(p => p.toString())
939
938
  };
940
939
  }
941
940
 
@@ -996,7 +995,7 @@ function getFrom(str, startToken, endToken) {
996
995
  const lastHalf = str.substring(start);
997
996
  const end = lastHalf.indexOf(endToken);
998
997
  if (end === -1) {
999
- throw Error(
998
+ throw new Error(
1000
999
  "Could not find endTime `" + endToken + "` in the given string."
1001
1000
  );
1002
1001
  }
@@ -1086,17 +1085,16 @@ function makeDefaults(html, userID, ctx) {
1086
1085
  //
1087
1086
  // Ben - July 15th 2017
1088
1087
  const newObj = {
1089
- av: userID,
1090
1088
  __user: userID,
1091
1089
  __req: (reqCounter++).toString(36),
1092
1090
  __rev: revision,
1093
1091
  __a: 1,
1094
- //__af: siteData.features,
1092
+ // __af: siteData.features,
1095
1093
  fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
1096
1094
  jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
1097
- //__spin_r: siteData.__spin_r,
1098
- //__spin_b: siteData.__spin_b,
1099
- //__spin_t: siteData.__spin_t,
1095
+ // __spin_r: siteData.__spin_r,
1096
+ // __spin_b: siteData.__spin_b,
1097
+ // __spin_t: siteData.__spin_t,
1100
1098
  };
1101
1099
 
1102
1100
  // @TODO this is probably not needed.
@@ -1147,78 +1145,118 @@ function makeDefaults(html, userID, ctx) {
1147
1145
  };
1148
1146
  }
1149
1147
 
1150
- function parseAndCheckLogin(ctx, http, retryCount) {
1151
- var delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
1152
- var _try = (tryData) => new Promise(function (resolve, reject) {
1153
- try {
1154
- resolve(tryData());
1155
- } catch (error) {
1156
- reject(error);
1157
- }
1158
- });
1159
- if (retryCount == undefined) retryCount = 0;
1160
-
1148
+ function parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall) {
1149
+ if (retryCount == undefined) {
1150
+ retryCount = 0;
1151
+ }
1152
+ if (sourceCall == undefined) {
1153
+ try {
1154
+ throw new Error();
1155
+ }
1156
+ catch (e) {
1157
+ sourceCall = e;
1158
+ }
1159
+ }
1161
1160
  return function (data) {
1162
- function any() {
1163
- log.verbose("parseAndCheckLogin", data.body);
1164
- if (data.statusCode >= 500 && data.statusCode < 600) {
1165
- if (retryCount >= 5) {
1166
- const err = new Error("Request retry failed. Check the `res` and `statusCode` property on this error.");
1167
- err.statusCode = data.statusCode;
1168
- err.res = data.body;
1169
- err.error = "Request retry failed. Check the `res` and `statusCode` property on this error.";
1170
- throw err;
1171
- }
1172
- retryCount++;
1173
- const retryTime = Math.floor(Math.random() * 5000);
1174
- log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
1175
- const url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
1176
- if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
1177
- return delay(retryTime)
1178
- .then(function () {
1179
- return http
1180
- .postFormData(url, ctx.jar, data.request.formData);
1181
- })
1182
- .then(parseAndCheckLogin(ctx, http, retryCount));
1183
- }
1184
- else {
1185
- return delay(retryTime)
1186
- .then(function () {
1187
- return http
1188
- .post(url, ctx.jar, data.request.formData);
1189
- })
1190
- .then(parseAndCheckLogin(ctx, http, retryCount));
1191
- }
1192
- }
1193
- if (data.statusCode !== 200)
1194
- throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
1195
-
1196
- let res = null;
1161
+ return bluebird.try(function () {
1162
+ log.verbose("parseAndCheckLogin", data.body);
1163
+ if (data.statusCode >= 500 && data.statusCode < 600) {
1164
+ if (retryCount >= 5) {
1165
+ throw new CustomError({
1166
+ message: "Request retry failed. Check the `res` and `statusCode` property on this error.",
1167
+ statusCode: data.statusCode,
1168
+ res: data.body,
1169
+ error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
1170
+ sourceCall: sourceCall
1171
+ });
1172
+ }
1173
+ retryCount++;
1174
+ const retryTime = Math.floor(Math.random() * 5000);
1175
+ log.warn(
1176
+ "parseAndCheckLogin",
1177
+ "Got status code " +
1178
+ data.statusCode +
1179
+ " - " +
1180
+ retryCount +
1181
+ ". attempt to retry in " +
1182
+ retryTime +
1183
+ " milliseconds..."
1184
+ );
1185
+ const url =
1186
+ data.request.uri.protocol +
1187
+ "//" +
1188
+ data.request.uri.hostname +
1189
+ data.request.uri.pathname;
1190
+ if (
1191
+ data.request.headers["Content-Type"].split(";")[0] ===
1192
+ "multipart/form-data"
1193
+ ) {
1194
+ return bluebird
1195
+ .delay(retryTime)
1196
+ .then(function () {
1197
+ return defaultFuncs.postFormData(
1198
+ url,
1199
+ ctx.jar,
1200
+ data.request.formData,
1201
+ {}
1202
+ );
1203
+ })
1204
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
1205
+ }
1206
+ else {
1207
+ return bluebird
1208
+ .delay(retryTime)
1209
+ .then(function () {
1210
+ return defaultFuncs.post(url, ctx.jar, data.request.formData);
1211
+ })
1212
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
1213
+ }
1214
+ }
1215
+ if (data.statusCode !== 200)
1216
+ throw new CustomError({
1217
+ message: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
1218
+ statusCode: data.statusCode,
1219
+ res: data.body,
1220
+ error: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
1221
+ sourceCall: sourceCall
1222
+ });
1223
+
1224
+ let res = null;
1197
1225
  try {
1198
1226
  res = JSON.parse(makeParsable(data.body));
1199
- } catch (e) {
1200
- const err = new Error("JSON.parse error. Check the `detail` property on this error.");
1201
- err.error = "JSON.parse error. Check the `detail` property on this error.";
1202
- err.detail = e;
1203
- err.res = data.body;
1204
- throw err;
1227
+ } catch (e) {
1228
+ throw new CustomError({
1229
+ message: "JSON.parse error. Check the `detail` property on this error.",
1230
+ detail: e,
1231
+ res: data.body,
1232
+ error: "JSON.parse error. Check the `detail` property on this error.",
1233
+ sourceCall: sourceCall
1234
+ });
1205
1235
  }
1206
1236
 
1207
1237
  // In some cases the response contains only a redirect URL which should be followed
1208
1238
  if (res.redirect && data.request.method === "GET") {
1209
- return http
1239
+ return defaultFuncs
1210
1240
  .get(res.redirect, ctx.jar)
1211
- .then(parseAndCheckLogin(ctx, http));
1212
- }
1241
+ .then(parseAndCheckLogin(ctx, defaultFuncs, undefined, sourceCall));
1242
+ }
1213
1243
 
1214
1244
  // TODO: handle multiple cookies?
1215
- if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
1216
- res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
1217
- const cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1245
+ if (
1246
+ res.jsmods &&
1247
+ res.jsmods.require &&
1248
+ Array.isArray(res.jsmods.require[0]) &&
1249
+ res.jsmods.require[0][0] === "Cookie"
1250
+ ) {
1251
+ res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace(
1252
+ "_js_",
1253
+ ""
1254
+ );
1255
+ const cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1218
1256
  const cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1219
1257
  ctx.jar.setCookie(cookie, "https://www.facebook.com");
1220
1258
  ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1221
- }
1259
+ }
1222
1260
 
1223
1261
  // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1224
1262
  // one for the next requests.
@@ -1238,16 +1276,33 @@ function parseAndCheckLogin(ctx, http, retryCount) {
1238
1276
  }
1239
1277
 
1240
1278
  if (res.error === 1357001) {
1241
- const err = new Error('Facebook blocked login. Please visit https://facebook.com and check your account.');
1242
- err.error = "Not logged in.";
1243
- throw err;
1279
+ throw new CustomError({
1280
+ message: "Facebook blocked login. Please visit https://facebook.com and check your account.",
1281
+ error: "Not logged in.",
1282
+ res: res,
1283
+ statusCode: data.statusCode,
1284
+ sourceCall: sourceCall
1285
+ });
1244
1286
  }
1245
1287
  return res;
1246
- }
1247
- return _try(any);
1288
+ });
1248
1289
  };
1249
1290
  }
1250
1291
 
1292
+ function checkLiveCookie(ctx, defaultFuncs) {
1293
+ return defaultFuncs
1294
+ .get("https://m.facebook.com/me", ctx.jar)
1295
+ .then(function (res) {
1296
+ if (res.body.indexOf(ctx.i_userID || ctx.userID) === -1) {
1297
+ throw new CustomError({
1298
+ message: "Not logged in.",
1299
+ error: "Not logged in."
1300
+ });
1301
+ }
1302
+ return true;
1303
+ });
1304
+ }
1305
+
1251
1306
  function saveCookies(jar) {
1252
1307
  return function (res) {
1253
1308
  const cookies = res.headers["set-cookie"] || [];
@@ -1379,25 +1434,11 @@ function decodeClientPayload(payload) {
1379
1434
  function getAppState(jar) {
1380
1435
  return jar
1381
1436
  .getCookies("https://www.facebook.com")
1437
+ .concat(jar.getCookies("https://facebook.com"))
1382
1438
  .concat(jar.getCookies("https://www.messenger.com"));
1383
1439
  }
1384
-
1385
- function createAccess_token(jar, globalOptions) {
1386
- return function (res) {
1387
- return get('https://business.facebook.com/business_locations', jar, null, globalOptions)
1388
- .then(function (resp) {
1389
- var accessToken = /"],\["(\S+)","436761779744620",{/g.exec(resp.body);
1390
- if (accessToken) accessToken = accessToken[1].split('"],["').pop();
1391
- else accessToken = 'NONE';
1392
- return [(res || resp.body), accessToken];
1393
- })
1394
- .catch(() => {
1395
- return [(res || null), 'NONE'];
1396
- })
1397
- }
1398
- }
1399
-
1400
1440
  module.exports = {
1441
+ CustomError,
1401
1442
  isReadableStream,
1402
1443
  get,
1403
1444
  post,
@@ -1436,5 +1477,5 @@ module.exports = {
1436
1477
  getAppState,
1437
1478
  getAdminTextMessageType,
1438
1479
  setProxy,
1439
- createAccess_token
1480
+ checkLiveCookie
1440
1481
  }
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('../utils');
4
-
5
- module.exports = function (http, api, ctx) {
6
- return function addExternalModule(moduleObj) {
7
- if (utils.getType(moduleObj) == 'Object') {
8
- for (let name in moduleObj) {
9
- if (utils.getType(moduleObj[name]) == 'Function')
10
- api[name] = moduleObj[name](http, api, ctx);
11
- else
12
- throw new Error(`Item "${name}" in moduleObj must be a function, not ${utils.getType(moduleObj[name])}!`);
13
- }
14
- } else
15
- throw new Error(`moduleObj must be an object, not ` + utils.getType(moduleObj) + `!`);
16
- }
17
- }
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function addUserToGroup(userID, threadID, callback) {
8
- let resolveFunc = function () { };
9
- let rejectFunc = function () { };
10
- const returnPromise = new Promise(function (resolve, reject) {
11
- resolveFunc = resolve;
12
- rejectFunc = reject;
13
- });
14
-
15
- if (
16
- !callback &&
17
- (utils.getType(threadID) === "Function" ||
18
- utils.getType(threadID) === "AsyncFunction")
19
- ) {
20
- throw new utils.CustomError({ error: "please pass a threadID as a second argument." });
21
- }
22
-
23
- if (!callback) {
24
- callback = function (err) {
25
- if (err) {
26
- return rejectFunc(err);
27
- }
28
- resolveFunc();
29
- };
30
- }
31
-
32
- if (
33
- utils.getType(threadID) !== "Number" &&
34
- utils.getType(threadID) !== "String"
35
- ) {
36
- throw new utils.CustomError({
37
- error:
38
- "ThreadID should be of type Number or String and not " +
39
- utils.getType(threadID) +
40
- "."
41
- });
42
- }
43
-
44
- if (utils.getType(userID) !== "Array") {
45
- userID = [userID];
46
- }
47
-
48
- const messageAndOTID = utils.generateOfflineThreadingID();
49
- const form = {
50
- client: "mercury",
51
- action_type: "ma-type:log-message",
52
- author: "fbid:" + (ctx.i_userID || ctx.userID),
53
- thread_id: "",
54
- timestamp: Date.now(),
55
- timestamp_absolute: "Today",
56
- timestamp_relative: utils.generateTimestampRelative(),
57
- timestamp_time_passed: "0",
58
- is_unread: false,
59
- is_cleared: false,
60
- is_forward: false,
61
- is_filtered_content: false,
62
- is_filtered_content_bh: false,
63
- is_filtered_content_account: false,
64
- is_spoof_warning: false,
65
- source: "source:chat:web",
66
- "source_tags[0]": "source:chat",
67
- log_message_type: "log:subscribe",
68
- status: "0",
69
- offline_threading_id: messageAndOTID,
70
- message_id: messageAndOTID,
71
- threading_id: utils.generateThreadingID(ctx.clientID),
72
- manual_retry_cnt: "0",
73
- thread_fbid: threadID
74
- };
75
-
76
- for (let i = 0; i < userID.length; i++) {
77
- if (
78
- utils.getType(userID[i]) !== "Number" &&
79
- utils.getType(userID[i]) !== "String"
80
- ) {
81
- throw new utils.CustomError({
82
- error:
83
- "Elements of userID should be of type Number or String and not " +
84
- utils.getType(userID[i]) +
85
- "."
86
- });
87
- }
88
-
89
- form["log_message_data[added_participants][" + i + "]"] =
90
- "fbid:" + userID[i];
91
- }
92
-
93
- defaultFuncs
94
- .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
95
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
- .then(function (resData) {
97
- if (!resData) {
98
- throw new utils.CustomError({ error: "Add to group failed." });
99
- }
100
- if (resData.error) {
101
- throw new utils.CustomError(resData);
102
- }
103
-
104
- return callback();
105
- })
106
- .catch(function (err) {
107
- log.error("addUserToGroup", err);
108
- return callback(err);
109
- });
110
-
111
- return returnPromise;
112
- };
113
- };
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
8
- if (utils.getType(threadID) !== "String") {
9
- throw new utils.CustomError({ error: "changeAdminStatus: threadID must be a string" });
10
- }
11
-
12
- if (utils.getType(adminIDs) === "String") {
13
- adminIDs = [adminIDs];
14
- }
15
-
16
- if (utils.getType(adminIDs) !== "Array") {
17
- throw new utils.CustomError({ error: "changeAdminStatus: adminIDs must be an array or string" });
18
- }
19
-
20
- if (utils.getType(adminStatus) !== "Boolean") {
21
- throw new utils.CustomError({ error: "changeAdminStatus: adminStatus must be a string" });
22
- }
23
-
24
- let resolveFunc = function () { };
25
- let rejectFunc = function () { };
26
- const returnPromise = new Promise(function (resolve, reject) {
27
- resolveFunc = resolve;
28
- rejectFunc = reject;
29
- });
30
-
31
- if (!callback) {
32
- callback = function (err) {
33
- if (err) {
34
- return rejectFunc(err);
35
- }
36
- resolveFunc();
37
- };
38
- }
39
-
40
- if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
41
- throw new utils.CustomError({ error: "changeAdminStatus: callback is not a function" });
42
- }
43
-
44
- const form = {
45
- "thread_fbid": threadID
46
- };
47
-
48
- let i = 0;
49
- for (const u of adminIDs) {
50
- form[`admin_ids[${i++}]`] = u;
51
- }
52
- form["add"] = adminStatus;
53
-
54
- defaultFuncs
55
- .post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
56
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
- .then(function (resData) {
58
- if (resData.error) {
59
- switch (resData.error) {
60
- case 1976004:
61
- throw new utils.CustomError({ error: "Cannot alter admin status: you are not an admin.", rawResponse: resData });
62
- case 1357031:
63
- throw new utils.CustomError({ error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData });
64
- default:
65
- throw new utils.CustomError({ error: "Cannot alter admin status: unknown error.", rawResponse: resData });
66
- }
67
- }
68
-
69
- callback();
70
- })
71
- .catch(function (err) {
72
- log.error("changeAdminStatus", err);
73
- return callback(err);
74
- });
75
-
76
- return returnPromise;
77
- };
78
- };
79
-