@dongdev/fca-unofficial 1.0.20 → 2.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.
Files changed (128) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +30 -30
  3. package/DOCS.md +727 -592
  4. package/README.md +94 -97
  5. package/func/logger.js +112 -0
  6. package/html.html +474 -0
  7. package/index.js +1 -379
  8. package/module/config.js +26 -0
  9. package/module/login.js +45 -0
  10. package/module/loginHelper.js +634 -0
  11. package/module/options.js +49 -0
  12. package/package.json +6 -39
  13. package/src/api/action/addExternalModule.js +25 -0
  14. package/src/api/action/changeAvatar.js +136 -0
  15. package/src/api/action/changeBio.js +76 -0
  16. package/src/api/action/getCurrentUserID.js +7 -0
  17. package/src/api/action/handleFriendRequest.js +57 -0
  18. package/src/api/action/logout.js +75 -0
  19. package/src/{refreshFb_dtsg.js → api/action/refreshFb_dtsg.js} +8 -8
  20. package/src/api/action/setPostReaction.js +107 -0
  21. package/src/api/action/unfriend.js +55 -0
  22. package/src/api/http/httpGet.js +65 -0
  23. package/src/api/http/httpPost.js +65 -0
  24. package/src/{postFormData.js → api/http/postFormData.js} +10 -10
  25. package/src/api/messaging/addUserToGroup.js +69 -0
  26. package/src/api/messaging/changeAdminStatus.js +103 -0
  27. package/src/api/messaging/changeArchivedStatus.js +55 -0
  28. package/src/api/messaging/changeBlockedStatus.js +49 -0
  29. package/src/api/messaging/changeGroupImage.js +135 -0
  30. package/src/api/messaging/changeNickname.js +59 -0
  31. package/src/api/messaging/changeThreadColor.js +65 -0
  32. package/src/api/messaging/createNewGroup.js +88 -0
  33. package/src/api/messaging/createPoll.js +70 -0
  34. package/src/api/messaging/deleteMessage.js +56 -0
  35. package/src/api/messaging/deleteThread.js +56 -0
  36. package/src/api/messaging/forwardAttachment.js +60 -0
  37. package/src/api/messaging/getEmojiUrl.js +29 -0
  38. package/src/api/messaging/getFriendsList.js +83 -0
  39. package/src/api/messaging/getMessage.js +834 -0
  40. package/src/api/messaging/getThreadHistory.js +681 -0
  41. package/src/api/messaging/handleMessageRequest.js +65 -0
  42. package/src/api/messaging/markAsDelivered.js +57 -0
  43. package/src/api/messaging/markAsRead.js +88 -0
  44. package/src/api/messaging/markAsReadAll.js +50 -0
  45. package/src/api/messaging/markAsSeen.js +61 -0
  46. package/src/api/messaging/muteThread.js +51 -0
  47. package/src/api/messaging/removeUserFromGroup.js +79 -0
  48. package/src/api/messaging/resolvePhotoUrl.js +44 -0
  49. package/src/api/messaging/searchForThread.js +53 -0
  50. package/src/api/messaging/sendMessage.js +306 -0
  51. package/src/api/messaging/sendMessageMqtt.js +321 -0
  52. package/src/api/messaging/sendTypingIndicator.js +110 -0
  53. package/src/{setMessageReaction.js → api/messaging/setMessageReaction.js} +20 -20
  54. package/src/api/messaging/setTitle.js +90 -0
  55. package/src/api/messaging/shareContact.js +51 -0
  56. package/src/api/messaging/threadColors.js +131 -0
  57. package/src/api/messaging/unsendMessage.js +44 -0
  58. package/src/api/messaging/uploadAttachment.js +93 -0
  59. package/src/api/socket/detail/buildStream.js +100 -0
  60. package/src/{listenMqtt.js → api/socket/listenMqtt.js} +122 -206
  61. package/src/api/threads/changeThreadEmoji.js +55 -0
  62. package/src/api/threads/getThreadInfo.js +572 -0
  63. package/src/{getThreadList.js → api/threads/getThreadList.js} +110 -54
  64. package/src/api/threads/getThreadPictures.js +79 -0
  65. package/src/api/users/getUserID.js +66 -0
  66. package/src/api/users/getUserInfo.js +88 -0
  67. package/src/core/sendReqMqtt.js +63 -0
  68. package/{lib → src}/database/models/index.js +12 -10
  69. package/{lib → src}/database/models/thread.js +5 -5
  70. package/{lib → src}/database/threadData.js +19 -14
  71. package/src/utils/client.js +159 -0
  72. package/src/utils/constants.js +13 -0
  73. package/src/utils/format.js +60 -0
  74. package/src/utils/headers.js +41 -0
  75. package/src/utils/index.js +1497 -0
  76. package/src/utils/request.js +147 -0
  77. package/lib/logger.js +0 -96
  78. package/src/addExternalModule.js +0 -19
  79. package/src/addUserToGroup.js +0 -113
  80. package/src/changeAdminStatus.js +0 -79
  81. package/src/changeArchivedStatus.js +0 -55
  82. package/src/changeAvatar.js +0 -126
  83. package/src/changeBio.js +0 -77
  84. package/src/changeBlockedStatus.js +0 -47
  85. package/src/changeGroupImage.js +0 -132
  86. package/src/changeNickname.js +0 -59
  87. package/src/changeThreadColor.js +0 -65
  88. package/src/changeThreadEmoji.js +0 -55
  89. package/src/createNewGroup.js +0 -86
  90. package/src/createPoll.js +0 -71
  91. package/src/deleteMessage.js +0 -56
  92. package/src/deleteThread.js +0 -56
  93. package/src/forwardAttachment.js +0 -60
  94. package/src/getCurrentUserID.js +0 -7
  95. package/src/getEmojiUrl.js +0 -29
  96. package/src/getFriendsList.js +0 -83
  97. package/src/getMessage.js +0 -796
  98. package/src/getThreadHistory.js +0 -666
  99. package/src/getThreadInfo.js +0 -535
  100. package/src/getThreadPictures.js +0 -79
  101. package/src/getUserID.js +0 -66
  102. package/src/getUserInfo.js +0 -80
  103. package/src/handleFriendRequest.js +0 -61
  104. package/src/handleMessageRequest.js +0 -65
  105. package/src/httpGet.js +0 -57
  106. package/src/httpPost.js +0 -57
  107. package/src/httpPostFormData.js +0 -63
  108. package/src/logout.js +0 -75
  109. package/src/markAsDelivered.js +0 -58
  110. package/src/markAsRead.js +0 -80
  111. package/src/markAsReadAll.js +0 -50
  112. package/src/markAsSeen.js +0 -59
  113. package/src/muteThread.js +0 -52
  114. package/src/removeUserFromGroup.js +0 -79
  115. package/src/resolvePhotoUrl.js +0 -45
  116. package/src/searchForThread.js +0 -53
  117. package/src/sendMessage.js +0 -328
  118. package/src/sendMessageMqtt.js +0 -316
  119. package/src/sendTypingIndicator.js +0 -103
  120. package/src/setPostReaction.js +0 -109
  121. package/src/setTitle.js +0 -86
  122. package/src/shareContact.js +0 -49
  123. package/src/threadColors.js +0 -131
  124. package/src/unfriend.js +0 -52
  125. package/src/unsendMessage.js +0 -49
  126. package/src/uploadAttachment.js +0 -95
  127. package/utils.js +0 -1387
  128. /package/{lib → func}/login.js +0 -0
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ const axios = require("axios");
4
+ const { CookieJar } = require("tough-cookie");
5
+ const { wrapper } = require("axios-cookiejar-support");
6
+ const FormData = require("form-data");
7
+ const { HttpsProxyAgent } = require("https-proxy-agent");
8
+
9
+ const headersMod = require("./headers");
10
+ const getHeaders = headersMod.getHeaders || headersMod;
11
+ const formatMod = require("./format");
12
+ const getType = formatMod.getType || formatMod;
13
+ const constMod = require("./constants");
14
+ const getFrom = constMod.getFrom || constMod;
15
+
16
+ const jar = new CookieJar();
17
+ const client = wrapper(axios.create({
18
+ jar,
19
+ withCredentials: true,
20
+ timeout: 60000,
21
+ validateStatus: s => s >= 200 && s < 600
22
+ }));
23
+
24
+ const delay = ms => new Promise(r => setTimeout(r, ms));
25
+
26
+ async function requestWithRetry(fn, retries = 3) {
27
+ let err;
28
+ for (let i = 0; i < retries; i++) {
29
+ try { return await fn(); } catch (e) {
30
+ err = e;
31
+ if (i === retries - 1) return e.response ? e.response : Promise.reject(e);
32
+ await delay((1 << i) * 1000 + Math.floor(Math.random() * 200));
33
+ }
34
+ }
35
+ throw err;
36
+ }
37
+
38
+ function cfg(base = {}) {
39
+ const { reqJar, headers, params, agent, timeout } = base;
40
+ return {
41
+ headers,
42
+ params,
43
+ jar: reqJar || jar,
44
+ withCredentials: true,
45
+ timeout: timeout || 60000,
46
+ httpAgent: agent || client.defaults.httpAgent,
47
+ httpsAgent: agent || client.defaults.httpsAgent,
48
+ proxy: false,
49
+ validateStatus: s => s >= 200 && s < 600
50
+ };
51
+ }
52
+
53
+ function cleanGet(url) {
54
+ return requestWithRetry(() => client.get(url, cfg()));
55
+ }
56
+
57
+ function get(url, reqJar, qs, options, ctx, customHeader) {
58
+ const headers = getHeaders(url, options, ctx, customHeader);
59
+ return requestWithRetry(() => client.get(url, cfg({ reqJar, headers, params: qs })));
60
+ }
61
+
62
+ function post(url, reqJar, form, options, ctx, customHeader) {
63
+ const headers = getHeaders(url, options, ctx, customHeader);
64
+ const ct = String(headers["Content-Type"] || headers["content-type"] || "application/x-www-form-urlencoded").toLowerCase();
65
+ let data;
66
+ if (ct.includes("json")) {
67
+ data = JSON.stringify(form || {});
68
+ headers["Content-Type"] = "application/json";
69
+ } else {
70
+ const p = new URLSearchParams();
71
+ if (form && typeof form === "object") {
72
+ for (const k of Object.keys(form)) {
73
+ let v = form[k];
74
+ if (getType(v) === "Object") v = JSON.stringify(v);
75
+ if (Array.isArray(v)) v.forEach(x => p.append(k, x));
76
+ else p.append(k, v);
77
+ }
78
+ }
79
+ data = p.toString();
80
+ headers["Content-Type"] = "application/x-www-form-urlencoded";
81
+ }
82
+ return requestWithRetry(() => client.post(url, data, cfg({ reqJar, headers })));
83
+ }
84
+
85
+ function postFormData(url, reqJar, form, qs, options, ctx) {
86
+ const fd = new FormData();
87
+ if (form && typeof form === "object") {
88
+ for (const k of Object.keys(form)) {
89
+ const v = form[k];
90
+ if (Array.isArray(v)) v.forEach(x => fd.append(k, x));
91
+ else fd.append(k, v);
92
+ }
93
+ }
94
+ const headers = { ...getHeaders(url, options, ctx), ...fd.getHeaders() };
95
+ return requestWithRetry(() => client.post(url, fd, cfg({ reqJar, headers, params: qs })));
96
+ }
97
+
98
+ function makeDefaults(html, userID, ctx) {
99
+ let reqCounter = 1;
100
+ const revision = getFrom(html || "", 'revision":', ",") || getFrom(html || "", '"client_revision":', ",") || "";
101
+ function mergeWithDefaults(obj) {
102
+ const base = {
103
+ av: userID,
104
+ __user: userID,
105
+ __req: (reqCounter++).toString(36),
106
+ __rev: revision,
107
+ __a: 1
108
+ };
109
+ if (ctx?.fb_dtsg) base.fb_dtsg = ctx.fb_dtsg;
110
+ if (ctx?.jazoest) base.jazoest = ctx.jazoest;
111
+ if (!obj) return base;
112
+ for (const k of Object.keys(obj)) if (!(k in base)) base[k] = obj[k];
113
+ return base;
114
+ }
115
+ return {
116
+ get: (url, j, qs, ctxx, customHeader = {}) =>
117
+ get(url, j, mergeWithDefaults(qs), ctx?.globalOptions, ctxx || ctx, customHeader),
118
+ post: (url, j, form, ctxx, customHeader = {}) =>
119
+ post(url, j, mergeWithDefaults(form), ctx?.globalOptions, ctxx || ctx, customHeader),
120
+ postFormData: (url, j, form, qs, ctxx) =>
121
+ postFormData(url, j, mergeWithDefaults(form), mergeWithDefaults(qs), ctx?.globalOptions, ctxx || ctx)
122
+ };
123
+ }
124
+
125
+ function setProxy(proxyUrl) {
126
+ if (!proxyUrl) {
127
+ client.defaults.httpAgent = undefined;
128
+ client.defaults.httpsAgent = undefined;
129
+ client.defaults.proxy = false;
130
+ return;
131
+ }
132
+ const agent = new HttpsProxyAgent(proxyUrl);
133
+ client.defaults.httpAgent = agent;
134
+ client.defaults.httpsAgent = agent;
135
+ client.defaults.proxy = false;
136
+ }
137
+
138
+ module.exports = {
139
+ cleanGet,
140
+ get,
141
+ post,
142
+ postFormData,
143
+ jar,
144
+ setProxy,
145
+ makeDefaults,
146
+ client
147
+ };
package/lib/logger.js DELETED
@@ -1,96 +0,0 @@
1
- const chalk = require('chalk');
2
- const gradient = require("gradient-string");
3
- const themes = [
4
- 'blue',
5
- 'dream2',
6
- 'dream',
7
- 'test',
8
- 'fiery',
9
- 'rainbow',
10
- 'pastel',
11
- 'cristal',
12
- 'red',
13
- 'aqua',
14
- 'pink',
15
- 'retro',
16
- 'sunlight',
17
- 'teen',
18
- 'summer',
19
- 'flower',
20
- 'ghost',
21
- 'hacker'
22
- ];
23
- const theme = themes[Math.floor(Math.random() * themes.length)];
24
- let co;
25
- let error;
26
- if (theme.toLowerCase() === 'blue') {
27
- co = gradient([{ color: "#1affa3", pos: 0.2 }, { color: "cyan", pos: 0.4 }, { color: "pink", pos: 0.6 }, { color: "cyan", pos: 0.8 }, { color: '#1affa3', pos: 1 }]);
28
- error = chalk.red.bold;
29
- } else if (theme == "dream2") {
30
- cra = gradient("blue", "pink")
31
- co = gradient("#a200ff", "#21b5ff", "#a200ff")
32
- } else if (theme.toLowerCase() === 'dream') {
33
- co = gradient([{ color: "blue", pos: 0.2 }, { color: "pink", pos: 0.3 }, { color: "gold", pos: 0.6 }, { color: "pink", pos: 0.8 }, { color: "blue", pos: 1 }]);
34
- error = chalk.red.bold;
35
- } else if (theme.toLowerCase() === 'fiery') {
36
- co = gradient("#fc2803", "#fc6f03", "#fcba03");
37
- error = chalk.red.bold;
38
- } else if (theme.toLowerCase() === 'rainbow') {
39
- co = gradient.rainbow
40
- error = chalk.red.bold;
41
- } else if (theme.toLowerCase() === 'pastel') {
42
- co = gradient.pastel
43
- error = chalk.red.bold;
44
- } else if (theme.toLowerCase() === 'cristal') {
45
- co = gradient.cristal
46
- error = chalk.red.bold;
47
- } else if (theme.toLowerCase() === 'red') {
48
- co = gradient("red", "orange");
49
- error = chalk.red.bold;
50
- } else if (theme.toLowerCase() === 'aqua') {
51
- co = gradient("#0030ff", "#4e6cf2");
52
- error = chalk.blueBright;
53
- } else if (theme.toLowerCase() === 'pink') {
54
- cra = gradient('purple', 'pink');
55
- co = gradient("#d94fff", "purple");
56
- } else if (theme.toLowerCase() === 'retro') {
57
- cra = gradient("#d94fff", "purple");
58
- co = gradient.retro;
59
- } else if (theme.toLowerCase() === 'sunlight') {
60
- cra = gradient("#f5bd31", "#f5e131");
61
- co = gradient("orange", "#ffff00", "#ffe600");
62
- } else if (theme.toLowerCase() === 'teen') {
63
- cra = gradient("#00a9c7", "#853858", "#853858", "#00a9c7");
64
- co = gradient.teen;
65
- } else if (theme.toLowerCase() === 'summer') {
66
- cra = gradient("#fcff4d", "#4de1ff");
67
- co = gradient.summer;
68
- } else if (theme.toLowerCase() === 'flower') {
69
- cra = gradient("blue", "purple", "yellow", "#81ff6e");
70
- co = gradient.pastel;
71
- } else if (theme.toLowerCase() === 'ghost') {
72
- cra = gradient("#0a658a", "#0a7f8a", "#0db5aa");
73
- co = gradient.mind;
74
- } else if (theme === 'hacker') {
75
- cra = chalk.hex('#4be813');
76
- co = gradient('#47a127', '#0eed19', '#27f231');
77
- } else {
78
- co = gradient("#243aff", "#4687f0", "#5800d4");
79
- error = chalk.red.bold;
80
- }
81
- module.exports = (text, type) => {
82
- switch (type) {
83
- case "warn":
84
- process.stderr.write(co(`\r[ FCA-WARN ] > ${text}`) + '\n');
85
- break;
86
- case "error":
87
- process.stderr.write(chalk.bold.hex("#ff0000").bold(`\r[ FCA-ERROR ]`) + ` > ${text}` + '\n');
88
- break;
89
- case "info":
90
- process.stderr.write(chalk.bold(co(`\r[ FCA-UNO ] > ${text}`) + '\n'));
91
- break;
92
- default:
93
- process.stderr.write(chalk.bold(co(`\r${String(type).toUpperCase()} ${text}`) + '\n'));
94
- break;
95
- }
96
- };
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- return function addExternalModule(moduleObj) {
7
- if (utils.getType(moduleObj) == "Object") {
8
- for (const apiName in moduleObj) {
9
- if (utils.getType(moduleObj[apiName]) == "Function") {
10
- api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
11
- } else {
12
- throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
13
- }
14
- }
15
- } else {
16
- throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
17
- }
18
- };
19
- };
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function addUserToGroup(userID, threadID, 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 (
16
- !callback &&
17
- (utils.getType(threadID) === "Function" ||
18
- utils.getType(threadID) === "AsyncFunction")
19
- ) {
20
- throw new utils.CustomError({ error: "please pass a threadID as a second argument." });
21
- }
22
-
23
- if (!callback) {
24
- callback = function (err) {
25
- if (err) {
26
- return rejectFunc(err);
27
- }
28
- resolveFunc();
29
- };
30
- }
31
-
32
- if (
33
- utils.getType(threadID) !== "Number" &&
34
- utils.getType(threadID) !== "String"
35
- ) {
36
- throw new utils.CustomError({
37
- error:
38
- "ThreadID should be of type Number or String and not " +
39
- utils.getType(threadID) +
40
- "."
41
- });
42
- }
43
-
44
- if (utils.getType(userID) !== "Array") {
45
- userID = [userID];
46
- }
47
-
48
- const messageAndOTID = utils.generateOfflineThreadingID();
49
- const form = {
50
- client: "mercury",
51
- action_type: "ma-type:log-message",
52
- author: "fbid:" + (ctx.i_userID || ctx.userID),
53
- thread_id: "",
54
- timestamp: Date.now(),
55
- timestamp_absolute: "Today",
56
- timestamp_relative: utils.generateTimestampRelative(),
57
- timestamp_time_passed: "0",
58
- is_unread: false,
59
- is_cleared: false,
60
- is_forward: false,
61
- is_filtered_content: false,
62
- is_filtered_content_bh: false,
63
- is_filtered_content_account: false,
64
- is_spoof_warning: false,
65
- source: "source:chat:web",
66
- "source_tags[0]": "source:chat",
67
- log_message_type: "log:subscribe",
68
- status: "0",
69
- offline_threading_id: messageAndOTID,
70
- message_id: messageAndOTID,
71
- threading_id: utils.generateThreadingID(ctx.clientID),
72
- manual_retry_cnt: "0",
73
- thread_fbid: threadID
74
- };
75
-
76
- for (let i = 0; i < userID.length; i++) {
77
- if (
78
- utils.getType(userID[i]) !== "Number" &&
79
- utils.getType(userID[i]) !== "String"
80
- ) {
81
- throw new utils.CustomError({
82
- error:
83
- "Elements of userID should be of type Number or String and not " +
84
- utils.getType(userID[i]) +
85
- "."
86
- });
87
- }
88
-
89
- form["log_message_data[added_participants][" + i + "]"] =
90
- "fbid:" + userID[i];
91
- }
92
-
93
- defaultFuncs
94
- .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
95
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
- .then(function (resData) {
97
- if (!resData) {
98
- throw new utils.CustomError({ error: "Add to group failed." });
99
- }
100
- if (resData.error) {
101
- throw new utils.CustomError(resData);
102
- }
103
-
104
- return callback();
105
- })
106
- .catch(function (err) {
107
- log.error("addUserToGroup", err);
108
- return callback(err);
109
- });
110
-
111
- return returnPromise;
112
- };
113
- };
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
8
- if (utils.getType(threadID) !== "String") {
9
- throw new utils.CustomError({ error: "changeAdminStatus: threadID must be a string" });
10
- }
11
-
12
- if (utils.getType(adminIDs) === "String") {
13
- adminIDs = [adminIDs];
14
- }
15
-
16
- if (utils.getType(adminIDs) !== "Array") {
17
- throw new utils.CustomError({ error: "changeAdminStatus: adminIDs must be an array or string" });
18
- }
19
-
20
- if (utils.getType(adminStatus) !== "Boolean") {
21
- throw new utils.CustomError({ error: "changeAdminStatus: adminStatus must be a string" });
22
- }
23
-
24
- let resolveFunc = function () { };
25
- let rejectFunc = function () { };
26
- const returnPromise = new Promise(function (resolve, reject) {
27
- resolveFunc = resolve;
28
- rejectFunc = reject;
29
- });
30
-
31
- if (!callback) {
32
- callback = function (err) {
33
- if (err) {
34
- return rejectFunc(err);
35
- }
36
- resolveFunc();
37
- };
38
- }
39
-
40
- if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
41
- throw new utils.CustomError({ error: "changeAdminStatus: callback is not a function" });
42
- }
43
-
44
- const form = {
45
- "thread_fbid": threadID
46
- };
47
-
48
- let i = 0;
49
- for (const u of adminIDs) {
50
- form[`admin_ids[${i++}]`] = u;
51
- }
52
- form["add"] = adminStatus;
53
-
54
- defaultFuncs
55
- .post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
56
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
- .then(function (resData) {
58
- if (resData.error) {
59
- switch (resData.error) {
60
- case 1976004:
61
- throw new utils.CustomError({ error: "Cannot alter admin status: you are not an admin.", rawResponse: resData });
62
- case 1357031:
63
- throw new utils.CustomError({ error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData });
64
- default:
65
- throw new utils.CustomError({ error: "Cannot alter admin status: unknown error.", rawResponse: resData });
66
- }
67
- }
68
-
69
- callback();
70
- })
71
- .catch(function (err) {
72
- log.error("changeAdminStatus", err);
73
- return callback(err);
74
- });
75
-
76
- return returnPromise;
77
- };
78
- };
79
-
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function changeArchivedStatus(threadOrThreads, archive, 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
- callback = function (err) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
20
- resolveFunc();
21
- };
22
- }
23
-
24
- const form = {};
25
-
26
- if (utils.getType(threadOrThreads) === "Array") {
27
- for (let i = 0; i < threadOrThreads.length; i++) {
28
- form["ids[" + threadOrThreads[i] + "]"] = archive;
29
- }
30
- } else {
31
- form["ids[" + threadOrThreads + "]"] = archive;
32
- }
33
-
34
- defaultFuncs
35
- .post(
36
- "https://www.facebook.com/ajax/mercury/change_archived_status.php",
37
- ctx.jar,
38
- form
39
- )
40
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
41
- .then(function (resData) {
42
- if (resData.error) {
43
- throw resData;
44
- }
45
-
46
- return callback();
47
- })
48
- .catch(function (err) {
49
- log.error("changeArchivedStatus", err);
50
- return callback(err);
51
- });
52
-
53
- return returnPromise;
54
- };
55
- };
@@ -1,126 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- function handleUpload(image, callback) {
8
- const uploads = [];
9
-
10
- const form = {
11
- profile_id: ctx.i_userID || ctx.userID,
12
- photo_source: 57,
13
- av: ctx.i_userID || ctx.userID,
14
- file: image
15
- };
16
-
17
- uploads.push(
18
- defaultFuncs
19
- .postFormData(
20
- "https://www.facebook.com/profile/picture/upload/",
21
- ctx.jar,
22
- form,
23
- {}
24
- )
25
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
26
- .then(function (resData) {
27
- if (resData.error) {
28
- throw resData;
29
- }
30
- return resData;
31
- })
32
- );
33
-
34
- // resolve all promises
35
- Promise
36
- .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(image, caption = "", timestamp = null, callback) {
47
- let resolveFunc = function () { };
48
- let rejectFunc = function () { };
49
- const returnPromise = new Promise(function (resolve, reject) {
50
- resolveFunc = resolve;
51
- rejectFunc = reject;
52
- });
53
-
54
- if (!timestamp && utils.getType(caption) === "Number") {
55
- timestamp = caption;
56
- caption = "";
57
- }
58
-
59
- if (!timestamp && !callback && (utils.getType(caption) == "Function" || utils.getType(caption) == "AsyncFunction")) {
60
- callback = caption;
61
- caption = "";
62
- timestamp = null;
63
- }
64
-
65
- if (!callback) callback = function (err, data) {
66
- if (err) {
67
- return rejectFunc(err);
68
- }
69
- resolveFunc(data);
70
- };
71
-
72
- if (!utils.isReadableStream(image))
73
- return callback("Image is not a readable stream");
74
-
75
- handleUpload(image, function (err, payload) {
76
- if (err) {
77
- return callback(err);
78
- }
79
-
80
- const form = {
81
- av: ctx.i_userID || ctx.userID,
82
- fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
83
- fb_api_caller_class: "RelayModern",
84
- doc_id: "5066134240065849",
85
- variables: JSON.stringify({
86
- input: {
87
- caption,
88
- existing_photo_id: payload[0].payload.fbid,
89
- expiration_time: timestamp,
90
- profile_id: ctx.i_userID || ctx.userID,
91
- profile_pic_method: "EXISTING",
92
- profile_pic_source: "TIMELINE",
93
- scaled_crop_rect: {
94
- height: 1,
95
- width: 1,
96
- x: 0,
97
- y: 0
98
- },
99
- skip_cropping: true,
100
- actor_id: ctx.i_userID || ctx.userID,
101
- client_mutation_id: Math.round(Math.random() * 19).toString()
102
- },
103
- isPage: false,
104
- isProfile: true,
105
- scale: 3
106
- })
107
- };
108
-
109
- defaultFuncs
110
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
111
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
112
- .then(function (resData) {
113
- if (resData.errors) {
114
- throw resData;
115
- }
116
- return callback(null, resData[0].data.profile_picture_set);
117
- })
118
- .catch(function (err) {
119
- log.error("changeAvatar", err);
120
- return callback(err);
121
- });
122
- });
123
-
124
- return returnPromise;
125
- };
126
- };