surya-sahil-fca 1.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.
- package/CHANGELOG.md +175 -0
- package/DOCS.md +2636 -0
- package/LICENSE-MIT +21 -0
- package/README.md +107 -0
- package/func/checkUpdate.js +222 -0
- package/func/logger.js +48 -0
- package/index.d.ts +746 -0
- package/index.js +8 -0
- package/module/config.js +34 -0
- package/module/login.js +126 -0
- package/module/loginHelper.js +747 -0
- package/module/options.js +45 -0
- package/package.json +82 -0
- package/src/api/messaging/changeGroupImage.js +90 -0
- package/src/api/messaging/changeNickname.js +70 -0
- package/src/api/messaging/changeThreadName.js +123 -0
- package/src/api/messaging/createCommentPost.js +207 -0
- package/src/api/messaging/sendMessage.js +272 -0
- package/src/api/messaging/sendTypingIndicator.js +67 -0
- package/src/api/messaging/setMessageReaction.js +76 -0
- package/src/api/messaging/setTitle.js +119 -0
- package/src/api/messaging/stickers.js +257 -0
- package/src/core/sendReqMqtt.js +96 -0
- package/src/database/models/index.js +49 -0
- package/src/database/models/thread.js +31 -0
- package/src/database/models/user.js +32 -0
- package/src/database/threadData.js +98 -0
- package/src/database/userData.js +89 -0
- package/src/utils/client.js +320 -0
- package/src/utils/constants.js +23 -0
- package/src/utils/format.js +1115 -0
- package/src/utils/headers.js +115 -0
- package/src/utils/request.js +305 -0
package/index.js
ADDED
package/module/config.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
|
|
34
|
+
module.exports = { loadConfig, defaultConfig };
|
package/module/login.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
// Handle fetch timeout errors gracefully
|
|
24
|
+
if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
|
|
25
|
+
errorCode === "ETIMEDOUT" ||
|
|
26
|
+
errorMessage.includes("Connect Timeout") ||
|
|
27
|
+
errorMessage.includes("fetch failed")) {
|
|
28
|
+
logger(`Network timeout error caught (non-fatal): ${errorMessage}`, "warn");
|
|
29
|
+
return; // Don't crash, just log
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Handle other network errors
|
|
33
|
+
if (errorCode === "ECONNREFUSED" ||
|
|
34
|
+
errorCode === "ENOTFOUND" ||
|
|
35
|
+
errorCode === "ECONNRESET" ||
|
|
36
|
+
errorMessage.includes("ECONNREFUSED") ||
|
|
37
|
+
errorMessage.includes("ENOTFOUND")) {
|
|
38
|
+
logger(`Network connection error caught (non-fatal): ${errorMessage}`, "warn");
|
|
39
|
+
return; // Don't crash, just log
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// For other unhandled rejections, log but don't crash
|
|
44
|
+
logger(`Unhandled promise rejection (non-fatal): ${reason && reason.message ? reason.message : String(reason)}`, "error");
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// Fallback if logger fails
|
|
47
|
+
console.error("[FCA-ERROR] Unhandled promise rejection:", reason);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Handle uncaught exceptions (last resort)
|
|
52
|
+
process.on("uncaughtException", (error) => {
|
|
53
|
+
try {
|
|
54
|
+
const errorMessage = error.message || String(error);
|
|
55
|
+
const errorCode = error.code;
|
|
56
|
+
|
|
57
|
+
// Handle fetch/network errors
|
|
58
|
+
if (errorCode === "UND_ERR_CONNECT_TIMEOUT" ||
|
|
59
|
+
errorCode === "ETIMEDOUT" ||
|
|
60
|
+
errorMessage.includes("Connect Timeout") ||
|
|
61
|
+
errorMessage.includes("fetch failed")) {
|
|
62
|
+
logger(`Uncaught network timeout error (non-fatal): ${errorMessage}`, "warn");
|
|
63
|
+
return; // Don't crash
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// For other uncaught exceptions, log but try to continue
|
|
67
|
+
logger(`Uncaught exception (attempting to continue): ${errorMessage}`, "error");
|
|
68
|
+
// Note: We don't exit here to allow bot to continue running
|
|
69
|
+
// In production, you might want to restart the process instead
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// Fallback if logger fails
|
|
72
|
+
console.error("[FCA-ERROR] Uncaught exception:", error);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function login(loginData, options, callback) {
|
|
78
|
+
if (getType(options) === "Function" || getType(options) === "AsyncFunction") {
|
|
79
|
+
callback = options;
|
|
80
|
+
options = {};
|
|
81
|
+
}
|
|
82
|
+
const globalOptions = {
|
|
83
|
+
selfListen: false,
|
|
84
|
+
selfListenEvent: false,
|
|
85
|
+
listenEvents: false,
|
|
86
|
+
listenTyping: false,
|
|
87
|
+
updatePresence: false,
|
|
88
|
+
forceLogin: false,
|
|
89
|
+
autoMarkDelivery: true,
|
|
90
|
+
autoMarkRead: false,
|
|
91
|
+
autoReconnect: true,
|
|
92
|
+
online: true,
|
|
93
|
+
emitReady: false,
|
|
94
|
+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
|
|
95
|
+
};
|
|
96
|
+
setOptions(globalOptions, options);
|
|
97
|
+
let prCallback = null;
|
|
98
|
+
let rejectFunc = null;
|
|
99
|
+
let resolveFunc = null;
|
|
100
|
+
let returnPromise = null;
|
|
101
|
+
if (getType(callback) !== "Function" && getType(callback) !== "AsyncFunction") {
|
|
102
|
+
returnPromise = new Promise(function (resolve, reject) {
|
|
103
|
+
resolveFunc = resolve;
|
|
104
|
+
rejectFunc = reject;
|
|
105
|
+
});
|
|
106
|
+
prCallback = function (error, api) {
|
|
107
|
+
if (error) return rejectFunc(error);
|
|
108
|
+
return resolveFunc(api);
|
|
109
|
+
};
|
|
110
|
+
callback = prCallback;
|
|
111
|
+
}
|
|
112
|
+
const proceed = () => loginHelper(loginData.appState, loginData.Cookie, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
|
113
|
+
if (config && config.autoUpdate) {
|
|
114
|
+
const p = checkAndUpdateVersion();
|
|
115
|
+
if (p && typeof p.then === "function") {
|
|
116
|
+
p.then(proceed).catch(err => callback(err));
|
|
117
|
+
} else {
|
|
118
|
+
proceed();
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
proceed();
|
|
122
|
+
}
|
|
123
|
+
return returnPromise;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = login;
|