@cexy/hoonfca 1.0.1 → 1.0.3

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
@@ -1,122 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- /**
7
- * Made by ChoruOfficial
8
- * Mqtt
9
- * Adds or removes members from a group chat with pre-checking.
10
- *
11
- * @param {"add" | "remove"} action The action to perform.
12
- * @param {string|string[]} userIDs The user ID or array of user IDs.
13
- * @param {string} threadID The ID of the group chat.
14
- * @param {Function} [callback] Optional callback function.
15
- * @returns {Promise<object>} A promise that resolves with information about the action.
16
- */
17
- return async function gcmember(action, userIDs, threadID, callback) {
18
- let _callback;
19
- if (typeof threadID === 'function') {
20
- _callback = threadID;
21
- threadID = null;
22
- } else if (typeof callback === 'function') {
23
- _callback = callback;
24
- }
25
-
26
- let resolvePromise, rejectPromise;
27
- const returnPromise = new Promise((resolve, reject) => {
28
- resolvePromise = resolve;
29
- rejectPromise = reject;
30
- });
31
-
32
- if (typeof _callback != "function") {
33
- _callback = (err, data) => {
34
- // Note: We will now rarely use the 'err' parameter for validation errors
35
- if (err) return rejectPromise(err);
36
- resolvePromise(data);
37
- }
38
- }
39
-
40
- try {
41
- const validActions = ["add", "remove"];
42
- action = action ? action.toLowerCase() : "";
43
-
44
-
45
- if (!validActions.includes(action)) {
46
- return _callback(null, { type: "error_gc", error: `Invalid action. Must be one of: ${validActions.join(", ")}` });
47
- }
48
- if (!userIDs || userIDs.length === 0) {
49
- return _callback(null, { type: "error_gc", error: "userIDs is required." });
50
- }
51
- if (!threadID) {
52
- return _callback(null, { type: "error_gc", error: "threadID is required." });
53
- }
54
- if (!ctx.mqttClient) {
55
- return _callback(null, { type: "error_gc", error: "Not connected to MQTT" });
56
- }
57
-
58
- const threadInfo = await api.getThreadInfo(threadID);
59
- if (!threadInfo) {
60
- return _callback(null, { type: "error_gc", error: "Could not retrieve thread information." });
61
- }
62
- if (threadInfo.isGroup === false) {
63
- return _callback(null, { type: "error_gc", error: "This feature is only for group chats, not private messages." });
64
- }
65
-
66
- const currentMembers = threadInfo.participantIDs;
67
- const usersToModify = Array.isArray(userIDs) ? userIDs : [userIDs];
68
- let queryPayload, query;
69
- let finalUsers = usersToModify;
70
-
71
- ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
72
- ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
73
-
74
- if (action === 'add') {
75
- const usersToAdd = usersToModify.filter(id => !currentMembers.includes(id));
76
- if (usersToAdd.length === 0) {
77
- return _callback(null, { type: "error_gc", error: "All specified users are already in the group." });
78
- }
79
- finalUsers = usersToAdd;
80
- queryPayload = { thread_key: parseInt(threadID), contact_ids: finalUsers.map(id => parseInt(id)), sync_group: 1 };
81
- query = { label: "23", payload: JSON.stringify(queryPayload), queue_name: threadID, task_id: ctx.wsTaskNumber };
82
-
83
- } else { // action is 'remove'
84
- const userToRemove = usersToModify[0];
85
- if (!currentMembers.includes(userToRemove)) {
86
- return _callback(null, { type: "error_gc", error: `User with ID ${userToRemove} is not in this group chat.` });
87
- }
88
- finalUsers = [userToRemove];
89
- queryPayload = { thread_id: threadID, contact_id: userToRemove, sync_group: 1 };
90
- query = { label: "140", payload: JSON.stringify(queryPayload), queue_name: "remove_participant_v2", task_id: ctx.wsTaskNumber };
91
- }
92
-
93
- const context = {
94
- app_id: ctx.appID,
95
- payload: { epoch_id: parseInt(utils.generateOfflineThreadingID()), tasks: [query], version_id: "24631415369801570" },
96
- request_id: ctx.wsReqNumber,
97
- type: 3
98
- };
99
- context.payload = JSON.stringify(context.payload);
100
-
101
- ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
102
- if (err) return _callback(err);
103
-
104
- const gcmemberInfo = {
105
- type: "gc_member_update",
106
- threadID: threadID,
107
- userIDs: finalUsers,
108
- action: action,
109
- senderID: ctx.userID,
110
- BotID: ctx.userID,
111
- timestamp: Date.now(),
112
- };
113
- return _callback(null, gcmemberInfo);
114
- });
115
- } catch (err) {
116
-
117
- return _callback(null, { type: "error_gc", error: err.message || "An unknown error occurred." });
118
- }
119
-
120
- return returnPromise;
121
- };
122
- };
@@ -1,123 +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 name of a group chat thread via MQTT.
10
- *
11
- * @param {string} newName The new name for the group chat.
12
- * @param {string} threadID The ID of the group chat thread.
13
- * @param {Function} [callback] Optional callback function to be invoked upon completion.
14
- * @param {string} [initiatorID] The ID of the user who initiated the group name 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 gcname(newName, 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 change the group chat name."));
67
- }
68
- if (typeof newName !== 'string') {
69
- return _callback(new Error("newName must be a string."));
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
- thread_name: newName,
82
- sync_group: 1,
83
- };
84
-
85
- const query = {
86
- failure_count: null,
87
- label: '32',
88
- payload: JSON.stringify(queryPayload),
89
- queue_name: threadID.toString(),
90
- task_id: ctx.wsTaskNumber,
91
- };
92
-
93
- const context = {
94
- app_id: ctx.appID,
95
- payload: {
96
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
97
- tasks: [query],
98
- version_id: '24631415369801570',
99
- },
100
- request_id: ctx.wsReqNumber,
101
- type: 3,
102
- };
103
- context.payload = JSON.stringify(context.payload);
104
-
105
- ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
106
- if (err) {
107
- return _callback(new Error(`MQTT publish failed for gcname: ${err.message || err}`));
108
- }
109
-
110
- const gcnameChangeEvent = {
111
- type: "thread_name_update",
112
- threadID: threadID,
113
- newName: newName,
114
- senderID: _initiatorID,
115
- BotID: ctx.userID,
116
- timestamp: Date.now(),
117
- };
118
- _callback(null, gcnameChangeEvent);
119
- });
120
-
121
- return returnPromise;
122
- };
123
- };
@@ -1,119 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- /**
7
- * Made by ChoruOfficial
8
- * Mqtt
9
- * Adds or removes an admin from a group chat with pre-checking.
10
- *
11
- * @param {"admin" | "unadmin"} action The action to perform.
12
- * @param {string} userID The ID of the user to promote or demote.
13
- * @param {string} threadID The ID of the group chat.
14
- * @param {Function} [callback] Optional callback function.
15
- * @returns {Promise<object>} A promise that resolves with information about the action.
16
- */
17
- return async function gcrule(action, userID, threadID, callback) {
18
- let _callback;
19
- if (typeof threadID === 'function') {
20
- _callback = threadID;
21
- threadID = null;
22
- } else if (typeof callback === 'function') {
23
- _callback = callback;
24
- }
25
-
26
- let resolvePromise, rejectPromise;
27
- const returnPromise = new Promise((resolve, reject) => {
28
- resolvePromise = resolve;
29
- rejectPromise = reject;
30
- });
31
-
32
- if (typeof _callback != "function") {
33
- _callback = (err, data) => {
34
- if (err) return rejectPromise(err);
35
- resolvePromise(data);
36
- }
37
- }
38
-
39
- try {
40
- const validActions = ["admin", "unadmin"];
41
- action = action ? action.toLowerCase() : "";
42
-
43
- if (!validActions.includes(action)) {
44
- return _callback(null, { type: "error_gc_rule", error: `Invalid action. Must be one of: ${validActions.join(", ")}` });
45
- }
46
- if (!userID) return _callback(null, { type: "error_gc_rule", error: "userID is required." });
47
- if (!threadID) return _callback(null, { type: "error_gc_rule", error: "threadID is required." });
48
- if (!ctx.mqttClient) return _callback(null, { type: "error_gc_rule", error: "Not connected to MQTT" });
49
-
50
- const threadInfo = await api.getThreadInfo(threadID);
51
- if (!threadInfo) {
52
- return _callback(null, { type: "error_gc_rule", error: "Could not retrieve thread information." });
53
- }
54
- if (threadInfo.isGroup === false) {
55
- return _callback(null, { type: "error_gc_rule", error: "This feature is only for group chats." });
56
- }
57
-
58
- const adminIDs = threadInfo.adminIDs || [];
59
- const isCurrentlyAdmin = adminIDs.some(admin => admin.id === userID);
60
-
61
- if (action === 'admin') {
62
- if (isCurrentlyAdmin) {
63
- return _callback(null, { type: "error_gc_rule", error: `User is already an admin.` });
64
- }
65
- } else { // action is 'unadmin'
66
- if (!isCurrentlyAdmin) {
67
- return _callback(null, { type: "error_gc_rule", error: `User is not an admin.` });
68
- }
69
- }
70
-
71
- const isAdminStatus = action === 'admin' ? 1 : 0;
72
- ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
73
- ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
74
-
75
- const queryPayload = {
76
- thread_key: parseInt(threadID),
77
- contact_id: parseInt(userID),
78
- is_admin: isAdminStatus
79
- };
80
- const query = {
81
- failure_count: null,
82
- label: "25",
83
- payload: JSON.stringify(queryPayload),
84
- queue_name: "admin_status",
85
- task_id: ctx.wsTaskNumber
86
- };
87
- const context = {
88
- app_id: ctx.appID,
89
- payload: {
90
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
91
- tasks: [query],
92
- version_id: "24631415369801570"
93
- },
94
- request_id: ctx.wsReqNumber,
95
- type: 3
96
- };
97
- context.payload = JSON.stringify(context.payload);
98
-
99
- ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
100
- if (err) return _callback(err);
101
- const gcruleInfo = {
102
- type: "gc_rule_update",
103
- threadID: threadID,
104
- userID: userID,
105
- action: action,
106
- senderID: ctx.userID,
107
- BotID: ctx.userID,
108
- timestamp: Date.now(),
109
- };
110
- return _callback(null, gcruleInfo);
111
- });
112
-
113
- } catch (err) {
114
- return _callback(null, { type: "error_gc_rule", error: err.message || "An unknown error occurred." });
115
- }
116
-
117
- return returnPromise;
118
- };
119
- };
@@ -1,111 +0,0 @@
1
- 'use strict';
2
-
3
- const utils = require('../utils');
4
-
5
- module.exports = function (defaultFuncs, api, ctx) {
6
- return function getAccess(authCode = '', callback) {
7
- var cb;
8
- var url = 'https://business.facebook.com/';
9
- var Referer = url + 'security/twofactor/reauth/?twofac_next=' + encodeURIComponent(url + 'content_management') + '&type=avoid_bypass&app_id=0&save_device=0';
10
- var rt = new Promise(function (resolve, reject) {
11
- cb = (error, token) => token ? resolve(token) : reject(error);
12
- });
13
-
14
- if (typeof authCode == 'function') {
15
- callback = authCode;
16
- authCode = '';
17
- }
18
- if (typeof callback == 'function') cb = callback;
19
- if (!!ctx.access_token)
20
- cb(null, ctx.access_token);
21
- else
22
- utils
23
- .get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, {
24
- noRef: true,
25
- Origin: url
26
- })
27
- .then(function (res) {
28
- var html = res.body;
29
- var lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
30
- return lsd;
31
- })
32
- .then(function (lsd) {
33
- function submitCode(code) {
34
- var pCb;
35
- var rtPromise = new Promise(function (resolve) {
36
- pCb = (error, token) => resolve(cb(error, token));
37
- });
38
- if (typeof code != 'string')
39
- pCb({
40
- error: 'submitCode',
41
- lerror: 'code must be string',
42
- continue: submitCode
43
- });
44
- else
45
- defaultFuncs
46
- .post(url + 'security/twofactor/reauth/enter/', ctx.jar, {
47
- approvals_code: code,
48
- save_device: true,
49
- lsd
50
- }, ctx.globalOptions, null, {
51
- Referer,
52
- Origin: url
53
- })
54
- .then(function (res) {
55
- var { payload } = JSON.parse(res.body.split(';').pop() || '{}');
56
- if (payload && !payload.codeConfirmed)
57
- throw {
58
- error: 'submitCode',
59
- lerror: payload.message,
60
- continue: submitCode
61
- }
62
-
63
- return;
64
- })
65
- .then(function () {
66
- return utils
67
- .get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, { noRef: true })
68
- .then(function (res) {
69
- var html = res.body;
70
- var token = /"accessToken":"(\S+)","clientID":/g.exec(html);
71
-
72
- return [html, token];
73
- });
74
- })
75
- .then(function (res) {
76
- if (!res[1])
77
- throw {
78
- error: 'token-undefined',
79
- htmlData: res[0]
80
- }
81
- ctx.access_token = res[1][1];
82
- return pCb(null, res[1][1]);
83
- })
84
- .catch(function (err) {
85
- utils.error('getAccess', err.error || err);
86
- return pCb(err);
87
- });
88
-
89
- return rtPromise;
90
- }
91
-
92
- if (authCode.length == 6 && !isNaN(authCode))
93
- submitCode(authCode.toString());
94
- else if (typeof callback == 'function')
95
- throw {
96
- error: 'submitCode',
97
- continue: submitCode
98
- }
99
- else
100
- throw {
101
- error: 'authentication code must be string or number or callback must be a function to continue'
102
- }
103
- })
104
- .catch(function (err) {
105
- utils.error('getAccess', typeof callback == 'function' ? (err.error || err) : err);
106
- return cb(err);
107
- });
108
-
109
- return rt;
110
- }
111
- }
@@ -1,88 +0,0 @@
1
-
2
- "use strict";
3
-
4
- const utils = require('../utils');
5
-
6
- /**
7
- * @param {Object} defaultFuncs
8
- * @param {Object} api
9
- * @param {Object} ctx
10
- * @returns {function(netData: Array<Object>): Object | null}
11
- */
12
- module.exports = (defaultFuncs, api, ctx) => {
13
- /**
14
- * @param {Array<Object>} netData - The array of all extracted JSON objects from the HTML.
15
- * @returns {Object|null} An object containing the bot's essential info, security tokens, and context accessor functions.
16
- */
17
- return function getBotInfo(netData) {
18
- if (!netData || !Array.isArray(netData)) {
19
- utils.error("getBotInfo", "netData is not a valid array.");
20
- return null;
21
- }
22
-
23
- /**
24
- * @param {string} key The configuration key to find (e.g., "MqttWebDeviceID").
25
- * @returns {Object|null} The configuration object or null if not found.
26
- */
27
- const findConfig = (key) => {
28
- for (const scriptData of netData) {
29
- if (scriptData.require) {
30
- for (const req of scriptData.require) {
31
- if (Array.isArray(req) && req[0] === key && req[2]) {
32
- return req[2];
33
- }
34
- if (Array.isArray(req) && req[3] && req[3][0]?.__bbox?.define) {
35
- for (const def of req[3][0].__bbox.define) {
36
- if (Array.isArray(def) && def[0].endsWith(key) && def[2]) {
37
- return def[2];
38
- }
39
- }
40
- }
41
- }
42
- }
43
- }
44
- return null;
45
- };
46
-
47
- const currentUserData = findConfig("CurrentUserInitialData");
48
- const dtsgInitialData = findConfig("DTSGInitialData");
49
- const dtsgInitData = findConfig("DTSGInitData");
50
- const lsdData = findConfig("LSD");
51
-
52
- if (!currentUserData || !dtsgInitialData) {
53
- utils.error("getBotInfo", "Could not find critical data (CurrentUserInitialData or DTSGInitialData).");
54
- return null;
55
- }
56
-
57
- const botInfo = {
58
- name: currentUserData.NAME,
59
- firstName: currentUserData.SHORT_NAME,
60
- uid: currentUserData.USER_ID,
61
- appID: currentUserData.APP_ID,
62
- dtsgToken: dtsgInitialData.token,
63
- lsdToken: lsdData ? lsdData.token : undefined,
64
- dtsgInit: dtsgInitData ? {
65
- token: dtsgInitData.token,
66
- async_get_token: dtsgInitData.async_get_token
67
- } : undefined,
68
-
69
- /**
70
- * @param {string} key The key of the value to retrieve.
71
- * @returns {any} The value from the context.
72
- */
73
- getCtx: (key) => ctx[key],
74
-
75
- /**
76
- * @param {string} key The key of the option to retrieve.
77
- * @returns {any} The value of the option.
78
- */
79
- getOptions: (key) => ctx.globalOptions[key],
80
-
81
- /**
82
- * @returns {string | undefined} The current region.
83
- */
84
- getRegion: () => ctx?.region
85
- };
86
- return botInfo;
87
- };
88
- };
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../utils");
4
-
5
- module.exports = (defaultFuncs, api, ctx) => {
6
- return async (callback) => {
7
- let resolveFunc = () => {};
8
- let rejectFunc = () => {};
9
- const returnPromise = new Promise((resolve, reject) => {
10
- resolveFunc = resolve;
11
- rejectFunc = reject;
12
- });
13
- if (!callback) {
14
- callback = (err, data) => {
15
- if (err) {
16
- return rejectFunc(err);
17
- }
18
- resolveFunc(data);
19
- };
20
- }
21
- utils.log("Fetching account info...");
22
- api.httpGet(`https://www.facebook.com/profile.php?id=${ctx.userID}`, null, {
23
- customUserAgent: utils.windowsUserAgent
24
- }, (err, data) => {
25
-
26
- if (err) throw err;
27
- const profileMatch = data.match(/"CurrentUserInitialData",\[\],\{(.*?)\},(.*?)\]/);
28
- if (profileMatch && profileMatch[1]){
29
- const accountJson = JSON.parse(`{${profileMatch[1]}}`);
30
- accountJson.name = accountJson.NAME;
31
- accountJson.uid = accountJson.USER_ID;
32
- delete accountJson.NAME;
33
- delete accountJson.USER_ID;
34
- return callback(null, {
35
- ...accountJson
36
- });
37
- } else return callback(null, { error: "Something went wrong. Maybe its possible that it has a limitation due to spam requests. You can try again later." });
38
- }, true);
39
- return returnPromise;
40
- };
41
- };
42
-
43
-
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- const GENDERS = {
6
- 0: "unknown",
7
- 1: "female_singular",
8
- 2: "male_singular",
9
- 3: "female_singular_guess",
10
- 4: "male_singular_guess",
11
- 5: "mixed",
12
- 6: "neuter_singular",
13
- 7: "unknown_singular",
14
- 8: "female_plural",
15
- 9: "male_plural",
16
- 10: "neuter_plural",
17
- 11: "unknown_plural"
18
- };
19
-
20
- function formatData(obj) {
21
- return Object.keys(obj).map(key => {
22
- const user = obj[key];
23
- return {
24
- alternateName: user.alternateName,
25
- firstName: user.firstName,
26
- gender: GENDERS[user.gender],
27
- userID: utils.formatID(user.id.toString()),
28
- isFriend: user.is_friend != null && user.is_friend ? true : false,
29
- fullName: user.name,
30
- profilePicture: user.thumbSrc,
31
- type: user.type,
32
- profileUrl: user.uri,
33
- vanity: user.vanity,
34
- isBirthday: !!user.is_birthday
35
- };
36
- });
37
- }
38
-
39
- module.exports = (defaultFuncs, api, ctx) => {
40
- return async function getFriendsList(callback) {
41
- let resolveFunc = () => {};
42
- let rejectFunc = () => {};
43
- const returnPromise = new Promise((resolve, reject) => {
44
- resolveFunc = resolve;
45
- rejectFunc = reject;
46
- });
47
-
48
- if (!callback) {
49
- callback = (err, result) => {
50
- if (err) return rejectFunc(err);
51
- resolveFunc(result);
52
- };
53
- }
54
-
55
- try {
56
- const res = await defaultFuncs.postFormData(
57
- "https://www.facebook.com/chat/user_info_all",
58
- ctx.jar,
59
- {},
60
- { viewer: ctx.userID }
61
- ).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
62
-
63
- if (!res) {
64
- throw { error: "getFriendsList returned empty object." };
65
- }
66
-
67
- if (res.error) {
68
- throw res;
69
- }
70
-
71
- callback(null, formatData(res.payload));
72
- } catch (err) {
73
- utils.error("getFriendsList", err);
74
- callback(err);
75
- }
76
-
77
- return returnPromise;
78
- };
79
- };