fca-smart-shankar 13.0.0 → 16.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.
- package/.cache/replit/env/latest +56 -0
- package/.cache/replit/env/latest.json +1 -0
- package/.cache/replit/modules/nodejs-14.res +1 -0
- package/.cache/replit/modules/replit.res +1 -0
- package/.cache/replit/modules/web.res +1 -0
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/typescript/5.5/package.json +1 -0
- package/.config/configstore/update-notifier-npm.json +4 -0
- package/.gitattributes +2 -0
- package/.replit +3 -12
- package/.upm/store.json +1 -1
- package/Extra/Balancer.js +49 -0
- package/Extra/Bypass/956/index.js +234 -0
- package/Extra/Bypass/test/aaaa.json +170 -0
- package/Extra/Bypass/test/index.js +188 -0
- package/Extra/Database/index.js +469 -0
- package/Extra/ExtraAddons.js +82 -0
- package/Extra/ExtraFindUID.js +62 -0
- package/Extra/ExtraGetThread.js +365 -0
- package/Extra/ExtraScreenShot.js +430 -0
- package/Extra/ExtraUptimeRobot.js +38 -0
- package/Extra/Html/Classic/script.js +119 -0
- package/Extra/Html/Classic/style.css +8 -0
- package/Extra/Security/AES_256_GCM/index.js +0 -0
- package/Extra/Security/Base/Step_1.js +6 -0
- package/Extra/Security/Base/Step_2.js +22 -0
- package/Extra/Security/Base/Step_3.js +22 -0
- package/Extra/Security/Base/index.js +191 -0
- package/Extra/Security/Index.js +5 -0
- package/Extra/Security/Step_1.js +6 -0
- package/Extra/Security/Step_2.js +22 -0
- package/Extra/Security/Step_3.js +22 -0
- package/Extra/Src/Change_Environment.js +24 -0
- package/Extra/Src/Check_Update.js +67 -0
- package/Extra/Src/History.js +115 -0
- package/Extra/Src/Instant_Update.js +65 -0
- package/Extra/Src/Last-Run.js +65 -0
- package/Extra/Src/Premium.js +81 -0
- package/Extra/Src/Release_Memory.js +160 -0
- package/Extra/Src/Websocket.js +213 -0
- package/Extra/Src/image/checkmate.jpg +0 -0
- package/Extra/Src/test.js +28 -0
- package/Extra/Src/uuid.js +137 -0
- package/Func/AcceptAgreement.js +31 -0
- package/Func/ClearCache.js +64 -0
- package/Func/ReportV1.js +54 -0
- package/LICENSE +678 -0
- package/Language/index.json +228 -0
- package/Main.js +1444 -0
- package/README.md +30 -175
- package/SECURITY.md +18 -0
- package/broadcast.js +44 -0
- package/index.js +414 -511
- package/logger.js +66 -0
- package/package.json +85 -370
- package/src/Dev_Horizon_Data.js +125 -0
- package/src/Dev_getThreadInfoOLD.js +422 -0
- package/src/Dev_shareTest2.js +68 -0
- package/src/Dev_shareTest3.js +71 -0
- package/src/Premium.js +25 -0
- package/src/Screenshot.js +83 -0
- package/src/addExternalModule.js +5 -14
- package/src/addUserToGroup.js +20 -56
- package/src/changeAdminStatus.js +20 -44
- package/src/changeArchivedStatus.js +11 -25
- package/src/{changeAvatarV2.js → changeAvt.js} +2 -3
- package/src/changeBio.js +15 -26
- package/src/changeBlockedStatus.js +8 -21
- package/src/changeGroupImage.js +24 -53
- package/src/changeNickname.js +13 -27
- package/src/changeThreadColor.js +19 -22
- package/src/changeThreadEmoji.js +11 -24
- package/src/createNewGroup.js +20 -38
- package/src/createPoll.js +16 -27
- package/src/deleteMessage.js +13 -24
- package/src/deleteThread.js +12 -25
- package/src/editMessage.js +53 -71
- package/src/forwardAttachment.js +15 -27
- package/src/getAccessToken.js +28 -0
- package/src/getCurrentUserID.js +1 -1
- package/src/getEmojiUrl.js +8 -10
- package/src/getFriendsList.js +15 -25
- package/src/getMessage.js +81 -813
- package/src/getThreadHistory.js +98 -241
- package/src/getThreadInfo.js +287 -90
- package/src/getThreadInfoOLD.js +422 -0
- package/src/getThreadList.js +157 -214
- package/src/getThreadMain.js +220 -0
- package/src/getThreadPictures.js +19 -39
- package/src/getUID.js +50 -113
- package/src/getUserID.js +14 -18
- package/src/getUserInfo.js +71 -65
- package/src/getUserInfoMain.js +65 -0
- package/src/getUserInfoV2.js +32 -0
- package/src/getUserInfoV3.js +63 -0
- package/src/getUserInfoV4.js +55 -0
- package/src/getUserInfoV5.js +61 -0
- package/src/handleFriendRequest.js +13 -24
- package/src/handleMessageRequest.js +20 -36
- package/src/httpGet.js +18 -34
- package/src/httpPost.js +18 -35
- package/src/httpPostFormData.js +24 -53
- package/src/listenMqtt.js +944 -680
- package/src/listenMqttV1.js +846 -0
- package/src/logout.js +15 -22
- package/src/markAsDelivered.js +15 -25
- package/src/markAsRead.js +27 -45
- package/src/markAsReadAll.js +14 -21
- package/src/markAsSeen.js +18 -28
- package/src/muteThread.js +12 -17
- package/src/removeUserFromGroup.js +17 -47
- package/src/resolvePhotoUrl.js +13 -21
- package/src/searchForThread.js +13 -23
- package/src/sendMessage.js +117 -178
- package/src/sendMqttMessage.js +71 -0
- package/src/sendTypingIndicator.js +16 -46
- package/src/setMessageReaction.js +20 -33
- package/src/setPostReaction.js +95 -105
- package/src/setTitle.js +18 -34
- package/src/shareContact.js +37 -92
- package/src/shareLink.js +4 -5
- package/src/threadColors.js +18 -110
- package/src/unfriend.js +9 -18
- package/src/unsendMessage.js +34 -31
- package/src/unsendMqttMessage.js +66 -0
- package/test/Database_Test.js +4 -0
- package/test/Db2.js +530 -0
- package/test/Shankar_Database/A_README.md +1 -0
- package/test/Shankar_Database/Database.db +0 -0
- package/test/data/shareAttach.js +1 -1
- package/test/env/.env +0 -0
- package/test/example-db.db +0 -0
- package/test/memoryleak.js +18 -0
- package/test/test.js +1 -1
- package/test/testname.js +1342 -0
- package/test/testv2.js +3 -0
- package/utils.js +2918 -1393
- package/CHANGELOG.md +0 -2
- package/LICENSE-MIT +0 -21
- package/generated-icon.png +0 -0
- package/replit.nix +0 -5
- package/shankar-fca.json +0 -4
- package/src/changeAvatar.js +0 -136
- package/src/changeBlockedStatusMqtt.js +0 -80
- package/src/changeCover.js +0 -73
- package/src/changeName.js +0 -79
- package/src/changeUsername.js +0 -59
- package/src/createCommentPost.js +0 -230
- package/src/createPost.js +0 -277
- package/src/data/getThreadInfo.json +0 -1
- package/src/editMessageOld.js +0 -67
- package/src/follow.js +0 -74
- package/src/getAccess.js +0 -112
- package/src/getAvatarUser.js +0 -78
- package/src/getRegion.js +0 -7
- package/src/getThreadHistoryDeprecated.js +0 -93
- package/src/getThreadInfoDeprecated.js +0 -80
- package/src/getThreadListDeprecated.js +0 -75
- package/src/listenNotification.js +0 -85
- package/src/pinMessage.js +0 -59
- package/src/refreshFb_dtsg.js +0 -89
- package/src/searchStickers.js +0 -53
- package/src/sendMessageMqtt.js +0 -322
- package/src/sendTypingIndicatorV2.js +0 -28
- package/src/setMessageReactionMqtt.js +0 -62
- package/src/setProfileGuard.js +0 -45
- package/src/setStoryReaction.js +0 -64
- package/src/stopListenMqtt.js +0 -26
- package/src/uploadAttachment.js +0 -94
package/src/sendMessage.js
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
/**
|
4
|
+
* Được Fix Hay Làm Màu Bởi: @HarryWakazaki
|
5
|
+
* 21/4/2022
|
6
|
+
*/
|
7
|
+
|
3
8
|
var utils = require("../utils");
|
4
9
|
var log = require("npmlog");
|
5
10
|
var bluebird = require("bluebird");
|
11
|
+
var fs = require('fs-extra');
|
6
12
|
|
7
13
|
var allowedProperties = {
|
8
14
|
attachment: true,
|
@@ -15,21 +21,16 @@ var allowedProperties = {
|
|
15
21
|
location: true,
|
16
22
|
};
|
17
23
|
|
24
|
+
var AntiText = "Your criminal activity was detected while attempting to send an Appstate file";
|
25
|
+
var Location_Stack;
|
26
|
+
|
18
27
|
module.exports = function (defaultFuncs, api, ctx) {
|
19
28
|
function uploadAttachment(attachments, callback) {
|
20
29
|
var uploads = [];
|
21
30
|
|
22
31
|
// create an array of promises
|
23
32
|
for (var i = 0; i < attachments.length; i++) {
|
24
|
-
if (!utils.isReadableStream(attachments[i])) {
|
25
|
-
throw {
|
26
|
-
error:
|
27
|
-
"Attachment should be a readable stream and not " +
|
28
|
-
utils.getType(attachments[i]) +
|
29
|
-
"."
|
30
|
-
};
|
31
|
-
}
|
32
|
-
|
33
|
+
if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
|
33
34
|
var form = {
|
34
35
|
upload_1024: attachments[i],
|
35
36
|
voice_clip: "true"
|
@@ -37,18 +38,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
37
38
|
|
38
39
|
uploads.push(
|
39
40
|
defaultFuncs
|
40
|
-
.postFormData(
|
41
|
-
"https://upload.facebook.com/ajax/mercury/upload.php",
|
42
|
-
ctx.jar,
|
43
|
-
form,
|
44
|
-
{}
|
45
|
-
)
|
41
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
46
42
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
47
43
|
.then(function (resData) {
|
48
|
-
if (resData.error)
|
49
|
-
throw resData;
|
50
|
-
}
|
51
|
-
|
44
|
+
if (resData.error) throw resData;
|
52
45
|
// We have to return the data unformatted unless we want to change it
|
53
46
|
// back in sendMessage.
|
54
47
|
return resData.payload.metadata[0];
|
@@ -59,9 +52,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
59
52
|
// resolve all promises
|
60
53
|
bluebird
|
61
54
|
.all(uploads)
|
62
|
-
.then(
|
63
|
-
|
64
|
-
})
|
55
|
+
.then(resData => callback(null, resData)
|
56
|
+
)
|
65
57
|
.catch(function (err) {
|
66
58
|
log.error("uploadAttachment", err);
|
67
59
|
return callback(err);
|
@@ -76,21 +68,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
76
68
|
};
|
77
69
|
|
78
70
|
defaultFuncs
|
79
|
-
.post(
|
80
|
-
"https://www.facebook.com/message_share_attachment/fromURI/",
|
81
|
-
ctx.jar,
|
82
|
-
form
|
83
|
-
)
|
71
|
+
.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
|
84
72
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
85
73
|
.then(function (resData) {
|
86
|
-
if (resData.error)
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
if (!resData.payload) {
|
91
|
-
return callback({ error: "Invalid url" });
|
92
|
-
}
|
93
|
-
|
74
|
+
if (resData.error) return callback(resData);
|
75
|
+
if (!resData.payload) return callback({ error: "Invalid url" });
|
94
76
|
callback(null, resData.payload.share_data.share_params);
|
95
77
|
})
|
96
78
|
.catch(function (err) {
|
@@ -106,22 +88,20 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
106
88
|
// 2. User is sending a message to a specific user.
|
107
89
|
// 3. No additional form params and the message goes to an existing group chat.
|
108
90
|
if (utils.getType(threadID) === "Array") {
|
109
|
-
for (var i = 0; i < threadID.length; i++)
|
110
|
-
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
111
|
-
}
|
91
|
+
for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
112
92
|
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
113
93
|
form["client_thread_id"] = "root:" + messageAndOTID;
|
114
94
|
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
115
|
-
}
|
95
|
+
}
|
96
|
+
else {
|
116
97
|
// This means that threadID is the id of a user, and the chat
|
117
98
|
// is a single person chat
|
118
99
|
if (isSingleUser) {
|
119
100
|
form["specific_to_list[0]"] = "fbid:" + threadID;
|
120
101
|
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
121
102
|
form["other_user_fbid"] = threadID;
|
122
|
-
} else {
|
123
|
-
form["thread_fbid"] = threadID;
|
124
103
|
}
|
104
|
+
else form["thread_fbid"] = threadID;
|
125
105
|
}
|
126
106
|
|
127
107
|
if (ctx.globalOptions.pageID) {
|
@@ -132,26 +112,31 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
132
112
|
form["creator_info[labelType]"] = "sent_message";
|
133
113
|
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
134
114
|
form["request_user_id"] = ctx.globalOptions.pageID;
|
135
|
-
form["creator_info[profileURI]"] =
|
136
|
-
|
115
|
+
form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
|
116
|
+
}
|
117
|
+
|
118
|
+
if (global.Fca.Require.FastConfig.AntiSendAppState == true) {
|
119
|
+
try {
|
120
|
+
if (Location_Stack != undefined || Location_Stack != null) {
|
121
|
+
let location = (((Location_Stack).replace("Error",'')).split('\n')[7]).split(' ');
|
122
|
+
let format = {
|
123
|
+
Source: (location[6]).split('s:')[0].replace("(",'') + 's',
|
124
|
+
Line: (location[6]).split('s:')[1].replace(")",'')
|
125
|
+
};
|
126
|
+
form.body = AntiText + "\n- Source: " + format.Source + "\n- Line: " + format.Line;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
catch (e) {}
|
137
130
|
}
|
138
131
|
|
139
132
|
defaultFuncs
|
140
133
|
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
141
134
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
142
135
|
.then(function (resData) {
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
|
136
|
+
Location_Stack = undefined;
|
137
|
+
if (!resData) return callback({ error: "Send message failed." });
|
147
138
|
if (resData.error) {
|
148
|
-
if (resData.error === 1545012)
|
149
|
-
log.warn(
|
150
|
-
"sendMessage",
|
151
|
-
"Got error 1545012. This might mean that you're not part of the conversation " +
|
152
|
-
threadID
|
153
|
-
);
|
154
|
-
}
|
139
|
+
if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
|
155
140
|
return callback(resData);
|
156
141
|
}
|
157
142
|
|
@@ -164,87 +149,68 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
164
149
|
} || p
|
165
150
|
);
|
166
151
|
}, null);
|
167
|
-
|
168
152
|
return callback(null, messageInfo);
|
169
153
|
})
|
170
154
|
.catch(function (err) {
|
171
155
|
log.error("sendMessage", err);
|
172
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
173
|
-
|
174
|
-
}
|
175
|
-
return callback(err);
|
156
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
157
|
+
return callback(err,null);
|
176
158
|
});
|
177
|
-
|
159
|
+
}
|
178
160
|
|
179
161
|
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
162
|
+
//Full Fix sendMessage
|
163
|
+
if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
|
164
|
+
else {
|
165
|
+
var THREADFIX = "ThreadID".replace("ThreadID",threadID); // i cũng đôn nâu
|
166
|
+
if (THREADFIX.length <= 15 || global.Fca.isUser.includes(threadID)) sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
167
|
+
else if (THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0 || global.Fca.isThread.includes(threadID)) sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
168
|
+
else {
|
169
|
+
if (global.Fca.Data.event.isGroup) {
|
170
|
+
sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
171
|
+
global.Fca.isThread.push(threadID);
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
175
|
+
global.Fca.isUser.push(threadID);
|
176
|
+
}
|
177
|
+
}
|
190
178
|
}
|
191
179
|
}
|
192
|
-
|
180
|
+
|
193
181
|
function handleUrl(msg, form, callback, cb) {
|
194
182
|
if (msg.url) {
|
195
183
|
form["shareable_attachment[share_type]"] = "100";
|
196
184
|
getUrl(msg.url, function (err, params) {
|
197
|
-
if (err)
|
198
|
-
return callback(err);
|
199
|
-
}
|
200
|
-
|
185
|
+
if (err) return callback(err);
|
201
186
|
form["shareable_attachment[share_params]"] = params;
|
202
187
|
cb();
|
203
188
|
});
|
204
|
-
} else {
|
205
|
-
cb();
|
206
189
|
}
|
190
|
+
else cb();
|
207
191
|
}
|
208
192
|
|
209
193
|
function handleLocation(msg, form, callback, cb) {
|
210
194
|
if (msg.location) {
|
211
|
-
if (msg.location.latitude == null || msg.location.longitude == null) {
|
212
|
-
return callback({ error: "location property needs both latitude and longitude" });
|
213
|
-
}
|
214
|
-
|
195
|
+
if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
|
215
196
|
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
216
197
|
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
217
198
|
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
218
199
|
}
|
219
|
-
|
220
200
|
cb();
|
221
201
|
}
|
222
202
|
|
223
203
|
function handleSticker(msg, form, callback, cb) {
|
224
|
-
if (msg.sticker)
|
225
|
-
form["sticker_id"] = msg.sticker;
|
226
|
-
}
|
204
|
+
if (msg.sticker) form["sticker_id"] = msg.sticker;
|
227
205
|
cb();
|
228
206
|
}
|
229
207
|
|
230
208
|
function handleEmoji(msg, form, callback, cb) {
|
231
|
-
if (msg.emojiSize != null && msg.emoji == null) {
|
232
|
-
return callback({ error: "emoji property is empty" });
|
233
|
-
}
|
209
|
+
if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
|
234
210
|
if (msg.emoji) {
|
235
|
-
if (msg.emojiSize == null)
|
236
|
-
|
237
|
-
}
|
238
|
-
if (
|
239
|
-
msg.emojiSize != "small" &&
|
240
|
-
msg.emojiSize != "medium" &&
|
241
|
-
msg.emojiSize != "large"
|
242
|
-
) {
|
243
|
-
return callback({ error: "emojiSize property is invalid" });
|
244
|
-
}
|
245
|
-
if (form["body"] != null && form["body"] != "") {
|
246
|
-
return callback({ error: "body is not empty" });
|
247
|
-
}
|
211
|
+
if (msg.emojiSize == null) msg.emojiSize = "medium";
|
212
|
+
if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
|
213
|
+
if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
|
248
214
|
form["body"] = msg.emoji;
|
249
215
|
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
250
216
|
}
|
@@ -259,15 +225,43 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
259
225
|
form["video_ids"] = [];
|
260
226
|
form["audio_ids"] = [];
|
261
227
|
|
262
|
-
if (utils.getType(msg.attachment) !== "Array")
|
263
|
-
|
228
|
+
if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
|
229
|
+
|
230
|
+
const isValidAttachment = attachment => /_id$/.test(attachment[0]);
|
231
|
+
|
232
|
+
if (msg.attachment.every(isValidAttachment)) {
|
233
|
+
msg.attachment.forEach(attachment => form[`${attachment[0]}s`].push(attachment[1]));
|
234
|
+
return cb();
|
264
235
|
}
|
265
236
|
|
266
|
-
|
267
|
-
|
268
|
-
|
237
|
+
if (global.Fca.Require.FastConfig.AntiSendAppState) {
|
238
|
+
try {
|
239
|
+
const AllowList = [".png", ".mp3", ".mp4", ".wav", ".gif", ".jpg", ".tff"];
|
240
|
+
const CheckList = [".json", ".js", ".txt", ".docx", '.php'];
|
241
|
+
var Has;
|
242
|
+
for (let i = 0; i < (msg.attachment).length; i++) {
|
243
|
+
if (utils.isReadableStream((msg.attachment)[i])) {
|
244
|
+
var path = (msg.attachment)[i].path != undefined ? (msg.attachment)[i].path : "nonpath";
|
245
|
+
if (AllowList.some(i => path.includes(i))) continue;
|
246
|
+
else if (CheckList.some(i => path.includes(i))) {
|
247
|
+
let data = fs.readFileSync(path, 'utf-8');
|
248
|
+
if (data.includes("datr")) {
|
249
|
+
Has = true;
|
250
|
+
var err = new Error();
|
251
|
+
Location_Stack = err.stack;
|
252
|
+
}
|
253
|
+
else continue;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
}
|
257
|
+
if (Has == true) {
|
258
|
+
msg.attachment = [fs.createReadStream(__dirname + "/../Extra/Src/Image/checkmate.jpg")];
|
259
|
+
}
|
269
260
|
}
|
270
|
-
|
261
|
+
catch (e) {}
|
262
|
+
}
|
263
|
+
uploadAttachment(msg.attachment, function (err, files) {
|
264
|
+
if (err) return callback(err);
|
271
265
|
files.forEach(function (file) {
|
272
266
|
var key = Object.keys(file);
|
273
267
|
var type = key[0]; // image_id, file_id, etc
|
@@ -275,33 +269,19 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
275
269
|
});
|
276
270
|
cb();
|
277
271
|
});
|
278
|
-
} else {
|
279
|
-
cb();
|
280
272
|
}
|
273
|
+
else cb();
|
281
274
|
}
|
282
275
|
|
283
276
|
function handleMention(msg, form, callback, cb) {
|
284
277
|
if (msg.mentions) {
|
285
278
|
for (let i = 0; i < msg.mentions.length; i++) {
|
286
279
|
const mention = msg.mentions[i];
|
287
|
-
|
288
280
|
const tag = mention.tag;
|
289
|
-
if (typeof tag !== "string") {
|
290
|
-
return callback({ error: "Mention tags must be strings." });
|
291
|
-
}
|
292
|
-
|
281
|
+
if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
|
293
282
|
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
294
|
-
|
295
|
-
if (
|
296
|
-
log.warn(
|
297
|
-
"handleMention",
|
298
|
-
'Mention for "' + tag + '" not found in message string.'
|
299
|
-
);
|
300
|
-
}
|
301
|
-
|
302
|
-
if (mention.id == null) {
|
303
|
-
log.warn("handleMention", "Mention id should be non-null.");
|
304
|
-
}
|
283
|
+
if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
|
284
|
+
if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
|
305
285
|
|
306
286
|
const id = mention.id || 0;
|
307
287
|
const emptyChar = '\u200E';
|
@@ -317,19 +297,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
317
297
|
|
318
298
|
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
319
299
|
typeof isGroup == "undefined" ? isGroup = null : "";
|
320
|
-
if (
|
321
|
-
|
322
|
-
(utils.getType(threadID) === "Function" ||
|
323
|
-
utils.getType(threadID) === "AsyncFunction")
|
324
|
-
) {
|
325
|
-
return threadID({ error: "Pass a threadID as a second argument." });
|
326
|
-
}
|
327
|
-
if (
|
328
|
-
!replyToMessage &&
|
329
|
-
utils.getType(callback) === "String"
|
330
|
-
) {
|
300
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
|
301
|
+
if (!replyToMessage && utils.getType(callback) === "String") {
|
331
302
|
replyToMessage = callback;
|
332
|
-
callback =
|
303
|
+
callback = function () { };
|
333
304
|
}
|
334
305
|
|
335
306
|
var resolveFunc = function () { };
|
@@ -350,48 +321,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
350
321
|
var threadIDType = utils.getType(threadID);
|
351
322
|
var messageIDType = utils.getType(replyToMessage);
|
352
323
|
|
353
|
-
if (msgType !== "String" && msgType !== "Object") {
|
354
|
-
return callback({
|
355
|
-
error:
|
356
|
-
"Message should be of type string or object and not " + msgType + "."
|
357
|
-
});
|
358
|
-
}
|
324
|
+
if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
|
359
325
|
|
360
326
|
// Changing this to accomodate an array of users
|
361
|
-
if (
|
362
|
-
threadIDType !== "Array" &&
|
363
|
-
threadIDType !== "Number" &&
|
364
|
-
threadIDType !== "String"
|
365
|
-
) {
|
366
|
-
return callback({
|
367
|
-
error:
|
368
|
-
"ThreadID should be of type number, string, or array and not " +
|
369
|
-
threadIDType +
|
370
|
-
"."
|
371
|
-
});
|
372
|
-
}
|
327
|
+
if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
|
373
328
|
|
374
|
-
if (replyToMessage && messageIDType !== 'String') {
|
375
|
-
return callback({
|
376
|
-
error:
|
377
|
-
"MessageID should be of type string and not " +
|
378
|
-
threadIDType +
|
379
|
-
"."
|
380
|
-
});
|
381
|
-
}
|
329
|
+
if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
|
382
330
|
|
383
|
-
if (msgType === "String") {
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
var disallowedProperties = Object.keys(msg).filter(
|
388
|
-
prop => !allowedProperties[prop]
|
389
|
-
);
|
390
|
-
if (disallowedProperties.length > 0) {
|
391
|
-
return callback({
|
392
|
-
error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`"
|
393
|
-
});
|
394
|
-
}
|
331
|
+
if (msgType === "String") msg = { body: msg };
|
332
|
+
var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
333
|
+
if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
|
395
334
|
|
396
335
|
var messageAndOTID = utils.generateOfflineThreadingID();
|
397
336
|
|
@@ -414,7 +353,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
414
353
|
is_spoof_warning: false,
|
415
354
|
source: "source:chat:web",
|
416
355
|
"source_tags[0]": "source:chat",
|
417
|
-
body: msg.body ? msg.body.toString() : "",
|
356
|
+
body: msg.body ? msg.body.toString().replace("\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f",' ') : "",
|
418
357
|
html_body: false,
|
419
358
|
ui_push_phase: "V3",
|
420
359
|
status: "0",
|
@@ -427,7 +366,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
427
366
|
signatureID: utils.getSignatureID(),
|
428
367
|
replied_to_message_id: replyToMessage
|
429
368
|
};
|
430
|
-
|
369
|
+
|
431
370
|
handleLocation(msg, form, callback, () =>
|
432
371
|
handleSticker(msg, form, callback, () =>
|
433
372
|
handleAttachment(msg, form, callback, () =>
|
@@ -444,4 +383,4 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
444
383
|
|
445
384
|
return returnPromise;
|
446
385
|
};
|
447
|
-
};
|
386
|
+
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/* eslint-disable linebreak-style */
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
var utils = require("../utils");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return function(text, threadID, messageID ,callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
|
11
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
12
|
+
resolveFunc = resolve;
|
13
|
+
rejectFunc = reject;
|
14
|
+
});
|
15
|
+
|
16
|
+
if (!callback && utils.getType(messageID) === "AsyncFunction" || !callback && utils.getType(messageID) === "Function") messageID = callback;
|
17
|
+
|
18
|
+
if (!callback) {
|
19
|
+
callback = function (err, data) {
|
20
|
+
if (err) return rejectFunc(err);
|
21
|
+
resolveFunc(data);
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
const Payload = {
|
26
|
+
thread_id: threadID,
|
27
|
+
otid: utils.generateOfflineThreadingID(),
|
28
|
+
source: 524289,
|
29
|
+
send_type: 1,
|
30
|
+
sync_group: 1,
|
31
|
+
mark_thread_read: 0,
|
32
|
+
text: text || "test",
|
33
|
+
initiating_source: 0
|
34
|
+
};
|
35
|
+
|
36
|
+
if (messageID != undefined || messageID != null) Payload.reply_metadata = {
|
37
|
+
reply_source_id: messageID,
|
38
|
+
reply_source_type: 1,
|
39
|
+
reply_type: 0
|
40
|
+
};
|
41
|
+
|
42
|
+
const Form = JSON.stringify({
|
43
|
+
app_id: "2220391788200892",
|
44
|
+
payload: JSON.stringify({
|
45
|
+
tasks: [{
|
46
|
+
label: 46,
|
47
|
+
payload: JSON.stringify(Payload),
|
48
|
+
queue_name: threadID,
|
49
|
+
task_id: Math.random() * 1001 << 0,
|
50
|
+
failure_count: null,
|
51
|
+
}],
|
52
|
+
epoch_id: utils.generateOfflineThreadingID(),
|
53
|
+
version_id: '7553237234719461',
|
54
|
+
|
55
|
+
}),
|
56
|
+
request_id: ++ctx.req_ID,
|
57
|
+
type: 3
|
58
|
+
});
|
59
|
+
|
60
|
+
ctx.mqttClient.publish('/ls_req', Form,{
|
61
|
+
qos: 1,
|
62
|
+
retain: false,
|
63
|
+
});
|
64
|
+
ctx.callback_Task[ctx.req_ID] = new Object({
|
65
|
+
callback,
|
66
|
+
type: "sendMqttMessage"
|
67
|
+
});
|
68
|
+
|
69
|
+
return returnPromise;
|
70
|
+
};
|
71
|
+
};
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
5
|
|
6
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
7
7
|
function makeTypingIndicator(typ, threadID, callback, isGroup) {
|
8
|
-
|
8
|
+
var form = {
|
9
9
|
typ: +typ,
|
10
10
|
to: "",
|
11
11
|
source: "mercury-chat",
|
12
|
-
thread: threadID
|
12
|
+
thread: threadID
|
13
13
|
};
|
14
14
|
|
15
15
|
// Check if thread is a single person chat or a group chat
|
@@ -22,10 +22,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
22
22
|
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
23
23
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
24
24
|
.then(function (resData) {
|
25
|
-
if (resData.error)
|
26
|
-
throw resData;
|
27
|
-
}
|
28
|
-
|
25
|
+
if (resData.error) throw resData;
|
29
26
|
return callback();
|
30
27
|
})
|
31
28
|
.catch(function (err) {
|
@@ -35,39 +32,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
35
32
|
}
|
36
33
|
return callback(err);
|
37
34
|
});
|
38
|
-
}
|
35
|
+
}
|
36
|
+
else {
|
39
37
|
api.getUserInfo(threadID, function (err, res) {
|
40
|
-
if (err)
|
41
|
-
return callback(err);
|
42
|
-
}
|
43
|
-
|
38
|
+
if (err) return callback(err);
|
44
39
|
// If id is single person chat
|
45
|
-
if (Object.keys(res).length > 0)
|
46
|
-
form.to = threadID;
|
47
|
-
}
|
48
|
-
|
40
|
+
if (Object.keys(res).length > 0) form.to = threadID;
|
49
41
|
defaultFuncs
|
50
|
-
.post(
|
51
|
-
"https://www.facebook.com/ajax/messaging/typ.php",
|
52
|
-
ctx.jar,
|
53
|
-
form,
|
54
|
-
)
|
42
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
55
43
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
56
44
|
.then(function (resData) {
|
57
|
-
if (resData.error)
|
58
|
-
throw resData;
|
59
|
-
}
|
60
|
-
|
45
|
+
if (resData.error) throw resData;
|
61
46
|
return callback();
|
62
47
|
})
|
63
48
|
.catch(function (err) {
|
64
49
|
log.error("sendTypingIndicator", err);
|
65
|
-
if (
|
66
|
-
utils.getType(err) == "Object" &&
|
67
|
-
err.error === "Not logged in."
|
68
|
-
) {
|
69
|
-
ctx.loggedIn = false;
|
70
|
-
}
|
50
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
71
51
|
return callback(err);
|
72
52
|
});
|
73
53
|
});
|
@@ -79,13 +59,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
79
59
|
utils.getType(callback) !== "Function" &&
|
80
60
|
utils.getType(callback) !== "AsyncFunction"
|
81
61
|
) {
|
82
|
-
if (callback)
|
83
|
-
|
84
|
-
"sendTypingIndicator",
|
85
|
-
"callback is not a function - ignoring.",
|
86
|
-
);
|
87
|
-
}
|
88
|
-
callback = () => {};
|
62
|
+
if (callback) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
|
63
|
+
callback = () => { };
|
89
64
|
}
|
90
65
|
|
91
66
|
makeTypingIndicator(true, threadID, callback, isGroup);
|
@@ -95,13 +70,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
95
70
|
utils.getType(cb) !== "Function" &&
|
96
71
|
utils.getType(cb) !== "AsyncFunction"
|
97
72
|
) {
|
98
|
-
if (cb)
|
99
|
-
|
100
|
-
"sendTypingIndicator",
|
101
|
-
"callback is not a function - ignoring.",
|
102
|
-
);
|
103
|
-
}
|
104
|
-
cb = () => {};
|
73
|
+
if (cb) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
|
74
|
+
cb = () => { };
|
105
75
|
}
|
106
76
|
|
107
77
|
makeTypingIndicator(false, threadID, cb, isGroup);
|