@cexy/hoonfca 1.0.4 → 1.0.6
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/CHANGELOG.md +181 -0
- package/DOCS.md +2636 -0
- package/LICENSE-MIT +21 -21
- package/README.md +632 -0
- package/func/checkUpdate.js +231 -0
- package/func/logger.js +48 -0
- package/index.d.ts +731 -605
- package/index.js +6 -774
- package/module/config.js +67 -0
- package/module/login.js +154 -0
- package/module/loginHelper.js +1034 -0
- package/module/options.js +54 -0
- package/package.json +54 -19
- package/src/api/action/addExternalModule.js +25 -0
- package/src/api/action/changeAvatar.js +137 -0
- package/src/{changeBio.js → api/action/changeBio.js} +75 -76
- package/src/api/action/enableAutoSaveAppState.js +73 -0
- package/src/{getCurrentUserID.js → api/action/getCurrentUserID.js} +7 -7
- package/src/{handleFriendRequest.js → api/action/handleFriendRequest.js} +57 -57
- package/src/api/action/logout.js +76 -0
- package/src/api/action/refreshFb_dtsg.js +48 -0
- package/src/api/action/setPostReaction.js +106 -0
- package/src/api/action/unfriend.js +54 -0
- package/src/api/http/httpGet.js +46 -0
- package/src/api/http/httpPost.js +52 -0
- package/src/api/http/postFormData.js +47 -0
- package/src/api/messaging/addUserToGroup.js +68 -0
- package/src/api/messaging/changeAdminStatus.js +122 -0
- package/src/api/messaging/changeArchivedStatus.js +55 -0
- package/src/api/messaging/changeBlockedStatus.js +48 -0
- package/src/api/messaging/changeGroupImage.js +90 -0
- package/src/api/messaging/changeNickname.js +70 -0
- package/src/api/messaging/changeThreadColor.js +79 -0
- package/src/api/messaging/changeThreadEmoji.js +106 -0
- package/src/{createNewGroup.js → api/messaging/createNewGroup.js} +88 -88
- package/src/api/messaging/createPoll.js +43 -0
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/{deleteMessage.js → api/messaging/deleteMessage.js} +56 -56
- package/src/{deleteThread.js → api/messaging/deleteThread.js} +56 -56
- package/src/api/messaging/editMessage.js +68 -0
- package/src/api/messaging/forwardAttachment.js +51 -0
- package/src/{getEmojiUrl.js → api/messaging/getEmojiUrl.js} +8 -8
- package/src/{getFriendsList.js → api/messaging/getFriendsList.js} +82 -84
- package/src/api/messaging/getMessage.js +829 -0
- package/src/api/messaging/getThemePictures.js +62 -0
- package/src/api/messaging/handleMessageRequest.js +65 -0
- package/src/{markAsDelivered.js → api/messaging/markAsDelivered.js} +57 -58
- package/src/{markAsRead.js → api/messaging/markAsRead.js} +88 -88
- package/src/{markAsReadAll.js → api/messaging/markAsReadAll.js} +49 -50
- package/src/api/messaging/markAsSeen.js +61 -0
- package/src/{muteThread.js → api/messaging/muteThread.js} +50 -52
- package/src/api/messaging/removeUserFromGroup.js +106 -0
- package/src/{resolvePhotoUrl.js → api/messaging/resolvePhotoUrl.js} +43 -45
- package/src/api/messaging/scheduler.js +264 -0
- package/src/{searchForThread.js → api/messaging/searchForThread.js} +52 -53
- package/src/api/messaging/sendMessage.js +272 -0
- package/src/api/messaging/sendTypingIndicator.js +67 -0
- package/src/api/messaging/setMessageReaction.js +76 -0
- package/src/api/messaging/setTitle.js +119 -0
- package/src/{shareContact.js → api/messaging/shareContact.js} +49 -53
- package/src/api/messaging/threadColors.js +128 -0
- package/src/api/messaging/unsendMessage.js +81 -0
- package/src/api/messaging/uploadAttachment.js +94 -0
- package/src/api/socket/core/connectMqtt.js +255 -0
- package/src/api/socket/core/emitAuth.js +106 -0
- package/src/api/socket/core/getSeqID.js +40 -0
- package/src/api/socket/core/getTaskResponseData.js +22 -0
- package/src/api/socket/core/markDelivery.js +12 -0
- package/src/api/socket/core/parseDelta.js +391 -0
- package/src/api/socket/detail/buildStream.js +208 -0
- package/src/api/socket/detail/constants.js +24 -0
- package/src/api/socket/listenMqtt.js +364 -0
- package/src/api/socket/middleware/index.js +216 -0
- package/src/{getThreadHistory.js → api/threads/getThreadHistory.js} +664 -647
- package/src/api/threads/getThreadInfo.js +438 -0
- package/src/{getThreadList.js → api/threads/getThreadList.js} +293 -292
- package/src/{getThreadPictures.js → api/threads/getThreadPictures.js} +78 -79
- package/src/{getUserID.js → api/users/getUserID.js} +65 -66
- package/src/api/users/getUserInfo.js +327 -0
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/core/sendReqMqtt.js +96 -0
- package/src/database/models/index.js +87 -0
- package/src/database/models/thread.js +45 -0
- package/src/database/models/user.js +46 -0
- package/src/database/threadData.js +98 -0
- package/src/database/userData.js +89 -0
- package/src/utils/client.js +320 -0
- package/src/utils/constants.js +23 -0
- package/{utils.js → src/utils/format.js} +1115 -1447
- package/src/utils/headers.js +115 -0
- package/src/utils/request.js +305 -0
- package/.travis.yml +0 -6
- package/src/addExternalModule.js +0 -23
- package/src/addUserToGroup.js +0 -113
- package/src/changeAdminStatus.js +0 -95
- package/src/changeApprovalMode.js +0 -79
- package/src/changeArchivedStatus.js +0 -55
- package/src/changeBlockedStatus.js +0 -47
- package/src/changeBlockedStatusMqtt.js +0 -86
- package/src/changeGroupImage.js +0 -133
- package/src/changeNickname.js +0 -59
- package/src/changeThreadColor.js +0 -71
- package/src/changeThreadEmoji.js +0 -55
- package/src/createPoll.js +0 -130
- package/src/editMessage.js +0 -63
- package/src/forwardAttachment.js +0 -60
- package/src/forwardMessage.js +0 -63
- package/src/getGroupsList.js +0 -83
- package/src/getMarketplace.js +0 -84
- package/src/getNotifications.js +0 -86
- package/src/getPagesList.js +0 -83
- package/src/getStories.js +0 -88
- package/src/getThreadInfo.js +0 -222
- package/src/getUserInfo.js +0 -128
- package/src/handleMessageRequest.js +0 -65
- package/src/httpGet.js +0 -58
- package/src/httpPost.js +0 -58
- package/src/listenMqtt.js +0 -1018
- package/src/logout.js +0 -75
- package/src/markAsSeen.js +0 -61
- package/src/pinMessage.js +0 -61
- package/src/removeUserFromGroup.js +0 -79
- package/src/searchUsers.js +0 -89
- package/src/sendComment.js +0 -161
- package/src/sendMessage.js +0 -457
- package/src/sendTypingIndicator.js +0 -179
- package/src/setBio.js +0 -86
- package/src/setMessageReaction.js +0 -186
- package/src/setPostReaction.js +0 -71
- package/src/setTheme.js +0 -313
- package/src/setTitle.js +0 -90
- package/src/shareLink.js +0 -62
- package/src/threadColors.js +0 -57
- package/src/unfriend.js +0 -53
- package/src/unsendMessage.js +0 -104
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const { setProxy } = require("../src/utils/request");
|
|
2
|
+
|
|
3
|
+
const Boolean_Option = [
|
|
4
|
+
"online",
|
|
5
|
+
"selfListen",
|
|
6
|
+
"listenEvents",
|
|
7
|
+
"updatePresence",
|
|
8
|
+
"forceLogin",
|
|
9
|
+
"autoMarkDelivery",
|
|
10
|
+
"autoMarkRead",
|
|
11
|
+
"listenTyping",
|
|
12
|
+
"autoReconnect",
|
|
13
|
+
"emitReady",
|
|
14
|
+
"selfListenEvent"
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
function setOptions(globalOptions, options = {}) {
|
|
18
|
+
for (const key of Object.keys(options)) {
|
|
19
|
+
if (Boolean_Option.includes(key)) {
|
|
20
|
+
globalOptions[key] = Boolean(options[key]);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
switch (key) {
|
|
25
|
+
case "userAgent":
|
|
26
|
+
globalOptions.userAgent =
|
|
27
|
+
options.userAgent ||
|
|
28
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case "proxy":
|
|
32
|
+
if (typeof options.proxy !== "string") {
|
|
33
|
+
delete globalOptions.proxy;
|
|
34
|
+
setProxy();
|
|
35
|
+
} else {
|
|
36
|
+
globalOptions.proxy = options.proxy;
|
|
37
|
+
setProxy(options.proxy);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
// Accept any future/custom option silently
|
|
43
|
+
globalOptions[key] = options[key];
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return globalOptions;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
setOptions,
|
|
53
|
+
Boolean_Option
|
|
54
|
+
};
|
package/package.json
CHANGED
|
@@ -1,47 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cexy/hoonfca",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Unofficial Facebook Chat API for Node.js - Interact with Facebook Messenger programmatically",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./index.js",
|
|
10
|
+
"default": "./index.js",
|
|
11
|
+
"types": "./index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"scripts": {
|
|
8
15
|
"test": "mocha",
|
|
9
|
-
"lint": "
|
|
10
|
-
"prettier": "npx prettier utils.js src/* --write"
|
|
16
|
+
"lint": "eslint ."
|
|
11
17
|
},
|
|
12
18
|
"repository": {
|
|
13
19
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/
|
|
20
|
+
"url": "git+https://github.com/Donix-VN/fca-unofficial.git"
|
|
15
21
|
},
|
|
16
22
|
"keywords": [
|
|
17
23
|
"facebook",
|
|
18
24
|
"chat",
|
|
19
25
|
"api",
|
|
20
26
|
"messenger",
|
|
21
|
-
"fca",
|
|
22
27
|
"bot",
|
|
28
|
+
"unofficial",
|
|
23
29
|
"automation",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
30
|
+
"facebook-api",
|
|
31
|
+
"facebook-chat",
|
|
32
|
+
"facebook-messenger",
|
|
33
|
+
"chatbot",
|
|
34
|
+
"nodejs",
|
|
35
|
+
"fca"
|
|
36
|
+
],
|
|
37
|
+
"author": {
|
|
38
|
+
"name": "DongDev",
|
|
39
|
+
"url": "https://www.facebook.com/mdong.dev"
|
|
40
|
+
},
|
|
41
|
+
"contributors": [
|
|
42
|
+
{
|
|
43
|
+
"name": "DongDev",
|
|
44
|
+
"url": "https://github.com/Donix-VN"
|
|
45
|
+
}
|
|
26
46
|
],
|
|
27
|
-
"author": "Rakib Hasan",
|
|
28
47
|
"license": "MIT",
|
|
29
48
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
49
|
+
"url": "https://github.com/Donix-VN/fca-unofficial/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/Donix-VN/fca-unofficial#readme",
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=12.0.0"
|
|
31
54
|
},
|
|
32
|
-
"homepage": "https://github.com/bdrakib123/rakibfca#readme",
|
|
33
55
|
"dependencies": {
|
|
34
|
-
"axios": "
|
|
56
|
+
"axios": "latest",
|
|
57
|
+
"axios-cookiejar-support": "^5.0.5",
|
|
58
|
+
"bluebird": "^3.7.2",
|
|
59
|
+
"chalk": "^4.1.2",
|
|
60
|
+
"cheerio": "^1.0.0-rc.10",
|
|
61
|
+
"duplexify": "^4.1.3",
|
|
62
|
+
"gradient-string": "^2.0.2",
|
|
63
|
+
"https-proxy-agent": "^4.0.0",
|
|
35
64
|
"mqtt": "^4.3.8",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"sequelize": "^6.
|
|
65
|
+
"npmlog": "^1.2.0",
|
|
66
|
+
"request": "^2.53.0",
|
|
67
|
+
"sequelize": "^6.37.6",
|
|
39
68
|
"sqlite3": "^5.1.7",
|
|
40
|
-
"totp-generator": "^0.0
|
|
69
|
+
"totp-generator": "^1.0.0",
|
|
70
|
+
"ws": "^8.18.1"
|
|
41
71
|
},
|
|
42
72
|
"devDependencies": {
|
|
43
|
-
"eslint": "^8.
|
|
44
|
-
"mocha": "^10.2.0"
|
|
45
|
-
|
|
73
|
+
"eslint": "^8.50.0",
|
|
74
|
+
"mocha": "^10.2.0"
|
|
75
|
+
},
|
|
76
|
+
"optionalDependencies": {},
|
|
77
|
+
"peerDependencies": {},
|
|
78
|
+
"publishConfig": {
|
|
79
|
+
"access": "public",
|
|
80
|
+
"registry": "https://registry.npmjs.org/"
|
|
46
81
|
}
|
|
47
82
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { getType } = require("../../utils/format");
|
|
4
|
+
|
|
5
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
6
|
+
return function addExternalModule(moduleObj) {
|
|
7
|
+
if (getType(moduleObj) == "Object") {
|
|
8
|
+
for (const apiName in moduleObj) {
|
|
9
|
+
if (getType(moduleObj[apiName]) == "Function") {
|
|
10
|
+
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Item "${apiName}" in moduleObj must be a function, not ${getType(
|
|
14
|
+
moduleObj[apiName]
|
|
15
|
+
)}!`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`moduleObj must be an object, not ${getType(moduleObj)}!`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const log = require("npmlog");
|
|
4
|
+
const { isReadableStream } = require("../../utils/constants");
|
|
5
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
|
6
|
+
const { formatID, getType } = require("../../utils/format");
|
|
7
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
8
|
+
function handleUpload(image, callback) {
|
|
9
|
+
const uploads = [];
|
|
10
|
+
|
|
11
|
+
const form = {
|
|
12
|
+
profile_id: ctx.userID,
|
|
13
|
+
photo_source: 57,
|
|
14
|
+
av: ctx.userID,
|
|
15
|
+
file: image
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
uploads.push(
|
|
19
|
+
defaultFuncs
|
|
20
|
+
.postFormData(
|
|
21
|
+
"https://www.facebook.com/profile/picture/upload/",
|
|
22
|
+
ctx.jar,
|
|
23
|
+
form,
|
|
24
|
+
{}
|
|
25
|
+
)
|
|
26
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
27
|
+
.then(function(resData) {
|
|
28
|
+
if (resData.error) {
|
|
29
|
+
throw resData;
|
|
30
|
+
}
|
|
31
|
+
return resData;
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// resolve all promises
|
|
36
|
+
Promise.all(uploads)
|
|
37
|
+
.then(function(resData) {
|
|
38
|
+
callback(null, resData);
|
|
39
|
+
})
|
|
40
|
+
.catch(function(err) {
|
|
41
|
+
log.error("handleUpload", err);
|
|
42
|
+
return callback(err);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return function changeAvatar(
|
|
47
|
+
image,
|
|
48
|
+
caption = "",
|
|
49
|
+
timestamp = null,
|
|
50
|
+
callback
|
|
51
|
+
) {
|
|
52
|
+
let resolveFunc = function() {};
|
|
53
|
+
let rejectFunc = function() {};
|
|
54
|
+
const returnPromise = new Promise(function(resolve, reject) {
|
|
55
|
+
resolveFunc = resolve;
|
|
56
|
+
rejectFunc = reject;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (!timestamp && getType(caption) === "Number") {
|
|
60
|
+
timestamp = caption;
|
|
61
|
+
caption = "";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
!timestamp &&
|
|
66
|
+
!callback &&
|
|
67
|
+
(getType(caption) == "Function" ||
|
|
68
|
+
getType(caption) == "AsyncFunction")
|
|
69
|
+
) {
|
|
70
|
+
callback = caption;
|
|
71
|
+
caption = "";
|
|
72
|
+
timestamp = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!callback)
|
|
76
|
+
callback = function(err, data) {
|
|
77
|
+
if (err) {
|
|
78
|
+
return rejectFunc(err);
|
|
79
|
+
}
|
|
80
|
+
resolveFunc(data);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (!isReadableStream(image))
|
|
84
|
+
return callback("Image is not a readable stream");
|
|
85
|
+
|
|
86
|
+
handleUpload(image, function(err, payload) {
|
|
87
|
+
if (err) {
|
|
88
|
+
return callback(err);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const form = {
|
|
92
|
+
av: ctx.i_userID || ctx.userID,
|
|
93
|
+
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
|
94
|
+
fb_api_caller_class: "RelayModern",
|
|
95
|
+
doc_id: "5066134240065849",
|
|
96
|
+
variables: JSON.stringify({
|
|
97
|
+
input: {
|
|
98
|
+
caption,
|
|
99
|
+
existing_photo_id: payload[0].payload.fbid,
|
|
100
|
+
expiration_time: timestamp,
|
|
101
|
+
profile_id: ctx.i_userID || ctx.userID,
|
|
102
|
+
profile_pic_method: "EXISTING",
|
|
103
|
+
profile_pic_source: "TIMELINE",
|
|
104
|
+
scaled_crop_rect: {
|
|
105
|
+
height: 1,
|
|
106
|
+
width: 1,
|
|
107
|
+
x: 0,
|
|
108
|
+
y: 0
|
|
109
|
+
},
|
|
110
|
+
skip_cropping: true,
|
|
111
|
+
actor_id: ctx.i_userID || ctx.userID,
|
|
112
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
|
113
|
+
},
|
|
114
|
+
isPage: false,
|
|
115
|
+
isProfile: true,
|
|
116
|
+
scale: 3
|
|
117
|
+
})
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
defaultFuncs
|
|
121
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
122
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
123
|
+
.then(function(resData) {
|
|
124
|
+
if (resData.errors) {
|
|
125
|
+
throw resData;
|
|
126
|
+
}
|
|
127
|
+
return callback(null, resData[0].data.profile_picture_set);
|
|
128
|
+
})
|
|
129
|
+
.catch(function(err) {
|
|
130
|
+
log.error("changeAvatar", err);
|
|
131
|
+
return callback(err);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return returnPromise;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
@@ -1,76 +1,75 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = function
|
|
7
|
-
return function changeBio(bio, publish, callback) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
resolveFunc = resolve;
|
|
12
|
-
rejectFunc = reject;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
if (!callback) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
) {
|
|
20
|
-
callback = publish;
|
|
21
|
-
} else {
|
|
22
|
-
callback = function
|
|
23
|
-
if (err) {
|
|
24
|
-
return rejectFunc(err);
|
|
25
|
-
}
|
|
26
|
-
resolveFunc();
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
publish = false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
bio = "";
|
|
37
|
-
publish = false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
fb_api_caller_class: "RelayModern",
|
|
42
|
-
fb_api_req_friendly_name: "ProfileCometSetBioMutation",
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
.then(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const log = require("npmlog");
|
|
4
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
|
5
|
+
const { getType } = require("../../utils/format");
|
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
7
|
+
return function changeBio(bio, publish, callback) {
|
|
8
|
+
let resolveFunc = function() {};
|
|
9
|
+
let rejectFunc = function() {};
|
|
10
|
+
const returnPromise = new Promise(function(resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!callback) {
|
|
16
|
+
if (
|
|
17
|
+
getType(publish) == "Function" ||
|
|
18
|
+
getType(publish) == "AsyncFunction"
|
|
19
|
+
) {
|
|
20
|
+
callback = publish;
|
|
21
|
+
} else {
|
|
22
|
+
callback = function(err) {
|
|
23
|
+
if (err) {
|
|
24
|
+
return rejectFunc(err);
|
|
25
|
+
}
|
|
26
|
+
resolveFunc();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (getType(publish) != "Boolean") {
|
|
32
|
+
publish = false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (getType(bio) != "String") {
|
|
36
|
+
bio = "";
|
|
37
|
+
publish = false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const form = {
|
|
41
|
+
fb_api_caller_class: "RelayModern",
|
|
42
|
+
fb_api_req_friendly_name: "ProfileCometSetBioMutation",
|
|
43
|
+
doc_id: "2725043627607610",
|
|
44
|
+
variables: JSON.stringify({
|
|
45
|
+
input: {
|
|
46
|
+
bio: bio,
|
|
47
|
+
publish_bio_feed_story: publish,
|
|
48
|
+
actor_id: ctx.i_userID || ctx.userID,
|
|
49
|
+
client_mutation_id: Math.round(Math.random() * 1024).toString()
|
|
50
|
+
},
|
|
51
|
+
hasProfileTileViewID: false,
|
|
52
|
+
profileTileViewID: null,
|
|
53
|
+
scale: 1
|
|
54
|
+
}),
|
|
55
|
+
av: ctx.i_userID || ctx.userID
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
defaultFuncs
|
|
59
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
60
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
61
|
+
.then(function(resData) {
|
|
62
|
+
if (resData.errors) {
|
|
63
|
+
throw resData;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return callback();
|
|
67
|
+
})
|
|
68
|
+
.catch(function(err) {
|
|
69
|
+
log.error("changeBio", err);
|
|
70
|
+
return callback(err);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return returnPromise;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const logger = require("../../../func/logger");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Enable automatic AppState saving
|
|
8
|
+
* @param {Object} options - Options for auto-save
|
|
9
|
+
* @param {string} [options.filePath] - Path to save AppState (default: "appstate.json")
|
|
10
|
+
* @param {number} [options.interval] - Save interval in milliseconds (default: 10 minutes)
|
|
11
|
+
* @param {boolean} [options.saveOnLogin] - Save immediately on login (default: true)
|
|
12
|
+
* @returns {Function} Function to disable auto-save
|
|
13
|
+
*/
|
|
14
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
15
|
+
return function enableAutoSaveAppState(options = {}) {
|
|
16
|
+
const filePath = options.filePath || path.join(process.cwd(), "appstate.json");
|
|
17
|
+
const interval = options.interval || 10 * 60 * 1000; // 10 minutes default
|
|
18
|
+
const saveOnLogin = options.saveOnLogin !== false; // default true
|
|
19
|
+
|
|
20
|
+
// Save function
|
|
21
|
+
function saveAppState() {
|
|
22
|
+
try {
|
|
23
|
+
const appState = api.getAppState();
|
|
24
|
+
if (!appState || !appState.appState || appState.appState.length === 0) {
|
|
25
|
+
logger("AppState is empty, skipping save", "warn");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const data = JSON.stringify(appState, null, 2);
|
|
30
|
+
fs.writeFileSync(filePath, data, "utf8");
|
|
31
|
+
logger(`AppState saved to ${filePath}`, "info");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger(`Error saving AppState: ${error && error.message ? error.message : String(error)}`, "error");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Save immediately if requested
|
|
38
|
+
let immediateSaveTimer = null;
|
|
39
|
+
if (saveOnLogin) {
|
|
40
|
+
// Delay a bit to ensure login is complete
|
|
41
|
+
immediateSaveTimer = setTimeout(() => {
|
|
42
|
+
saveAppState();
|
|
43
|
+
immediateSaveTimer = null;
|
|
44
|
+
}, 2000);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Set up interval
|
|
48
|
+
const intervalId = setInterval(saveAppState, interval);
|
|
49
|
+
logger(`Auto-save AppState enabled: ${filePath} (every ${Math.round(interval / 1000 / 60)} minutes)`, "info");
|
|
50
|
+
|
|
51
|
+
// Store interval ID for cleanup
|
|
52
|
+
if (!ctx._autoSaveInterval) {
|
|
53
|
+
ctx._autoSaveInterval = [];
|
|
54
|
+
}
|
|
55
|
+
ctx._autoSaveInterval.push(intervalId);
|
|
56
|
+
|
|
57
|
+
// Return disable function
|
|
58
|
+
return function disableAutoSaveAppState() {
|
|
59
|
+
// Clear immediate save timer if still pending
|
|
60
|
+
if (immediateSaveTimer) {
|
|
61
|
+
clearTimeout(immediateSaveTimer);
|
|
62
|
+
immediateSaveTimer = null;
|
|
63
|
+
}
|
|
64
|
+
// Clear interval
|
|
65
|
+
clearInterval(intervalId);
|
|
66
|
+
const index = ctx._autoSaveInterval ? ctx._autoSaveInterval.indexOf(intervalId) : -1;
|
|
67
|
+
if (index !== -1) {
|
|
68
|
+
ctx._autoSaveInterval.splice(index, 1);
|
|
69
|
+
}
|
|
70
|
+
logger("Auto-save AppState disabled", "info");
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = function
|
|
4
|
-
return function getCurrentUserID() {
|
|
5
|
-
return ctx.userID;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
4
|
+
return function getCurrentUserID() {
|
|
5
|
+
return ctx.userID;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = function
|
|
7
|
-
return function handleFriendRequest(userID, accept, callback) {
|
|
8
|
-
if (
|
|
9
|
-
throw {
|
|
10
|
-
error: "Please pass a boolean as a second argument."
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
resolveFunc = resolve;
|
|
18
|
-
rejectFunc = reject;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
if (!callback) {
|
|
22
|
-
callback = function
|
|
23
|
-
if (err) {
|
|
24
|
-
return rejectFunc(err);
|
|
25
|
-
}
|
|
26
|
-
resolveFunc(friendList);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
viewer_id: ctx.userID,
|
|
32
|
-
"frefs[0]": "jwl",
|
|
33
|
-
floc: "friend_center_requests",
|
|
34
|
-
ref: "/reqs.php",
|
|
35
|
-
action: accept ? "confirm" : "reject"
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
defaultFuncs
|
|
39
|
-
.post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
|
|
40
|
-
.then(
|
|
41
|
-
.then(function
|
|
42
|
-
if (resData.payload.err) {
|
|
43
|
-
throw {
|
|
44
|
-
err: resData.payload.err
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return callback();
|
|
49
|
-
})
|
|
50
|
-
.catch(function
|
|
51
|
-
log.error("handleFriendRequest", err);
|
|
52
|
-
return callback(err);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return returnPromise;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const log = require("npmlog");
|
|
4
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
|
5
|
+
const { getType } = require("../../utils/format");
|
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
7
|
+
return function handleFriendRequest(userID, accept, callback) {
|
|
8
|
+
if (getType(accept) !== "Boolean") {
|
|
9
|
+
throw {
|
|
10
|
+
error: "Please pass a boolean as a second argument."
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let resolveFunc = function() {};
|
|
15
|
+
let rejectFunc = function() {};
|
|
16
|
+
const returnPromise = new Promise(function(resolve, reject) {
|
|
17
|
+
resolveFunc = resolve;
|
|
18
|
+
rejectFunc = reject;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (!callback) {
|
|
22
|
+
callback = function(err, friendList) {
|
|
23
|
+
if (err) {
|
|
24
|
+
return rejectFunc(err);
|
|
25
|
+
}
|
|
26
|
+
resolveFunc(friendList);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const form = {
|
|
31
|
+
viewer_id: ctx.userID,
|
|
32
|
+
"frefs[0]": "jwl",
|
|
33
|
+
floc: "friend_center_requests",
|
|
34
|
+
ref: "/reqs.php",
|
|
35
|
+
action: accept ? "confirm" : "reject"
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
defaultFuncs
|
|
39
|
+
.post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
|
|
40
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
41
|
+
.then(function(resData) {
|
|
42
|
+
if (resData.payload.err) {
|
|
43
|
+
throw {
|
|
44
|
+
err: resData.payload.err
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return callback();
|
|
49
|
+
})
|
|
50
|
+
.catch(function(err) {
|
|
51
|
+
log.error("handleFriendRequest", err);
|
|
52
|
+
return callback(err);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return returnPromise;
|
|
56
|
+
};
|
|
57
|
+
};
|