alicezetion 1.0.3 → 1.0.5
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/modules.stamp +1 -0
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +536 -604
- package/package.json +78 -75
- package/replit.nix +6 -0
- package/src/addExternalModule.js +15 -0
- package/{alice → src}/addUserToGroup.js +77 -113
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/{alice → src}/changeBio.js +64 -77
- package/{alice → src}/changeBlockedStatus.js +36 -47
- package/{alice → src}/changeGroupImage.js +105 -129
- package/src/changeNickname.js +43 -0
- package/{alice → src}/changeThreadColor.js +61 -71
- package/src/changeThreadEmoji.js +41 -0
- package/src/chat.js +315 -0
- package/{alice → src}/createNewGroup.js +70 -86
- package/{alice → src}/createPoll.js +59 -71
- package/src/deleteMessage.js +44 -0
- package/src/deleteThread.js +42 -0
- package/src/forwardAttachment.js +47 -0
- package/src/forwardMessage.js +0 -0
- package/{alice → src}/getCurrentUserID.js +7 -7
- package/{alice → src}/getEmojiUrl.js +27 -29
- package/{alice → src}/getFriendsList.js +73 -84
- package/{alice → src}/getThreadHistory.js +537 -645
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/{alice → src}/getThreadInfo.js +171 -206
- package/src/getThreadInfoDeprecated.js +56 -0
- package/{alice → src}/getThreadList.js +213 -238
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/{alice → src}/getUserID.js +61 -66
- package/{alice → src}/getUserInfo.js +66 -72
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/{alice → src}/httpGet.js +47 -52
- package/{alice → src}/httpPost.js +47 -52
- package/src/listen.js +553 -0
- package/src/listenMqtt-Test.js +687 -0
- package/src/listenMqtt.js +677 -0
- package/{alice → src}/logout.js +68 -75
- package/{alice → src}/markAsDelivered.js +47 -58
- package/{alice → src}/markAsRead.js +70 -80
- package/{alice/seen.js → src/markAsReadAll.js} +39 -49
- package/{alice → src}/markAsSeen.js +48 -59
- package/{alice → src}/muteThread.js +45 -52
- package/src/removeUserFromGroup.js +45 -0
- package/{alice → src}/resolvePhotoUrl.js +36 -45
- package/src/searchForThread.js +42 -0
- package/{alice → src}/sendTypingIndicator.js +70 -103
- package/{alice/react.js → src/setMessageReaction.js} +103 -117
- package/{alice → src}/setPostReaction.js +63 -76
- package/{alice → src}/setTitle.js +70 -86
- package/src/threadColors.js +41 -0
- package/{alice → src}/unfriend.js +42 -52
- package/{alice → src}/unsendMessage.js +39 -49
- package/utils.js +1193 -1357
- package/alice/addExternalModule.js +0 -19
- package/alice/changeAdminStatus.js +0 -79
- package/alice/changeArchivedStatus.js +0 -55
- package/alice/changeNickname.js +0 -59
- package/alice/changeThreadEmoji.js +0 -55
- package/alice/chat.js +0 -459
- package/alice/deleteMessage.js +0 -56
- package/alice/deleteThread.js +0 -56
- package/alice/forwardAttachment.js +0 -60
- package/alice/getThreadHistoryDeprecated.js +0 -93
- package/alice/getThreadInfoDeprecated.js +0 -80
- package/alice/getThreadListDeprecated.js +0 -75
- package/alice/getThreadPictures.js +0 -79
- package/alice/handleFriendRequest.js +0 -61
- package/alice/handleMessageRequest.js +0 -65
- package/alice/listenMqtt.js +0 -789
- package/alice/removeUserFromGroup.js +0 -79
- package/alice/searchForThread.js +0 -53
- package/alice/threadColors.js +0 -57
- package/test/data/shareAttach.js +0 -146
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +0 -7
- package/test/example-config.json +0 -18
- package/test/test-page.js +0 -140
- package/test/test.js +0 -385
@@ -1,52 +1,45 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
// muteSecond: -1=permanent mute, 0=unmute, 60=one minute, 3600=one hour, etc.
|
8
|
-
return function muteThread(threadID, muteSeconds, callback) {
|
9
|
-
var resolveFunc = function(){};
|
10
|
-
var rejectFunc = function(){};
|
11
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
12
|
-
resolveFunc = resolve;
|
13
|
-
rejectFunc = reject;
|
14
|
-
});
|
15
|
-
|
16
|
-
if (!callback) {
|
17
|
-
callback = function (err,
|
18
|
-
if (err)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
log.error("muteThread", err);
|
47
|
-
return callback(err);
|
48
|
-
});
|
49
|
-
|
50
|
-
return returnPromise;
|
51
|
-
};
|
52
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
// muteSecond: -1=permanent mute, 0=unmute, 60=one minute, 3600=one hour, etc.
|
8
|
+
return function muteThread(threadID, muteSeconds, callback) {
|
9
|
+
var resolveFunc = function () { };
|
10
|
+
var rejectFunc = function () { };
|
11
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
12
|
+
resolveFunc = resolve;
|
13
|
+
rejectFunc = reject;
|
14
|
+
});
|
15
|
+
|
16
|
+
if (!callback) {
|
17
|
+
callback = function (err, data) {
|
18
|
+
if (err) return rejectFunc(err);
|
19
|
+
|
20
|
+
resolveFunc(data);
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
var form = {
|
25
|
+
thread_fbid: threadID,
|
26
|
+
mute_settings: muteSeconds
|
27
|
+
};
|
28
|
+
|
29
|
+
defaultFuncs
|
30
|
+
.post("https://www.facebook.com/ajax/mercury/change_mute_thread.php", ctx.jar, form)
|
31
|
+
.then(utils.saveCookies(ctx.jar))
|
32
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
33
|
+
.then(function (resData) {
|
34
|
+
if (resData.error) throw resData;
|
35
|
+
|
36
|
+
return callback();
|
37
|
+
})
|
38
|
+
.catch(function (err) {
|
39
|
+
log.error("muteThread", err);
|
40
|
+
return callback(err);
|
41
|
+
});
|
42
|
+
|
43
|
+
return returnPromise;
|
44
|
+
};
|
45
|
+
};
|
@@ -0,0 +1,45 @@
|
|
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 removeUserFromGroup(userID, threadID, callback) {
|
8
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
9
|
+
if (utils.getType(threadID) !== "Number" && utils.getType(threadID) !== "String") throw { error: "threadID should be of type Number or String and not " + utils.getType(threadID) + "." };
|
10
|
+
if (utils.getType(userID) !== "Number" && utils.getType(userID) !== "String") throw { error: "userID should be of type Number or String and not " + utils.getType(userID) + "." };
|
11
|
+
|
12
|
+
var resolveFunc = function () { };
|
13
|
+
var rejectFunc = function () { };
|
14
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
15
|
+
resolveFunc = resolve;
|
16
|
+
rejectFunc = reject;
|
17
|
+
});
|
18
|
+
|
19
|
+
if (!callback) {
|
20
|
+
callback = function (err, data) {
|
21
|
+
if (err) return rejectFunc(err);
|
22
|
+
resolveFunc(data);
|
23
|
+
};
|
24
|
+
}
|
25
|
+
|
26
|
+
var form = {
|
27
|
+
uid: userID,
|
28
|
+
tid: threadID
|
29
|
+
};
|
30
|
+
|
31
|
+
defaultFuncs
|
32
|
+
.post("https://www.facebook.com/chat/remove_participants", ctx.jar, form)
|
33
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
34
|
+
.then(function (resData) {
|
35
|
+
if (!resData) throw { error: "Remove from group failed." };
|
36
|
+
if (resData.error) throw resData;
|
37
|
+
return callback();
|
38
|
+
})
|
39
|
+
.catch(function (err) {
|
40
|
+
log.error("removeUserFromGroup", "» Bailing out of trying to parse response");
|
41
|
+
return callback(err);
|
42
|
+
});
|
43
|
+
return returnPromise;
|
44
|
+
};
|
45
|
+
};
|
@@ -1,45 +1,36 @@
|
|
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 resolvePhotoUrl(photoID, callback) {
|
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,
|
17
|
-
if (err)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
})
|
38
|
-
.catch(err => {
|
39
|
-
log.error("resolvePhotoUrl", err);
|
40
|
-
return callback(err);
|
41
|
-
});
|
42
|
-
|
43
|
-
return returnPromise;
|
44
|
-
};
|
45
|
-
};
|
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 resolvePhotoUrl(photoID, callback) {
|
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
|
+
defaultFuncs
|
23
|
+
.get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, { photo_id: photoID })
|
24
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
25
|
+
.then(resData => {
|
26
|
+
if (resData.error) throw resData;
|
27
|
+
var photoUrl = resData.jsmods.require[0][3][0];
|
28
|
+
return callback(null, photoUrl);
|
29
|
+
})
|
30
|
+
.catch(err => {
|
31
|
+
log.error("resolvePhotoUrl", err);
|
32
|
+
return callback(err);
|
33
|
+
});
|
34
|
+
return returnPromise;
|
35
|
+
};
|
36
|
+
};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
return function searchForThread(name, callback) {
|
7
|
+
var resolveFunc = function () { };
|
8
|
+
var rejectFunc = function () { };
|
9
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
10
|
+
resolveFunc = resolve;
|
11
|
+
rejectFunc = reject;
|
12
|
+
});
|
13
|
+
|
14
|
+
if (!callback) {
|
15
|
+
callback = function (err, data) {
|
16
|
+
if (err) return rejectFunc(err);
|
17
|
+
resolveFunc(data);
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
var tmpForm = {
|
22
|
+
client: "web_messenger",
|
23
|
+
query: name,
|
24
|
+
offset: 0,
|
25
|
+
limit: 21,
|
26
|
+
index: "fbid"
|
27
|
+
};
|
28
|
+
|
29
|
+
defaultFuncs
|
30
|
+
.post("https://www.facebook.com/ajax/mercury/search_threads.php", ctx.jar, tmpForm)
|
31
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
32
|
+
.then(function (resData) {
|
33
|
+
if (resData.error) throw resData;
|
34
|
+
if (!resData.payload.mercury_payload.threads) return callback({ error: "Could not find thread `" + name + "`." });
|
35
|
+
return callback(
|
36
|
+
null,
|
37
|
+
resData.payload.mercury_payload.threads.map(utils.formatThread)
|
38
|
+
);
|
39
|
+
});
|
40
|
+
return returnPromise;
|
41
|
+
};
|
42
|
+
};
|
@@ -1,103 +1,70 @@
|
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
.
|
23
|
-
.then(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if (
|
72
|
-
utils.getType(callback) !== "Function" &&
|
73
|
-
utils.getType(callback) !== "AsyncFunction"
|
74
|
-
) {
|
75
|
-
if (callback) {
|
76
|
-
log.warn(
|
77
|
-
"sendTypingIndicator",
|
78
|
-
"callback is not a function - ignoring."
|
79
|
-
);
|
80
|
-
}
|
81
|
-
callback = () => { };
|
82
|
-
}
|
83
|
-
|
84
|
-
makeTypingIndicator(true, threadID, callback, isGroup);
|
85
|
-
|
86
|
-
return function end(cb) {
|
87
|
-
if (
|
88
|
-
utils.getType(cb) !== "Function" &&
|
89
|
-
utils.getType(cb) !== "AsyncFunction"
|
90
|
-
) {
|
91
|
-
if (cb) {
|
92
|
-
log.warn(
|
93
|
-
"sendTypingIndicator",
|
94
|
-
"callback is not a function - ignoring."
|
95
|
-
);
|
96
|
-
}
|
97
|
-
cb = () => { };
|
98
|
-
}
|
99
|
-
|
100
|
-
makeTypingIndicator(false, threadID, cb, isGroup);
|
101
|
-
};
|
102
|
-
};
|
103
|
-
};
|
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) form.to = threadID;
|
19
|
+
|
20
|
+
defaultFuncs
|
21
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
22
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
23
|
+
.then(function (resData) {
|
24
|
+
if (resData.error) throw resData;
|
25
|
+
return callback();
|
26
|
+
})
|
27
|
+
.catch(function (err) {
|
28
|
+
log.error("sendTypingIndicator", err);
|
29
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in") ctx.loggedIn = false;
|
30
|
+
return callback(err);
|
31
|
+
});
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
api.getUserInfo(threadID, function (err, res) {
|
35
|
+
if (err) return callback(err);
|
36
|
+
// If id is single person chat
|
37
|
+
if (Object.keys(res).length > 0) form.to = threadID;
|
38
|
+
defaultFuncs
|
39
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
40
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
41
|
+
.then(function (resData) {
|
42
|
+
if (resData.error) throw resData;
|
43
|
+
return callback();
|
44
|
+
})
|
45
|
+
.catch(function (err) {
|
46
|
+
log.error("sendTypingIndicator", err);
|
47
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
48
|
+
return callback(err);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
return function sendTypingIndicator(threadID, callback, isGroup) {
|
55
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
56
|
+
if (callback) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
|
57
|
+
callback = () => { };
|
58
|
+
}
|
59
|
+
|
60
|
+
makeTypingIndicator(true, threadID, callback, isGroup);
|
61
|
+
|
62
|
+
return function end(cb) {
|
63
|
+
if (utils.getType(cb) !== "Function" && utils.getType(cb) !== "AsyncFunction") {
|
64
|
+
if (cb) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
|
65
|
+
cb = () => { };
|
66
|
+
}
|
67
|
+
makeTypingIndicator(false, threadID, cb, isGroup);
|
68
|
+
};
|
69
|
+
};
|
70
|
+
};
|
@@ -1,117 +1,103 @@
|
|
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,
|
17
|
-
if (err)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
case "\uD83D\
|
26
|
-
case "\uD83D\
|
27
|
-
case "\uD83D\
|
28
|
-
case "\uD83D\
|
29
|
-
case "\uD83D\
|
30
|
-
case "\
|
31
|
-
case "\uD83D\
|
32
|
-
case "
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
break;
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
if (resData.error) {
|
106
|
-
throw resData;
|
107
|
-
}
|
108
|
-
callback(null);
|
109
|
-
})
|
110
|
-
.catch(function(err) {
|
111
|
-
log.error("setReaction", err);
|
112
|
-
return callback(err);
|
113
|
-
});
|
114
|
-
|
115
|
-
return returnPromise;
|
116
|
-
};
|
117
|
-
};
|
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("https://www.facebook.com/webgraphql/mutation/", ctx.jar, {}, qs)
|
91
|
+
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
92
|
+
.then(function (resData) {
|
93
|
+
if (!resData) throw { error: "setReaction returned empty object." };
|
94
|
+
if (resData.error) throw resData;
|
95
|
+
callback(null);
|
96
|
+
})
|
97
|
+
.catch(function (err) {
|
98
|
+
log.error("setReaction", err);
|
99
|
+
return callback(err);
|
100
|
+
});
|
101
|
+
return returnPromise;
|
102
|
+
};
|
103
|
+
};
|