alicezetion 1.7.0 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/Extra/Database/index.js +399 -0
- package/Extra/Database/methods.js +286 -0
- package/Extra/ExtraAddons.js +213 -0
- package/Extra/ExtraGetThread.js +1 -0
- package/Extra/ExtraUptimeRobot.js +59 -0
- package/Extra/PM2/ecosystem.config.js +23 -0
- package/Extra/Src/Last-Run.js +48 -0
- package/Language/index.json +151 -0
- package/StateCrypt.js +22 -0
- package/broadcast.js +42 -0
- package/index.js +755 -533
- package/logger.js +21 -0
- package/package.json +35 -21
- package/replit.nix +0 -3
- package/src/addExternalModule.js +23 -0
- package/{leiamnash → src}/addUserToGroup.js +11 -23
- package/{leiamnash → src}/changeAdminStatus.js +32 -16
- package/{leiamnash → src}/changeArchivedStatus.js +9 -17
- package/src/changeAvt.js +91 -0
- package/{leiamnash → src}/changeBio.js +16 -24
- package/{leiamnash → src}/changeBlockedStatus.js +13 -18
- package/{leiamnash → src}/changeGroupImage.js +14 -23
- package/{leiamnash → src}/changeNickname.js +9 -14
- package/{leiamnash → src}/changeThreadColor.js +6 -10
- package/{leiamnash → src}/changeThreadEmoji.js +6 -11
- package/{leiamnash → src}/chat.js +116 -127
- package/{leiamnash → src}/createNewGroup.js +19 -27
- package/{leiamnash → src}/createPoll.js +6 -12
- package/{leiamnash → src}/deleteMessage.js +8 -13
- package/{leiamnash → src}/deleteThread.js +7 -14
- package/{leiamnash → src}/forwardAttachment.js +9 -16
- package/src/getAccessToken.js +32 -0
- package/{leiamnash → src}/getCurrentUserID.js +0 -0
- package/{leiamnash → src}/getEmojiUrl.js +1 -2
- package/{leiamnash → src}/getFriendsList.js +11 -14
- package/src/getMessage.js +84 -0
- package/{leiamnash → src}/getThreadHistory.js +27 -38
- package/{leiamnash → src}/getThreadHistoryDeprecated.js +14 -25
- package/src/getThreadInfo.js +197 -0
- package/{leiamnash → src}/getThreadInfoDeprecated.js +12 -24
- package/{leiamnash → src}/getThreadList.js +122 -88
- package/{leiamnash → src}/getThreadListDeprecated.js +9 -20
- package/{leiamnash → src}/getThreadPictures.js +9 -17
- package/{leiamnash → src}/getUserID.js +8 -11
- package/{leiamnash → src}/getUserInfo.js +12 -16
- package/src/getUserInfoV2.js +35 -0
- package/src/handleFriendRequest.js +47 -0
- package/{leiamnash → src}/handleMessageRequest.js +12 -22
- package/{leiamnash → src}/httpGet.js +15 -13
- package/{leiamnash → src}/httpPost.js +14 -13
- package/src/httpPostFormData.js +46 -0
- package/src/listenMqtt.js +1280 -0
- package/{leiamnash → src}/logout.js +7 -9
- package/{leiamnash → src}/markAsDelivered.js +14 -18
- package/{leiamnash → src}/markAsRead.js +30 -28
- package/{leiamnash → src}/markAsSeen.js +18 -19
- package/{leiamnash → src}/muteThread.js +7 -8
- package/{leiamnash/setMessageReaction.js → src/react.js} +15 -18
- package/{leiamnash → src}/removeUserFromGroup.js +13 -20
- package/{leiamnash → src}/resolvePhotoUrl.js +7 -13
- package/{leiamnash → src}/searchForThread.js +8 -13
- package/{leiamnash/markAsReadAll.js → src/seen.js} +10 -13
- package/{leiamnash → src}/sendTypingIndicator.js +23 -31
- package/src/setPostReaction.js +104 -0
- package/{leiamnash → src}/setTitle.js +15 -21
- package/src/threadColors.js +39 -0
- package/{leiamnash → src}/unfriend.js +9 -13
- package/{leiamnash/unsendMessage.js → src/unsend.js} +7 -16
- package/utils.js +1112 -1236
- package/leiamnash/addExternalModule.js +0 -19
- package/leiamnash/changeApprovalMode.js +0 -80
- package/leiamnash/getThreadInfo.js +0 -212
- package/leiamnash/handleFriendRequest.js +0 -61
- package/leiamnash/listenMqtt.js +0 -1129
- package/leiamnash/setPostReaction.js +0 -76
- package/leiamnash/threadColors.js +0 -57
@@ -23,9 +23,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
23
23
|
)
|
24
24
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
25
25
|
.then(function(resData) {
|
26
|
-
if (resData.error)
|
27
|
-
throw resData;
|
28
|
-
}
|
26
|
+
if (resData.error) throw resData;
|
29
27
|
|
30
28
|
return resData.payload.metadata[0];
|
31
29
|
})
|
@@ -34,9 +32,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
34
32
|
// resolve all promises
|
35
33
|
bluebird
|
36
34
|
.all(uploads)
|
37
|
-
.then(
|
38
|
-
callback(null, resData);
|
39
|
-
})
|
35
|
+
.then(resData => callback(null, resData))
|
40
36
|
.catch(function(err) {
|
41
37
|
log.error("handleUpload", err);
|
42
38
|
return callback(err);
|
@@ -48,22 +44,19 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
48
44
|
!callback &&
|
49
45
|
(utils.getType(threadID) === "Function" ||
|
50
46
|
utils.getType(threadID) === "AsyncFunction")
|
51
|
-
)
|
47
|
+
)
|
52
48
|
throw { error: "please pass a threadID as a second argument." };
|
53
|
-
}
|
54
49
|
|
55
|
-
var resolveFunc = function(){};
|
56
|
-
var rejectFunc = function(){};
|
57
|
-
var returnPromise = new Promise(function
|
50
|
+
var resolveFunc = function() {};
|
51
|
+
var rejectFunc = function() {};
|
52
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
58
53
|
resolveFunc = resolve;
|
59
54
|
rejectFunc = reject;
|
60
55
|
});
|
61
56
|
|
62
57
|
if (!callback) {
|
63
58
|
callback = function(err) {
|
64
|
-
if (err)
|
65
|
-
return rejectFunc(err);
|
66
|
-
}
|
59
|
+
if (err) return rejectFunc(err);
|
67
60
|
resolveFunc();
|
68
61
|
};
|
69
62
|
}
|
@@ -99,23 +92,21 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
99
92
|
};
|
100
93
|
|
101
94
|
handleUpload(image, function(err, payload) {
|
102
|
-
if (err)
|
103
|
-
return callback(err);
|
104
|
-
}
|
95
|
+
if (err) return callback(err);
|
105
96
|
|
106
97
|
form["thread_image_id"] = payload[0]["image_id"];
|
107
98
|
form["thread_id"] = threadID;
|
108
99
|
|
109
100
|
defaultFuncs
|
110
|
-
.post(
|
101
|
+
.post(
|
102
|
+
"https://www.facebook.com/messaging/set_thread_image/",
|
103
|
+
ctx.jar,
|
104
|
+
form
|
105
|
+
)
|
111
106
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
112
107
|
.then(function(resData) {
|
113
108
|
// check for errors here
|
114
|
-
|
115
|
-
if (resData.error) {
|
116
|
-
throw resData;
|
117
|
-
}
|
118
|
-
|
109
|
+
if (resData.error) throw resData;
|
119
110
|
return callback();
|
120
111
|
})
|
121
112
|
.catch(function(err) {
|
@@ -5,17 +5,15 @@ var log = require("npmlog");
|
|
5
5
|
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function changeNickname(nickname, threadID, participantID, callback) {
|
8
|
-
var resolveFunc = function(){};
|
9
|
-
var rejectFunc = function(){};
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
if (!callback) {
|
15
|
-
callback = function
|
16
|
-
if (err)
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
15
|
+
callback = function(err) {
|
16
|
+
if (err) return rejectFunc(err);
|
19
17
|
resolveFunc();
|
20
18
|
};
|
21
19
|
}
|
@@ -34,18 +32,15 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
34
32
|
)
|
35
33
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
34
|
.then(function(resData) {
|
37
|
-
if (resData.error === 1545014)
|
35
|
+
if (resData.error === 1545014)
|
38
36
|
throw { error: "Trying to change nickname of user isn't in thread" };
|
39
|
-
|
40
|
-
if (resData.error === 1357031) {
|
37
|
+
if (resData.error === 1357031)
|
41
38
|
throw {
|
42
39
|
error:
|
43
40
|
"Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname."
|
44
41
|
};
|
45
|
-
|
46
|
-
if (resData.error)
|
47
|
-
throw resData;
|
48
|
-
}
|
42
|
+
|
43
|
+
if (resData.error) throw resData;
|
49
44
|
|
50
45
|
return callback();
|
51
46
|
})
|
@@ -5,18 +5,16 @@ var log = require("npmlog");
|
|
5
5
|
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function changeThreadColor(color, threadID, callback) {
|
8
|
-
var resolveFunc = function(){};
|
9
|
-
var rejectFunc = function(){};
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
16
|
callback = function(err) {
|
17
|
-
if (err)
|
18
|
-
return rejectFunc(err);
|
19
|
-
}
|
17
|
+
if (err) return rejectFunc(err);
|
20
18
|
resolveFunc(err);
|
21
19
|
};
|
22
20
|
}
|
@@ -25,12 +23,11 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
25
23
|
var colorList = Object.keys(api.threadColors).map(function(name) {
|
26
24
|
return api.threadColors[name];
|
27
25
|
});
|
28
|
-
if (!colorList.includes(validatedColor))
|
26
|
+
if (!colorList.includes(validatedColor))
|
29
27
|
throw {
|
30
28
|
error:
|
31
29
|
"The color you are trying to use is not a valid thread color. Use api.threadColors to find acceptable values."
|
32
30
|
};
|
33
|
-
}
|
34
31
|
|
35
32
|
var form = {
|
36
33
|
dpr: 1,
|
@@ -55,9 +52,8 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
55
52
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
56
53
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
57
54
|
.then(function(resData) {
|
58
|
-
if (resData[resData.length - 1].error_results > 0)
|
55
|
+
if (resData[resData.length - 1].error_results > 0)
|
59
56
|
throw resData[0].o0.errors;
|
60
|
-
}
|
61
57
|
|
62
58
|
return callback();
|
63
59
|
})
|
@@ -5,18 +5,16 @@ var log = require("npmlog");
|
|
5
5
|
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function changeThreadEmoji(emoji, threadID, callback) {
|
8
|
-
var resolveFunc = function(){};
|
9
|
-
var rejectFunc = function(){};
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
16
|
callback = function(err) {
|
17
|
-
if (err)
|
18
|
-
return rejectFunc(err);
|
19
|
-
}
|
17
|
+
if (err) return rejectFunc(err);
|
20
18
|
resolveFunc();
|
21
19
|
};
|
22
20
|
}
|
@@ -33,15 +31,12 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
33
31
|
)
|
34
32
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
33
|
.then(function(resData) {
|
36
|
-
if (resData.error === 1357031)
|
34
|
+
if (resData.error === 1357031)
|
37
35
|
throw {
|
38
36
|
error:
|
39
37
|
"Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji."
|
40
38
|
};
|
41
|
-
|
42
|
-
if (resData.error) {
|
43
|
-
throw resData;
|
44
|
-
}
|
39
|
+
if (resData.error) throw resData;
|
45
40
|
|
46
41
|
return callback();
|
47
42
|
})
|
@@ -1,5 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
/**
|
4
|
+
* Được Fix Hay Làm Màu Bởi: @KanzuWakazaki
|
5
|
+
* 19/2/2022
|
6
|
+
*/
|
7
|
+
|
3
8
|
var utils = require("../utils");
|
4
9
|
var log = require("npmlog");
|
5
10
|
var bluebird = require("bluebird");
|
@@ -12,24 +17,22 @@ var allowedProperties = {
|
|
12
17
|
emojiSize: true,
|
13
18
|
body: true,
|
14
19
|
mentions: true,
|
15
|
-
location: true
|
20
|
+
location: true
|
16
21
|
};
|
17
22
|
|
18
|
-
module.exports = function
|
23
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
19
24
|
function uploadAttachment(attachments, callback) {
|
20
25
|
var uploads = [];
|
21
26
|
|
22
27
|
// create an array of promises
|
23
28
|
for (var i = 0; i < attachments.length; i++) {
|
24
|
-
if (!utils.isReadableStream(attachments[i]))
|
29
|
+
if (!utils.isReadableStream(attachments[i]))
|
25
30
|
throw {
|
26
31
|
error:
|
27
32
|
"Attachment should be a readable stream and not " +
|
28
33
|
utils.getType(attachments[i]) +
|
29
34
|
"."
|
30
35
|
};
|
31
|
-
}
|
32
|
-
|
33
36
|
var form = {
|
34
37
|
upload_1024: attachments[i],
|
35
38
|
voice_clip: "true"
|
@@ -44,11 +47,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
44
47
|
{}
|
45
48
|
)
|
46
49
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
47
|
-
.then(function
|
48
|
-
if (resData.error)
|
49
|
-
throw resData;
|
50
|
-
}
|
51
|
-
|
50
|
+
.then(function(resData) {
|
51
|
+
if (resData.error) throw resData;
|
52
52
|
// We have to return the data unformatted unless we want to change it
|
53
53
|
// back in sendMessage.
|
54
54
|
return resData.payload.metadata[0];
|
@@ -59,10 +59,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
59
59
|
// resolve all promises
|
60
60
|
bluebird
|
61
61
|
.all(uploads)
|
62
|
-
.then(
|
63
|
-
|
64
|
-
})
|
65
|
-
.catch(function (err) {
|
62
|
+
.then(resData => callback(null, resData))
|
63
|
+
.catch(function(err) {
|
66
64
|
log.error("uploadAttachment", err);
|
67
65
|
return callback(err);
|
68
66
|
});
|
@@ -82,18 +80,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
82
80
|
form
|
83
81
|
)
|
84
82
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
85
|
-
.then(function
|
86
|
-
if (resData.error)
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
if (!resData.payload) {
|
91
|
-
return callback({ error: "Invalid url" });
|
92
|
-
}
|
93
|
-
|
83
|
+
.then(function(resData) {
|
84
|
+
if (resData.error) return callback(resData);
|
85
|
+
if (!resData.payload) return callback({ error: "Invalid url" });
|
94
86
|
callback(null, resData.payload.share_data.share_params);
|
95
87
|
})
|
96
|
-
.catch(function
|
88
|
+
.catch(function(err) {
|
97
89
|
log.error("getUrl", err);
|
98
90
|
return callback(err);
|
99
91
|
});
|
@@ -106,9 +98,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
106
98
|
// 2. User is sending a message to a specific user.
|
107
99
|
// 3. No additional form params and the message goes to an existing group chat.
|
108
100
|
if (utils.getType(threadID) === "Array") {
|
109
|
-
for (var i = 0; i < threadID.length; i++)
|
101
|
+
for (var i = 0; i < threadID.length; i++)
|
110
102
|
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
111
|
-
}
|
112
103
|
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
113
104
|
form["client_thread_id"] = "root:" + messageAndOTID;
|
114
105
|
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
@@ -119,9 +110,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
119
110
|
form["specific_to_list[0]"] = "fbid:" + threadID;
|
120
111
|
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
121
112
|
form["other_user_fbid"] = threadID;
|
122
|
-
} else
|
123
|
-
form["thread_fbid"] = threadID;
|
124
|
-
}
|
113
|
+
} else form["thread_fbid"] = threadID;
|
125
114
|
}
|
126
115
|
|
127
116
|
if (ctx.globalOptions.pageID) {
|
@@ -139,23 +128,19 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
139
128
|
defaultFuncs
|
140
129
|
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
141
130
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
142
|
-
.then(function
|
143
|
-
if (!resData) {
|
144
|
-
return callback({ error: "Send message failed." });
|
145
|
-
}
|
146
|
-
|
131
|
+
.then(function(resData) {
|
132
|
+
if (!resData) return callback({ error: "Send message failed." });
|
147
133
|
if (resData.error) {
|
148
|
-
if (resData.error === 1545012)
|
134
|
+
if (resData.error === 1545012)
|
149
135
|
log.warn(
|
150
136
|
"sendMessage",
|
151
137
|
"Got error 1545012. This might mean that you're not part of the conversation " +
|
152
|
-
|
138
|
+
threadID
|
153
139
|
);
|
154
|
-
}
|
155
140
|
return callback(resData);
|
156
141
|
}
|
157
142
|
|
158
|
-
var messageInfo = resData.payload.actions.reduce(function
|
143
|
+
var messageInfo = resData.payload.actions.reduce(function(p, v) {
|
159
144
|
return (
|
160
145
|
{
|
161
146
|
threadID: v.thread_fbid,
|
@@ -164,87 +149,111 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
164
149
|
} || p
|
165
150
|
);
|
166
151
|
}, null);
|
167
|
-
|
168
152
|
return callback(null, messageInfo);
|
169
153
|
})
|
170
|
-
.catch(function
|
154
|
+
.catch(function(err) {
|
171
155
|
log.error("sendMessage", err);
|
172
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
156
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
173
157
|
ctx.loggedIn = false;
|
174
|
-
}
|
175
158
|
return callback(err);
|
176
159
|
});
|
177
160
|
}
|
178
161
|
|
179
162
|
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
180
|
-
//
|
181
|
-
//
|
182
|
-
|
183
|
-
if (utils.getType(threadID) === "Array") {
|
163
|
+
// đôi lời từ ai đó :v
|
164
|
+
// 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
|
165
|
+
if (utils.getType(threadID) === "Array")
|
184
166
|
sendContent(form, threadID, false, messageAndOTID, callback);
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
else
|
167
|
+
else {
|
168
|
+
var THREADFIX = "ThreadID".replace("ThreadID", threadID); // i cũng đôn nâu
|
169
|
+
if (THREADFIX.length <= 15 || global.isUser.includes(threadID))
|
189
170
|
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
171
|
+
else if (
|
172
|
+
(THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0) ||
|
173
|
+
global.isThread.includes(threadID)
|
174
|
+
)
|
175
|
+
sendContent(
|
176
|
+
form,
|
177
|
+
threadID,
|
178
|
+
threadID.length === 15,
|
179
|
+
messageAndOTID,
|
180
|
+
callback
|
181
|
+
);
|
182
|
+
else {
|
183
|
+
try {
|
184
|
+
var { getInfo } = require("../Extra/ExtraAddons");
|
185
|
+
getInfo(threadID)
|
186
|
+
.then(_ => {
|
187
|
+
global.isUser.push(threadID);
|
188
|
+
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
189
|
+
})
|
190
|
+
.catch(function(_) {
|
191
|
+
global.isThread.push(threadID);
|
192
|
+
sendContent(
|
193
|
+
form,
|
194
|
+
threadID,
|
195
|
+
threadID.length === 15,
|
196
|
+
messageAndOTID,
|
197
|
+
callback
|
198
|
+
);
|
199
|
+
});
|
200
|
+
} catch (e) {
|
201
|
+
sendContent(
|
202
|
+
form,
|
203
|
+
threadID,
|
204
|
+
threadID.length === 15,
|
205
|
+
messageAndOTID,
|
206
|
+
callback
|
207
|
+
);
|
208
|
+
}
|
209
|
+
}
|
190
210
|
}
|
191
211
|
}
|
192
212
|
|
193
213
|
function handleUrl(msg, form, callback, cb) {
|
194
214
|
if (msg.url) {
|
195
215
|
form["shareable_attachment[share_type]"] = "100";
|
196
|
-
getUrl(msg.url, function
|
197
|
-
if (err)
|
198
|
-
return callback(err);
|
199
|
-
}
|
200
|
-
|
216
|
+
getUrl(msg.url, function(err, params) {
|
217
|
+
if (err) return callback(err);
|
201
218
|
form["shareable_attachment[share_params]"] = params;
|
202
219
|
cb();
|
203
220
|
});
|
204
|
-
} else
|
205
|
-
cb();
|
206
|
-
}
|
221
|
+
} else cb();
|
207
222
|
}
|
208
223
|
|
209
224
|
function handleLocation(msg, form, callback, cb) {
|
210
225
|
if (msg.location) {
|
211
|
-
if (msg.location.latitude == null || msg.location.longitude == null)
|
212
|
-
return callback({
|
213
|
-
|
214
|
-
|
215
|
-
form["location_attachment[coordinates][latitude]"] =
|
216
|
-
|
226
|
+
if (msg.location.latitude == null || msg.location.longitude == null)
|
227
|
+
return callback({
|
228
|
+
error: "location property needs both latitude and longitude"
|
229
|
+
});
|
230
|
+
form["location_attachment[coordinates][latitude]"] =
|
231
|
+
msg.location.latitude;
|
232
|
+
form["location_attachment[coordinates][longitude]"] =
|
233
|
+
msg.location.longitude;
|
217
234
|
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
218
235
|
}
|
219
|
-
|
220
236
|
cb();
|
221
237
|
}
|
222
238
|
|
223
239
|
function handleSticker(msg, form, callback, cb) {
|
224
|
-
if (msg.sticker)
|
225
|
-
form["sticker_id"] = msg.sticker;
|
226
|
-
}
|
240
|
+
if (msg.sticker) form["sticker_id"] = msg.sticker;
|
227
241
|
cb();
|
228
242
|
}
|
229
243
|
|
230
244
|
function handleEmoji(msg, form, callback, cb) {
|
231
|
-
if (msg.emojiSize != null && msg.emoji == null)
|
245
|
+
if (msg.emojiSize != null && msg.emoji == null)
|
232
246
|
return callback({ error: "emoji property is empty" });
|
233
|
-
}
|
234
247
|
if (msg.emoji) {
|
235
|
-
if (msg.emojiSize == null)
|
236
|
-
msg.emojiSize = "medium";
|
237
|
-
}
|
248
|
+
if (msg.emojiSize == null) msg.emojiSize = "medium";
|
238
249
|
if (
|
239
250
|
msg.emojiSize != "small" &&
|
240
251
|
msg.emojiSize != "medium" &&
|
241
252
|
msg.emojiSize != "large"
|
242
|
-
)
|
253
|
+
)
|
243
254
|
return callback({ error: "emojiSize property is invalid" });
|
244
|
-
|
245
|
-
if (form["body"] != null && form["body"] != "") {
|
255
|
+
if (form["body"] != null && form["body"] != "")
|
246
256
|
return callback({ error: "body is not empty" });
|
247
|
-
}
|
248
257
|
form["body"] = msg.emoji;
|
249
258
|
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
250
259
|
}
|
@@ -259,52 +268,39 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
259
268
|
form["video_ids"] = [];
|
260
269
|
form["audio_ids"] = [];
|
261
270
|
|
262
|
-
if (utils.getType(msg.attachment) !== "Array")
|
271
|
+
if (utils.getType(msg.attachment) !== "Array")
|
263
272
|
msg.attachment = [msg.attachment];
|
264
|
-
}
|
265
|
-
|
266
|
-
uploadAttachment(msg.attachment, function (err, files) {
|
267
|
-
if (err) {
|
268
|
-
return callback(err);
|
269
|
-
}
|
270
273
|
|
271
|
-
|
274
|
+
uploadAttachment(msg.attachment, function(err, files) {
|
275
|
+
if (err) return callback(err);
|
276
|
+
files.forEach(function(file) {
|
272
277
|
var key = Object.keys(file);
|
273
278
|
var type = key[0]; // image_id, file_id, etc
|
274
279
|
form["" + type + "s"].push(file[type]); // push the id
|
275
280
|
});
|
276
281
|
cb();
|
277
282
|
});
|
278
|
-
} else
|
279
|
-
cb();
|
280
|
-
}
|
283
|
+
} else cb();
|
281
284
|
}
|
282
285
|
|
283
286
|
function handleMention(msg, form, callback, cb) {
|
284
287
|
if (msg.mentions) {
|
285
288
|
for (let i = 0; i < msg.mentions.length; i++) {
|
286
289
|
const mention = msg.mentions[i];
|
287
|
-
|
288
290
|
const tag = mention.tag;
|
289
|
-
if (typeof tag !== "string")
|
291
|
+
if (typeof tag !== "string")
|
290
292
|
return callback({ error: "Mention tags must be strings." });
|
291
|
-
}
|
292
|
-
|
293
293
|
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
294
|
-
|
295
|
-
if (offset < 0) {
|
294
|
+
if (offset < 0)
|
296
295
|
log.warn(
|
297
296
|
"handleMention",
|
298
297
|
'Mention for "' + tag + '" not found in message string.'
|
299
298
|
);
|
300
|
-
|
301
|
-
|
302
|
-
if (mention.id == null) {
|
299
|
+
if (mention.id == null)
|
303
300
|
log.warn("handleMention", "Mention id should be non-null.");
|
304
|
-
}
|
305
301
|
|
306
302
|
const id = mention.id || 0;
|
307
|
-
const emptyChar =
|
303
|
+
const emptyChar = "\u200E";
|
308
304
|
form["body"] = emptyChar + msg.body;
|
309
305
|
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
310
306
|
form["profile_xmd[" + i + "][length]"] = tag.length;
|
@@ -315,32 +311,34 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
315
311
|
cb();
|
316
312
|
}
|
317
313
|
|
318
|
-
return function sendMessage(
|
319
|
-
|
314
|
+
return function sendMessage(
|
315
|
+
msg,
|
316
|
+
threadID,
|
317
|
+
callback,
|
318
|
+
replyToMessage,
|
319
|
+
isGroup
|
320
|
+
) {
|
321
|
+
typeof isGroup == "undefined" ? (isGroup = null) : "";
|
320
322
|
if (
|
321
323
|
!callback &&
|
322
324
|
(utils.getType(threadID) === "Function" ||
|
323
325
|
utils.getType(threadID) === "AsyncFunction")
|
324
|
-
)
|
326
|
+
)
|
325
327
|
return threadID({ error: "Pass a threadID as a second argument." });
|
326
|
-
|
327
|
-
if (
|
328
|
-
!replyToMessage &&
|
329
|
-
utils.getType(callback) === "String"
|
330
|
-
) {
|
328
|
+
if (!replyToMessage && utils.getType(callback) === "String") {
|
331
329
|
replyToMessage = callback;
|
332
|
-
callback =
|
330
|
+
callback = function() {};
|
333
331
|
}
|
334
332
|
|
335
|
-
var resolveFunc = function
|
336
|
-
var rejectFunc = function
|
337
|
-
var returnPromise = new Promise(function
|
333
|
+
var resolveFunc = function() {};
|
334
|
+
var rejectFunc = function() {};
|
335
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
338
336
|
resolveFunc = resolve;
|
339
337
|
rejectFunc = reject;
|
340
338
|
});
|
341
339
|
|
342
340
|
if (!callback) {
|
343
|
-
callback = function
|
341
|
+
callback = function(err, data) {
|
344
342
|
if (err) return rejectFunc(err);
|
345
343
|
resolveFunc(data);
|
346
344
|
};
|
@@ -350,48 +348,39 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
350
348
|
var threadIDType = utils.getType(threadID);
|
351
349
|
var messageIDType = utils.getType(replyToMessage);
|
352
350
|
|
353
|
-
if (msgType !== "String" && msgType !== "Object")
|
351
|
+
if (msgType !== "String" && msgType !== "Object")
|
354
352
|
return callback({
|
355
353
|
error:
|
356
354
|
"Message should be of type string or object and not " + msgType + "."
|
357
355
|
});
|
358
|
-
}
|
359
356
|
|
360
357
|
// Changing this to accomodate an array of users
|
361
358
|
if (
|
362
359
|
threadIDType !== "Array" &&
|
363
360
|
threadIDType !== "Number" &&
|
364
361
|
threadIDType !== "String"
|
365
|
-
)
|
362
|
+
)
|
366
363
|
return callback({
|
367
364
|
error:
|
368
365
|
"ThreadID should be of type number, string, or array and not " +
|
369
366
|
threadIDType +
|
370
367
|
"."
|
371
368
|
});
|
372
|
-
}
|
373
369
|
|
374
|
-
if (replyToMessage && messageIDType !==
|
370
|
+
if (replyToMessage && messageIDType !== "String")
|
375
371
|
return callback({
|
376
372
|
error:
|
377
|
-
"MessageID should be of type string and not " +
|
378
|
-
threadIDType +
|
379
|
-
"."
|
373
|
+
"MessageID should be of type string and not " + threadIDType + "."
|
380
374
|
});
|
381
|
-
}
|
382
|
-
|
383
|
-
if (msgType === "String") {
|
384
|
-
msg = { body: msg };
|
385
|
-
}
|
386
375
|
|
376
|
+
if (msgType === "String") msg = { body: msg };
|
387
377
|
var disallowedProperties = Object.keys(msg).filter(
|
388
378
|
prop => !allowedProperties[prop]
|
389
379
|
);
|
390
|
-
if (disallowedProperties.length > 0)
|
380
|
+
if (disallowedProperties.length > 0)
|
391
381
|
return callback({
|
392
382
|
error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`"
|
393
383
|
});
|
394
|
-
}
|
395
384
|
|
396
385
|
var messageAndOTID = utils.generateOfflineThreadingID();
|
397
386
|
|