shadowx-fca 8.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 (174) hide show
  1. package/README.md +1066 -0
  2. package/build/messagix.dll +0 -0
  3. package/build/messagix.so +0 -0
  4. package/checkUpdate.js +393 -0
  5. package/config.json +17 -0
  6. package/e2ee.js +563 -0
  7. package/e2eetest.js +356 -0
  8. package/index.js +611 -0
  9. package/lib/index.mjs +1412 -0
  10. package/logger.js +500 -0
  11. package/package.json +65 -0
  12. package/src/GetBotInfo.js +66 -0
  13. package/src/OldMessage.js +182 -0
  14. package/src/Screenshot.js +83 -0
  15. package/src/addExternalModule.js +13 -0
  16. package/src/addUserToGroup.js +33 -0
  17. package/src/approveGroupJoinRequests.js +18 -0
  18. package/src/changeAdminStatus.js +16 -0
  19. package/src/changeArchivedStatus.js +17 -0
  20. package/src/changeAvatar.js +136 -0
  21. package/src/changeAvatarV2.js +86 -0
  22. package/src/changeAvt.js +85 -0
  23. package/src/changeBio.js +76 -0
  24. package/src/changeBlockedStatus.js +20 -0
  25. package/src/changeBlockedStatusMqtt.js +80 -0
  26. package/src/changeCover.js +72 -0
  27. package/src/changeGroupImage.js +16 -0
  28. package/src/changeName.js +79 -0
  29. package/src/changeNickname.js +16 -0
  30. package/src/changeThreadColor.js +15 -0
  31. package/src/changeThreadEmoji.js +15 -0
  32. package/src/changeThreadMemberNickname.js +6 -0
  33. package/src/changeUsername.js +59 -0
  34. package/src/createCommentPost.js +230 -0
  35. package/src/createNewGroup.js +38 -0
  36. package/src/createNote.js +35 -0
  37. package/src/createPoll.js +27 -0
  38. package/src/createPost.js +276 -0
  39. package/src/createThemeAI.js +129 -0
  40. package/src/data/cache/system/data.json +4 -0
  41. package/src/data/cache/system/datahandle.js +21 -0
  42. package/src/data/getThreadInfo.json +1 -0
  43. package/src/deleteComment.js +23 -0
  44. package/src/deleteMessage.js +15 -0
  45. package/src/deleteThread.js +15 -0
  46. package/src/denyGroupJoinRequests.js +18 -0
  47. package/src/e2ee/crypto.js +173 -0
  48. package/src/e2ee/index.js +144 -0
  49. package/src/e2ee/proto/ArmadilloApplication.proto +281 -0
  50. package/src/e2ee/proto/ArmadilloICDC.proto +14 -0
  51. package/src/e2ee/proto/ConsumerApplication.proto +232 -0
  52. package/src/e2ee/proto/MessageApplication.proto +82 -0
  53. package/src/e2ee/proto/MessageTransport.proto +77 -0
  54. package/src/e2ee/proto/WACommon.proto +66 -0
  55. package/src/e2ee/proto/WAMediaTransport.proto +176 -0
  56. package/src/e2ee/proto/proto-writer.ts +76 -0
  57. package/src/e2ee/protocol.js +196 -0
  58. package/src/e2ee/ratchet.js +219 -0
  59. package/src/e2ee/store.js +182 -0
  60. package/src/e2ee.js +8 -0
  61. package/src/editMessage.js +56 -0
  62. package/src/editMessageOld.js +67 -0
  63. package/src/enableReactions.js +24 -0
  64. package/src/follow.js +74 -0
  65. package/src/followUser.js +23 -0
  66. package/src/forwardAttachment.js +16 -0
  67. package/src/friendList.js +98 -0
  68. package/src/getAccess.js +112 -0
  69. package/src/getAppState.js +13 -0
  70. package/src/getAvatarUser.js +11 -0
  71. package/src/getBio.js +24 -0
  72. package/src/getBotInitialData.js +42 -0
  73. package/src/getCtx.js +5 -0
  74. package/src/getCurrentUserID.js +6 -0
  75. package/src/getEmojiUrl.js +29 -0
  76. package/src/getFriendsList.js +36 -0
  77. package/src/getMessage.js +37 -0
  78. package/src/getNotes.js +17 -0
  79. package/src/getOptions.js +5 -0
  80. package/src/getPinnedMessages.js +33 -0
  81. package/src/getPostInfo.js +17 -0
  82. package/src/getProfileInfo.js +17 -0
  83. package/src/getPublicData.js +25 -0
  84. package/src/getRegion.js +7 -0
  85. package/src/getRepInfo.js +17 -0
  86. package/src/getStickerPacks.js +25 -0
  87. package/src/getStickers.js +39 -0
  88. package/src/getStoryReactions.js +18 -0
  89. package/src/getThreadHistory.js +45 -0
  90. package/src/getThreadHistoryDeprecated.js +71 -0
  91. package/src/getThreadInfo.js +73 -0
  92. package/src/getThreadInfoDeprecated.js +56 -0
  93. package/src/getThreadList.js +76 -0
  94. package/src/getThreadListDeprecated.js +46 -0
  95. package/src/getThreadPictures.js +59 -0
  96. package/src/getThreadTheme.js +77 -0
  97. package/src/getUID.js +17 -0
  98. package/src/getUserID.js +17 -0
  99. package/src/getUserInfo.js +28 -0
  100. package/src/handleFriendRequest.js +21 -0
  101. package/src/handleMessageRequest.js +15 -0
  102. package/src/httpGet.js +13 -0
  103. package/src/httpPost.js +12 -0
  104. package/src/httpPostFormData.js +12 -0
  105. package/src/listenE2EE.js +75 -0
  106. package/src/listenMqtt.js +802 -0
  107. package/src/listenNotification.js +85 -0
  108. package/src/logout.js +22 -0
  109. package/src/markAsDelivered.js +17 -0
  110. package/src/markAsRead.js +14 -0
  111. package/src/markAsReadAll.js +15 -0
  112. package/src/markAsSeen.js +15 -0
  113. package/src/metaTheme.js +185 -0
  114. package/src/muteThread.js +52 -0
  115. package/src/note.js +228 -0
  116. package/src/pin.js +53 -0
  117. package/src/pinMessage.js +6 -0
  118. package/src/postComment.js +29 -0
  119. package/src/postFormData.js +46 -0
  120. package/src/reactToComment.js +31 -0
  121. package/src/reactToPost.js +32 -0
  122. package/src/refreshFb_dtsg.js +31 -0
  123. package/src/removeSuspiciousAccount.js +74 -0
  124. package/src/removeUserFromGroup.js +15 -0
  125. package/src/reply.js +442 -0
  126. package/src/resolvePhotoUrl.js +15 -0
  127. package/src/searchForThread.js +20 -0
  128. package/src/searchFriends.js +28 -0
  129. package/src/searchStickers.js +53 -0
  130. package/src/send.js +46 -0
  131. package/src/sendAudio.js +8 -0
  132. package/src/sendBroadcast.js +93 -0
  133. package/src/sendButtons.js +161 -0
  134. package/src/sendComment.js +159 -0
  135. package/src/sendEmoji.js +10 -0
  136. package/src/sendFile.js +9 -0
  137. package/src/sendFriendRequest.js +33 -0
  138. package/src/sendGif.js +24 -0
  139. package/src/sendImage.js +9 -0
  140. package/src/sendLocation.js +9 -0
  141. package/src/sendMessage.js +487 -0
  142. package/src/sendMessage1.js +309 -0
  143. package/src/sendMessageMqtt.js +68 -0
  144. package/src/sendSticker.js +8 -0
  145. package/src/sendTypingIndicator.js +36 -0
  146. package/src/sendTypingIndicatorV2.js +28 -0
  147. package/src/sendVideo.js +9 -0
  148. package/src/sessionGuard.js +130 -0
  149. package/src/setActiveStatus.js +16 -0
  150. package/src/setMessageReaction.js +61 -0
  151. package/src/setMessageReactionMqtt.js +62 -0
  152. package/src/setOptions.js +22 -0
  153. package/src/setPollVote.js +17 -0
  154. package/src/setPostReaction.js +112 -0
  155. package/src/setProfileGuard.js +44 -0
  156. package/src/setProfileLock.js +93 -0
  157. package/src/setStoryReaction.js +129 -0
  158. package/src/setStorySeen.js +99 -0
  159. package/src/setThreadTheme.js +17 -0
  160. package/src/setTitle.js +15 -0
  161. package/src/shareContact.js +33 -0
  162. package/src/shareLink.js +8 -0
  163. package/src/sharePost.js +31 -0
  164. package/src/stopListenMqtt.js +23 -0
  165. package/src/storyManager.js +353 -0
  166. package/src/suggestFriend.js +128 -0
  167. package/src/threadColors.js +131 -0
  168. package/src/unfollowUser.js +23 -0
  169. package/src/unfriend.js +15 -0
  170. package/src/unpinMessage.js +6 -0
  171. package/src/unsendMessage.js +14 -0
  172. package/src/uploadAttachment.js +58 -0
  173. package/src/uploadImageToImgbb.js +29 -0
  174. package/utils.js +2945 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var logger = require("../logger");
5
+ var bluebird = require("bluebird");
6
+
7
+ var allowedProperties = {
8
+ attachment: true, url: true, sticker: true, emoji: true,
9
+ emojiSize: true, body: true, mentions: true, location: true,
10
+ };
11
+
12
+ module.exports = function (defaultFuncs, api, ctx) {
13
+
14
+ function uploadAttachment(attachments, callback) {
15
+ var uploads = [];
16
+ for (var i = 0; i < attachments.length; i++) {
17
+ if (!utils.isReadableStream(attachments[i])) {
18
+ return callback({ error: "Attachment must be a readable stream." });
19
+ }
20
+ uploads.push(
21
+ defaultFuncs.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, {
22
+ upload_1024: attachments[i],
23
+ voice_clip: "true"
24
+ })
25
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
26
+ .then(resData => {
27
+ if (resData.error) throw resData;
28
+ return resData.payload.metadata[0];
29
+ })
30
+ );
31
+ }
32
+ bluebird.all(uploads)
33
+ .then(resData => callback(null, resData))
34
+ .catch(err => { logger.error("OldMessage.upload", err); callback(err); });
35
+ }
36
+
37
+ function getUrl(url, callback) {
38
+ defaultFuncs.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, {
39
+ image_height: 960, image_width: 960, uri: url
40
+ })
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ .then(resData => {
43
+ if (resData.error) return callback(resData);
44
+ if (!resData.payload) return callback({ error: "Invalid URL" });
45
+ callback(null, resData.payload.share_data.share_params);
46
+ })
47
+ .catch(err => { logger.error("OldMessage.getUrl", err); callback(err); });
48
+ }
49
+
50
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
51
+ if (utils.getType(threadID) === "Array") {
52
+ for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
53
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
54
+ form["client_thread_id"] = "root:" + messageAndOTID;
55
+ } else {
56
+ if (isSingleUser) {
57
+ form["specific_to_list[0]"] = "fbid:" + threadID;
58
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
59
+ form["other_user_fbid"] = threadID;
60
+ } else {
61
+ form["thread_fbid"] = threadID;
62
+ }
63
+ }
64
+
65
+ if (ctx.globalOptions.pageID) {
66
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
67
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
68
+ form["creator_info[creatorID]"] = ctx.userID;
69
+ form["creator_info[creatorType]"] = "direct_admin";
70
+ }
71
+
72
+ defaultFuncs.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
73
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
74
+ .then(resData => {
75
+ if (!resData.payload) throw resData;
76
+ var messageID = (resData.payload.actions && resData.payload.actions[0] &&
77
+ resData.payload.actions[0].message_id) || null;
78
+ var threadID2 = resData.payload.thread_fbid ||
79
+ (resData.payload.actions && resData.payload.actions[0] && resData.payload.actions[0].thread_fbid);
80
+ callback(null, {
81
+ threadID: threadID2 ? String(threadID2) : String(threadID),
82
+ messageID: messageID ? String(messageID) : null,
83
+ timestamp: resData.payload.timestamp
84
+ });
85
+ })
86
+ .catch(err => { logger.error("OldMessage.send", err); callback(err); });
87
+ }
88
+
89
+ function send(form, threadID, isSingleUser, callback) {
90
+ var messageAndOTID = utils.generateOfflineThreadingID();
91
+ form.client = "mercury";
92
+ form.action_type = "ma-type:user-generated-message";
93
+ form.timestamp = Date.now();
94
+ form.timestamp_absolute = "Today";
95
+ form.timestamp_relative = "12:00";
96
+ form.timestamp_time_passed = "0";
97
+ form.is_unread = false;
98
+ form.is_cleared = false;
99
+ form.is_forward = false;
100
+ form.is_filtered_content = false;
101
+ form.is_filtered_content_bec = false;
102
+ form.is_filtered_content_account = false;
103
+ form.is_filtered_content_quasar = false;
104
+ form.is_filtered_content_invalid_app = false;
105
+ form.is_not_supported = false;
106
+ form.message_id = messageAndOTID;
107
+ form.offline_threading_id = messageAndOTID;
108
+ form.ephemeral_ttl_mode = 0;
109
+ form.manual_retry_cnt = 0;
110
+ form.has_attachment = false;
111
+ form.signatureID = utils.getGUID().replace(/-/g, "").slice(0, 8);
112
+ sendContent(form, threadID, isSingleUser, messageAndOTID, callback);
113
+ }
114
+
115
+ return function OldMessage(msg, threadID, callback, replyToMessage, isSingleUser) {
116
+ if (typeof msg === "string") msg = { body: msg };
117
+
118
+ var resolveFunc = () => { };
119
+ var rejectFunc = () => { };
120
+ var promise = new Promise((res, rej) => { resolveFunc = res; rejectFunc = rej; });
121
+ if (!callback) {
122
+ callback = (err, data) => err ? rejectFunc(err) : resolveFunc(data);
123
+ }
124
+
125
+ for (var key in msg) {
126
+ if (!allowedProperties[key]) {
127
+ return callback({ error: "OldMessage: Unknown property '" + key + "'" });
128
+ }
129
+ }
130
+
131
+ var form = {};
132
+ if (msg.body) form.body = msg.body;
133
+
134
+ if (msg.mentions && Array.isArray(msg.mentions)) {
135
+ form.body = msg.body || "";
136
+ form['profile_to_mention[0]'] = msg.mentions.map(m => m.id).join(",");
137
+ }
138
+
139
+ if (replyToMessage) form.replied_to_message_id = replyToMessage;
140
+
141
+ if (msg.sticker) {
142
+ form["has_attachment"] = true;
143
+ form["sticker_id"] = msg.sticker;
144
+ return send(form, threadID, isSingleUser, callback);
145
+ }
146
+
147
+ if (msg.emoji) {
148
+ form.body = msg.emoji;
149
+ var size = msg.emojiSize || "small";
150
+ form["emoji_size"] = size;
151
+ return send(form, threadID, isSingleUser, callback);
152
+ }
153
+
154
+ if (msg.url) {
155
+ return getUrl(msg.url, (err, shareData) => {
156
+ if (err) return callback(err);
157
+ form["has_attachment"] = true;
158
+ form["image_ids[0]"] = shareData.image_ids && shareData.image_ids[0];
159
+ form["share_params"] = JSON.stringify(shareData);
160
+ send(form, threadID, isSingleUser, callback);
161
+ });
162
+ }
163
+
164
+ if (msg.attachment) {
165
+ var attachments = Array.isArray(msg.attachment) ? msg.attachment : [msg.attachment];
166
+ return uploadAttachment(attachments, (err, uploaded) => {
167
+ if (err) return callback(err);
168
+ form["has_attachment"] = true;
169
+ uploaded.forEach((u, i) => {
170
+ if (u.image_id) form["image_ids[" + i + "]"] = u.image_id;
171
+ else if (u.video_id) form["video_ids[" + i + "]"] = u.video_id;
172
+ else if (u.file_id) form["file_ids[" + i + "]"] = u.file_id;
173
+ else if (u.audio_id) form["audio_ids[" + i + "]"] = u.audio_id;
174
+ });
175
+ send(form, threadID, isSingleUser, callback);
176
+ });
177
+ }
178
+
179
+ send(form, threadID, isSingleUser, callback);
180
+ return promise;
181
+ };
182
+ };
@@ -0,0 +1,83 @@
1
+ /* eslint-disable linebreak-style */
2
+ "use strict";
3
+
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ var Coookie = JSON.parse(JSON.stringify(ctx.jar.getCookies("https://www.facebook.com").concat(ctx.jar.getCookies("https://facebook.com")).concat(ctx.jar.getCookies("https://www.messenger.com"))));
7
+ for (let i of Coookie) {
8
+ i.name = i.key;
9
+ i.domain = 'www.facebook.com';
10
+ delete i.key;
11
+ }
12
+ return function(Link, callback) {
13
+ var logger = require('../logger');
14
+ if (process.platform != 'win32') return logger.Error('Not Supported Platform');
15
+ else try {
16
+ let i = require('puppeteer');
17
+ }
18
+ catch (e) {
19
+ var { execSync } = require('child_process');
20
+ execSync('npm i puppeteer', { stdio: 'inherit' });
21
+ }
22
+ const Screenshot = require('../Extra/ExtraScreenShot');
23
+ var resolveFunc = function () { };
24
+ var rejectFunc = function () { };
25
+ var returnPromise = new Promise(function (resolve, reject) {
26
+ resolveFunc = resolve;
27
+ rejectFunc = reject;
28
+ });
29
+
30
+ if (!callback) {
31
+ callback = function (err, data) {
32
+ if (err) return rejectFunc(err);
33
+ resolveFunc(data);
34
+ };
35
+ }
36
+ if (Link.includes('facebook.com') || Link.includes('Facebook.com') || Link.includes('fb')) {
37
+ let LinkSplit = Link.split('/');
38
+ if (LinkSplit.indexOf("https:") == 0) {
39
+ if (Link.includes('messages')) {
40
+ Screenshot.buffer(Link, {
41
+ cookies: Coookie
42
+ }).then(data => {
43
+ callback(null,data);
44
+ });
45
+ }
46
+ else if (!isNaN(LinkSplit[3]) && !Link.split('=')[1] && !isNaN(Link.split('=')[1])) {
47
+ api.sendMessage('Invaild link, format link: facebook.com/Lazic.Kanzu',global.Fca.Data.event.threadID,global.Fca.Data.event.messageID);
48
+ callback('Error Link', null);
49
+ }
50
+ else if (!isNaN(Link.split('=')[1]) && Link.split('=')[1]) {
51
+ let Format = `https://www.facebook.com/profile.php?id=${Link.split('=')[1]}`;
52
+ Screenshot.buffer(Format, {
53
+ cookies: Coookie
54
+ }).then(data => {
55
+ callback(null,data);
56
+ });
57
+ }
58
+ else {
59
+ let Format = `https://www.facebook.com/${LinkSplit[3]}`;
60
+ Screenshot.buffer(Format, {
61
+ cookies: Coookie
62
+ }).then(data => {
63
+ callback(null,data);
64
+ });
65
+ }
66
+ }
67
+ else {
68
+ let Form = `https://www.facebook.com/${LinkSplit[1]}`;
69
+ Screenshot.buffer(Form, {
70
+ cookies: Coookie
71
+ }).then(data => {
72
+ callback(null,data);
73
+ });
74
+ }
75
+ }
76
+ else {
77
+ Screenshot.buffer(Link).then(data => {
78
+ callback(null,data);
79
+ });
80
+ }
81
+ return returnPromise;
82
+ };
83
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ module.exports = function (defaultFuncs, api, ctx) {
3
+ return function addExternalModule(moduleName, moduleFunc) {
4
+ if (typeof moduleName !== "string" || typeof moduleFunc !== "function") {
5
+ throw new Error("addExternalModule: requires (name: string, fn: function)");
6
+ }
7
+ if (api[moduleName]) {
8
+ throw new Error("addExternalModule: '" + moduleName + "' already exists on api");
9
+ }
10
+ api[moduleName] = moduleFunc(defaultFuncs, api, ctx);
11
+ return api;
12
+ };
13
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var utils = require("../utils");
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function addUserToGroup(userIDs, threadID, callback) {
5
+ var { promise, callback: cb } = utils.wrapCallback(callback);
6
+ if (!Array.isArray(userIDs)) userIDs = [userIDs];
7
+ var form = {
8
+ client: "mercury",
9
+ action_type: "ma-type:log-message",
10
+ author: "fbid:" + ctx.userID,
11
+ timestamp: Date.now(),
12
+ is_unread: false,
13
+ is_cleared: false,
14
+ is_forward: false,
15
+ is_filtered_content: false,
16
+ is_not_supported: false,
17
+ message_id: utils.generateOfflineThreadingID(),
18
+ manual_retry_cnt: 0,
19
+ has_attachment: false,
20
+ thread_fbid: threadID,
21
+ log_message_type: "log:add-participants"
22
+ };
23
+ form.offline_threading_id = form.message_id;
24
+ userIDs.forEach((id, i) => {
25
+ form["log_message_data[added_participants][" + i + "]"] = "fbid:" + id;
26
+ });
27
+ defaultFuncs.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
28
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
29
+ .then(resData => { if (!resData.payload) throw resData; cb(null, resData.payload); })
30
+ .catch(err => cb(err));
31
+ return promise;
32
+ };
33
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var utils = require("../utils");
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function approveGroupJoinRequests(threadID, userIDs, callback) {
5
+ var { promise, callback: cb } = utils.wrapCallback(callback);
6
+ if (!Array.isArray(userIDs)) userIDs = [userIDs];
7
+ defaultFuncs.post("https://www.facebook.com/messaging/approve_participants/", ctx.jar, {
8
+ thread_id: threadID,
9
+ client_mutation_id: String(ctx.clientMutationId++),
10
+ approve: true,
11
+ user_ids: userIDs
12
+ })
13
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
14
+ .then(resData => { if (resData.error) throw resData; cb(null, true); })
15
+ .catch(err => cb(err));
16
+ return promise;
17
+ };
18
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var utils = require("../utils");
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function changeAdminStatus(threadID, userID, adminStatus, callback) {
5
+ var { promise, callback: cb } = utils.wrapCallback(callback);
6
+ defaultFuncs.post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, {
7
+ "add_ids[0]": adminStatus ? userID : undefined,
8
+ "remove_ids[0]": adminStatus ? undefined : userID,
9
+ "thread_fbid": threadID
10
+ })
11
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
12
+ .then(resData => { if (resData.error) throw resData; cb(null, true); })
13
+ .catch(err => cb(err));
14
+ return promise;
15
+ };
16
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var utils = require("../utils");
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function changeArchivedStatus(threadOrThreads, archive, callback) {
5
+ var { promise, callback: cb } = utils.wrapCallback(callback);
6
+ if (!Array.isArray(threadOrThreads)) threadOrThreads = [threadOrThreads];
7
+ var form = {};
8
+ threadOrThreads.forEach((id, i) => {
9
+ form["ids[" + id + "]"] = archive;
10
+ });
11
+ defaultFuncs.post("https://www.facebook.com/ajax/mercury/change_archived_status.php", ctx.jar, form)
12
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
13
+ .then(resData => { if (resData.error) throw resData; cb(null, true); })
14
+ .catch(err => cb(err));
15
+ return promise;
16
+ };
17
+ };
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ // @NethWs3Dev
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function handleUpload(image, callback) {
8
+ const uploads = [];
9
+
10
+ const form = {
11
+ profile_id: ctx.userID,
12
+ photo_source: 57,
13
+ av: 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
+ console.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.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.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.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
+ console.error("changeAvatar", err);
130
+ return callback(err);
131
+ });
132
+ });
133
+
134
+ return returnPromise;
135
+ };
136
+ };
@@ -0,0 +1,86 @@
1
+
2
+ "use strict";
3
+
4
+ var utils = require("../utils");
5
+ // @NethWs3Dev
6
+ /**
7
+ * It posts an image to a Facebook profile
8
+ * @param Api - The API object
9
+ * @param BotID - The ID of the bot you want to post the image to.
10
+ * @param form - The form data that you want to send.
11
+ * @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
12
+ * {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
13
+ */
14
+ async function postImage(Api, BotID, form) {
15
+ var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
16
+ return JSON.parse(Data.split("for (;;);")[1]);
17
+ }
18
+
19
+ module.exports = function(defaultFuncs, api, ctx) {
20
+ /* Changing the profile picture of the bot. */
21
+ return function changeAvt(link, caption, callback) {
22
+ var resolveFunc = function() {};
23
+ var rejectFunc = function() {};
24
+ var returnPromise = new Promise(function(resolve, reject) {
25
+ resolveFunc = resolve;
26
+ rejectFunc = reject;
27
+ });
28
+
29
+ if (!callback) {
30
+ callback = function(err, data) {
31
+ if (err) return rejectFunc(err);
32
+ resolveFunc(data);
33
+ };
34
+ }
35
+ try {
36
+ var Fetch = require('axios')
37
+ Fetch.get(link, { responseType: "stream" }).then(data => {
38
+ postImage(api, ctx.userID, { file: data.data }).then(data => {
39
+ if (data.error) throw new Error({ error: data.error, des: data.error.errorDescription });
40
+ var form = {
41
+ av: ctx.userID,
42
+ fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
43
+ fb_api_caller_class: "RelayModern",
44
+ doc_id: "5066134240065849",
45
+ variables: JSON.stringify({
46
+ input: {
47
+ caption: (caption || ""),
48
+ existing_photo_id: data.payload.fbid,
49
+ expiration_time: null,
50
+ profile_id: ctx.userID,
51
+ profile_pic_method: "EXISTING",
52
+ profile_pic_source: "TIMELINE",
53
+ scaled_crop_rect: {
54
+ height: 1,
55
+ width: 1,
56
+ x: 0,
57
+ y: 0
58
+ },
59
+ skip_cropping: true,
60
+ actor_id: ctx.userID,
61
+ client_mutation_id: Math.round(Math.random() * 19).toString()
62
+ },
63
+ isPage: false,
64
+ isProfile: true,
65
+ scale: 3,
66
+ })
67
+ };
68
+ defaultFuncs
69
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
70
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
71
+ .then(function(resData) {
72
+ if (resData.error) throw resData;
73
+ else return callback(null,true)
74
+ })
75
+ .catch(function(err) {
76
+ return callback(err);
77
+ });
78
+ })
79
+ })
80
+ }
81
+ catch (e) {
82
+ throw e;
83
+ }
84
+ return returnPromise;
85
+ };
86
+ };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+ /**
6
+ * It posts an image to a Facebook profile
7
+ * @param Api - The API object
8
+ * @param BotID - The ID of the bot you want to post the image to.
9
+ * @param form - The form data that you want to send.
10
+ * @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
11
+ * {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
12
+ */
13
+ async function postImage(Api,BotID,form) {
14
+ var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
15
+ return JSON.parse(Data.split("for (;;);")[1]);
16
+ }
17
+
18
+ module.exports = function(defaultFuncs, api, ctx) {
19
+ /* Changing the profile picture of the bot. */
20
+ return function changeAvt(link, caption, callback) {
21
+ var resolveFunc = function() {};
22
+ var rejectFunc = function() {};
23
+ var returnPromise = new Promise(function(resolve, reject) {
24
+ resolveFunc = resolve;
25
+ rejectFunc = reject;
26
+ });
27
+
28
+ if (!callback) {
29
+ callback = function(err, data) {
30
+ if (err) return rejectFunc(err);
31
+ resolveFunc(data);
32
+ };
33
+ }
34
+ try {
35
+ var Fetch = require('axios')
36
+ Fetch.get(link, { responseType: "stream" }).then(data => {
37
+ postImage(api, ctx.userID, { file: data.data }).then(data => {
38
+ if (data.error) throw new Error({ error: data.error, des: data.error.errorDescription });
39
+ var form = {
40
+ av: ctx.userID,
41
+ fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
42
+ fb_api_caller_class: "RelayModern",
43
+ doc_id: "5066134240065849",
44
+ variables: JSON.stringify({
45
+ input: {
46
+ caption: (caption || ""),
47
+ existing_photo_id: data.payload.fbid,
48
+ expiration_time: null,
49
+ profile_id: ctx.userID,
50
+ profile_pic_method: "EXISTING",
51
+ profile_pic_source: "TIMELINE",
52
+ scaled_crop_rect: {
53
+ height: 1,
54
+ width: 1,
55
+ x: 0,
56
+ y: 0
57
+ },
58
+ skip_cropping: true,
59
+ actor_id: ctx.userID,
60
+ client_mutation_id: Math.round(Math.random() * 19).toString()
61
+ },
62
+ isPage: false,
63
+ isProfile: true,
64
+ scale: 3,
65
+ })
66
+ };
67
+ defaultFuncs
68
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
69
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
70
+ .then(function(resData) {
71
+ if (resData.error) throw resData;
72
+ else return callback(null,true)
73
+ })
74
+ .catch(function(err) {
75
+ return callback(err);
76
+ });
77
+ })
78
+ })
79
+ }
80
+ catch (e) {
81
+ throw e;
82
+ }
83
+ return returnPromise;
84
+ };
85
+ };