@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.
Files changed (135) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/DOCS.md +2636 -0
  3. package/LICENSE-MIT +21 -21
  4. package/README.md +632 -0
  5. package/func/checkUpdate.js +231 -0
  6. package/func/logger.js +48 -0
  7. package/index.d.ts +731 -605
  8. package/index.js +6 -774
  9. package/module/config.js +67 -0
  10. package/module/login.js +154 -0
  11. package/module/loginHelper.js +1034 -0
  12. package/module/options.js +54 -0
  13. package/package.json +54 -19
  14. package/src/api/action/addExternalModule.js +25 -0
  15. package/src/api/action/changeAvatar.js +137 -0
  16. package/src/{changeBio.js → api/action/changeBio.js} +75 -76
  17. package/src/api/action/enableAutoSaveAppState.js +73 -0
  18. package/src/{getCurrentUserID.js → api/action/getCurrentUserID.js} +7 -7
  19. package/src/{handleFriendRequest.js → api/action/handleFriendRequest.js} +57 -57
  20. package/src/api/action/logout.js +76 -0
  21. package/src/api/action/refreshFb_dtsg.js +48 -0
  22. package/src/api/action/setPostReaction.js +106 -0
  23. package/src/api/action/unfriend.js +54 -0
  24. package/src/api/http/httpGet.js +46 -0
  25. package/src/api/http/httpPost.js +52 -0
  26. package/src/api/http/postFormData.js +47 -0
  27. package/src/api/messaging/addUserToGroup.js +68 -0
  28. package/src/api/messaging/changeAdminStatus.js +122 -0
  29. package/src/api/messaging/changeArchivedStatus.js +55 -0
  30. package/src/api/messaging/changeBlockedStatus.js +48 -0
  31. package/src/api/messaging/changeGroupImage.js +90 -0
  32. package/src/api/messaging/changeNickname.js +70 -0
  33. package/src/api/messaging/changeThreadColor.js +79 -0
  34. package/src/api/messaging/changeThreadEmoji.js +106 -0
  35. package/src/{createNewGroup.js → api/messaging/createNewGroup.js} +88 -88
  36. package/src/api/messaging/createPoll.js +43 -0
  37. package/src/api/messaging/createThemeAI.js +98 -0
  38. package/src/{deleteMessage.js → api/messaging/deleteMessage.js} +56 -56
  39. package/src/{deleteThread.js → api/messaging/deleteThread.js} +56 -56
  40. package/src/api/messaging/editMessage.js +68 -0
  41. package/src/api/messaging/forwardAttachment.js +51 -0
  42. package/src/{getEmojiUrl.js → api/messaging/getEmojiUrl.js} +8 -8
  43. package/src/{getFriendsList.js → api/messaging/getFriendsList.js} +82 -84
  44. package/src/api/messaging/getMessage.js +829 -0
  45. package/src/api/messaging/getThemePictures.js +62 -0
  46. package/src/api/messaging/handleMessageRequest.js +65 -0
  47. package/src/{markAsDelivered.js → api/messaging/markAsDelivered.js} +57 -58
  48. package/src/{markAsRead.js → api/messaging/markAsRead.js} +88 -88
  49. package/src/{markAsReadAll.js → api/messaging/markAsReadAll.js} +49 -50
  50. package/src/api/messaging/markAsSeen.js +61 -0
  51. package/src/{muteThread.js → api/messaging/muteThread.js} +50 -52
  52. package/src/api/messaging/removeUserFromGroup.js +106 -0
  53. package/src/{resolvePhotoUrl.js → api/messaging/resolvePhotoUrl.js} +43 -45
  54. package/src/api/messaging/scheduler.js +264 -0
  55. package/src/{searchForThread.js → api/messaging/searchForThread.js} +52 -53
  56. package/src/api/messaging/sendMessage.js +272 -0
  57. package/src/api/messaging/sendTypingIndicator.js +67 -0
  58. package/src/api/messaging/setMessageReaction.js +76 -0
  59. package/src/api/messaging/setTitle.js +119 -0
  60. package/src/{shareContact.js → api/messaging/shareContact.js} +49 -53
  61. package/src/api/messaging/threadColors.js +128 -0
  62. package/src/api/messaging/unsendMessage.js +81 -0
  63. package/src/api/messaging/uploadAttachment.js +94 -0
  64. package/src/api/socket/core/connectMqtt.js +255 -0
  65. package/src/api/socket/core/emitAuth.js +106 -0
  66. package/src/api/socket/core/getSeqID.js +40 -0
  67. package/src/api/socket/core/getTaskResponseData.js +22 -0
  68. package/src/api/socket/core/markDelivery.js +12 -0
  69. package/src/api/socket/core/parseDelta.js +391 -0
  70. package/src/api/socket/detail/buildStream.js +208 -0
  71. package/src/api/socket/detail/constants.js +24 -0
  72. package/src/api/socket/listenMqtt.js +364 -0
  73. package/src/api/socket/middleware/index.js +216 -0
  74. package/src/{getThreadHistory.js → api/threads/getThreadHistory.js} +664 -647
  75. package/src/api/threads/getThreadInfo.js +438 -0
  76. package/src/{getThreadList.js → api/threads/getThreadList.js} +293 -292
  77. package/src/{getThreadPictures.js → api/threads/getThreadPictures.js} +78 -79
  78. package/src/{getUserID.js → api/users/getUserID.js} +65 -66
  79. package/src/api/users/getUserInfo.js +327 -0
  80. package/src/api/users/getUserInfoV2.js +134 -0
  81. package/src/core/sendReqMqtt.js +96 -0
  82. package/src/database/models/index.js +87 -0
  83. package/src/database/models/thread.js +45 -0
  84. package/src/database/models/user.js +46 -0
  85. package/src/database/threadData.js +98 -0
  86. package/src/database/userData.js +89 -0
  87. package/src/utils/client.js +320 -0
  88. package/src/utils/constants.js +23 -0
  89. package/{utils.js → src/utils/format.js} +1115 -1447
  90. package/src/utils/headers.js +115 -0
  91. package/src/utils/request.js +305 -0
  92. package/.travis.yml +0 -6
  93. package/src/addExternalModule.js +0 -23
  94. package/src/addUserToGroup.js +0 -113
  95. package/src/changeAdminStatus.js +0 -95
  96. package/src/changeApprovalMode.js +0 -79
  97. package/src/changeArchivedStatus.js +0 -55
  98. package/src/changeBlockedStatus.js +0 -47
  99. package/src/changeBlockedStatusMqtt.js +0 -86
  100. package/src/changeGroupImage.js +0 -133
  101. package/src/changeNickname.js +0 -59
  102. package/src/changeThreadColor.js +0 -71
  103. package/src/changeThreadEmoji.js +0 -55
  104. package/src/createPoll.js +0 -130
  105. package/src/editMessage.js +0 -63
  106. package/src/forwardAttachment.js +0 -60
  107. package/src/forwardMessage.js +0 -63
  108. package/src/getGroupsList.js +0 -83
  109. package/src/getMarketplace.js +0 -84
  110. package/src/getNotifications.js +0 -86
  111. package/src/getPagesList.js +0 -83
  112. package/src/getStories.js +0 -88
  113. package/src/getThreadInfo.js +0 -222
  114. package/src/getUserInfo.js +0 -128
  115. package/src/handleMessageRequest.js +0 -65
  116. package/src/httpGet.js +0 -58
  117. package/src/httpPost.js +0 -58
  118. package/src/listenMqtt.js +0 -1018
  119. package/src/logout.js +0 -75
  120. package/src/markAsSeen.js +0 -61
  121. package/src/pinMessage.js +0 -61
  122. package/src/removeUserFromGroup.js +0 -79
  123. package/src/searchUsers.js +0 -89
  124. package/src/sendComment.js +0 -161
  125. package/src/sendMessage.js +0 -457
  126. package/src/sendTypingIndicator.js +0 -179
  127. package/src/setBio.js +0 -86
  128. package/src/setMessageReaction.js +0 -186
  129. package/src/setPostReaction.js +0 -71
  130. package/src/setTheme.js +0 -313
  131. package/src/setTitle.js +0 -90
  132. package/src/shareLink.js +0 -62
  133. package/src/threadColors.js +0 -57
  134. package/src/unfriend.js +0 -53
  135. package/src/unsendMessage.js +0 -104
@@ -0,0 +1,67 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const logger = require("../func/logger");
4
+
5
+ const defaultConfig = {
6
+ autoUpdate: false,
7
+ mqtt: {
8
+ enabled: true,
9
+ reconnectInterval: 3600
10
+ },
11
+ autoLogin: true,
12
+ credentials: {
13
+ email: "",
14
+ password: "",
15
+ twofactor: ""
16
+ }
17
+ };
18
+
19
+ function loadConfig() {
20
+ const configPath = path.join(process.cwd(), "fca-config.json");
21
+ let config = {};
22
+
23
+ try {
24
+ if (!fs.existsSync(configPath)) {
25
+ config = { ...defaultConfig };
26
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
27
+ } else {
28
+ const fileContent = fs.readFileSync(configPath, "utf8");
29
+ config = JSON.parse(fileContent);
30
+
31
+ // Merge with defaults
32
+ config = {
33
+ ...defaultConfig,
34
+ ...config,
35
+ mqtt: {
36
+ ...defaultConfig.mqtt,
37
+ ...(config.mqtt || {})
38
+ },
39
+ credentials: {
40
+ ...defaultConfig.credentials,
41
+ ...(config.credentials || {})
42
+ }
43
+ };
44
+
45
+ // Save updated config if new keys were added
46
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
47
+ }
48
+ } catch (err) {
49
+ logger(`Config error: ${err.message}`, "error");
50
+
51
+ config = { ...defaultConfig };
52
+
53
+ try {
54
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
55
+ } catch (_) {}
56
+ }
57
+
58
+ return {
59
+ config,
60
+ configPath
61
+ };
62
+ }
63
+
64
+ module.exports = {
65
+ loadConfig,
66
+ defaultConfig
67
+ };
@@ -0,0 +1,154 @@
1
+ const { getType } = require("../src/utils/format");
2
+ const { setOptions } = require("./options");
3
+ const { loadConfig } = require("./config");
4
+ const { checkAndUpdateVersion } = require("../func/checkUpdate");
5
+ const loginHelper = require("./loginHelper");
6
+ const logger = require("../func/logger");
7
+
8
+ const { config } = loadConfig();
9
+ global.fca = { config };
10
+
11
+ // Global error handlers to prevent bot crashes
12
+ // Handle unhandled promise rejections (e.g., fetch timeouts, network errors)
13
+ if (!global.fca._errorHandlersInstalled) {
14
+ global.fca._errorHandlersInstalled = true;
15
+
16
+ process.on("unhandledRejection", (reason, promise) => {
17
+ try {
18
+ // Check if it's a fetch/network timeout error
19
+ if (reason && typeof reason === "object") {
20
+ const errorCode = reason.code || reason.cause?.code;
21
+ const errorMessage = reason.message || String(reason);
22
+
23
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
24
+ if (errorMessage.includes("No Sequelize instance passed")) {
25
+ return; // Silently ignore - already handled
26
+ }
27
+
28
+ // Handle fetch timeout errors gracefully
29
+ if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
30
+ errorCode === "ETIMEDOUT" ||
31
+ errorMessage.includes("Connect Timeout") ||
32
+ errorMessage.includes("fetch failed")) {
33
+ logger(`Network timeout error caught (non-fatal): ${errorMessage}`, "warn");
34
+ return; // Don't crash, just log
35
+ }
36
+
37
+ // Handle other network errors
38
+ if (errorCode === "ECONNREFUSED" ||
39
+ errorCode === "ENOTFOUND" ||
40
+ errorCode === "ECONNRESET" ||
41
+ errorMessage.includes("ECONNREFUSED") ||
42
+ errorMessage.includes("ENOTFOUND")) {
43
+ logger(`Network connection error caught (non-fatal): ${errorMessage}`, "warn");
44
+ return; // Don't crash, just log
45
+ }
46
+ }
47
+
48
+ // For other unhandled rejections, log but don't crash
49
+ logger(`Unhandled promise rejection (non-fatal): ${reason && reason.message ? reason.message : String(reason)}`, "error");
50
+ } catch (e) {
51
+ // Fallback if logger fails
52
+ console.error("[FCA-ERROR] Unhandled promise rejection:", reason);
53
+ }
54
+ });
55
+
56
+ // Handle uncaught exceptions (last resort)
57
+ process.on("uncaughtException", (error) => {
58
+ try {
59
+ const errorMessage = error.message || String(error);
60
+ const errorCode = error.code;
61
+
62
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
63
+ if (errorMessage.includes("No Sequelize instance passed")) {
64
+ return; // Silently ignore - already handled
65
+ }
66
+
67
+ // Handle fetch/network errors
68
+ if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
69
+ errorCode === "ETIMEDOUT" ||
70
+ errorMessage.includes("Connect Timeout") ||
71
+ errorMessage.includes("fetch failed")) {
72
+ logger(`Uncaught network timeout error (non-fatal): ${errorMessage}`, "warn");
73
+ return; // Don't crash
74
+ }
75
+
76
+ // For other uncaught exceptions, log but try to continue
77
+ logger(`Uncaught exception (attempting to continue): ${errorMessage}`, "error");
78
+ // Note: We don't exit here to allow bot to continue running
79
+ // In production, you might want to restart the process instead
80
+ } catch (e) {
81
+ // Fallback if logger fails
82
+ console.error("[FCA-ERROR] Uncaught exception:", error);
83
+ }
84
+ });
85
+ }
86
+
87
+ function login(loginData, options, callback) {
88
+ if (getType(options) === "Function" || getType(options) === "AsyncFunction") {
89
+ callback = options;
90
+ options = {};
91
+ }
92
+ const globalOptions = {
93
+ selfListen: false,
94
+ selfListenEvent: false,
95
+ listenEvents: false,
96
+ listenTyping: false,
97
+ updatePresence: false,
98
+ forceLogin: false,
99
+ autoMarkDelivery: true,
100
+ autoMarkRead: false,
101
+ autoReconnect: true,
102
+ online: true,
103
+ emitReady: false,
104
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
105
+ };
106
+ setOptions(globalOptions, options);
107
+ let prCallback = null;
108
+ let rejectFunc = null;
109
+ let resolveFunc = null;
110
+ let returnPromise = null;
111
+ if (getType(callback) !== "Function" && getType(callback) !== "AsyncFunction") {
112
+ returnPromise = new Promise(function (resolve, reject) {
113
+ resolveFunc = resolve;
114
+ rejectFunc = reject;
115
+ });
116
+ prCallback = function (error, api) {
117
+ if (error) return rejectFunc(error);
118
+ return resolveFunc(api);
119
+ };
120
+ callback = prCallback;
121
+ }
122
+
123
+
124
+ const proceed = () =>
125
+ loginHelper(
126
+ loginData.appState,
127
+ loginData.Cookie,
128
+ loginData.email,
129
+ loginData.password,
130
+ globalOptions,
131
+ callback,
132
+ prCallback
133
+ );
134
+
135
+ // Login immediately
136
+ proceed();
137
+
138
+ // Run update check in background (never block login)
139
+ if (config && config.autoUpdate) {
140
+ setImmediate(async () => {
141
+ try {
142
+ await checkAndUpdateVersion();
143
+ } catch (err) {
144
+ logger(
145
+ `Background update check failed: ${err.message || err}`,
146
+ "warn"
147
+ );
148
+ }
149
+ });
150
+ }
151
+ return returnPromise;
152
+ }
153
+
154
+ module.exports = login;