shadowx-fca 1.2.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.
- package/index.js +479 -0
- package/package.json +55 -0
- package/src/OldMessage.js +329 -0
- package/src/Screenshot.js +83 -0
- package/src/addExternalModule.js +25 -0
- package/src/addUserToGroup.js +115 -0
- package/src/changeAdminStatus.js +103 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeAvatar.js +136 -0
- package/src/changeAvatarV2.js +86 -0
- package/src/changeAvt.js +85 -0
- package/src/changeBio.js +76 -0
- package/src/changeBlockedStatus.js +49 -0
- package/src/changeBlockedStatusMqtt.js +80 -0
- package/src/changeCover.js +72 -0
- package/src/changeGroupImage.js +135 -0
- package/src/changeName.js +79 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +65 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/changeUsername.js +59 -0
- package/src/createCommentPost.js +230 -0
- package/src/createNewGroup.js +88 -0
- package/src/createPoll.js +71 -0
- package/src/createPost.js +276 -0
- package/src/data/cache/system/data.json +4 -0
- package/src/data/cache/system/datahandle.js +21 -0
- package/src/data/getThreadInfo.json +1 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/editMessage.js +68 -0
- package/src/editMessageOld.js +67 -0
- package/src/follow.js +74 -0
- package/src/forwardAttachment.js +60 -0
- package/src/friendList.js +103 -0
- package/src/getAccess.js +112 -0
- package/src/getAvatarUser.js +78 -0
- package/src/getBotInitialData.js +42 -0
- package/src/getCtx.js +5 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +83 -0
- package/src/getMessage.js +847 -0
- package/src/getOptions.js +5 -0
- package/src/getRegion.js +7 -0
- package/src/getThreadHistory.js +680 -0
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +232 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getThreadTheme.js +82 -0
- package/src/getUID.js +119 -0
- package/src/getUserID.js +61 -0
- package/src/getUserInfo.js +66 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/httpPostFormData.js +70 -0
- package/src/listenMqtt.js +870 -0
- package/src/listenNotification.js +85 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +47 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +40 -0
- package/src/markAsSeen.js +48 -0
- package/src/metaTheme.js +190 -0
- package/src/muteThread.js +45 -0
- package/src/note.js +228 -0
- package/src/pinMessage.js +59 -0
- package/src/refreshFb_dtsg.js +89 -0
- package/src/removeSuspiciousAccount.js +79 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/reply.js +442 -0
- package/src/resolvePhotoUrl.js +45 -0
- package/src/searchForThread.js +53 -0
- package/src/searchFriends.js +139 -0
- package/src/searchStickers.js +53 -0
- package/src/send.js +46 -0
- package/src/sendComment.js +159 -0
- package/src/sendFriendRequest.js +113 -0
- package/src/sendMessage.js +243 -0
- package/src/sendMessageMqtt.js +322 -0
- package/src/sendTypingIndicator.js +101 -0
- package/src/sendTypingIndicatorV2.js +28 -0
- package/src/setActiveStatus.js +93 -0
- package/src/setMessageReaction.js +122 -0
- package/src/setMessageReactionMqtt.js +62 -0
- package/src/setPostReaction.js +112 -0
- package/src/setProfileGuard.js +44 -0
- package/src/setProfileLock.js +98 -0
- package/src/setStoryReaction.js +134 -0
- package/src/setStorySeen.js +109 -0
- package/src/setThreadTheme.js +103 -0
- package/src/setTitle.js +90 -0
- package/src/shareContact.js +110 -0
- package/src/shareLink.js +59 -0
- package/src/stopListenMqtt.js +23 -0
- package/src/storyManager.js +358 -0
- package/src/suggestFriend.js +133 -0
- package/src/threadColors.js +131 -0
- package/src/unfriend.js +52 -0
- package/src/unsendMessage.js +45 -0
- package/src/uploadAttachment.js +93 -0
- package/utils.js +2867 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("../utils");
|
|
4
|
+
var log = require("npmlog");
|
|
5
|
+
var bluebird = require("bluebird");
|
|
6
|
+
|
|
7
|
+
var allowedProperties = {
|
|
8
|
+
attachment: true,
|
|
9
|
+
url: true,
|
|
10
|
+
sticker: true,
|
|
11
|
+
emoji: true,
|
|
12
|
+
emojiSize: true,
|
|
13
|
+
body: true,
|
|
14
|
+
mentions: true,
|
|
15
|
+
location: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
19
|
+
function uploadAttachment(attachments, callback) {
|
|
20
|
+
var uploads = [];
|
|
21
|
+
|
|
22
|
+
// create an array of promises
|
|
23
|
+
for (var i = 0; i < attachments.length; i++) {
|
|
24
|
+
if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
|
|
25
|
+
var form = {
|
|
26
|
+
upload_1024: attachments[i],
|
|
27
|
+
voice_clip: "true"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
uploads.push(
|
|
31
|
+
defaultFuncs
|
|
32
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {}, {})
|
|
33
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
34
|
+
.then(function (resData) {
|
|
35
|
+
if (resData.error) throw resData;
|
|
36
|
+
// We have to return the data unformatted unless we want to change it
|
|
37
|
+
// back in sendMessage.
|
|
38
|
+
return resData.payload.metadata[0];
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// resolve all promises
|
|
44
|
+
bluebird
|
|
45
|
+
.all(uploads)
|
|
46
|
+
.then(resData => callback(null, resData))
|
|
47
|
+
.catch(function (err) {
|
|
48
|
+
log.error("uploadAttachment", err);
|
|
49
|
+
return callback(err);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getUrl(url, callback) {
|
|
54
|
+
var form = {
|
|
55
|
+
image_height: 960,
|
|
56
|
+
image_width: 960,
|
|
57
|
+
uri: url
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
defaultFuncs
|
|
61
|
+
.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
|
|
62
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
63
|
+
.then(function (resData) {
|
|
64
|
+
if (resData.error) return callback(resData);
|
|
65
|
+
if (!resData.payload) return callback({ error: "Invalid url" });
|
|
66
|
+
callback(null, resData.payload.share_data.share_params);
|
|
67
|
+
})
|
|
68
|
+
.catch(function (err) {
|
|
69
|
+
log.error("getUrl", err);
|
|
70
|
+
return callback(err);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
|
75
|
+
// There are three cases here:
|
|
76
|
+
// 1. threadID is of type array, where we're starting a new group chat with users
|
|
77
|
+
// specified in the array.
|
|
78
|
+
// 2. User is sending a message to a specific user.
|
|
79
|
+
// 3. No additional form params and the message goes to an existing group chat.
|
|
80
|
+
if (utils.getType(threadID) === "Array") {
|
|
81
|
+
for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
|
82
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
|
83
|
+
form["client_thread_id"] = "root:" + messageAndOTID;
|
|
84
|
+
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// This means that threadID is the id of a user, and the chat
|
|
88
|
+
// is a single person chat
|
|
89
|
+
if (isSingleUser) {
|
|
90
|
+
form["specific_to_list[0]"] = "fbid:" + threadID;
|
|
91
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
|
92
|
+
form["other_user_fbid"] = threadID;
|
|
93
|
+
}
|
|
94
|
+
else form["thread_fbid"] = threadID;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (ctx.globalOptions.pageID) {
|
|
98
|
+
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
|
99
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
|
100
|
+
form["creator_info[creatorID]"] = ctx.userID;
|
|
101
|
+
form["creator_info[creatorType]"] = "direct_admin";
|
|
102
|
+
form["creator_info[labelType]"] = "sent_message";
|
|
103
|
+
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
|
104
|
+
form["request_user_id"] = ctx.globalOptions.pageID;
|
|
105
|
+
form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
defaultFuncs
|
|
109
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
|
110
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
111
|
+
.then(function (resData) {
|
|
112
|
+
if (!resData) return callback({ error: "Send message failed." });
|
|
113
|
+
if (resData.error) {
|
|
114
|
+
if (resData.error === 1545012) {
|
|
115
|
+
log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
log.error("sendMessage", resData);
|
|
119
|
+
}
|
|
120
|
+
return callback(resData);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var messageInfo = resData.payload.actions.reduce(function (p, v) {
|
|
124
|
+
return (
|
|
125
|
+
{
|
|
126
|
+
threadID: v.thread_fbid,
|
|
127
|
+
messageID: v.message_id,
|
|
128
|
+
timestamp: v.timestamp
|
|
129
|
+
} || p
|
|
130
|
+
);
|
|
131
|
+
}, null);
|
|
132
|
+
|
|
133
|
+
return callback(null, messageInfo);
|
|
134
|
+
})
|
|
135
|
+
.catch(function (err) {
|
|
136
|
+
log.error("sendMessage", err);
|
|
137
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
|
138
|
+
return callback(err);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
|
143
|
+
// We're doing a query to this to check if the given id is the id of
|
|
144
|
+
// a user or of a group chat. The form will be different depending
|
|
145
|
+
// on that.
|
|
146
|
+
if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
|
|
147
|
+
else {
|
|
148
|
+
if (utils.getType(isGroup) != "Boolean") sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
|
149
|
+
else sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function handleUrl(msg, form, callback, cb) {
|
|
154
|
+
if (msg.url) {
|
|
155
|
+
form["shareable_attachment[share_type]"] = "100";
|
|
156
|
+
getUrl(msg.url, function (err, params) {
|
|
157
|
+
if (err) return callback(err);
|
|
158
|
+
form["shareable_attachment[share_params]"] = params;
|
|
159
|
+
cb();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
else cb();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function handleLocation(msg, form, callback, cb) {
|
|
166
|
+
if (msg.location) {
|
|
167
|
+
if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
|
|
168
|
+
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
|
169
|
+
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
|
170
|
+
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
|
171
|
+
}
|
|
172
|
+
cb();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function handleSticker(msg, form, callback, cb) {
|
|
176
|
+
if (msg.sticker) form["sticker_id"] = msg.sticker;
|
|
177
|
+
cb();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function handleEmoji(msg, form, callback, cb) {
|
|
181
|
+
if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
|
|
182
|
+
if (msg.emoji) {
|
|
183
|
+
if (msg.emojiSize == null) msg.emojiSize = "medium";
|
|
184
|
+
if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
|
|
185
|
+
if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
|
|
186
|
+
form["body"] = msg.emoji;
|
|
187
|
+
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
|
188
|
+
}
|
|
189
|
+
cb();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function handleAttachment(msg, form, callback, cb) {
|
|
193
|
+
if (msg.attachment) {
|
|
194
|
+
form["image_ids"] = [];
|
|
195
|
+
form["gif_ids"] = [];
|
|
196
|
+
form["file_ids"] = [];
|
|
197
|
+
form["video_ids"] = [];
|
|
198
|
+
form["audio_ids"] = [];
|
|
199
|
+
|
|
200
|
+
if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
|
|
201
|
+
if (msg.attachment.every(e=>/_id$/.test(e[0]))) {
|
|
202
|
+
//console.log(msg.attachment)
|
|
203
|
+
msg.attachment.map(e=>form[`${e[0]}s`].push(e[1]));
|
|
204
|
+
return cb();
|
|
205
|
+
}
|
|
206
|
+
uploadAttachment(msg.attachment, function (err, files) {
|
|
207
|
+
if (err) return callback(err);
|
|
208
|
+
files.forEach(function (file) {
|
|
209
|
+
var key = Object.keys(file);
|
|
210
|
+
var type = key[0]; // image_id, file_id, etc
|
|
211
|
+
form["" + type + "s"].push(file[type]); // push the id
|
|
212
|
+
});
|
|
213
|
+
cb();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else cb();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function handleMention(msg, form, callback, cb) {
|
|
220
|
+
if (msg.mentions) {
|
|
221
|
+
for (let i = 0; i < msg.mentions.length; i++) {
|
|
222
|
+
const mention = msg.mentions[i];
|
|
223
|
+
const tag = mention.tag;
|
|
224
|
+
if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
|
|
225
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
|
226
|
+
if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
|
|
227
|
+
if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
|
|
228
|
+
|
|
229
|
+
const id = mention.id || 0;
|
|
230
|
+
const emptyChar = '\u200E';
|
|
231
|
+
form["body"] = emptyChar + msg.body;
|
|
232
|
+
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
|
233
|
+
form["profile_xmd[" + i + "][length]"] = tag.length;
|
|
234
|
+
form["profile_xmd[" + i + "][id]"] = id;
|
|
235
|
+
form["profile_xmd[" + i + "][type]"] = "p";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
cb();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
|
242
|
+
typeof isGroup == "undefined" ? isGroup = null : "";
|
|
243
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
|
|
244
|
+
if (!replyToMessage && utils.getType(callback) === "String") {
|
|
245
|
+
replyToMessage = callback;
|
|
246
|
+
callback = function () { };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
var resolveFunc = function () { };
|
|
250
|
+
var rejectFunc = function () { };
|
|
251
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
252
|
+
resolveFunc = resolve;
|
|
253
|
+
rejectFunc = reject;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
if (!callback) {
|
|
257
|
+
callback = function (err, data) {
|
|
258
|
+
if (err) return rejectFunc(err);
|
|
259
|
+
resolveFunc(data);
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var msgType = utils.getType(msg);
|
|
264
|
+
var threadIDType = utils.getType(threadID);
|
|
265
|
+
var messageIDType = utils.getType(replyToMessage);
|
|
266
|
+
|
|
267
|
+
if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
|
|
268
|
+
|
|
269
|
+
// Changing this to accomodate an array of users
|
|
270
|
+
if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
|
|
271
|
+
|
|
272
|
+
if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
|
|
273
|
+
|
|
274
|
+
if (msgType === "String") msg = { body: msg };
|
|
275
|
+
var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
|
276
|
+
if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
|
|
277
|
+
|
|
278
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
|
279
|
+
// console.log(messageAndOTID)
|
|
280
|
+
var form = {
|
|
281
|
+
client: "mercury",
|
|
282
|
+
action_type: "ma-type:user-generated-message",
|
|
283
|
+
author: "fbid:" + ctx.userID,
|
|
284
|
+
timestamp: Date.now(),
|
|
285
|
+
timestamp_absolute: "Today",
|
|
286
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
287
|
+
timestamp_time_passed: "0",
|
|
288
|
+
is_unread: false,
|
|
289
|
+
is_cleared: false,
|
|
290
|
+
is_forward: false,
|
|
291
|
+
is_filtered_content: false,
|
|
292
|
+
is_filtered_content_bh: false,
|
|
293
|
+
is_filtered_content_account: false,
|
|
294
|
+
is_filtered_content_quasar: false,
|
|
295
|
+
is_filtered_content_invalid_app: false,
|
|
296
|
+
is_spoof_warning: false,
|
|
297
|
+
source: "source:chat:web",
|
|
298
|
+
"source_tags[0]": "source:chat",
|
|
299
|
+
body: msg.body ? msg.body.toString() : "",
|
|
300
|
+
html_body: false,
|
|
301
|
+
ui_push_phase: "V3",
|
|
302
|
+
status: "0",
|
|
303
|
+
offline_threading_id: messageAndOTID,
|
|
304
|
+
message_id: messageAndOTID,
|
|
305
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
|
306
|
+
"ephemeral_ttl_mode:": "0",
|
|
307
|
+
manual_retry_cnt: "0",
|
|
308
|
+
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
|
309
|
+
signatureID: utils.getSignatureID(),
|
|
310
|
+
replied_to_message_id: replyToMessage
|
|
311
|
+
};
|
|
312
|
+
// console.log(form)
|
|
313
|
+
|
|
314
|
+
handleLocation(msg, form, callback, () =>
|
|
315
|
+
handleSticker(msg, form, callback, () =>
|
|
316
|
+
handleAttachment(msg, form, callback, () =>
|
|
317
|
+
handleUrl(msg, form, callback, () =>
|
|
318
|
+
handleEmoji(msg, form, callback, () =>
|
|
319
|
+
handleMention(msg, form, callback, () =>
|
|
320
|
+
send(form, threadID, messageAndOTID, callback, isGroup)
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
return returnPromise;
|
|
328
|
+
};
|
|
329
|
+
};
|
|
@@ -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,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
return function addExternalModule(moduleObj) {
|
|
7
|
+
if (utils.getType(moduleObj) == "Object") {
|
|
8
|
+
for (const apiName in moduleObj) {
|
|
9
|
+
if (utils.getType(moduleObj[apiName]) == "Function") {
|
|
10
|
+
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(
|
|
14
|
+
moduleObj[apiName],
|
|
15
|
+
)}!`,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`moduleObj must be an object, not ${utils.getType(moduleObj)}!`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
// @NethWs3Dev
|
|
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({
|
|
21
|
+
error: "please pass a threadID as a second argument.",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!callback) {
|
|
26
|
+
callback = function (err) {
|
|
27
|
+
if (err) {
|
|
28
|
+
return rejectFunc(err);
|
|
29
|
+
}
|
|
30
|
+
resolveFunc();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
utils.getType(threadID) !== "Number" &&
|
|
36
|
+
utils.getType(threadID) !== "String"
|
|
37
|
+
) {
|
|
38
|
+
throw new utils.CustomError({
|
|
39
|
+
error:
|
|
40
|
+
"ThreadID should be of type Number or String and not " +
|
|
41
|
+
utils.getType(threadID) +
|
|
42
|
+
".",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (utils.getType(userID) !== "Array") {
|
|
47
|
+
userID = [userID];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const messageAndOTID = utils.generateOfflineThreadingID();
|
|
51
|
+
const form = {
|
|
52
|
+
client: "mercury",
|
|
53
|
+
action_type: "ma-type:log-message",
|
|
54
|
+
author: "fbid:" + (ctx.userID),
|
|
55
|
+
thread_id: "",
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
timestamp_absolute: "Today",
|
|
58
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
59
|
+
timestamp_time_passed: "0",
|
|
60
|
+
is_unread: false,
|
|
61
|
+
is_cleared: false,
|
|
62
|
+
is_forward: false,
|
|
63
|
+
is_filtered_content: false,
|
|
64
|
+
is_filtered_content_bh: false,
|
|
65
|
+
is_filtered_content_account: false,
|
|
66
|
+
is_spoof_warning: false,
|
|
67
|
+
source: "source:chat:web",
|
|
68
|
+
"source_tags[0]": "source:chat",
|
|
69
|
+
log_message_type: "log:subscribe",
|
|
70
|
+
status: "0",
|
|
71
|
+
offline_threading_id: messageAndOTID,
|
|
72
|
+
message_id: messageAndOTID,
|
|
73
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
|
74
|
+
manual_retry_cnt: "0",
|
|
75
|
+
thread_fbid: threadID,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < userID.length; i++) {
|
|
79
|
+
if (
|
|
80
|
+
utils.getType(userID[i]) !== "Number" &&
|
|
81
|
+
utils.getType(userID[i]) !== "String"
|
|
82
|
+
) {
|
|
83
|
+
throw new utils.CustomError({
|
|
84
|
+
error:
|
|
85
|
+
"Elements of userID should be of type Number or String and not " +
|
|
86
|
+
utils.getType(userID[i]) +
|
|
87
|
+
".",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
form["log_message_data[added_participants][" + i + "]"] =
|
|
92
|
+
"fbid:" + userID[i];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
defaultFuncs
|
|
96
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
|
97
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
98
|
+
.then(function (resData) {
|
|
99
|
+
if (!resData) {
|
|
100
|
+
throw new utils.CustomError({ error: "Add to group failed." });
|
|
101
|
+
}
|
|
102
|
+
if (resData.error) {
|
|
103
|
+
throw new utils.CustomError(resData);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return callback();
|
|
107
|
+
})
|
|
108
|
+
.catch(function (err) {
|
|
109
|
+
console.error("addUserToGroup", err);
|
|
110
|
+
return callback(err);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return returnPromise;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
// @NethWs3Dev
|
|
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({
|
|
10
|
+
error: "changeAdminStatus: threadID must be a string",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (utils.getType(adminIDs) === "String") {
|
|
15
|
+
adminIDs = [adminIDs];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (utils.getType(adminIDs) !== "Array") {
|
|
19
|
+
throw new utils.CustomError({
|
|
20
|
+
error: "changeAdminStatus: adminIDs must be an array or string",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (utils.getType(adminStatus) !== "Boolean") {
|
|
25
|
+
throw new utils.CustomError({
|
|
26
|
+
error: "changeAdminStatus: adminStatus must be a string",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let resolveFunc = function () {};
|
|
31
|
+
let rejectFunc = function () {};
|
|
32
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
33
|
+
resolveFunc = resolve;
|
|
34
|
+
rejectFunc = reject;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!callback) {
|
|
38
|
+
callback = function (err) {
|
|
39
|
+
if (err) {
|
|
40
|
+
return rejectFunc(err);
|
|
41
|
+
}
|
|
42
|
+
resolveFunc();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
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
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const form = {
|
|
56
|
+
thread_fbid: threadID,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
let i = 0;
|
|
60
|
+
for (const u of adminIDs) {
|
|
61
|
+
form[`admin_ids[${i++}]`] = u;
|
|
62
|
+
}
|
|
63
|
+
form["add"] = adminStatus;
|
|
64
|
+
|
|
65
|
+
defaultFuncs
|
|
66
|
+
.post(
|
|
67
|
+
"https://www.facebook.com/messaging/save_admins/?dpr=1",
|
|
68
|
+
ctx.jar,
|
|
69
|
+
form,
|
|
70
|
+
)
|
|
71
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
72
|
+
.then(function (resData) {
|
|
73
|
+
if (resData.error) {
|
|
74
|
+
switch (resData.error) {
|
|
75
|
+
case 1976004:
|
|
76
|
+
throw new utils.CustomError({
|
|
77
|
+
error: "Cannot alter admin status: you are not an admin.",
|
|
78
|
+
rawResponse: resData,
|
|
79
|
+
});
|
|
80
|
+
case 1357031:
|
|
81
|
+
throw new utils.CustomError({
|
|
82
|
+
error:
|
|
83
|
+
"Cannot alter admin status: this thread is not a group chat.",
|
|
84
|
+
rawResponse: resData,
|
|
85
|
+
});
|
|
86
|
+
default:
|
|
87
|
+
throw new utils.CustomError({
|
|
88
|
+
error: "Cannot alter admin status: unknown error.",
|
|
89
|
+
rawResponse: resData,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
callback();
|
|
95
|
+
})
|
|
96
|
+
.catch(function (err) {
|
|
97
|
+
console.error("changeAdminStatus", err);
|
|
98
|
+
return callback(err);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return returnPromise;
|
|
102
|
+
};
|
|
103
|
+
};
|