fca-smart-shankar 10.9.1 → 13.0.0

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 (169) hide show
  1. package/.replit +12 -3
  2. package/.upm/store.json +1 -1
  3. package/CHANGELOG.md +2 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +175 -30
  6. package/generated-icon.png +0 -0
  7. package/index.js +511 -414
  8. package/package.json +370 -85
  9. package/replit.nix +5 -0
  10. package/shankar-fca.json +4 -0
  11. package/src/addExternalModule.js +14 -5
  12. package/src/addUserToGroup.js +56 -20
  13. package/src/changeAdminStatus.js +44 -20
  14. package/src/changeArchivedStatus.js +25 -11
  15. package/src/changeAvatar.js +136 -0
  16. package/src/{changeAvt.js → changeAvatarV2.js} +3 -2
  17. package/src/changeBio.js +26 -15
  18. package/src/changeBlockedStatus.js +21 -8
  19. package/src/changeBlockedStatusMqtt.js +80 -0
  20. package/src/changeCover.js +73 -0
  21. package/src/changeGroupImage.js +53 -24
  22. package/src/changeName.js +79 -0
  23. package/src/changeNickname.js +27 -13
  24. package/src/changeThreadColor.js +22 -19
  25. package/src/changeThreadEmoji.js +24 -11
  26. package/src/changeUsername.js +59 -0
  27. package/src/createCommentPost.js +230 -0
  28. package/src/createNewGroup.js +38 -20
  29. package/src/createPoll.js +27 -16
  30. package/src/createPost.js +277 -0
  31. package/src/data/getThreadInfo.json +1 -0
  32. package/src/deleteMessage.js +24 -13
  33. package/src/deleteThread.js +25 -12
  34. package/src/editMessage.js +71 -53
  35. package/src/editMessageOld.js +67 -0
  36. package/src/follow.js +74 -0
  37. package/src/forwardAttachment.js +27 -15
  38. package/src/getAccess.js +112 -0
  39. package/src/getAvatarUser.js +78 -0
  40. package/src/getCurrentUserID.js +1 -1
  41. package/src/getEmojiUrl.js +10 -8
  42. package/src/getFriendsList.js +25 -15
  43. package/src/getMessage.js +813 -81
  44. package/src/getRegion.js +7 -0
  45. package/src/getThreadHistory.js +241 -98
  46. package/src/getThreadHistoryDeprecated.js +93 -0
  47. package/src/getThreadInfo.js +90 -287
  48. package/src/getThreadInfoDeprecated.js +80 -0
  49. package/src/getThreadList.js +214 -157
  50. package/src/getThreadListDeprecated.js +75 -0
  51. package/src/getThreadPictures.js +39 -19
  52. package/src/getUID.js +113 -50
  53. package/src/getUserID.js +18 -14
  54. package/src/getUserInfo.js +65 -71
  55. package/src/handleFriendRequest.js +24 -13
  56. package/src/handleMessageRequest.js +36 -20
  57. package/src/httpGet.js +34 -18
  58. package/src/httpPost.js +35 -18
  59. package/src/httpPostFormData.js +53 -24
  60. package/src/listenMqtt.js +680 -944
  61. package/src/listenNotification.js +85 -0
  62. package/src/logout.js +22 -15
  63. package/src/markAsDelivered.js +25 -15
  64. package/src/markAsRead.js +45 -27
  65. package/src/markAsReadAll.js +21 -14
  66. package/src/markAsSeen.js +28 -18
  67. package/src/muteThread.js +17 -12
  68. package/src/pinMessage.js +59 -0
  69. package/src/refreshFb_dtsg.js +89 -0
  70. package/src/removeUserFromGroup.js +47 -17
  71. package/src/resolvePhotoUrl.js +21 -13
  72. package/src/searchForThread.js +23 -13
  73. package/src/searchStickers.js +53 -0
  74. package/src/sendMessage.js +178 -117
  75. package/src/sendMessageMqtt.js +322 -0
  76. package/src/sendTypingIndicator.js +46 -16
  77. package/src/sendTypingIndicatorV2.js +28 -0
  78. package/src/setMessageReaction.js +33 -20
  79. package/src/setMessageReactionMqtt.js +62 -0
  80. package/src/setPostReaction.js +105 -95
  81. package/src/setProfileGuard.js +45 -0
  82. package/src/setStoryReaction.js +64 -0
  83. package/src/setTitle.js +34 -18
  84. package/src/shareContact.js +92 -37
  85. package/src/shareLink.js +5 -4
  86. package/src/stopListenMqtt.js +26 -0
  87. package/src/threadColors.js +110 -18
  88. package/src/unfriend.js +18 -9
  89. package/src/unsendMessage.js +31 -34
  90. package/src/uploadAttachment.js +94 -0
  91. package/test/data/shareAttach.js +1 -1
  92. package/test/test.js +1 -1
  93. package/utils.js +1393 -2918
  94. package/.cache/replit/env/latest +0 -56
  95. package/.cache/replit/env/latest.json +0 -1
  96. package/.cache/replit/modules/nodejs-14.res +0 -1
  97. package/.cache/replit/modules/replit.res +0 -1
  98. package/.cache/replit/modules/web.res +0 -1
  99. package/.cache/replit/modules.stamp +0 -0
  100. package/.cache/typescript/5.5/package.json +0 -1
  101. package/.config/configstore/update-notifier-npm.json +0 -4
  102. package/.gitattributes +0 -2
  103. package/Extra/Balancer.js +0 -49
  104. package/Extra/Bypass/956/index.js +0 -234
  105. package/Extra/Bypass/test/aaaa.json +0 -170
  106. package/Extra/Bypass/test/index.js +0 -188
  107. package/Extra/Database/index.js +0 -469
  108. package/Extra/ExtraAddons.js +0 -82
  109. package/Extra/ExtraFindUID.js +0 -62
  110. package/Extra/ExtraGetThread.js +0 -365
  111. package/Extra/ExtraScreenShot.js +0 -430
  112. package/Extra/ExtraUptimeRobot.js +0 -38
  113. package/Extra/Html/Classic/script.js +0 -119
  114. package/Extra/Html/Classic/style.css +0 -8
  115. package/Extra/Security/AES_256_GCM/index.js +0 -0
  116. package/Extra/Security/Base/Step_1.js +0 -6
  117. package/Extra/Security/Base/Step_2.js +0 -22
  118. package/Extra/Security/Base/Step_3.js +0 -22
  119. package/Extra/Security/Base/index.js +0 -191
  120. package/Extra/Security/Index.js +0 -5
  121. package/Extra/Security/Step_1.js +0 -6
  122. package/Extra/Security/Step_2.js +0 -22
  123. package/Extra/Security/Step_3.js +0 -22
  124. package/Extra/Src/Change_Environment.js +0 -24
  125. package/Extra/Src/Check_Update.js +0 -67
  126. package/Extra/Src/History.js +0 -115
  127. package/Extra/Src/Instant_Update.js +0 -65
  128. package/Extra/Src/Last-Run.js +0 -65
  129. package/Extra/Src/Premium.js +0 -81
  130. package/Extra/Src/Release_Memory.js +0 -160
  131. package/Extra/Src/Websocket.js +0 -213
  132. package/Extra/Src/image/checkmate.jpg +0 -0
  133. package/Extra/Src/test.js +0 -28
  134. package/Extra/Src/uuid.js +0 -137
  135. package/Func/AcceptAgreement.js +0 -31
  136. package/Func/ClearCache.js +0 -64
  137. package/Func/ReportV1.js +0 -54
  138. package/LICENSE +0 -678
  139. package/Language/index.json +0 -228
  140. package/Main.js +0 -1444
  141. package/SECURITY.md +0 -18
  142. package/broadcast.js +0 -44
  143. package/logger.js +0 -66
  144. package/src/Dev_Horizon_Data.js +0 -125
  145. package/src/Dev_getThreadInfoOLD.js +0 -422
  146. package/src/Dev_shareTest2.js +0 -68
  147. package/src/Dev_shareTest3.js +0 -71
  148. package/src/Premium.js +0 -25
  149. package/src/Screenshot.js +0 -83
  150. package/src/getAccessToken.js +0 -28
  151. package/src/getThreadInfoOLD.js +0 -422
  152. package/src/getThreadMain.js +0 -220
  153. package/src/getUserInfoMain.js +0 -65
  154. package/src/getUserInfoV2.js +0 -32
  155. package/src/getUserInfoV3.js +0 -63
  156. package/src/getUserInfoV4.js +0 -55
  157. package/src/getUserInfoV5.js +0 -61
  158. package/src/listenMqttV1.js +0 -846
  159. package/src/sendMqttMessage.js +0 -71
  160. package/src/unsendMqttMessage.js +0 -66
  161. package/test/Database_Test.js +0 -4
  162. package/test/Db2.js +0 -530
  163. package/test/Shankar_Database/A_README.md +0 -1
  164. package/test/Shankar_Database/Database.db +0 -0
  165. package/test/env/.env +0 -0
  166. package/test/example-db.db +0 -0
  167. package/test/memoryleak.js +0 -18
  168. package/test/testname.js +0 -1342
  169. package/test/testv2.js +0 -3
@@ -3,10 +3,12 @@
3
3
  const utils = require("../utils");
4
4
  const log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
8
8
  if (utils.getType(threadID) !== "String") {
9
- throw {error: "changeAdminStatus: threadID must be a string"};
9
+ throw new utils.CustomError({
10
+ error: "changeAdminStatus: threadID must be a string",
11
+ });
10
12
  }
11
13
 
12
14
  if (utils.getType(adminIDs) === "String") {
@@ -14,16 +16,20 @@ module.exports = function(defaultFuncs, api, ctx) {
14
16
  }
15
17
 
16
18
  if (utils.getType(adminIDs) !== "Array") {
17
- throw {error: "changeAdminStatus: adminIDs must be an array or string"};
19
+ throw new utils.CustomError({
20
+ error: "changeAdminStatus: adminIDs must be an array or string",
21
+ });
18
22
  }
19
23
 
20
24
  if (utils.getType(adminStatus) !== "Boolean") {
21
- throw {error: "changeAdminStatus: adminStatus must be a string"};
25
+ throw new utils.CustomError({
26
+ error: "changeAdminStatus: adminStatus must be a string",
27
+ });
22
28
  }
23
29
 
24
- var resolveFunc = function(){};
25
- var rejectFunc = function(){};
26
- var returnPromise = new Promise(function (resolve, reject) {
30
+ let resolveFunc = function () {};
31
+ let rejectFunc = function () {};
32
+ const returnPromise = new Promise(function (resolve, reject) {
27
33
  resolveFunc = resolve;
28
34
  rejectFunc = reject;
29
35
  });
@@ -37,43 +43,61 @@ module.exports = function(defaultFuncs, api, ctx) {
37
43
  };
38
44
  }
39
45
 
40
- if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
41
- throw {error: "changeAdminStatus: callback is not a function"};
46
+ if (
47
+ utils.getType(callback) !== "Function" &&
48
+ utils.getType(callback) !== "AsyncFunction"
49
+ ) {
50
+ throw new utils.CustomError({
51
+ error: "changeAdminStatus: callback is not a function",
52
+ });
42
53
  }
43
54
 
44
- let form = {
45
- "thread_fbid": threadID,
55
+ const form = {
56
+ thread_fbid: threadID,
46
57
  };
47
58
 
48
59
  let i = 0;
49
- for (let u of adminIDs) {
60
+ for (const u of adminIDs) {
50
61
  form[`admin_ids[${i++}]`] = u;
51
62
  }
52
63
  form["add"] = adminStatus;
53
64
 
54
65
  defaultFuncs
55
- .post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
66
+ .post(
67
+ "https://www.facebook.com/messaging/save_admins/?dpr=1",
68
+ ctx.jar,
69
+ form,
70
+ )
56
71
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
- .then(function(resData) {
72
+ .then(function (resData) {
58
73
  if (resData.error) {
59
74
  switch (resData.error) {
60
75
  case 1976004:
61
- throw { error: "Cannot alter admin status: you are not an admin.", rawResponse: resData };
76
+ throw new utils.CustomError({
77
+ error: "Cannot alter admin status: you are not an admin.",
78
+ rawResponse: resData,
79
+ });
62
80
  case 1357031:
63
- throw { error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData };
81
+ throw new utils.CustomError({
82
+ error:
83
+ "Cannot alter admin status: this thread is not a group chat.",
84
+ rawResponse: resData,
85
+ });
64
86
  default:
65
- throw { error: "Cannot alter admin status: unknown error.", rawResponse: resData };
87
+ throw new utils.CustomError({
88
+ error: "Cannot alter admin status: unknown error.",
89
+ rawResponse: resData,
90
+ });
66
91
  }
67
92
  }
68
93
 
69
94
  callback();
70
95
  })
71
- .catch(function(err) {
96
+ .catch(function (err) {
72
97
  log.error("changeAdminStatus", err);
73
98
  return callback(err);
74
99
  });
75
-
100
+
76
101
  return returnPromise;
77
102
  };
78
103
  };
79
-
@@ -1,34 +1,48 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeArchivedStatus(threadOrThreads, archive, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) return rejectFunc(err);
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
18
20
  resolveFunc();
19
21
  };
20
22
  }
21
23
 
22
- var form = {};
24
+ const form = {};
23
25
 
24
- if (utils.getType(threadOrThreads) === "Array") for (var i = 0; i < threadOrThreads.length; i++) form["ids[" + threadOrThreads[i] + "]"] = archive;
25
- else form["ids[" + threadOrThreads + "]"] = archive;
26
+ if (utils.getType(threadOrThreads) === "Array") {
27
+ for (let i = 0; i < threadOrThreads.length; i++) {
28
+ form["ids[" + threadOrThreads[i] + "]"] = archive;
29
+ }
30
+ } else {
31
+ form["ids[" + threadOrThreads + "]"] = archive;
32
+ }
26
33
 
27
34
  defaultFuncs
28
- .post("https://www.facebook.com/ajax/mercury/change_archived_status.php", ctx.jar, form)
35
+ .post(
36
+ "https://www.facebook.com/ajax/mercury/change_archived_status.php",
37
+ ctx.jar,
38
+ form,
39
+ )
29
40
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
41
  .then(function (resData) {
31
- if (resData.error) throw resData;
42
+ if (resData.error) {
43
+ throw resData;
44
+ }
45
+
32
46
  return callback();
33
47
  })
34
48
  .catch(function (err) {
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function handleUpload(image, callback) {
8
+ const uploads = [];
9
+
10
+ const form = {
11
+ profile_id: ctx.i_userID || ctx.userID,
12
+ photo_source: 57,
13
+ av: ctx.i_userID || ctx.userID,
14
+ file: image,
15
+ };
16
+
17
+ uploads.push(
18
+ defaultFuncs
19
+ .postFormData(
20
+ "https://www.facebook.com/profile/picture/upload/",
21
+ ctx.jar,
22
+ form,
23
+ {},
24
+ )
25
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
26
+ .then(function (resData) {
27
+ if (resData.error) {
28
+ throw resData;
29
+ }
30
+ return resData;
31
+ }),
32
+ );
33
+
34
+ // resolve all promises
35
+ Promise.all(uploads)
36
+ .then(function (resData) {
37
+ callback(null, resData);
38
+ })
39
+ .catch(function (err) {
40
+ log.error("handleUpload", err);
41
+ return callback(err);
42
+ });
43
+ }
44
+
45
+ return function changeAvatar(
46
+ image,
47
+ caption = "",
48
+ timestamp = null,
49
+ callback,
50
+ ) {
51
+ let resolveFunc = function () {};
52
+ let rejectFunc = function () {};
53
+ const returnPromise = new Promise(function (resolve, reject) {
54
+ resolveFunc = resolve;
55
+ rejectFunc = reject;
56
+ });
57
+
58
+ if (!timestamp && utils.getType(caption) === "Number") {
59
+ timestamp = caption;
60
+ caption = "";
61
+ }
62
+
63
+ if (
64
+ !timestamp &&
65
+ !callback &&
66
+ (utils.getType(caption) == "Function" ||
67
+ utils.getType(caption) == "AsyncFunction")
68
+ ) {
69
+ callback = caption;
70
+ caption = "";
71
+ timestamp = null;
72
+ }
73
+
74
+ if (!callback)
75
+ callback = function (err, data) {
76
+ if (err) {
77
+ return rejectFunc(err);
78
+ }
79
+ resolveFunc(data);
80
+ };
81
+
82
+ if (!utils.isReadableStream(image))
83
+ return callback("Image is not a readable stream");
84
+
85
+ handleUpload(image, function (err, payload) {
86
+ if (err) {
87
+ return callback(err);
88
+ }
89
+
90
+ const form = {
91
+ av: ctx.i_userID || ctx.userID,
92
+ fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
93
+ fb_api_caller_class: "RelayModern",
94
+ doc_id: "5066134240065849",
95
+ variables: JSON.stringify({
96
+ input: {
97
+ caption,
98
+ existing_photo_id: payload[0].payload.fbid,
99
+ expiration_time: timestamp,
100
+ profile_id: ctx.i_userID || ctx.userID,
101
+ profile_pic_method: "EXISTING",
102
+ profile_pic_source: "TIMELINE",
103
+ scaled_crop_rect: {
104
+ height: 1,
105
+ width: 1,
106
+ x: 0,
107
+ y: 0,
108
+ },
109
+ skip_cropping: true,
110
+ actor_id: ctx.i_userID || ctx.userID,
111
+ client_mutation_id: Math.round(Math.random() * 19).toString(),
112
+ },
113
+ isPage: false,
114
+ isProfile: true,
115
+ scale: 3,
116
+ }),
117
+ };
118
+
119
+ defaultFuncs
120
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
121
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
122
+ .then(function (resData) {
123
+ if (resData.errors) {
124
+ throw resData;
125
+ }
126
+ return callback(null, resData[0].data.profile_picture_set);
127
+ })
128
+ .catch(function (err) {
129
+ log.error("changeAvatar", err);
130
+ return callback(err);
131
+ });
132
+ });
133
+
134
+ return returnPromise;
135
+ };
136
+ };
@@ -1,3 +1,4 @@
1
+
1
2
  "use strict";
2
3
 
3
4
  var utils = require("../utils");
@@ -10,7 +11,7 @@ var log = require("npmlog");
10
11
  * @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
11
12
  * {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
12
13
  */
13
- async function postImage(Api,BotID,form) {
14
+ async function postImage(Api, BotID, form) {
14
15
  var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
15
16
  return JSON.parse(Data.split("for (;;);")[1]);
16
17
  }
@@ -82,4 +83,4 @@ module.exports = function(defaultFuncs, api, ctx) {
82
83
  }
83
84
  return returnPromise;
84
85
  };
85
- };
86
+ };
package/src/changeBio.js CHANGED
@@ -1,34 +1,43 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeBio(bio, publish, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") callback = publish;
17
- else {
16
+ if (
17
+ utils.getType(publish) == "Function" ||
18
+ utils.getType(publish) == "AsyncFunction"
19
+ ) {
20
+ callback = publish;
21
+ } else {
18
22
  callback = function (err) {
19
- if (err) return rejectFunc(err);
23
+ if (err) {
24
+ return rejectFunc(err);
25
+ }
20
26
  resolveFunc();
21
27
  };
22
28
  }
23
29
  }
24
30
 
25
- if (utils.getType(publish) != "Boolean") publish = false;
31
+ if (utils.getType(publish) != "Boolean") {
32
+ publish = false;
33
+ }
34
+
26
35
  if (utils.getType(bio) != "String") {
27
36
  bio = "";
28
37
  publish = false;
29
38
  }
30
39
 
31
- var form = {
40
+ const form = {
32
41
  fb_api_caller_class: "RelayModern",
33
42
  fb_api_req_friendly_name: "ProfileCometSetBioMutation",
34
43
  // This doc_is is valid as of May 23, 2020
@@ -37,21 +46,23 @@ module.exports = function (defaultFuncs, api, ctx) {
37
46
  input: {
38
47
  bio: bio,
39
48
  publish_bio_feed_story: publish,
40
- actor_id: ctx.userID,
41
- client_mutation_id: Math.round(Math.random() * 1024).toString()
49
+ actor_id: ctx.i_userID || ctx.userID,
50
+ client_mutation_id: Math.round(Math.random() * 1024).toString(),
42
51
  },
43
52
  hasProfileTileViewID: false,
44
53
  profileTileViewID: null,
45
- scale: 1
54
+ scale: 1,
46
55
  }),
47
- av: ctx.userID
56
+ av: ctx.i_userID || ctx.userID,
48
57
  };
49
58
 
50
59
  defaultFuncs
51
60
  .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
52
61
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
53
62
  .then(function (resData) {
54
- if (resData.errors) throw resData;
63
+ if (resData.errors) {
64
+ throw resData;
65
+ }
55
66
 
56
67
  return callback();
57
68
  })
@@ -1,30 +1,43 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeBlockedStatus(userID, block, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) return rejectFunc(err);
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
18
20
  resolveFunc();
19
21
  };
20
22
  }
21
23
 
22
24
  defaultFuncs
23
- .post(`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`, ctx.jar, { fbid: userID })
25
+ .post(
26
+ `https://www.facebook.com/messaging/${
27
+ block ? "" : "un"
28
+ }block_messages/`,
29
+ ctx.jar,
30
+ {
31
+ fbid: userID,
32
+ },
33
+ )
24
34
  .then(utils.saveCookies(ctx.jar))
25
35
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
26
36
  .then(function (resData) {
27
- if (resData.error) throw resData;
37
+ if (resData.error) {
38
+ throw resData;
39
+ }
40
+
28
41
  return callback();
29
42
  })
30
43
  .catch(function (err) {
@@ -0,0 +1,80 @@
1
+
2
+ 'use strict';
3
+
4
+ const { generateOfflineThreadingID, getCurrentTimestamp, getGUID } = require('../utils.js');
5
+
6
+ function isCallable(func) {
7
+ try {
8
+ Reflect.apply(func, null, []);
9
+ return true;
10
+ } catch (error) {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ module.exports = function (defaultFuncs, api, ctx) {
16
+ return function changeBlockedStatusMqtt(userID, status, type, callback) {
17
+ if (!ctx.mqttClient) {
18
+ throw new Error('Not connected to MQTT');
19
+ }
20
+
21
+ ctx.wsReqNumber += 1;
22
+ ctx.wsTaskNumber += 1;
23
+
24
+ const label = '334';
25
+ let userBlockAction = 0;
26
+
27
+ switch (type) {
28
+ case 'messenger':
29
+ if (status) {
30
+ userBlockAction = 1; // Block
31
+ } else {
32
+ userBlockAction = 0; // Unblock
33
+ }
34
+ break;
35
+ case 'facebook':
36
+ if (status) {
37
+ userBlockAction = 3; // Block
38
+ } else {
39
+ userBlockAction = 2; // Unblock
40
+ }
41
+ break;
42
+ default:
43
+ throw new Error('Invalid type');
44
+ }
45
+
46
+ const taskPayload = {
47
+ blockee_id: userID,
48
+ request_id: getGUID(),
49
+ user_block_action: userBlockAction,
50
+ };
51
+
52
+ const payload = JSON.stringify(taskPayload);
53
+ const version = '25393437286970779';
54
+
55
+ const task = {
56
+ failure_count: null,
57
+ label: label,
58
+ payload: payload,
59
+ queue_name: 'native_sync_block',
60
+ task_id: ctx.wsTaskNumber,
61
+ };
62
+
63
+ const content = {
64
+ app_id: '2220391788200892',
65
+ payload: JSON.stringify({
66
+ tasks: [task],
67
+ epoch_id: parseInt(generateOfflineThreadingID()),
68
+ version_id: version,
69
+ }),
70
+ request_id: ctx.wsReqNumber,
71
+ type: 3,
72
+ };
73
+
74
+ if (isCallable(callback)) {
75
+ ctx.reqCallbacks[ctx.wsReqNumber] = callback;
76
+ }
77
+
78
+ ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
79
+ };
80
+ };
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../utils.js');
4
+ var log = require('npmlog');
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeCover(image, callback) {
8
+ var cb;
9
+ var rt = new Promise(function (resolve, reject) {
10
+ cb = (error, url) => error ? reject(error) : resolve(url);
11
+ });
12
+
13
+ if (typeof image == 'function') {
14
+ callback = image;
15
+ image = null;
16
+ }
17
+ if (typeof callback == 'function') cb = callback;
18
+ if (!utils.isReadableStream(image)) {
19
+ var error = 'image should be a readable stream, not ' + utils.getType(image);
20
+ log.error('changeCover', error);
21
+ cb(error);
22
+ }
23
+ else {
24
+ defaultFuncs
25
+ .postFormData('https://www.facebook.com/profile/picture/upload/', ctx.jar, {
26
+ profile_id: ctx.userID,
27
+ photo_source: 57,
28
+ av: ctx.userID,
29
+ file: image
30
+ })
31
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
32
+ .then(function (res) {
33
+ if (res.error || res.errors || !res.payload)
34
+ throw res;
35
+
36
+ var vari = {
37
+ input: {
38
+ attribution_id_v2: `ProfileCometCollectionRoot.react,comet.profile.collection.photos_by,unexpected,${Date.now()},770083,,;ProfileCometCollectionRoot.react,comet.profile.collection.photos_albums,unexpected,${Date.now()},470774,,;ProfileCometCollectionRoot.react,comet.profile.collection.photos,unexpected,${Date.now()},94740,,;ProfileCometCollectionRoot.react,comet.profile.collection.saved_reels_on_profile,unexpected,${Date.now()},89669,,;ProfileCometCollectionRoot.react,comet.profile.collection.reels_tab,unexpected,${Date.now()},152201,,`,
39
+ cover_photo_id: res.payload.fbid,
40
+ focus: {
41
+ x: 0.5,
42
+ y: 1
43
+ },
44
+ target_user_id: ctx.userID,
45
+ actor_id: ctx.userID,
46
+ client_mutation_id: Math.round(Math.random() * 19).toString()
47
+ },
48
+ scale: 1,
49
+ contextualProfileContext: null
50
+ }
51
+ return defaultFuncs
52
+ .post('https://www.facebook.com/api/graphql', ctx.jar, {
53
+ doc_id: 8247793861913071,
54
+ server_timestamps: true,
55
+ fb_api_req_friendly_name: 'ProfileCometCoverPhotoUpdateMutation',
56
+ variables: JSON.stringify(vari)
57
+ })
58
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
59
+ })
60
+ .then(function (res) {
61
+ if (res.errors)
62
+ throw res;
63
+ return cb(null, res.data.user_update_cover_photo.user.cover_photo.photo.url);
64
+ })
65
+ .catch(function (err) {
66
+ log.error('changeCover', err);
67
+ return cb(err);
68
+ });
69
+ }
70
+
71
+ return rt;
72
+ }
73
+ }