@cexy/hoonfca 1.0.1 → 1.0.2

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 (170) hide show
  1. package/.travis.yml +6 -0
  2. package/LICENSE-MIT +21 -0
  3. package/index.d.ts +620 -0
  4. package/index.js +778 -1
  5. package/package.json +31 -84
  6. package/src/{apis/addExternalModule.js → addExternalModule.js} +4 -5
  7. package/src/addUserToGroup.js +113 -0
  8. package/src/changeAdminStatus.js +95 -0
  9. package/src/changeApprovalMode.js +79 -0
  10. package/src/changeArchivedStatus.js +55 -0
  11. package/src/changeBio.js +76 -0
  12. package/src/changeBlockedStatus.js +47 -0
  13. package/src/changeBlockedStatusMqtt.js +86 -0
  14. package/src/changeGroupImage.js +133 -0
  15. package/src/changeNickname.js +59 -0
  16. package/src/changeThreadColor.js +71 -0
  17. package/src/{apis/changeThreadEmoji.js → changeThreadEmoji.js} +8 -6
  18. package/src/createNewGroup.js +88 -0
  19. package/src/createPoll.js +130 -0
  20. package/src/deleteMessage.js +56 -0
  21. package/src/deleteThread.js +56 -0
  22. package/src/editMessage.js +63 -0
  23. package/src/forwardAttachment.js +60 -0
  24. package/src/forwardMessage.js +63 -0
  25. package/src/getCurrentUserID.js +7 -0
  26. package/src/getEmojiUrl.js +29 -0
  27. package/src/getFriendsList.js +84 -0
  28. package/src/getGroupsList.js +83 -0
  29. package/src/getMarketplace.js +84 -0
  30. package/src/getNotifications.js +86 -0
  31. package/src/getPagesList.js +83 -0
  32. package/src/getStories.js +88 -0
  33. package/src/getThreadHistory.js +647 -0
  34. package/src/getThreadInfo.js +222 -0
  35. package/src/getThreadList.js +292 -0
  36. package/src/getThreadPictures.js +79 -0
  37. package/src/getUserID.js +66 -0
  38. package/src/getUserInfo.js +128 -0
  39. package/src/handleFriendRequest.js +57 -0
  40. package/src/handleMessageRequest.js +65 -0
  41. package/src/{apis/httpGet.js → httpGet.js} +15 -20
  42. package/src/httpPost.js +58 -0
  43. package/src/listenMqtt.js +1018 -0
  44. package/src/logout.js +75 -0
  45. package/src/markAsDelivered.js +58 -0
  46. package/src/{apis/markAsRead.js → markAsRead.js} +19 -30
  47. package/src/markAsReadAll.js +50 -0
  48. package/src/markAsSeen.js +61 -0
  49. package/src/muteThread.js +52 -0
  50. package/src/pinMessage.js +61 -0
  51. package/src/removeUserFromGroup.js +79 -0
  52. package/src/resolvePhotoUrl.js +45 -0
  53. package/src/searchForThread.js +53 -0
  54. package/src/searchUsers.js +89 -0
  55. package/src/sendComment.js +161 -0
  56. package/src/sendMessage.js +457 -0
  57. package/src/sendTypingIndicator.js +179 -0
  58. package/src/setBio.js +86 -0
  59. package/src/setMessageReaction.js +186 -0
  60. package/src/setPostReaction.js +71 -0
  61. package/src/setTheme.js +313 -0
  62. package/src/setTitle.js +90 -0
  63. package/src/shareContact.js +53 -0
  64. package/src/shareLink.js +62 -0
  65. package/src/threadColors.js +57 -0
  66. package/src/unfriend.js +53 -0
  67. package/src/unsendMessage.js +104 -0
  68. package/utils.js +1447 -0
  69. package/LICENSE +0 -3
  70. package/README.md +0 -491
  71. package/examples/login-with-cookies.js +0 -102
  72. package/examples/verify.js +0 -70
  73. package/src/apis/addUserToGroup.js +0 -108
  74. package/src/apis/changeAdminStatus.js +0 -148
  75. package/src/apis/changeArchivedStatus.js +0 -61
  76. package/src/apis/changeAvatar.js +0 -103
  77. package/src/apis/changeBio.js +0 -69
  78. package/src/apis/changeBlockedStatus.js +0 -54
  79. package/src/apis/changeGroupImage.js +0 -136
  80. package/src/apis/changeThreadColor.js +0 -116
  81. package/src/apis/comment.js +0 -207
  82. package/src/apis/createAITheme.js +0 -129
  83. package/src/apis/createNewGroup.js +0 -79
  84. package/src/apis/createPoll.js +0 -73
  85. package/src/apis/deleteMessage.js +0 -44
  86. package/src/apis/deleteThread.js +0 -52
  87. package/src/apis/e2ee.js +0 -17
  88. package/src/apis/editMessage.js +0 -70
  89. package/src/apis/emoji.js +0 -124
  90. package/src/apis/fetchThemeData.js +0 -82
  91. package/src/apis/follow.js +0 -81
  92. package/src/apis/forwardMessage.js +0 -52
  93. package/src/apis/friend.js +0 -243
  94. package/src/apis/gcmember.js +0 -122
  95. package/src/apis/gcname.js +0 -123
  96. package/src/apis/gcrule.js +0 -119
  97. package/src/apis/getAccess.js +0 -111
  98. package/src/apis/getBotInfo.js +0 -88
  99. package/src/apis/getBotInitialData.js +0 -43
  100. package/src/apis/getFriendsList.js +0 -79
  101. package/src/apis/getMessage.js +0 -423
  102. package/src/apis/getTheme.js +0 -95
  103. package/src/apis/getThemeInfo.js +0 -116
  104. package/src/apis/getThreadHistory.js +0 -239
  105. package/src/apis/getThreadInfo.js +0 -267
  106. package/src/apis/getThreadList.js +0 -232
  107. package/src/apis/getThreadPictures.js +0 -58
  108. package/src/apis/getUserID.js +0 -117
  109. package/src/apis/getUserInfo.js +0 -513
  110. package/src/apis/getUserInfoV2.js +0 -146
  111. package/src/apis/handleMessageRequest.js +0 -50
  112. package/src/apis/httpPost.js +0 -89
  113. package/src/apis/httpPostFormData.js +0 -69
  114. package/src/apis/listenMqtt.js +0 -1236
  115. package/src/apis/listenSpeed.js +0 -179
  116. package/src/apis/logout.js +0 -87
  117. package/src/apis/markAsDelivered.js +0 -47
  118. package/src/apis/markAsReadAll.js +0 -40
  119. package/src/apis/markAsSeen.js +0 -70
  120. package/src/apis/mqttDeltaValue.js +0 -278
  121. package/src/apis/muteThread.js +0 -45
  122. package/src/apis/nickname.js +0 -132
  123. package/src/apis/notes.js +0 -163
  124. package/src/apis/pinMessage.js +0 -150
  125. package/src/apis/produceMetaTheme.js +0 -180
  126. package/src/apis/realtime.js +0 -182
  127. package/src/apis/removeUserFromGroup.js +0 -117
  128. package/src/apis/resolvePhotoUrl.js +0 -58
  129. package/src/apis/searchForThread.js +0 -154
  130. package/src/apis/sendMessage.js +0 -354
  131. package/src/apis/sendMessageMqtt.js +0 -249
  132. package/src/apis/sendTypingIndicator.js +0 -91
  133. package/src/apis/setMessageReaction.js +0 -27
  134. package/src/apis/setMessageReactionMqtt.js +0 -61
  135. package/src/apis/setThreadTheme.js +0 -260
  136. package/src/apis/setThreadThemeMqtt.js +0 -94
  137. package/src/apis/share.js +0 -107
  138. package/src/apis/shareContact.js +0 -66
  139. package/src/apis/stickers.js +0 -257
  140. package/src/apis/story.js +0 -181
  141. package/src/apis/theme.js +0 -233
  142. package/src/apis/unfriend.js +0 -47
  143. package/src/apis/unsendMessage.js +0 -17
  144. package/src/engine/client.js +0 -92
  145. package/src/engine/models/buildAPI.js +0 -152
  146. package/src/engine/models/loginHelper.js +0 -519
  147. package/src/engine/models/setOptions.js +0 -88
  148. package/src/security/e2ee.js +0 -109
  149. package/src/types/index.d.ts +0 -498
  150. package/src/utils/antiSuspension.js +0 -506
  151. package/src/utils/auth-helpers.js +0 -149
  152. package/src/utils/autoReLogin.js +0 -336
  153. package/src/utils/axios.js +0 -436
  154. package/src/utils/cache.js +0 -54
  155. package/src/utils/clients.js +0 -282
  156. package/src/utils/constants.js +0 -410
  157. package/src/utils/formatters/data/formatAttachment.js +0 -370
  158. package/src/utils/formatters/data/formatDelta.js +0 -109
  159. package/src/utils/formatters/index.js +0 -159
  160. package/src/utils/formatters/value/formatCookie.js +0 -91
  161. package/src/utils/formatters/value/formatDate.js +0 -36
  162. package/src/utils/formatters/value/formatID.js +0 -16
  163. package/src/utils/formatters.js +0 -1373
  164. package/src/utils/headers.js +0 -230
  165. package/src/utils/index.js +0 -153
  166. package/src/utils/monitoring.js +0 -333
  167. package/src/utils/rateLimiter.js +0 -319
  168. package/src/utils/tokenRefresh.js +0 -657
  169. package/src/utils/user-agents.js +0 -238
  170. package/src/utils/validation.js +0 -157
package/src/apis/e2ee.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- const e2ee = require('../security/e2ee');
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- return {
7
- enable() { e2ee.enable(ctx); },
8
- disable() { e2ee.disable(ctx); },
9
- isEnabled() { return e2ee.isEnabled(ctx); },
10
- getPublicKey() { return e2ee.getPublicKey(ctx); },
11
- setPeerKey(threadID, peerPublicKeyB64) { e2ee.setPeerKey(ctx, threadID, peerPublicKeyB64); },
12
- clearPeerKey(threadID) { e2ee.clearPeerKey(ctx, threadID); },
13
- hasPeer(threadID) { return e2ee.hasPeer(ctx, threadID); },
14
- encrypt(threadID, text) { return e2ee.encrypt(ctx, threadID, text); },
15
- decrypt(threadID, armored) { return e2ee.decrypt(ctx, threadID, armored); }
16
- };
17
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- /**
3
- * @author RFS-ADRENO
4
- * @rewrittenBy Isai Ivanov
5
- */
6
-
7
- const utils = require('../utils');
8
-
9
- function canBeCalled(func) {
10
- try {
11
- Reflect.apply(func, null, []);
12
- return true;
13
- } catch (error) {
14
- return false;
15
- }
16
- }
17
-
18
- /**
19
- * A function for editing bot's messages.
20
- * @param {string} text - The text with which the bot will edit its messages.
21
- * @param {string} messageID - The message ID of the message the bot will edit.
22
- * @param {Object} callback - Callback for the function.
23
- */
24
-
25
- module.exports = function (defaultFuncs, api, ctx) {
26
- return function editMessage(text, messageID, callback) {
27
- if (!ctx.mqttClient) {
28
- throw new Error('Not connected to MQTT');
29
- }
30
-
31
- ctx.wsReqNumber += 1;
32
- ctx.wsTaskNumber += 1;
33
-
34
- const queryPayload = {
35
- message_id: messageID,
36
- text
37
- };
38
-
39
- const query = {
40
- failure_count: null,
41
- label: '742',
42
- payload: JSON.stringify(queryPayload),
43
- queue_name: 'edit_message',
44
- task_id: ctx.wsTaskNumber
45
- };
46
-
47
- const context = {
48
- app_id: '2220391788200892',
49
- payload: {
50
- data_trace_id: null,
51
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
52
- tasks: [query],
53
- version_id: '6903494529735864'
54
- },
55
- request_id: ctx.wsReqNumber,
56
- type: 3
57
- };
58
-
59
- context.payload = JSON.stringify(context.payload);
60
-
61
-
62
-
63
-
64
-
65
- ctx.mqttClient.publish('/ls_req', JSON.stringify(context), {
66
- qos: 1, retain: false
67
- });
68
- };
69
- };
70
-
package/src/apis/emoji.js DELETED
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- /**
7
- * Made by Choru Official
8
- * Mqtt
9
- * Sets the custom emoji for a specific Facebook thread via MQTT.
10
- *
11
- * @param {string} emoji The emoji character to set as the custom emoji (e.g., "👍", "❤️").
12
- * @param {string} threadID The ID of the thread where the emoji will be set.
13
- * @param {Function} [callback] Optional callback function to be invoked upon completion.
14
- * @param {string} [initiatorID] The ID of the user who initiated the emoji change (e.g., from event.senderID).
15
- * @returns {Promise<object>} A promise that resolves with a structured event object on success or rejects on error.
16
- */
17
- return function emoji(emoji, threadID, callback, initiatorID) {
18
- let _callback;
19
- let _initiatorID;
20
-
21
- let _resolvePromise;
22
- let _rejectPromise;
23
- const returnPromise = new Promise((resolve, reject) => {
24
- _resolvePromise = resolve;
25
- _rejectPromise = reject;
26
- });
27
-
28
- if (utils.getType(callback) === "Function" || utils.getType(callback) === "AsyncFunction") {
29
- _callback = callback;
30
- _initiatorID = initiatorID;
31
- } else if (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction") {
32
- _callback = threadID;
33
- threadID = null;
34
- _initiatorID = callback;
35
- } else if (utils.getType(callback) === "string") {
36
- _initiatorID = callback;
37
- _callback = undefined;
38
- } else {
39
- _callback = undefined;
40
- _initiatorID = undefined;
41
- }
42
-
43
- if (!_callback) {
44
- _callback = function (__err, __data) {
45
- if (__err) _rejectPromise(__err);
46
- else _resolvePromise(__data);
47
- };
48
- } else {
49
- const originalCallback = _callback;
50
- _callback = function(__err, __data) {
51
- if (__err) {
52
- originalCallback(__err);
53
- _rejectPromise(__err);
54
- } else {
55
- originalCallback(null, __data);
56
- _resolvePromise(__data);
57
- }
58
- };
59
- }
60
-
61
- _initiatorID = _initiatorID || ctx.userID;
62
-
63
- threadID = threadID || ctx.threadID;
64
-
65
- if (!threadID) {
66
- return _callback(new Error("threadID is required to set an emoji."));
67
- }
68
- if (!emoji) {
69
- return _callback(new Error("An emoji character is required."));
70
- }
71
-
72
- if (!ctx.mqttClient) {
73
- return _callback(new Error("Not connected to MQTT"));
74
- }
75
-
76
- ctx.wsReqNumber += 1;
77
- ctx.wsTaskNumber += 1;
78
-
79
- const queryPayload = {
80
- thread_key: threadID.toString(),
81
- custom_emoji: emoji,
82
- avatar_sticker_instruction_key_id: null,
83
- sync_group: 1,
84
- };
85
-
86
- const query = {
87
- failure_count: null,
88
- label: '100003',
89
- payload: JSON.stringify(queryPayload),
90
- queue_name: 'thread_quick_reaction',
91
- task_id: ctx.wsTaskNumber,
92
- };
93
-
94
- const context = {
95
- app_id: ctx.appID,
96
- payload: {
97
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
98
- tasks: [query],
99
- version_id: '24631415369801570',
100
- },
101
- request_id: ctx.wsReqNumber,
102
- type: 3,
103
- };
104
- context.payload = JSON.stringify(context.payload);
105
-
106
- ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
107
- if (err) {
108
- return _callback(new Error(`MQTT publish failed for emoji: ${err.message || err}`));
109
- }
110
-
111
- const emojiChangeEvent = {
112
- type: "thread_emoji_update",
113
- threadID: threadID,
114
- newEmoji: emoji,
115
- senderID: _initiatorID,
116
- BotID: ctx.userID,
117
- timestamp: Date.now(),
118
- };
119
- _callback(null, emojiChangeEvent);
120
- });
121
-
122
- return returnPromise;
123
- };
124
- };
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("npmlog");
4
- const utils = require("../utils");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function fetchThemeData(themeID, callback) {
8
- let resolveFunc, rejectFunc;
9
- const promise = new Promise((resolve, reject) => {
10
- resolveFunc = resolve;
11
- rejectFunc = reject;
12
- });
13
-
14
- const done = callback || function (err, data) {
15
- if (err) return rejectFunc(err);
16
- resolveFunc(data);
17
- };
18
-
19
- if (!themeID) {
20
- done({ error: "Theme ID is a required parameter" });
21
- return promise;
22
- }
23
-
24
- const payload = {
25
- av: ctx.userID,
26
- __user: ctx.userID,
27
- __a: 1,
28
- __req: utils.getSignatureID(),
29
- fb_dtsg: ctx.fb_dtsg,
30
- lsd: ctx.fb_dtsg,
31
- jazoest: ctx.jazoest,
32
- fb_api_caller_class: "RelayModern",
33
- fb_api_req_friendly_name: "MWPThreadThemeProviderQuery",
34
- variables: JSON.stringify({ id: themeID.toString() }),
35
- server_timestamps: true,
36
- doc_id: "9734829906576883"
37
- };
38
-
39
- defaultFuncs
40
- .post("https://www.facebook.com/api/graphql/", ctx.jar, payload)
41
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
- .then(async (res) => {
43
- if (res.errors) throw res.errors;
44
-
45
- const data = res?.data?.messenger_thread_theme;
46
- if (!data) throw new Error("Theme data could not be located in the response");
47
-
48
- const output = {
49
- id: data.id,
50
- name: data.accessibility_label,
51
- description: data.description,
52
- gradient_colors: data.gradient_colors || [data.fallback_color],
53
- message_text_color: data.message_text_color || data.fallback_color,
54
- title_bar_button_tint_color: data.title_bar_button_tint_color || data.fallback_color,
55
- inbound_message_gradient_colors: data.inbound_message_gradient_colors || data.gradient_colors || [data.fallback_color],
56
- composer_input_background_color: data.composer_input_background_color || data.fallback_color,
57
- background_asset: data.background_asset || null,
58
- alternative_themes: data.alternative_themes || [],
59
- primary_color: data.gradient_colors?.[0] || data.fallback_color,
60
- backgroundImage: data.background_asset?.image?.uri || null
61
- };
62
-
63
- // Fetch detailed data for the first alternative theme if available
64
- if (output.alternative_themes.length > 0) {
65
- try {
66
- output.alternative_themes[0] = await api.fetchThemeData(output.alternative_themes[0]);
67
- } catch (e) {
68
- // If fetching fails, keep as ID
69
- log.warn("fetchThemeData", `Failed to fetch alternative theme ${output.alternative_themes[0]}: ${e.message}`);
70
- }
71
- }
72
-
73
- done(null, output);
74
- })
75
- .catch((err) => {
76
- log.error("fetchThemeData", err);
77
- done(err);
78
- });
79
-
80
- return promise;
81
- };
82
- };
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Author @YanMaglinte
5
- * https://github.com/YANDEVA
6
- * * Example:
7
- * api.follow("100090794779367", true);
8
- * jsdocs @ChoruOfficial
9
- */
10
-
11
- /**
12
- * @param {object} defaultFuncs The default functions for making API requests.
13
- * @param {object} api The full API object.
14
- * @param {object} ctx The context object.
15
- * @returns {function(senderID: string, boolean: boolean, callback?: (err: any, data?: any) => void): void} The follow function.
16
- */
17
- module.exports = function (defaultFuncs, api, ctx) {
18
- /**
19
- * Follows or unfollows a user on Facebook.
20
- * @param {string} senderID The ID of the user to follow or unfollow.
21
- * @param {boolean} boolean Set to `true` to follow the user, `false` to unfollow.
22
- * @param {(err: any, data?: any) => void} [callback] An optional callback function.
23
- */
24
- return function follow(senderID, boolean, callback) {
25
- let form;
26
- if (boolean) {
27
- form = {
28
- av: ctx.userID,
29
- fb_api_req_friendly_name: "CometUserFollowMutation",
30
- fb_api_caller_class: "RelayModern",
31
- doc_id: "25472099855769847",
32
- variables: JSON.stringify({
33
- input: {
34
- attribution_id_v2:
35
- "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,via_cold_start,1717249218695,723451,250100865708545,,",
36
- is_tracking_encrypted: true,
37
- subscribe_location: "PROFILE",
38
- subscribee_id: senderID,
39
- tracking: null,
40
- actor_id: ctx.userID,
41
- client_mutation_id: "1",
42
- },
43
- scale: 1,
44
- }),
45
- };
46
- } else {
47
- form = {
48
- av: ctx.userID,
49
- fb_api_req_friendly_name: "CometUserUnfollowMutation",
50
- fb_api_caller_class: "RelayModern",
51
- doc_id: "25472099855769847",
52
- variables: JSON.stringify({
53
- action_render_location: "WWW_COMET_FRIEND_MENU",
54
- input: {
55
- attribution_id_v2:
56
- "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,tap_search_bar,1717294006136,602597,250100865708545,,",
57
- is_tracking_encrypted: true,
58
- subscribe_location: "PROFILE",
59
- tracking: null,
60
- unsubscribee_id: senderID,
61
- actor_id: ctx.userID,
62
- client_mutation_id: "10",
63
- },
64
- scale: 1,
65
- }),
66
- };
67
- }
68
-
69
- api.httpPost("https://www.facebook.com/api/graphql/", form, (err, data) => {
70
- if (err) {
71
- if (typeof callback === "function") {
72
- callback(err);
73
- }
74
- } else {
75
- if (typeof callback === "function") {
76
- callback(null, data);
77
- }
78
- }
79
- });
80
- };
81
- };
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- module.exports = (defaultFuncs, api, ctx) => {
6
- return async function forwardMessage(messageID, threadIDs, callback) {
7
- let resolveFunc = () => {};
8
- let rejectFunc = () => {};
9
- const returnPromise = new Promise((resolve, reject) => {
10
- resolveFunc = resolve;
11
- rejectFunc = reject;
12
- });
13
-
14
- if (!callback) {
15
- callback = (err, result) => {
16
- if (err) return rejectFunc(err);
17
- resolveFunc(result);
18
- };
19
- }
20
-
21
- try {
22
- if (!Array.isArray(threadIDs)) {
23
- threadIDs = [threadIDs];
24
- }
25
-
26
- const form = {
27
- message_id: messageID
28
- };
29
-
30
- threadIDs.forEach(id => {
31
- form[`recipient_ids[${id}]`] = id;
32
- });
33
-
34
- const res = await defaultFuncs.post(
35
- "https://www.facebook.com/ajax/mercury/forward_message.php",
36
- ctx.jar,
37
- form
38
- ).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
39
-
40
- if (res && res.error) {
41
- throw res;
42
- }
43
-
44
- callback(null, { success: true, forwardedTo: threadIDs });
45
- } catch (err) {
46
- utils.error("forwardMessage", err);
47
- callback(err);
48
- }
49
-
50
- return returnPromise;
51
- };
52
- };
@@ -1,243 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- /**
6
- * @ChoruOfficial
7
- * @description A module for managing friend-related actions like listing friends, handling requests, and getting suggestions.
8
- * @param {Object} defaultFuncs The default functions provided by the API wrapper.
9
- * @param {Object} api The full API object.
10
- * @param {Object} ctx The context object containing the user's session state (e.g., userID, jar, fb_dtsg).
11
- * @returns {Object} A `friendModule` object with methods for friend interactions.
12
- */
13
- module.exports = function (defaultFuncs, api, ctx) {
14
-
15
- /**
16
- * A private helper function to standardize friend data from various GraphQL endpoints.
17
- * @private
18
- * @param {Object} data The raw data object from a GraphQL response.
19
- * @param {('requests'|'suggestions'|'list')} type The type of data to format, which determines the path to the user list.
20
- * @returns {Array<Object>} An array of formatted friend objects, each containing `userID`, `name`, `profilePicture`, `socialContext`, and `url`.
21
- */
22
- function formatFriends(data, type) {
23
- const viewer = data?.data?.viewer;
24
- let edges;
25
- if (type === 'requests' && viewer?.friend_requests?.edges) {
26
- edges = viewer.friend_requests.edges;
27
- } else if (type === 'suggestions' && viewer?.people_you_may_know?.edges) {
28
- edges = viewer.people_you_may_know.edges;
29
- } else if (type === 'list' && data?.data?.node?.all_collections?.nodes[0]?.style_renderer?.collection?.pageItems?.edges) {
30
- edges = data.data.node.all_collections.nodes[0].style_renderer.collection.pageItems.edges;
31
- } else {
32
- return [];
33
- }
34
- return edges.map(edge => {
35
- const node = edge.node;
36
- return {
37
- userID: node.id || node.node?.id,
38
- name: node.name || node.title?.text,
39
- profilePicture: node.profile_picture?.uri || node.image?.uri,
40
- socialContext: node.social_context?.text || node.subtitle_text?.text,
41
- url: node.url
42
- };
43
- });
44
- }
45
-
46
- const friendModule = {
47
- /**
48
- * @namespace api.friend
49
- * @description A collection of functions for interacting with friends.
50
- * @license Ex-it
51
- * @author ChoruOfficial
52
- */
53
-
54
- /**
55
- * Fetches the list of incoming friend requests.
56
- * @async
57
- * @returns {Promise<Array<Object>>} A promise that resolves to an array of friend request objects.
58
- * @throws {Error} If the API request fails or returns an error.
59
- */
60
- requests: async function() {
61
- try {
62
- const form = {
63
- av: ctx.userID,
64
- __user: ctx.userID,
65
- __a: "1",
66
- fb_dtsg: ctx.fb_dtsg,
67
- jazoest: ctx.jazoest,
68
- lsd: ctx.lsd,
69
- fb_api_caller_class: "RelayModern",
70
- fb_api_req_friendly_name: "FriendingCometRootContentQuery",
71
- variables: JSON.stringify({ scale: 3 }),
72
- doc_id: "9103543533085580"
73
- };
74
- const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
75
- if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
76
- return formatFriends(res.data, 'requests');
77
- } catch (err) {
78
- throw err;
79
- }
80
- },
81
-
82
- /**
83
- * Accepts a friend request.
84
- * @async
85
- * @param {string} identifier The user ID or name of the person whose friend request is to be accepted. If a name is provided, the function will search through pending requests.
86
- * @returns {Promise<Object>} A promise that resolves to the API response data upon successful acceptance.
87
- * @throws {Error} If the identifier is missing, the user is not found in requests, or the API call fails.
88
- */
89
- accept: async function(identifier) {
90
- try {
91
- if (!identifier) throw new Error("A name or user ID is required.");
92
- let targetUserID = identifier;
93
- if (isNaN(identifier)) {
94
- const requests = await friendModule.requests();
95
- const found = requests.find(req => req.name.toLowerCase().includes(identifier.toLowerCase()));
96
- if (!found) throw new Error(`Could not find any friend request matching "${identifier}".`);
97
- targetUserID = found.userID;
98
- }
99
- const variables = {
100
- input: {
101
- friend_requester_id: targetUserID,
102
- friending_channel: "FRIENDS_HOME_MAIN",
103
- actor_id: ctx.userID,
104
- client_mutation_id: Math.floor(Math.random() * 10 + 1).toString()
105
- },
106
- scale: 3
107
- };
108
- const form = {
109
- av: ctx.userID,
110
- __user: ctx.userID,
111
- __a: "1",
112
- fb_dtsg: ctx.fb_dtsg,
113
- jazoest: ctx.jazoest,
114
- lsd: ctx.lsd,
115
- fb_api_caller_class: "RelayModern",
116
- fb_api_req_friendly_name: "FriendingCometFriendRequestConfirmMutation",
117
- variables: JSON.stringify(variables),
118
- doc_id: "24630768433181357"
119
- };
120
- const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
121
- if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
122
- return res.data.data;
123
- } catch (err) {
124
- if (err.message?.includes("1431004")) {
125
- throw new Error("I cannot accept this friend request right now. There might be a problem with the account or you need to wait.");
126
- }
127
- throw err;
128
- }
129
- },
130
-
131
- /**
132
- * Fetches the friend list for a given user ID.
133
- * @async
134
- * @param {string} [userID=ctx.userID] The ID of the user whose friend list to fetch. Defaults to the logged-in user.
135
- * @returns {Promise<Array<Object>>} A promise that resolves to an array of formatted friend objects.
136
- * @throws {Error} If the API request fails.
137
- */
138
- list: async function(userID = ctx.userID) {
139
- try {
140
- const sectionToken = Buffer.from(`app_section:${userID}:2356318349`).toString('base64');
141
- const variables = {
142
- collectionToken: null,
143
- scale: 2,
144
- sectionToken: sectionToken,
145
- useDefaultActor: false,
146
- userID: userID
147
- };
148
- const form = {
149
- av: ctx.userID,
150
- __user: ctx.userID,
151
- __a: "1",
152
- fb_dtsg: ctx.fb_dtsg,
153
- jazoest: ctx.jazoest,
154
- lsd: ctx.lsd,
155
- fb_api_caller_class: "RelayModern",
156
- fb_api_req_friendly_name: "ProfileCometTopAppSectionQuery",
157
- variables: JSON.stringify(variables),
158
- doc_id: "24492266383698794"
159
- };
160
- const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
161
- if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
162
- return formatFriends(res.data, 'list');
163
- } catch(err) {
164
- throw err;
165
- }
166
- },
167
-
168
- /**
169
- * @namespace api.friend.suggest
170
- * @description Functions for managing friend suggestions.
171
- */
172
- suggest: {
173
- /**
174
- * Fetches a list of suggested friends (People You May Know).
175
- * @async
176
- * @param {number} [limit=30] The maximum number of suggestions to fetch.
177
- * @returns {Promise<Array<Object>>} A promise that resolves to an array of suggested friend objects.
178
- * @throws {Error} If the API request fails.
179
- */
180
- list: async function(limit = 30) {
181
- try {
182
- const form = {
183
- av: ctx.userID,
184
- __user: ctx.userID,
185
- __a: "1",
186
- fb_dtsg: ctx.fb_dtsg,
187
- jazoest: ctx.jazoest,
188
- lsd: ctx.lsd,
189
- fb_api_caller_class: "RelayModern",
190
- fb_api_req_friendly_name: "FriendingCometPYMKPanelPaginationQuery",
191
- variables: JSON.stringify({ count: limit, cursor: null, scale: 3 }),
192
- doc_id: "9917809191634193"
193
- };
194
- const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
195
- if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
196
- return formatFriends(res.data, 'suggestions');
197
- } catch(err) {
198
- throw err;
199
- }
200
- },
201
- /**
202
- * Sends a friend request to a user.
203
- * @async
204
- * @param {string} userID The ID of the user to send the friend request to.
205
- * @returns {Promise<Object>} A promise that resolves to the API response data on success.
206
- * @throws {Error} If the userID is missing or the API request fails.
207
- */
208
- request: async function(userID) {
209
- try {
210
- if (!userID) throw new Error("userID is required.");
211
- const variables = {
212
- input: {
213
- friend_requestee_ids: [userID],
214
- friending_channel: "FRIENDS_HOME_MAIN",
215
- actor_id: ctx.userID,
216
- client_mutation_id: Math.floor(Math.random() * 10 + 1).toString()
217
- },
218
- scale: 3
219
- };
220
- const form = {
221
- av: ctx.userID,
222
- __user: ctx.userID,
223
- __a: "1",
224
- fb_dtsg: ctx.fb_dtsg,
225
- jazoest: ctx.jazoest,
226
- lsd: ctx.lsd,
227
- fb_api_caller_class: "RelayModern",
228
- fb_api_req_friendly_name: "FriendingCometFriendRequestSendMutation",
229
- variables: JSON.stringify(variables),
230
- doc_id: "23982103144788355"
231
- };
232
- const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
233
- if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
234
- return res.data.data;
235
- } catch(err) {
236
- throw err;
237
- }
238
- }
239
- }
240
- };
241
-
242
- return friendModule;
243
- };