fca-nx 6.8.6 → 7.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.
@@ -20,15 +20,14 @@ const getTaskResponseData = require("./core/getTaskResponseData");
20
20
  const createEmitAuth = require("./core/emitAuth");
21
21
  const createMiddlewareSystem = require("./middleware");
22
22
 
23
- const CYCLE_MS_DEFAULT = 0; // [Hardened7] auto-cycle OFF. A 1h cycle tears the socket down and opens a new MQTT session — after ~2h that looks like repeated logins and gets the account suspended.
24
- const RECONNECT_DELAY_MS_DEFAULT = 12000;
23
+ const CYCLE_MS_DEFAULT = 60 * 60 * 1000;
24
+ const RECONNECT_DELAY_MS_DEFAULT = 3000;
25
25
  const UNSUB_ALL_TIMEOUT_MS = 5000;
26
- const MAX_MQTT_RECONNECT_DELAY_MS = 120000;
27
- const MAX_MQTT_RECONNECT_COOLDOWN_MS = 45 * 60 * 1000; // long quiet period, do not hammer
28
- const MAX_MQTT_RECONNECT_ATTEMPTS = 6;
29
- const HEARTBEAT_INTERVAL_MS = 60000;
30
- const HEARTBEAT_TIMEOUT_MS = 20000;
31
- const MIN_FORCE_CYCLE_MS = 10 * 60 * 1000;
26
+ const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
27
+ const MAX_MQTT_RECONNECT_COOLDOWN_MS = 10 * 60 * 1000; // long cooldown after exhausting fast retries - never give up permanently
28
+ const MAX_MQTT_RECONNECT_ATTEMPTS = 10;
29
+ const HEARTBEAT_INTERVAL_MS = 30000;
30
+ const HEARTBEAT_TIMEOUT_MS = 10000;
32
31
 
33
32
  const parseDelta = createParseDelta({ parseAndCheckLogin });
34
33
  const emitAuth = createEmitAuth({ logger });
@@ -110,20 +109,9 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
110
109
  let isReconnecting = false;
111
110
 
112
111
  function getReconnectDelay() {
113
- // [Hardened] Immediate reconnect is OPT-IN only (FCA_NX_MQTT_IMMEDIATE_RECONNECT=1).
114
- // Default scheduled backoff avoids overlapping sessions that Facebook treats as multi-login.
115
- // When enabled: attempts 0/1 fire at once, then 1s, 2s, 4s ... up to 60s.
116
- const immediate = process.env.FCA_NX_MQTT_IMMEDIATE_RECONNECT === "1";
117
- if (immediate) {
118
- if (reconnectAttempts <= 1) return 0;
119
- const fast = Math.min(1000 * Math.pow(2, reconnectAttempts - 2), MAX_MQTT_RECONNECT_DELAY_MS);
120
- const j = Math.floor(Math.random() * Math.min(500, fast * 0.2));
121
- return Math.min(fast + j, MAX_MQTT_RECONNECT_DELAY_MS);
122
- }
123
112
  const base = conf.reconnectDelayMs || RECONNECT_DELAY_MS_DEFAULT;
124
113
  const exp = Math.min(base * Math.pow(2, reconnectAttempts), MAX_MQTT_RECONNECT_DELAY_MS);
125
- // [Hardened5] wider jitter (20-40%) so reconnect timing looks less scripted
126
- const jitter = Math.floor(Math.random() * Math.min(4000, exp * 0.4));
114
+ const jitter = Math.floor(Math.random() * Math.min(1000, exp * 0.2));
127
115
  return Math.min(exp + jitter, MAX_MQTT_RECONNECT_DELAY_MS);
128
116
  }
129
117
 
@@ -132,11 +120,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
132
120
  logger("mqtt getSeqID skipped - ending", "warn");
133
121
  return Promise.resolve();
134
122
  }
135
- // [Hardened6] single-flight: avoid parallel getSeqID (looks like multi-session)
136
- if (ctx._getSeqIDInFlight) {
137
- logger("mqtt getSeqID skipped - already in flight", "warn");
138
- return ctx._getSeqIDInFlight;
139
- }
140
123
 
141
124
  const form = {
142
125
  av: ctx.globalOptions.pageID || ctx.userID,
@@ -157,11 +140,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
157
140
  };
158
141
 
159
142
  logger("mqtt getSeqID call", "info");
160
- const _seqP = Promise.resolve().then(function () {
161
- return getSeqIDFactory(defaultFuncs, api, ctx, globalCallback, form);
162
- }).finally(function () { ctx._getSeqIDInFlight = null; });
163
- ctx._getSeqIDInFlight = _seqP;
164
- return _seqP
143
+ return getSeqIDFactory(defaultFuncs, api, ctx, globalCallback, form)
165
144
  .then(() => {
166
145
  logger("mqtt getSeqID done", "info");
167
146
  ctx._cycling = false;
@@ -222,10 +201,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
222
201
 
223
202
  lastPongTime = Date.now();
224
203
 
225
- // [Hardened6] jittered heartbeat interval so pings are not perfectly periodic
226
- const hbBase = conf.heartbeatInterval || HEARTBEAT_INTERVAL_MS;
227
- const hbEvery = hbBase + Math.floor(Math.random() * Math.min(8000, hbBase * 0.25));
228
- let missedPongs = 0;
229
204
  heartbeatTimer = setInterval(() => {
230
205
  if (!isConnected()) {
231
206
  stopHeartbeat();
@@ -233,24 +208,19 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
233
208
  }
234
209
 
235
210
  const now = Date.now();
236
- const limit = (conf.heartbeatTimeout || HEARTBEAT_TIMEOUT_MS) * 4;
237
- if (now - lastPongTime > limit) {
238
- missedPongs += 1;
239
- // mqtt.js keepalive already sends PINGREQ. A custom /ping every
240
- // few seconds is not what Messenger web does, and force-cycling
241
- // on one late pong opens a second session (suspend ~1-2h).
242
- if (missedPongs >= 3) {
243
- logger("mqtt heartbeat: silent too long, closing socket once", "warn");
244
- missedPongs = 0;
245
- stopHeartbeat();
246
- try { ctx.mqttClient.end(true); } catch (_) { }
247
- return;
248
- }
249
- logger("mqtt heartbeat: packet late, waiting", "warn");
250
- } else {
251
- missedPongs = 0;
211
+ if (now - lastPongTime > (conf.heartbeatTimeout || HEARTBEAT_TIMEOUT_MS) * 3) {
212
+ logger("mqtt heartbeat: no response, forcing reconnect", "warn");
213
+ forceCycle();
214
+ return;
252
215
  }
253
- }, hbEvery);
216
+
217
+ try {
218
+ ctx.mqttClient.publish("/ping", JSON.stringify({ timestamp: Date.now() }), { qos: 0 });
219
+ logger("mqtt heartbeat sent", "debug");
220
+ } catch (err) {
221
+ logger(`mqtt heartbeat error: ${err.message}`, "warn");
222
+ }
223
+ }, conf.heartbeatInterval || HEARTBEAT_INTERVAL_MS);
254
224
  }
255
225
 
256
226
  function stopHeartbeat() {
@@ -301,7 +271,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
301
271
  });
302
272
  }
303
273
 
304
- function endQuietly(next, soft) {
274
+ function endQuietly(next) {
305
275
  stopHeartbeat();
306
276
 
307
277
  const finish = () => {
@@ -312,15 +282,11 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
312
282
  } catch (_) { }
313
283
 
314
284
  ctx.mqttClient = undefined;
285
+ ctx.lastSeqId = null;
286
+ ctx.syncToken = undefined;
315
287
  ctx.t_mqttCalled = false;
316
288
  ctx._ending = false;
317
289
  ctx._cycling = false;
318
- // Soft cycle keeps seq + appstate saver. Wiping them on every
319
- // reconnect forces a full re-login and looks like a new device.
320
- if (!soft) {
321
- ctx.lastSeqId = null;
322
- ctx.syncToken = undefined;
323
- }
324
290
 
325
291
  if (ctx._reconnectTimer) {
326
292
  clearTimeout(ctx._reconnectTimer);
@@ -335,18 +301,23 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
335
301
  ctx.tasks.clear();
336
302
  }
337
303
 
338
- if (!soft) {
339
- if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
340
- ctx._userInfoIntervals.forEach(interval => {
341
- try { clearInterval(interval); } catch (_) { }
342
- });
343
- ctx._userInfoIntervals = [];
344
- }
304
+ if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
305
+ ctx._userInfoIntervals.forEach(interval => {
306
+ try { clearInterval(interval); } catch (_) { }
307
+ });
308
+ ctx._userInfoIntervals = [];
309
+ }
345
310
 
346
- if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
347
- try { ctx._scheduler.destroy(); } catch (_) { }
348
- ctx._scheduler = undefined;
349
- }
311
+ if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
312
+ ctx._autoSaveInterval.forEach(interval => {
313
+ try { clearInterval(interval); } catch (_) { }
314
+ });
315
+ ctx._autoSaveInterval = [];
316
+ }
317
+
318
+ if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
319
+ try { ctx._scheduler.destroy(); } catch (_) { }
320
+ ctx._scheduler = undefined;
350
321
  }
351
322
 
352
323
  reconnectAttempts = 0;
@@ -357,10 +328,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
357
328
 
358
329
  try {
359
330
  if (ctx.mqttClient) {
360
- if (!soft && isConnected()) {
361
- try {
362
- ctx.mqttClient.publish("/foreground_state", JSON.stringify({ foreground: false }), { qos: 0 });
363
- } catch (_) { }
331
+ if (isConnected()) {
364
332
  try {
365
333
  ctx.mqttClient.publish("/browser_close", "{}", { qos: 0 });
366
334
  } catch (_) { }
@@ -376,18 +344,15 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
376
344
 
377
345
  function delayedReconnect() {
378
346
  if (ctx._ending) return;
379
- // [Hardened6] debounce: if a reconnect is already scheduled, keep it
347
+ const d = getReconnectDelay();
348
+ logger(`mqtt reconnect in ${d}ms`, "info");
349
+
380
350
  if (ctx._reconnectTimer) {
381
- logger("mqtt reconnect already scheduled - debounce", "warn");
382
- return;
351
+ clearTimeout(ctx._reconnectTimer);
352
+ ctx._reconnectTimer = null;
383
353
  }
384
- let d = getReconnectDelay();
385
- // Always add a little extra jitter on the scheduled path (even when d is small)
386
- if (d > 0) d += Math.floor(Math.random() * 1500);
387
- logger(d === 0 ? "mqtt reconnecting immediately" : `mqtt reconnect in ${d}ms`, "info");
388
354
 
389
355
  ctx._reconnectTimer = setTimeout(() => {
390
- ctx._reconnectTimer = null;
391
356
  if (!ctx._ending) {
392
357
  isReconnecting = false;
393
358
  getSeqIDWrapper();
@@ -395,7 +360,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
395
360
  }, d);
396
361
  }
397
362
 
398
- function forceCycle() /* hardened6 */ {
363
+ function forceCycle() {
399
364
  if (ctx._cycling) {
400
365
  logger("mqtt force cycle already in progress", "warn");
401
366
  return;
@@ -404,13 +369,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
404
369
  logger("mqtt force cycle skipped - ending", "warn");
405
370
  return;
406
371
  }
407
- // [Hardened7] minimum 10 min between forced cycles
408
- const now = Date.now();
409
- if (ctx._lastForceCycleAt && (now - ctx._lastForceCycleAt) < MIN_FORCE_CYCLE_MS) {
410
- logger("mqtt force cycle skipped - too soon since last cycle", "warn");
411
- return;
412
- }
413
- ctx._lastForceCycleAt = now;
414
372
 
415
373
  ctx._cycling = true;
416
374
  ctx._ending = true;
@@ -418,21 +376,14 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
418
376
 
419
377
  stopHeartbeat();
420
378
 
421
- const finish = () => {
422
- ctx._ending = false;
423
- ctx._cycling = false;
424
- if (conf.reconnectAfterStop || conf.autoReconnect !== false) {
425
- delayedReconnect();
426
- }
427
- };
428
-
429
379
  unsubAll(() => {
430
- try {
431
- endQuietly(finish, true);
432
- } catch (e) {
433
- logger(`mqtt force cycle endQuietly error: ${e && e.message ? e.message : e}`, "warn");
434
- finish();
435
- }
380
+ endQuietly(() => {
381
+ ctx._ending = false;
382
+ ctx._cycling = false;
383
+ if (conf.reconnectAfterStop || conf.autoReconnect !== false) {
384
+ delayedReconnect();
385
+ }
386
+ });
436
387
  });
437
388
  }
438
389
 
@@ -457,16 +408,44 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
457
408
  if (!ctx.mqttClient) return;
458
409
 
459
410
  ctx.mqttClient.removeAllListeners("packetreceive");
460
-
461
- // Do not remove "close" / "error". connectMqtt already owns reconnect.
462
- // Replacing those handlers made every drop run getSeqID (a fresh login)
463
- // and sometimes opened a second socket — that is what suspends the account.
411
+ ctx.mqttClient.removeAllListeners("close");
412
+ ctx.mqttClient.removeAllListeners("error");
413
+
414
+ // [Fixed by xalman] mqtt.js does NOT emit a "pong" event - that was never firing,
415
+ // so lastPongTime was never refreshed and the heartbeat below kept
416
+ // force-reconnecting the account roughly every minute (this is what
417
+ // looked like periodic auto logout). The library's own keepalive
418
+ // (keepalive: 30 in connectMqtt.js) sends PINGREQ/PINGRESP
419
+ // internally; we detect the PINGRESP via "packetreceive" instead.
420
+ // Any other incoming packet (e.g. real messages) also proves the
421
+ // connection is alive, so it counts too.
464
422
  ctx.mqttClient.on("packetreceive", (packet) => {
465
423
  lastPongTime = Date.now();
466
424
  if (packet && packet.cmd === "pingresp") {
467
425
  logger("mqtt pong received", "debug");
468
426
  }
469
427
  });
428
+
429
+ ctx.mqttClient.once("close", () => {
430
+ logger("mqtt connection closed", "warn");
431
+ stopHeartbeat();
432
+ if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
433
+ if (!isReconnecting) {
434
+ isReconnecting = true;
435
+ delayedReconnect();
436
+ }
437
+ }
438
+ });
439
+
440
+ ctx.mqttClient.once("error", (err) => {
441
+ logger(`mqtt error: ${err.message}`, "error");
442
+ if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
443
+ if (!isReconnecting) {
444
+ isReconnecting = true;
445
+ forceCycle();
446
+ }
447
+ }
448
+ });
470
449
  }
471
450
 
472
451
  return function (callback) {
@@ -531,17 +510,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
531
510
 
532
511
  installPostGuard();
533
512
 
534
- if (ctx.mqttClient && ctx.mqttClient.connected) {
535
- logger("mqtt already connected - not opening a second session", "info");
536
- attachClientListeners();
537
- startHeartbeat();
538
- api.stopListening = msgEmitter.stopListening;
539
- api.stopListeningAsync = msgEmitter.stopListeningAsync;
540
- api.forceReconnect = forceCycle;
541
- api.isMqttConnected = isConnected;
542
- return msgEmitter;
543
- }
544
-
545
513
  if (!ctx.firstListen) ctx.lastSeqId = null;
546
514
  ctx.syncToken = undefined;
547
515
  ctx.t_mqttCalled = false;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var utils = require("../../utils/utils");
4
+ var { getTextEffectId, getTextEffectIds } = require("../../utils/textEffects");
4
5
 
5
6
  module.exports = function (defaultFuncs, api, ctx) {
6
7
  return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
@@ -33,6 +34,11 @@ module.exports = function (defaultFuncs, api, ctx) {
33
34
  multitab_env: 0
34
35
  };
35
36
 
37
+ var textEffectId = getTextEffectId(msg);
38
+ if (textEffectId) payload0.text_effect_id = textEffectId;
39
+ var effectArray = getTextEffectIds(msg);
40
+ if (effectArray.length) payload0.text_effect_ids = effectArray;
41
+
36
42
  if (msg.sticker) { payload0.send_type = 2; payload0.sticker_id = msg.sticker; }
37
43
  if (replyToMessage || msg.replyToMessage) {
38
44
  payload0.reply_metadata = {
@@ -65,8 +65,8 @@ function createFallbackNamespaces(api) {
65
65
  setEmoji: bindOptionalMethod(api, "changeThreadEmoji"),
66
66
  setNickname: bindOptionalMethod(api, "changeNickname"),
67
67
  createPoll: bindOptionalMethod(api, "createPoll"),
68
- createThemeAI: bindLiveMethod(api, "createThemeAI"),
69
- getThemePictures: bindLiveMethod(api, "getThemePictures"),
68
+ createThemeAI: bindOptionalMethod(api, "createThemeAI"),
69
+ getThemePictures: bindOptionalMethod(api, "getThemePictures"),
70
70
  delete: bindOptionalMethod(api, "deleteThread"),
71
71
  colors: readOptionalMember(api, "threadColors"),
72
72
  handleMessageRequest: bindOptionalMethod(api, "handleMessageRequest"),
@@ -16,16 +16,16 @@ try {
16
16
  storage: path.join(databasePath, "database.sqlite"),
17
17
  logging: false,
18
18
  pool: {
19
- max: 1,
19
+ max: 5,
20
20
  min: 0,
21
- acquire: 8000,
22
- idle: 5000
21
+ acquire: 30000,
22
+ idle: 10000
23
23
  },
24
24
  retry: {
25
- max: 1
25
+ max: 3
26
26
  },
27
27
  dialectOptions: {
28
- timeout: 8000
28
+ timeout: 5000
29
29
  },
30
30
  isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
31
31
  });
@@ -69,9 +69,6 @@ try {
69
69
  if (!sequelize) {
70
70
  throw new Error("Sequelize instance not initialized");
71
71
  }
72
- await sequelize.query("PRAGMA journal_mode=WAL;");
73
- await sequelize.query("PRAGMA synchronous=NORMAL;");
74
- await sequelize.query("PRAGMA busy_timeout=8000;");
75
72
  await sequelize.sync({ force: false });
76
73
  } catch (error) {
77
74
  console.error("Failed to synchronize models:", error && error.message ? error.message : String(error));
@@ -20,12 +20,12 @@
20
20
  */
21
21
 
22
22
  // One version pin used everywhere. Bump this in one place when needed.
23
- const CHROME_VERSION = "131.0.6778.205"; // [Hardened5] realistic build, not x.0.0.0 (bot-looking)
23
+ const CHROME_VERSION = "139.0.0.0";
24
24
  const CHROME_MAJOR = CHROME_VERSION.split(".")[0];
25
25
 
26
26
  const DEFAULT_IDENTITY = Object.freeze({
27
27
  userAgent: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${CHROME_VERSION} Safari/537.36`,
28
- acceptLanguage: "en-US,en;q=0.9,bn;q=0.8", // mild secondary locale is common in BD/SA users
28
+ acceptLanguage: "en-US,en;q=0.9",
29
29
  secChUa: `"Chromium";v="${CHROME_MAJOR}", "Not;A=Brand";v="24", "Google Chrome";v="${CHROME_MAJOR}"`,
30
30
  secChUaMobile: "?0",
31
31
  secChUaPlatform: '"Windows"',
@@ -14,22 +14,6 @@ const {
14
14
  isPairArrayList,
15
15
  } = require("./helpers");
16
16
 
17
-
18
- // [Hardened5] mild global spacing between FB Graph/API posts to avoid bursty bot patterns.
19
- // Does NOT block forever - only adds a small delay when calls are very close together.
20
- let __lastFbPostAt = 0;
21
- const __MIN_FB_POST_GAP_MS = 180; // ~5-6 req/s max sustained, still fast enough for bots
22
- async function __paceFbPost(url) {
23
- try {
24
- const u = String(url || "");
25
- if (!/facebook\.com|messenger\.com/i.test(u)) return;
26
- const now = Date.now();
27
- const wait = __MIN_FB_POST_GAP_MS - (now - __lastFbPostAt);
28
- if (wait > 0) await new Promise(r => setTimeout(r, wait + Math.floor(Math.random() * 80)));
29
- __lastFbPostAt = Date.now();
30
- } catch (_) {}
31
- }
32
-
33
17
  function cleanGet(url, ctx) {
34
18
  return requestWithRetry(() => client.get(url, cfg()), 3, 1000, ctx);
35
19
  }
@@ -2,19 +2,8 @@
2
2
 
3
3
  const { delay } = require("./client");
4
4
 
5
- // [Hardened5] light spacing for FB hosts to reduce burst fingerprints
6
- let __lastFbAt = 0;
7
- async function __pace() {
8
- const now = Date.now();
9
- const gap = 150 + Math.floor(Math.random() * 100);
10
- const wait = gap - (now - __lastFbAt);
11
- if (wait > 0) await delay(wait);
12
- __lastFbAt = Date.now();
13
- }
14
-
15
5
  async function requestWithRetry(fn, retries = 3, baseDelay = 1000, ctx) {
16
6
  let lastError;
17
- try { await __pace(); } catch (_) {}
18
7
  const emit = (event, payload) => {
19
8
  try {
20
9
  if (ctx && ctx._emitter && typeof ctx._emitter.emit === "function") {
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ const TEXT_EFFECTS = Object.freeze({
4
+ hearts: "1",
5
+ heart: "1",
6
+ love: "1",
7
+ gift: "2",
8
+ present: "2",
9
+ box: "2",
10
+ giftbox: "2",
11
+ fire: "3",
12
+ flame: "3",
13
+ hot: "3",
14
+ confetti: "4",
15
+ confecti: "4",
16
+ party: "4",
17
+ celebrate: "4",
18
+ celebration: "4",
19
+ sparkles: "5",
20
+ sparkle: "5",
21
+ star: "5",
22
+ stars: "5",
23
+ magic: "5"
24
+ });
25
+
26
+ const EFFECT_PROPERTIES = [
27
+ "textEffect",
28
+ "text_effect",
29
+ "text_effect_id",
30
+ "textEffectId",
31
+ "textEffectID",
32
+ "effect",
33
+ "effect_id",
34
+ "effectID",
35
+ "text_effect_name",
36
+ "effectName",
37
+ "effect_name"
38
+ ];
39
+
40
+ function toTextEffectId(effect) {
41
+ if (effect === null || effect === undefined) return null;
42
+ if (typeof effect === "number" && Number.isFinite(effect)) return String(effect);
43
+ if (typeof effect !== "string") return null;
44
+
45
+ const value = effect.trim();
46
+ if (!value) return null;
47
+ return TEXT_EFFECTS[value.toLowerCase()] || value;
48
+ }
49
+
50
+ function getTextEffectId(message) {
51
+ if (!message || typeof message !== "object") return null;
52
+ for (const property of EFFECT_PROPERTIES) {
53
+ if (message[property] !== undefined && message[property] !== null) {
54
+ const effectID = toTextEffectId(message[property]);
55
+ if (effectID) return effectID;
56
+ }
57
+ }
58
+
59
+ const rawIDs = Array.isArray(message.text_effect_ids)
60
+ ? message.text_effect_ids
61
+ : [message.text_effect_ids];
62
+ for (const rawID of rawIDs) {
63
+ const effectID = toTextEffectId(rawID);
64
+ if (effectID) return effectID;
65
+ }
66
+ return null;
67
+ }
68
+
69
+ function getTextEffectIds(message) {
70
+ if (!message || typeof message !== "object") return [];
71
+ const rawIDs = Array.isArray(message.text_effect_ids)
72
+ ? message.text_effect_ids
73
+ : [message.text_effect_ids];
74
+ const ids = rawIDs
75
+ .map(toTextEffectId)
76
+ .filter(Boolean);
77
+ // [Hardened7] `effect: "fire"` / `textEffect` / `effectName` only produced the single id; the
78
+ // array form (text_effect_ids) stayed empty, and Messenger reads the array. Always send both.
79
+ if (!ids.length) {
80
+ const single = getTextEffectId(message);
81
+ if (single) ids.push(single);
82
+ }
83
+ return ids;
84
+ }
85
+
86
+ module.exports = {
87
+ EFFECT_PROPERTIES,
88
+ TEXT_EFFECTS,
89
+ getTextEffectId,
90
+ getTextEffectIds,
91
+ toTextEffectId
92
+ };
@@ -1,41 +0,0 @@
1
- "use strict";
2
- /**
3
- * Single-instance lock per account. Two processes logged into the same account at the same time
4
- * (overlapping Railway deploys, a forgotten second start) produce Facebook's
5
- * "You can't create multiple sessions" restriction. The lock file lives in FCA_NX_STATE_DIR and is
6
- * refreshed every 30s; a lock not refreshed for 120s (crashed process) is considered stale.
7
- * FCA_NX_INSTANCE_LOCK=off disables it.
8
- */
9
- const fs = require("fs");
10
- const path = require("path");
11
- const STALE_MS = 120000;
12
- let timer = null;
13
-
14
- function acquire(userID) {
15
- if (/^(off|0|false)$/i.test(String(process.env.FCA_NX_INSTANCE_LOCK || ""))) return { ok: true };
16
- const dir = process.env.FCA_NX_STATE_DIR || path.join(process.cwd(), ".fca-nx");
17
- const file = path.join(dir, "instance_" + String(userID || "default") + ".lock");
18
- try {
19
- fs.mkdirSync(dir, { recursive: true });
20
- try {
21
- const cur = JSON.parse(fs.readFileSync(file, "utf8"));
22
- if (cur && cur.pid !== process.pid && Date.now() - cur.at < STALE_MS) {
23
- let alive = true;
24
- try { process.kill(cur.pid, 0); } catch (e) { alive = e.code === "EPERM"; }
25
- // pid namespaces differ between containers, so trust a fresh heartbeat over kill(0)
26
- if (alive || Date.now() - cur.at < 45000) return { ok: false, pid: cur.pid };
27
- }
28
- } catch (_) {}
29
- const beat = () => { try { fs.writeFileSync(file, JSON.stringify({ pid: process.pid, at: Date.now() })); } catch (_) {} };
30
- beat();
31
- if (timer) clearInterval(timer);
32
- timer = setInterval(beat, 30000);
33
- if (timer.unref) timer.unref();
34
- const release = () => { try { const c = JSON.parse(fs.readFileSync(file, "utf8")); if (c.pid === process.pid) fs.unlinkSync(file); } catch (_) {} };
35
- process.once("exit", release);
36
- for (const sig of ["SIGINT", "SIGTERM"]) process.once(sig, () => { release(); process.exit(0); });
37
- } catch (_) { /* never block login because of the lock itself */ }
38
- return { ok: true };
39
- }
40
-
41
- module.exports = { acquire };
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Login-location consistency guard.
5
- *
6
- * Facebook flags accounts that are logged in from many different IPs/locations. Before a
7
- * cookie login we look up the public IP this process uses (through the same proxy/agent the
8
- * bot uses for Facebook), compare it with the IP of the previous login (stored on disk) and:
9
- * - warn loudly when it changed (default), or
10
- * - refuse to log in when FCA_NX_IP_GUARD=block (use with a static proxy / fixed-IP host).
11
- *
12
- * FCA_NX_IP_GUARD=off disables it. FCA_NX_STATE_DIR (default ./.fca-nx) holds the state file;
13
- * on Railway point it at a Volume so it survives deploys.
14
- */
15
-
16
- const fs = require("fs");
17
- const path = require("path");
18
- const logger = require("../../func/logger");
19
-
20
- const ENDPOINTS = [
21
- "https://api.ipify.org?format=json",
22
- "https://ipinfo.io/json"
23
- ];
24
-
25
- function stateFile() {
26
- const dir = process.env.FCA_NX_STATE_DIR || path.join(process.cwd(), ".fca-nx");
27
- return { dir, file: path.join(dir, "last_login_ip.json") };
28
- }
29
-
30
- async function lookupIP(client) {
31
- for (const url of ENDPOINTS) {
32
- try {
33
- const res = await client.get(url, { timeout: 5000, headers: { Accept: "application/json" } });
34
- const ip = res && res.data && (res.data.ip || res.data.query);
35
- if (typeof ip === "string" && ip) return { ip, country: res.data.country || null, region: res.data.region || null };
36
- } catch (_) { /* try next */ }
37
- }
38
- return null;
39
- }
40
-
41
- /** @returns {Promise<{ok:boolean, changed:boolean, ip:string|null, previous:string|null}>} */
42
- async function checkLoginIP(client, userID) {
43
- const mode = String(process.env.FCA_NX_IP_GUARD || "warn").toLowerCase();
44
- if (mode === "off" || mode === "0" || mode === "false") return { ok: true, changed: false, ip: null, previous: null };
45
- const now = await lookupIP(client);
46
- if (!now) {
47
- logger("ipGuard: could not determine public IP (continuing)", "warn");
48
- return { ok: true, changed: false, ip: null, previous: null };
49
- }
50
- const { dir, file } = stateFile();
51
- let all = {};
52
- try { all = JSON.parse(fs.readFileSync(file, "utf8")) || {}; } catch (_) {}
53
- const key = String(userID || "default");
54
- const prev = all[key] && all[key].ip ? all[key] : null;
55
- const changed = !!prev && prev.ip !== now.ip;
56
- if (changed) {
57
- const msg = `ipGuard: login IP changed ${prev.ip} -> ${now.ip}. Logging into the same account from different IPs/locations is a top cause of "automated behaviour", checkpoints and suspensions. Use ONE host with a fixed IP (or a static proxy via the 'proxy' option).`;
58
- if (mode === "block") {
59
- logger(msg + " Login refused (FCA_NX_IP_GUARD=block). Set FCA_NX_IP_GUARD=warn to override.", "error");
60
- return { ok: false, changed: true, ip: now.ip, previous: prev.ip };
61
- }
62
- logger(msg, "warn");
63
- }
64
- try {
65
- fs.mkdirSync(dir, { recursive: true });
66
- all[key] = { ip: now.ip, country: now.country, region: now.region, at: new Date().toISOString() };
67
- fs.writeFileSync(file, JSON.stringify(all, null, 2));
68
- } catch (_) {}
69
- return { ok: true, changed, ip: now.ip, previous: prev ? prev.ip : null };
70
- }
71
-
72
- module.exports = { checkLoginIP, lookupIP };