@dongdev/fca-unofficial 3.0.25 → 3.0.28

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 (35) hide show
  1. package/.gitattributes +2 -0
  2. package/CHANGELOG.md +196 -190
  3. package/DOCS.md +3 -6
  4. package/Fca_Database/database.sqlite +0 -0
  5. package/LICENSE-MIT +1 -1
  6. package/README.md +1 -1
  7. package/index.d.ts +745 -746
  8. package/module/config.js +29 -33
  9. package/module/login.js +133 -136
  10. package/module/loginHelper.js +1240 -1048
  11. package/module/options.js +44 -45
  12. package/package.json +81 -82
  13. package/src/api/messaging/changeAdminStatus.js +56 -56
  14. package/src/api/messaging/changeGroupImage.js +2 -1
  15. package/src/api/messaging/changeThreadEmoji.js +47 -47
  16. package/src/api/messaging/createPoll.js +25 -25
  17. package/src/api/messaging/deleteMessage.js +110 -30
  18. package/src/api/messaging/forwardAttachment.js +28 -28
  19. package/src/api/messaging/removeUserFromGroup.js +28 -73
  20. package/src/api/messaging/sendMessage.js +15 -17
  21. package/src/api/messaging/sendTypingIndicator.js +23 -23
  22. package/src/api/messaging/setMessageReaction.js +57 -60
  23. package/src/api/messaging/setTitle.js +47 -47
  24. package/src/api/messaging/uploadAttachment.js +471 -73
  25. package/src/api/socket/core/connectMqtt.js +250 -250
  26. package/src/api/socket/core/emitAuth.js +1 -1
  27. package/src/api/socket/core/getSeqID.js +322 -40
  28. package/src/api/socket/core/parseDelta.js +368 -377
  29. package/src/api/socket/listenMqtt.js +371 -360
  30. package/src/utils/client.js +2 -312
  31. package/src/utils/cookies.js +68 -0
  32. package/src/utils/format.js +117 -90
  33. package/src/utils/loginParser.js +347 -0
  34. package/src/utils/messageFormat.js +1173 -0
  35. package/src/api/socket/core/markDelivery.js +0 -12
package/module/config.js CHANGED
@@ -1,34 +1,30 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const logger = require("../func/logger");
4
- const defaultConfig = {
5
- autoUpdate: true,
6
- mqtt: { enabled: true, reconnectInterval: 3600 },
7
- autoLogin: true,
8
- credentials: { email: "", password: "", twofactor: "" }
9
- };
10
-
11
- function loadConfig() {
12
- const configPath = path.join(process.cwd(), "fca-config.json");
13
- let config;
14
- if (!fs.existsSync(configPath)) {
15
- try {
16
- fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
17
- config = defaultConfig;
18
- } catch (err) {
19
- logger(`Error writing config file: ${err.message}`, "error");
20
- config = defaultConfig;
21
- }
22
- } else {
23
- try {
24
- const fileContent = fs.readFileSync(configPath, "utf8");
25
- config = Object.assign({}, defaultConfig, JSON.parse(fileContent));
26
- } catch (err) {
27
- logger(`Error reading config file: ${err.message}`, "error");
28
- config = defaultConfig;
29
- }
30
- }
31
- return { config, configPath };
32
- }
33
-
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const logger = require("../func/logger");
4
+ const defaultConfig = {
5
+ autoUpdate: true,
6
+ mqtt: { enabled: true, reconnectInterval: 3600 },
7
+ autoLogin: true,
8
+ apiServer: "https://minhdong.site",
9
+ apiKey: "",
10
+ credentials: { email: "", password: "", twofactor: "" }
11
+ };
12
+
13
+ function loadConfig() {
14
+ const configPath = path.join(process.cwd(), "fca-config.json");
15
+ let config;
16
+ if (!fs.existsSync(configPath)) {
17
+ config = defaultConfig;
18
+ } else {
19
+ try {
20
+ const fileContent = fs.readFileSync(configPath, "utf8");
21
+ config = Object.assign({}, defaultConfig, JSON.parse(fileContent));
22
+ } catch (err) {
23
+ logger(`Error reading config file: ${err.message}`, "error");
24
+ config = defaultConfig;
25
+ }
26
+ }
27
+ return { config, configPath };
28
+ }
29
+
34
30
  module.exports = { loadConfig, defaultConfig };
package/module/login.js CHANGED
@@ -1,136 +1,133 @@
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
- const proceed = () => loginHelper(loginData.appState, loginData.Cookie, loginData.email, loginData.password, globalOptions, callback, prCallback);
123
- if (config && config.autoUpdate) {
124
- const p = checkAndUpdateVersion();
125
- if (p && typeof p.then === "function") {
126
- p.then(proceed).catch(err => callback(err));
127
- } else {
128
- proceed();
129
- }
130
- } else {
131
- proceed();
132
- }
133
- return returnPromise;
134
- }
135
-
136
- module.exports = login;
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 - silent
52
+ }
53
+ });
54
+
55
+ // Handle uncaught exceptions (last resort)
56
+ process.on("uncaughtException", (error) => {
57
+ try {
58
+ const errorMessage = error.message || String(error);
59
+ const errorCode = error.code;
60
+
61
+ // Suppress Sequelize instance errors (handled gracefully in getBackupModel)
62
+ if (errorMessage.includes("No Sequelize instance passed")) {
63
+ return; // Silently ignore - already handled
64
+ }
65
+
66
+ // Handle fetch/network errors
67
+ if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
68
+ errorCode === "ETIMEDOUT" ||
69
+ errorMessage.includes("Connect Timeout") ||
70
+ errorMessage.includes("fetch failed")) {
71
+ logger(`Uncaught network timeout error (non-fatal): ${errorMessage}`, "warn");
72
+ return; // Don't crash
73
+ }
74
+
75
+ // For other uncaught exceptions, log but try to continue
76
+ logger(`Uncaught exception (attempting to continue): ${errorMessage}`, "error");
77
+ // Note: We don't exit here to allow bot to continue running
78
+ // In production, you might want to restart the process instead
79
+ } catch (e) {
80
+ // Fallback if logger fails - silent
81
+ }
82
+ });
83
+ }
84
+
85
+ function login(loginData, options, callback) {
86
+ if (getType(options) === "Function" || getType(options) === "AsyncFunction") {
87
+ callback = options;
88
+ options = {};
89
+ }
90
+ const globalOptions = {
91
+ selfListen: false,
92
+ selfListenEvent: false,
93
+ listenEvents: false,
94
+ listenTyping: false,
95
+ updatePresence: false,
96
+ forceLogin: false,
97
+ autoMarkRead: false,
98
+ autoReconnect: true,
99
+ online: true,
100
+ emitReady: false,
101
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
102
+ };
103
+ setOptions(globalOptions, options);
104
+ let prCallback = null;
105
+ let rejectFunc = null;
106
+ let resolveFunc = null;
107
+ let returnPromise = null;
108
+ if (getType(callback) !== "Function" && getType(callback) !== "AsyncFunction") {
109
+ returnPromise = new Promise(function (resolve, reject) {
110
+ resolveFunc = resolve;
111
+ rejectFunc = reject;
112
+ });
113
+ prCallback = function (error, api) {
114
+ if (error) return rejectFunc(error);
115
+ return resolveFunc(api);
116
+ };
117
+ callback = prCallback;
118
+ }
119
+ const proceed = () => loginHelper(loginData.appState, loginData.Cookie, loginData.email, loginData.password, globalOptions, callback, prCallback);
120
+ if (config && config.autoUpdate) {
121
+ const p = checkAndUpdateVersion();
122
+ if (p && typeof p.then === "function") {
123
+ p.then(proceed).catch(err => callback(err));
124
+ } else {
125
+ proceed();
126
+ }
127
+ } else {
128
+ proceed();
129
+ }
130
+ return returnPromise;
131
+ }
132
+
133
+ module.exports = login;