metacord 0.0.1-security → 1.2.3-Beta

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of metacord might be problematic. Click here for more details.

Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/MetaCord_Config.json +14 -0
  3. package/MetaCord_Database/Database.sqlite +0 -0
  4. package/MetaCord_Database/Do not delete this folder or any of the files in it +0 -0
  5. package/README.md +207 -5
  6. package/index.js +678 -0
  7. package/logger.js +16 -0
  8. package/package.json +38 -3
  9. package/src/addExternalModule.js +16 -0
  10. package/src/addUserToGroup.js +78 -0
  11. package/src/changeAdminStatus.js +78 -0
  12. package/src/changeArchivedStatus.js +41 -0
  13. package/src/changeBio.js +65 -0
  14. package/src/changeBlockedStatus.js +36 -0
  15. package/src/changeGroupImage.js +106 -0
  16. package/src/changeNickname.js +45 -0
  17. package/src/changeThreadColor.js +62 -0
  18. package/src/changeThreadEmoji.js +42 -0
  19. package/src/createNewGroup.js +70 -0
  20. package/src/createPoll.js +60 -0
  21. package/src/deleteMessage.js +45 -0
  22. package/src/deleteThread.js +43 -0
  23. package/src/forwardAttachment.js +48 -0
  24. package/src/getCurrentUserID.js +7 -0
  25. package/src/getEmojiUrl.js +27 -0
  26. package/src/getFriendsList.js +73 -0
  27. package/src/getOnlineTime.js +31 -0
  28. package/src/getThreadHistory.js +193 -0
  29. package/src/getThreadInfo.js +197 -0
  30. package/src/getThreadList.js +213 -0
  31. package/src/getThreadPictures.js +59 -0
  32. package/src/getUID.js +57 -0
  33. package/src/getUserID.js +62 -0
  34. package/src/getUserInfo.js +66 -0
  35. package/src/handleFriendRequest.js +49 -0
  36. package/src/handleMessageRequest.js +49 -0
  37. package/src/httpGet.js +49 -0
  38. package/src/httpPost.js +48 -0
  39. package/src/httpPostFormData.js +41 -0
  40. package/src/listenMqtt.js +634 -0
  41. package/src/logout.js +68 -0
  42. package/src/markAsDelivered.js +48 -0
  43. package/src/markAsRead.js +70 -0
  44. package/src/markAsReadAll.js +43 -0
  45. package/src/markAsSeen.js +51 -0
  46. package/src/muteThread.js +47 -0
  47. package/src/removeUserFromGroup.js +49 -0
  48. package/src/resolvePhotoUrl.js +37 -0
  49. package/src/searchForThread.js +43 -0
  50. package/src/sendMessage.js +334 -0
  51. package/src/sendTypingIndicator.js +80 -0
  52. package/src/setMessageReaction.js +109 -0
  53. package/src/setPostReaction.js +102 -0
  54. package/src/setTitle.js +74 -0
  55. package/src/threadColors.js +39 -0
  56. package/src/unfriend.js +43 -0
  57. package/src/unsendMessage.js +40 -0
  58. package/utils/Database.js +42 -0
  59. package/utils/Extension.js +138 -0
  60. package/utils/Html/MetaCord.png +0 -0
  61. package/utils/Html/index.html +200 -0
  62. package/utils/StateCrypt.js +53 -0
  63. package/utils.js +1249 -0
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Được Fix Hay Làm Màu Bởi: @KanzuWakazaki
5
+ * 19/2/2022
6
+ */
7
+
8
+ var utils = require("../utils");
9
+ var log = require("npmlog");
10
+ var bluebird = require("bluebird");
11
+
12
+ var allowedProperties = {
13
+ attachment: true,
14
+ url: true,
15
+ sticker: true,
16
+ emoji: true,
17
+ emojiSize: true,
18
+ body: true,
19
+ mentions: true,
20
+ location: true,
21
+ };
22
+
23
+ module.exports = function (defaultFuncs, api, ctx) {
24
+ function uploadAttachment(attachments, callback) {
25
+ var uploads = [];
26
+
27
+ // create an array of promises
28
+ for (var i = 0; i < attachments.length; i++) {
29
+ if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
30
+ var form = {
31
+ upload_1024: attachments[i],
32
+ voice_clip: "true"
33
+ };
34
+
35
+ uploads.push(
36
+ defaultFuncs
37
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
38
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
39
+ .then(function (resData) {
40
+ if (resData.error) throw resData;
41
+ // We have to return the data unformatted unless we want to change it
42
+ // back in sendMessage.
43
+ return resData.payload.metadata[0];
44
+ })
45
+ );
46
+ }
47
+
48
+ // resolve all promises
49
+ bluebird
50
+ .all(uploads)
51
+ .then(resData => callback(null, resData)
52
+ )
53
+ .catch(function (err) {
54
+ log.error("uploadAttachment", err);
55
+ return callback(err);
56
+ });
57
+ }
58
+
59
+ function getUrl(url, callback) {
60
+ var form = {
61
+ image_height: 960,
62
+ image_width: 960,
63
+ uri: url
64
+ };
65
+
66
+ defaultFuncs
67
+ .post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
68
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
69
+ .then(function (resData) {
70
+ if (resData.error) return callback(resData);
71
+ if (!resData.payload) return callback({ error: "Invalid url" });
72
+ callback(null, resData.payload.share_data.share_params);
73
+ })
74
+ .catch(function (err) {
75
+ log.error("getUrl", err);
76
+ return callback(err);
77
+ });
78
+ }
79
+
80
+
81
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
82
+ // There are three cases here:
83
+ // 1. threadID is of type array, where we're starting a new group chat with users
84
+ // specified in the array.
85
+ // 2. User is sending a message to a specific user.
86
+ // 3. No additional form params and the message goes to an existing group chat.
87
+ if (utils.getType(threadID) === "Array") {
88
+ for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
89
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
90
+ form["client_thread_id"] = "root:" + messageAndOTID;
91
+ log.info("sendMessage", "Sending message to multiple users: " + threadID);
92
+ }
93
+ else {
94
+ // This means that threadID is the id of a user, and the chat
95
+ // is a single person chat
96
+ if (isSingleUser) {
97
+ form["specific_to_list[0]"] = "fbid:" + threadID;
98
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
99
+ form["other_user_fbid"] = threadID;
100
+ }
101
+ else form["thread_fbid"] = threadID;
102
+ }
103
+
104
+ if (ctx.globalOptions.pageID) {
105
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
106
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
107
+ form["creator_info[creatorID]"] = ctx.userID;
108
+ form["creator_info[creatorType]"] = "direct_admin";
109
+ form["creator_info[labelType]"] = "sent_message";
110
+ form["creator_info[pageID]"] = ctx.globalOptions.pageID;
111
+ form["request_user_id"] = ctx.globalOptions.pageID;
112
+ form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
113
+ }
114
+
115
+ defaultFuncs
116
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
117
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
118
+ .then(function (resData) {
119
+ if (!resData) return callback({ error: "Send message failed." });
120
+ if (resData.error) {
121
+ if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
122
+ return callback(resData);
123
+ }
124
+
125
+ var messageInfo = resData.payload.actions.reduce(function (p, v) {
126
+ return (
127
+ {
128
+ threadID: v.thread_fbid,
129
+ messageID: v.message_id,
130
+ timestamp: v.timestamp
131
+ } || p
132
+ );
133
+ }, null);
134
+ return callback(null, messageInfo);
135
+ })
136
+ .catch(function (err) {
137
+ log.error("sendMessage", err);
138
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
139
+ return callback(err);
140
+ });
141
+ }
142
+
143
+ function send(form, threadID, messageAndOTID, callback, isGroup) {
144
+ // đôi lời từ ai đó :v
145
+ // cái này chỉ fix send ko được tin nhắn thôi chứ i cũng đôn nâu cách fix lắm nên là có gì ae fix giùm nha kkk
146
+ if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
147
+ else {
148
+ var THREADFIX = "ThreadID".replace("ThreadID",threadID); // i cũng đôn nâu
149
+ if (THREADFIX.length <= 15) sendContent(form, threadID, !isGroup, messageAndOTID, callback);
150
+ else if (THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0) sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
151
+ else sendContent(form, threadID, !isGroup, messageAndOTID, callback);
152
+ }
153
+ }
154
+
155
+ /*
156
+ * Giải Thích :
157
+ * Theo Sự Quan Sát Của ... Thì Thấy Rằng Số UID Facebook vs ThreadID Có Sự Trên Lệch Số ( Số ) Với Nhau
158
+ * nên đã lợi dụng điều đó làm main :v
159
+ ! utils.getType(threadID) Sẽ Không Được Sử Dụng Nữa Vì Nó Toàn Là Undefined :v
160
+ */
161
+
162
+ function handleUrl(msg, form, callback, cb) {
163
+ if (msg.url) {
164
+ form["shareable_attachment[share_type]"] = "100";
165
+ getUrl(msg.url, function (err, params) {
166
+ if (err) return callback(err);
167
+ form["shareable_attachment[share_params]"] = params;
168
+ cb();
169
+ });
170
+ }
171
+ else cb();
172
+ }
173
+
174
+ function handleLocation(msg, form, callback, cb) {
175
+ if (msg.location) {
176
+ if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
177
+ form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
178
+ form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
179
+ form["location_attachment[is_current_location]"] = !!msg.location.current;
180
+ }
181
+ cb();
182
+ }
183
+
184
+ function handleSticker(msg, form, callback, cb) {
185
+ if (msg.sticker) form["sticker_id"] = msg.sticker;
186
+ cb();
187
+ }
188
+
189
+ function handleEmoji(msg, form, callback, cb) {
190
+ if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
191
+ if (msg.emoji) {
192
+ if (msg.emojiSize == null) msg.emojiSize = "medium";
193
+ if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
194
+ if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
195
+ form["body"] = msg.emoji;
196
+ form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
197
+ }
198
+ cb();
199
+ }
200
+
201
+ function handleAttachment(msg, form, callback, cb) {
202
+ if (msg.attachment) {
203
+ form["image_ids"] = [];
204
+ form["gif_ids"] = [];
205
+ form["file_ids"] = [];
206
+ form["video_ids"] = [];
207
+ form["audio_ids"] = [];
208
+
209
+ if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
210
+
211
+ uploadAttachment(msg.attachment, function (err, files) {
212
+ if (err) return callback(err);
213
+ files.forEach(function (file) {
214
+ var key = Object.keys(file);
215
+ var type = key[0]; // image_id, file_id, etc
216
+ form["" + type + "s"].push(file[type]); // push the id
217
+ });
218
+ cb();
219
+ });
220
+ }
221
+ else cb();
222
+ }
223
+
224
+ function handleMention(msg, form, callback, cb) {
225
+ if (msg.mentions) {
226
+ for (let i = 0; i < msg.mentions.length; i++) {
227
+ const mention = msg.mentions[i];
228
+ const tag = mention.tag;
229
+ if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
230
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
231
+ if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
232
+ if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
233
+
234
+ const id = mention.id || 0;
235
+ const emptyChar = '\u200E';
236
+ form["body"] = emptyChar + msg.body;
237
+ form["profile_xmd[" + i + "][offset]"] = offset + 1;
238
+ form["profile_xmd[" + i + "][length]"] = tag.length;
239
+ form["profile_xmd[" + i + "][id]"] = id;
240
+ form["profile_xmd[" + i + "][type]"] = "p";
241
+ }
242
+ }
243
+ cb();
244
+ }
245
+
246
+ return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
247
+ typeof isGroup == "undefined" ? isGroup = null : "";
248
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
249
+ if (!replyToMessage && utils.getType(callback) === "String") {
250
+ replyToMessage = callback;
251
+ callback = function () { };
252
+ }
253
+
254
+ var resolveFunc = function () { };
255
+ var rejectFunc = function () { };
256
+ var returnPromise = new Promise(function (resolve, reject) {
257
+ resolveFunc = resolve;
258
+ rejectFunc = reject;
259
+ });
260
+
261
+ if (!callback) {
262
+ callback = function (err, data) {
263
+ if (err) return rejectFunc(err);
264
+ resolveFunc(data);
265
+ };
266
+ }
267
+
268
+ var msgType = utils.getType(msg);
269
+ var threadIDType = utils.getType(threadID);
270
+ var messageIDType = utils.getType(replyToMessage);
271
+
272
+ if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
273
+
274
+ // Changing this to accomodate an array of users
275
+ if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
276
+
277
+ if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
278
+
279
+ if (msgType === "String") msg = { body: msg };
280
+ var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
281
+ if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
282
+
283
+ var messageAndOTID = utils.generateOfflineThreadingID();
284
+
285
+ var form = {
286
+ client: "mercury",
287
+ action_type: "ma-type:user-generated-message",
288
+ author: "fbid:" + ctx.userID,
289
+ timestamp: Date.now(),
290
+ timestamp_absolute: "Today",
291
+ timestamp_relative: utils.generateTimestampRelative(),
292
+ timestamp_time_passed: "0",
293
+ is_unread: false,
294
+ is_cleared: false,
295
+ is_forward: false,
296
+ is_filtered_content: false,
297
+ is_filtered_content_bh: false,
298
+ is_filtered_content_account: false,
299
+ is_filtered_content_quasar: false,
300
+ is_filtered_content_invalid_app: false,
301
+ is_spoof_warning: false,
302
+ source: "source:chat:web",
303
+ "source_tags[0]": "source:chat",
304
+ body: msg.body ? msg.body.toString() : "",
305
+ html_body: false,
306
+ ui_push_phase: "V3",
307
+ status: "0",
308
+ offline_threading_id: messageAndOTID,
309
+ message_id: messageAndOTID,
310
+ threading_id: utils.generateThreadingID(ctx.clientID),
311
+ "ephemeral_ttl_mode:": "0",
312
+ manual_retry_cnt: "0",
313
+ has_attachment: !!(msg.attachment || msg.url || msg.sticker),
314
+ signatureID: utils.getSignatureID(),
315
+ replied_to_message_id: replyToMessage
316
+ };
317
+
318
+ handleLocation(msg, form, callback, () =>
319
+ handleSticker(msg, form, callback, () =>
320
+ handleAttachment(msg, form, callback, () =>
321
+ handleUrl(msg, form, callback, () =>
322
+ handleEmoji(msg, form, callback, () =>
323
+ handleMention(msg, form, callback, () =>
324
+ send(form, threadID, messageAndOTID, callback, isGroup)
325
+ )
326
+ )
327
+ )
328
+ )
329
+ )
330
+ );
331
+
332
+ return returnPromise;
333
+ };
334
+ };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function makeTypingIndicator(typ, threadID, callback, isGroup) {
8
+ var form = {
9
+ typ: +typ,
10
+ to: "",
11
+ source: "mercury-chat",
12
+ thread: threadID
13
+ };
14
+
15
+ // Check if thread is a single person chat or a group chat
16
+ // More info on this is in api.sendMessage
17
+ if (utils.getType(isGroup) == "Boolean") {
18
+ if (!isGroup) {
19
+ form.to = threadID;
20
+ }
21
+ defaultFuncs
22
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
23
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
+ .then(function (resData) {
25
+ if (resData.error) throw resData;
26
+ return callback();
27
+ })
28
+ .catch(function (err) {
29
+ log.error("sendTypingIndicator", err);
30
+ if (utils.getType(err) == "Object" && err.error === "Not logged in") {
31
+ ctx.loggedIn = false;
32
+ }
33
+ return callback(err);
34
+ });
35
+ }
36
+ else {
37
+ api.getUserInfo(threadID, function (err, res) {
38
+ if (err) return callback(err);
39
+ // If id is single person chat
40
+ if (Object.keys(res).length > 0) form.to = threadID;
41
+ defaultFuncs
42
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
43
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
44
+ .then(function (resData) {
45
+ if (resData.error) throw resData;
46
+ return callback();
47
+ })
48
+ .catch(function (err) {
49
+ log.error("sendTypingIndicator", err);
50
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
51
+ return callback(err);
52
+ });
53
+ });
54
+ }
55
+ }
56
+
57
+ return function sendTypingIndicator(threadID, callback, isGroup) {
58
+ if (
59
+ utils.getType(callback) !== "Function" &&
60
+ utils.getType(callback) !== "AsyncFunction"
61
+ ) {
62
+ if (callback) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
63
+ callback = () => { };
64
+ }
65
+
66
+ makeTypingIndicator(true, threadID, callback, isGroup);
67
+
68
+ return function end(cb) {
69
+ if (
70
+ utils.getType(cb) !== "Function" &&
71
+ utils.getType(cb) !== "AsyncFunction"
72
+ ) {
73
+ if (cb) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
74
+ cb = () => { };
75
+ }
76
+
77
+ makeTypingIndicator(false, threadID, cb, isGroup);
78
+ };
79
+ };
80
+ };
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err, data) {
17
+ if (err) return rejectFunc(err);
18
+ resolveFunc(data);
19
+ };
20
+ }
21
+
22
+ switch (reaction) {
23
+ case "\uD83D\uDE0D": //:heart_eyes:
24
+ case "\uD83D\uDE06": //:laughing:
25
+ case "\uD83D\uDE2E": //:open_mouth:
26
+ case "\uD83D\uDE22": //:cry:
27
+ case "\uD83D\uDE20": //:angry:
28
+ case "\uD83D\uDC4D": //:thumbsup:
29
+ case "\uD83D\uDC4E": //:thumbsdown:
30
+ case "\u2764": //:heart:
31
+ case "\uD83D\uDC97": //:glowingheart:
32
+ case "":
33
+ //valid
34
+ break;
35
+ case ":heart_eyes:":
36
+ case ":love:":
37
+ reaction = "\uD83D\uDE0D";
38
+ break;
39
+ case ":laughing:":
40
+ case ":haha:":
41
+ reaction = "\uD83D\uDE06";
42
+ break;
43
+ case ":open_mouth:":
44
+ case ":wow:":
45
+ reaction = "\uD83D\uDE2E";
46
+ break;
47
+ case ":cry:":
48
+ case ":sad:":
49
+ reaction = "\uD83D\uDE22";
50
+ break;
51
+ case ":angry:":
52
+ reaction = "\uD83D\uDE20";
53
+ break;
54
+ case ":thumbsup:":
55
+ case ":like:":
56
+ reaction = "\uD83D\uDC4D";
57
+ break;
58
+ case ":thumbsdown:":
59
+ case ":dislike:":
60
+ reaction = "\uD83D\uDC4E";
61
+ break;
62
+ case ":heart:":
63
+ reaction = "\u2764";
64
+ break;
65
+ case ":glowingheart:":
66
+ reaction = "\uD83D\uDC97";
67
+ break;
68
+ default:
69
+ if (forceCustomReaction) break;
70
+ return callback({ error: "Reaction is not a valid emoji." });
71
+ }
72
+
73
+ var variables = {
74
+ data: {
75
+ client_mutation_id: ctx.clientMutationId++,
76
+ actor_id: ctx.userID,
77
+ action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
78
+ message_id: messageID,
79
+ reaction: reaction
80
+ }
81
+ };
82
+
83
+ var qs = {
84
+ doc_id: "1491398900900362",
85
+ variables: JSON.stringify(variables),
86
+ dpr: 1
87
+ };
88
+
89
+ defaultFuncs
90
+ .postFormData(
91
+ "https://www.facebook.com/webgraphql/mutation/",
92
+ ctx.jar,
93
+ {},
94
+ qs
95
+ )
96
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
97
+ .then(function (resData) {
98
+ if (!resData) throw { error: "setReaction returned empty object." };
99
+ if (resData.error) throw resData;
100
+ callback(null);
101
+ })
102
+ .catch(function (err) {
103
+ log.error("setReaction", err);
104
+ return callback(err);
105
+ });
106
+
107
+ return returnPromise;
108
+ };
109
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @fix by NTKhang
3
+ * update as Thursday, 10 February 2022
4
+ * do not remove the author name to get more updates
5
+ */
6
+
7
+ "use strict";
8
+
9
+ var utils = require("../utils");
10
+ var log = require("npmlog");
11
+
12
+ function formatData(resData) {
13
+ return {
14
+ viewer_feedback_reaction_info: resData.feedback_react.feedback.viewer_feedback_reaction_info,
15
+ supported_reactions: resData.feedback_react.feedback.supported_reactions,
16
+ top_reactions: resData.feedback_react.feedback.top_reactions.edges,
17
+ reaction_count: resData.feedback_react.feedback.reaction_count
18
+ };
19
+ }
20
+
21
+ module.exports = function(defaultFuncs, api, ctx) {
22
+ return function setPostReaction(postID, type, callback) {
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
+ if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
32
+ callback = type;
33
+ type = 0;
34
+ }
35
+ else {
36
+ callback = function (err, data) {
37
+ if (err) {
38
+ return rejectFunc(err);
39
+ }
40
+ resolveFunc(data);
41
+ };
42
+ }
43
+ }
44
+
45
+ var map = {
46
+ unlike: 0,
47
+ like: 1,
48
+ heart: 2,
49
+ love: 16,
50
+ haha: 4,
51
+ wow: 3,
52
+ sad: 7,
53
+ angry: 8
54
+ };
55
+
56
+ if (utils.getType(type) !== "Number" && utils.getType(type) === "String") {
57
+ type = map[type.toLowerCase()];
58
+ }
59
+ else {
60
+ throw {
61
+ error: "setPostReaction: Invalid reaction type"
62
+ };
63
+ }
64
+
65
+ var form = {
66
+ av: ctx.userID,
67
+ fb_api_caller_class: "RelayModern",
68
+ fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
69
+ doc_id: "4769042373179384",
70
+ variables: JSON.stringify({
71
+ input: {
72
+ actor_id: ctx.userID,
73
+ feedback_id: (new Buffer.from("feedback:" + postID)).toString("base64"),
74
+ feedback_reaction: type,
75
+ feedback_source: "OBJECT",
76
+ is_tracking_encrypted: true,
77
+ tracking: [],
78
+ session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
79
+ client_mutation_id: Math.round(Math.random() * 19).toString()
80
+ },
81
+ useDefaultActor: false,
82
+ scale: 3
83
+ })
84
+ };
85
+
86
+ defaultFuncs
87
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
88
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
89
+ .then(function(resData) {
90
+ if (resData.errors) {
91
+ throw resData;
92
+ }
93
+ return callback(null, formatData(resData.data));
94
+ })
95
+ .catch(function(err) {
96
+ log.error("setPostReaction", err);
97
+ return callback(err);
98
+ });
99
+
100
+ return returnPromise;
101
+ };
102
+ };
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function setTitle(newTitle, threadID, callback) {
8
+ if (
9
+ !callback &&
10
+ (utils.getType(threadID) === "Function" ||
11
+ utils.getType(threadID) === "AsyncFunction")
12
+ ) throw { error: "please pass a threadID as a second argument." };
13
+
14
+
15
+ var resolveFunc = function () { };
16
+ var rejectFunc = function () { };
17
+ var returnPromise = new Promise(function (resolve, reject) {
18
+ resolveFunc = resolve;
19
+ rejectFunc = reject;
20
+ });
21
+
22
+ if (!callback) {
23
+ callback = function (err, data) {
24
+ if (err) return rejectFunc(err);
25
+ resolveFunc(data);
26
+ };
27
+ }
28
+
29
+ var messageAndOTID = utils.generateOfflineThreadingID();
30
+ var form = {
31
+ client: "mercury",
32
+ action_type: "ma-type:log-message",
33
+ author: "fbid:" + ctx.userID,
34
+ author_email: "",
35
+ coordinates: "",
36
+ timestamp: Date.now(),
37
+ timestamp_absolute: "Today",
38
+ timestamp_relative: utils.generateTimestampRelative(),
39
+ timestamp_time_passed: "0",
40
+ is_unread: false,
41
+ is_cleared: false,
42
+ is_forward: false,
43
+ is_filtered_content: false,
44
+ is_spoof_warning: false,
45
+ source: "source:chat:web",
46
+ "source_tags[0]": "source:chat",
47
+ status: "0",
48
+ offline_threading_id: messageAndOTID,
49
+ message_id: messageAndOTID,
50
+ threading_id: utils.generateThreadingID(ctx.clientID),
51
+ manual_retry_cnt: "0",
52
+ thread_fbid: threadID,
53
+ thread_name: newTitle,
54
+ thread_id: threadID,
55
+ log_message_type: "log:thread-name"
56
+ };
57
+
58
+ defaultFuncs
59
+ .post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
60
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
61
+ .then(function (resData) {
62
+ if (resData.error && resData.error === 1545012) throw { error: "Cannot change chat title: Not member of chat." };
63
+ if (resData.error && resData.error === 1545003) throw { error: "Cannot set title of single-user chat." };
64
+ if (resData.error) throw resData;
65
+ return callback();
66
+ })
67
+ .catch(function (err) {
68
+ log.error("setTitle", err);
69
+ return callback(err);
70
+ });
71
+
72
+ return returnPromise;
73
+ };
74
+ };