shadowx-fca 1.2.0 → 2.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/checkUpdate.js +112 -0
- package/index.js +106 -1
- package/package.json +2 -2
- package/utils.js +298 -230
package/checkUpdate.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const { execSync } = require('child_process');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
async function checkForFCAUpdate() {
|
|
7
|
+
try {
|
|
8
|
+
console.log('\x1b[33m%s\x1b[0m', '🔍 Checking for shadowx-fca updates...');
|
|
9
|
+
|
|
10
|
+
// Get latest version from npm registry
|
|
11
|
+
const { data: npmData } = await axios.get(
|
|
12
|
+
'https://registry.npmjs.org/shadowx-fca/latest'
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const latestVersion = npmData.version;
|
|
16
|
+
|
|
17
|
+
// Check current installed version in node_modules
|
|
18
|
+
let currentVersion = '1.0.8';
|
|
19
|
+
const nodeModulesPackagePath = path.join(process.cwd(), 'node_modules', 'shadowx-fca', 'package.json');
|
|
20
|
+
if (fs.existsSync(nodeModulesPackagePath)) {
|
|
21
|
+
const installedPackage = JSON.parse(fs.readFileSync(nodeModulesPackagePath, 'utf-8'));
|
|
22
|
+
currentVersion = installedPackage.version;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (latestVersion !== currentVersion) {
|
|
26
|
+
console.log('\x1b[32m%s\x1b[0m', `✨ New shadowx-fca version available: ${latestVersion} (current: ${currentVersion})`);
|
|
27
|
+
console.log('\x1b[33m%s\x1b[0m', '📦 Updating shadowx-fca package...');
|
|
28
|
+
|
|
29
|
+
// Show changelog
|
|
30
|
+
try {
|
|
31
|
+
const { data: changesData } = await axios.get(
|
|
32
|
+
'https://raw.githubusercontent.com/mueidmursalinrifat/shadowx-fca/main/CHANGELOG.md'
|
|
33
|
+
);
|
|
34
|
+
console.log('\x1b[36m%s\x1b[0m', '📋 Recent Changes:');
|
|
35
|
+
const latestChanges = changesData.split('##')[1]?.split('\n').slice(0, 5).join('\n');
|
|
36
|
+
if (latestChanges) {
|
|
37
|
+
console.log(latestChanges);
|
|
38
|
+
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
// Silently ignore changelog fetch errors
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Update npm package
|
|
44
|
+
await updateNpmPackage(latestVersion);
|
|
45
|
+
|
|
46
|
+
// Update version in user's package.json
|
|
47
|
+
await updateUserPackageJson(latestVersion);
|
|
48
|
+
|
|
49
|
+
console.log('\x1b[32m%s\x1b[0m', '✅ shadowx-fca updated successfully!');
|
|
50
|
+
console.log('\x1b[33m%s\x1b[0m', '🔄 Restarting to apply changes...');
|
|
51
|
+
|
|
52
|
+
// Restart the process
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
process.exit(2);
|
|
55
|
+
}, 1000);
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
} else {
|
|
59
|
+
console.log('\x1b[32m%s\x1b[0m', `✅ shadowx-fca is up to date (v${currentVersion})`);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.log('\x1b[31m%s\x1b[0m', '❌ Failed to check for shadowx-fca updates:', error.message);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function updateNpmPackage(version) {
|
|
69
|
+
try {
|
|
70
|
+
console.log('\x1b[36m%s\x1b[0m', `📦 Running npm install shadowx-fca@${version}...`);
|
|
71
|
+
|
|
72
|
+
// Execute npm install command
|
|
73
|
+
execSync(`npm install shadowx-fca@${version} --save`, {
|
|
74
|
+
cwd: process.cwd(),
|
|
75
|
+
stdio: 'inherit'
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
console.log('\x1b[32m%s\x1b[0m', '✅ Package installed successfully!');
|
|
79
|
+
return true;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.log('\x1b[31m%s\x1b[0m', '❌ Failed to install package:', error.message);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function updateUserPackageJson(version) {
|
|
87
|
+
try {
|
|
88
|
+
const userPackageJsonPath = path.join(process.cwd(), 'package.json');
|
|
89
|
+
|
|
90
|
+
if (!fs.existsSync(userPackageJsonPath)) {
|
|
91
|
+
console.log('\x1b[33m%s\x1b[0m', '⚠️ No package.json found in user project');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const packageJson = JSON.parse(fs.readFileSync(userPackageJsonPath, 'utf-8'));
|
|
96
|
+
|
|
97
|
+
// Update stfca version in dependencies
|
|
98
|
+
if (packageJson.dependencies && packageJson.dependencies.stfca) {
|
|
99
|
+
packageJson.dependencies.stfca = `^${version}`;
|
|
100
|
+
fs.writeFileSync(userPackageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
101
|
+
console.log('\x1b[32m%s\x1b[0m', `✅ Updated package.json to shadowx-fca@${version}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return true;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.log('\x1b[31m%s\x1b[0m', '⚠️ Failed to update user package.json:', error.message);
|
|
107
|
+
// Don't throw - this is not critical
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = { checkForFCAUpdate, updateNpmPackage, updateUserPackageJson };
|
package/index.js
CHANGED
|
@@ -3,11 +3,28 @@
|
|
|
3
3
|
var utils = require("./utils");
|
|
4
4
|
var cheerio = require("cheerio");
|
|
5
5
|
var log = require("npmlog");
|
|
6
|
-
|
|
6
|
+
var { checkForFCAUpdate } = require("./checkUpdate");
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
/*var { getThemeColors } = require("../../func/utils/log.js");
|
|
10
|
+
var logger = require("../../func/utils/log.js");
|
|
11
|
+
var { cra, cv, cb, co } = getThemeColors();*/
|
|
7
12
|
log.maxRecordSize = 100;
|
|
8
13
|
var checkVerified = null;
|
|
9
14
|
const Boolean_Option = ['online', 'selfListen', 'listenEvents', 'updatePresence', 'forceLogin', 'autoMarkDelivery', 'autoMarkRead', 'listenTyping', 'autoReconnect', 'emitReady'];
|
|
10
15
|
global.ditconmemay = false;
|
|
16
|
+
global.stfcaUpdateChecked = false;
|
|
17
|
+
|
|
18
|
+
// Auto-check for updates on package load (non-blocking)
|
|
19
|
+
if (!global.stfcaUpdateChecked) {
|
|
20
|
+
global.stfcaUpdateChecked = true;
|
|
21
|
+
const { checkForFCAUpdate } = require("./checkUpdate");
|
|
22
|
+
setImmediate(() => {
|
|
23
|
+
checkForFCAUpdate().catch(() => {
|
|
24
|
+
// Silent fail - don't interrupt user's bot
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
function setOptions(globalOptions, options) {
|
|
13
30
|
Object.keys(options).map(function (key) {
|
|
@@ -173,6 +190,86 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
173
190
|
reqCallbacks: {},
|
|
174
191
|
threadTypes: {} // Store thread type (dm/group) for each thread
|
|
175
192
|
};
|
|
193
|
+
let config = { enableTypingIndicator: false, typingDuration: 4000 };
|
|
194
|
+
try {
|
|
195
|
+
// Prefer global root config (project-level), but fallback to fca/config.json if present.
|
|
196
|
+
const rootConfigPath = path.join(process.cwd(), 'config.json');
|
|
197
|
+
if (fs.existsSync(rootConfigPath)) {
|
|
198
|
+
const rootConfig = JSON.parse(fs.readFileSync(rootConfigPath, 'utf8'));
|
|
199
|
+
if (rootConfig && typeof rootConfig === 'object') {
|
|
200
|
+
if (typeof rootConfig.enableTypingIndicator !== 'undefined') config.enableTypingIndicator = rootConfig.enableTypingIndicator;
|
|
201
|
+
if (typeof rootConfig.typingDuration !== 'undefined') config.typingDuration = rootConfig.typingDuration;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const fcaConfigPath = path.join(__dirname, 'config.json');
|
|
206
|
+
if (fs.existsSync(fcaConfigPath)) {
|
|
207
|
+
const fcaConfig = JSON.parse(fs.readFileSync(fcaConfigPath, 'utf8'));
|
|
208
|
+
if (fcaConfig && typeof fcaConfig === 'object') {
|
|
209
|
+
if (typeof fcaConfig.enableTypingIndicator !== 'undefined') config.enableTypingIndicator = fcaConfig.enableTypingIndicator;
|
|
210
|
+
if (typeof fcaConfig.typingDuration !== 'undefined') config.typingDuration = fcaConfig.typingDuration;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (global.GoatBot && global.GoatBot.config) {
|
|
215
|
+
if (typeof global.GoatBot.config.enableTypingIndicator !== 'undefined') config.enableTypingIndicator = global.GoatBot.config.enableTypingIndicator;
|
|
216
|
+
if (typeof global.GoatBot.config.typingDuration !== 'undefined') config.typingDuration = global.GoatBot.config.typingDuration;
|
|
217
|
+
}
|
|
218
|
+
} catch (e) {
|
|
219
|
+
console.log('Error loading config.json:', e);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const refreshFcaConfig = () => {
|
|
223
|
+
try {
|
|
224
|
+
// Defaults first
|
|
225
|
+
const updatedConfig = { enableTypingIndicator: false, typingDuration: 4000 };
|
|
226
|
+
|
|
227
|
+
// Layered config sources
|
|
228
|
+
if (fs.existsSync(path.join(process.cwd(), 'config.json'))) {
|
|
229
|
+
const rootConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'config.json'), 'utf8'));
|
|
230
|
+
if (rootConfig && typeof rootConfig === 'object') {
|
|
231
|
+
if (typeof rootConfig.enableTypingIndicator !== 'undefined') updatedConfig.enableTypingIndicator = rootConfig.enableTypingIndicator;
|
|
232
|
+
if (typeof rootConfig.typingDuration !== 'undefined') updatedConfig.typingDuration = rootConfig.typingDuration;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (fs.existsSync(path.join(__dirname, 'config.json'))) {
|
|
237
|
+
const fcaConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'), 'utf8'));
|
|
238
|
+
if (fcaConfig && typeof fcaConfig === 'object') {
|
|
239
|
+
if (typeof fcaConfig.enableTypingIndicator !== 'undefined') updatedConfig.enableTypingIndicator = fcaConfig.enableTypingIndicator;
|
|
240
|
+
if (typeof fcaConfig.typingDuration !== 'undefined') updatedConfig.typingDuration = fcaConfig.typingDuration;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (global.GoatBot && global.GoatBot.config) {
|
|
245
|
+
if (typeof global.GoatBot.config.enableTypingIndicator !== 'undefined') updatedConfig.enableTypingIndicator = global.GoatBot.config.enableTypingIndicator;
|
|
246
|
+
if (typeof global.GoatBot.config.typingDuration !== 'undefined') updatedConfig.typingDuration = global.GoatBot.config.typingDuration;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
ctx.config = updatedConfig;
|
|
250
|
+
config = updatedConfig;
|
|
251
|
+
if (global.GoatBot) global.GoatBot.config = global.GoatBot.config || {};
|
|
252
|
+
if (global.GoatBot && typeof global.GoatBot.config.enableTypingIndicator !== 'undefined') {
|
|
253
|
+
global.GoatBot.config.enableTypingIndicator = updatedConfig.enableTypingIndicator;
|
|
254
|
+
}
|
|
255
|
+
if (global.GoatBot && typeof global.GoatBot.config.typingDuration !== 'undefined') {
|
|
256
|
+
global.GoatBot.config.typingDuration = updatedConfig.typingDuration;
|
|
257
|
+
}
|
|
258
|
+
} catch (e) {
|
|
259
|
+
console.log('Failed to refresh fca config:', e);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// Initial config load
|
|
264
|
+
refreshFcaConfig();
|
|
265
|
+
|
|
266
|
+
// Accessible runtime API for config reload
|
|
267
|
+
ctx.refreshFcaConfig = refreshFcaConfig;
|
|
268
|
+
if (global.GoatBot) {
|
|
269
|
+
global.GoatBot.refreshFcaConfig = refreshFcaConfig;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
ctx.config = config;
|
|
176
273
|
var api = {
|
|
177
274
|
setOptions: setOptions.bind(null, globalOptions),
|
|
178
275
|
getAppState: () => utils.getAppState(jar),
|
|
@@ -426,6 +523,14 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
426
523
|
|
|
427
524
|
|
|
428
525
|
function login(loginData, options, callback) {
|
|
526
|
+
// Check for updates (non-blocking, only once per session)
|
|
527
|
+
if (!global.stfcaUpdateChecked) {
|
|
528
|
+
global.stfcaUpdateChecked = true;
|
|
529
|
+
checkForFCAUpdate().catch(err => {
|
|
530
|
+
// Silently ignore update check errors to not block login
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
429
534
|
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
|
430
535
|
callback = options;
|
|
431
536
|
options = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shadowx-fca",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Unofficial Facebook Chat API for Node.js with Auto-Update System - modify by Mueid Mursalin Rifat",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/mueidmursalinrifat/
|
|
18
|
+
"url": "git+https://github.com/mueidmursalinrifat/shadowx-fca.git"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"facebook",
|