ayman-fca 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ayman-fca",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Facebook Chat API for Node.js — مكتبة KIRA بوت | © 2025 Ayman",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "LICENSE"
22
22
  ],
23
23
  "scripts": {
24
- "test": "echo \"ayman-fca v1.0 by Ayman\""
24
+ "test": "echo \"ayman-fca v1.0.1 by Ayman\""
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
@@ -60,7 +60,7 @@
60
60
  "form-data": "^4.0.0",
61
61
  "gradient-string": "^2.0.2",
62
62
  "https-proxy-agent": "^7.0.0",
63
- "mqtt": "^5.3.4",
63
+ "mqtt": "^4.3.7",
64
64
  "sequelize": "^6.37.6",
65
65
  "sqlite3": "^5.1.7",
66
66
  "tough-cookie": "^4.1.4",
@@ -1,24 +1,15 @@
1
1
  // ============================================================
2
2
  // AYMAN-FCA v2.0 — MQTT Core Connection
3
3
  // © 2025 Ayman. All Rights Reserved.
4
- //
5
- // 🔑 أسرار الاستمرارية في هذا الملف:
6
- // • UUID جديد لكل دورة اتصال (يخدع Facebook)
7
- // • keepalive 60s (أكثر استقراراً من 10s)
8
- // • connectTimeout 15s (كافٍ للشبكات البطيئة)
9
- // • User-Agent عشوائي في كل اتصال
10
- // • معالجة offline/close/error بذكاء
11
- // • حد أقصى 15 محاولة مع backoff تصاعدي
12
4
  // ============================================================
13
5
  "use strict";
14
6
 
15
7
  const { formatID } = require("../../../utils/format");
16
8
 
17
- const DEFAULT_RECONNECT_MS = 3000;
18
- const T_MS_WAIT_MS = 12000;
19
- const MAX_RECONNECT = 15;
9
+ const DEFAULT_RECONNECT_MS = 3000;
10
+ const T_MS_WAIT_MS = 12000;
11
+ const MAX_RECONNECT = 15;
20
12
 
21
- // ✅ من ws3: UUID جديد لكل دورة — يمنع Facebook من تتبع الجلسة
22
13
  function generateUUID() {
23
14
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
24
15
  const r = Math.random() * 16 | 0;
@@ -26,13 +17,44 @@ function generateUUID() {
26
17
  });
27
18
  }
28
19
 
29
- // User-Agent عشوائي لكل اتصال MQTT
30
- const CHROME_VERSIONS = ["120.0.0.0","122.0.0.0","124.0.0.0","126.0.0.0"];
20
+ const CHROME_VERSIONS = ["120.0.0.0", "122.0.0.0", "124.0.0.0", "126.0.0.0"];
31
21
  function randomUA() {
32
22
  const v = CHROME_VERSIONS[Math.floor(Math.random() * CHROME_VERSIONS.length)];
33
23
  return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${v} Safari/537.36`;
34
24
  }
35
25
 
26
+ // ── Banner ───────────────────────────────────────────────────
27
+ let _bannerShown = false;
28
+ function showBanner() {
29
+ if (_bannerShown) return;
30
+ _bannerShown = true;
31
+ const R = "\x1b[0m", B = "\x1b[1m";
32
+ const CY = "\x1b[36m", GD = "\x1b[33m", GR = "\x1b[32m", MG = "\x1b[35m", BL = "\x1b[34m";
33
+ const lines = [
34
+ "",
35
+ `${CY}${B} █████╗ ██╗ ██╗███╗ ███╗ █████╗ ███╗ ██╗${R}`,
36
+ `${CY}${B} ██╔══██╗╚██╗ ██╔╝████╗ ████║██╔══██╗████╗ ██║${R}`,
37
+ `${GD}${B} ███████║ ╚████╔╝ ██╔████╔██║███████║██╔██╗ ██║${R}`,
38
+ `${GD}${B} ██╔══██║ ╚██╔╝ ██║╚██╔╝██║██╔══██║██║╚██╗██║${R}`,
39
+ `${MG}${B} ██║ ██║ ██║ ██║ ╚═╝ ██║██║ ██║██║ ╚████║${R}`,
40
+ `${MG}${B} ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝${R}`,
41
+ "",
42
+ `${BL}${B} ███████╗ ██████╗ █████╗ ${R}`,
43
+ `${BL}${B} ██╔════╝██╔════╝██╔══██╗${R}`,
44
+ `${CY}${B} █████╗ ██║ ███████║${R}`,
45
+ `${CY}${B} ██╔══╝ ██║ ██╔══██║${R}`,
46
+ `${GR}${B} ██║ ╚██████╗██║ ██║${R}`,
47
+ `${GR}${B} ╚═╝ ╚═════╝╚═╝ ╚═╝${R}`,
48
+ "",
49
+ `${GD}${B} ╔══════════════════════════════════════╗${R}`,
50
+ `${GD}${B} ║ AYMAN-FCA v2.0 — by Ayman 🚀 ║${R}`,
51
+ `${GD}${B} ║ Facebook Chat API for Node.js ║${R}`,
52
+ `${GD}${B} ╚══════════════════════════════════════╝${R}`,
53
+ "",
54
+ ];
55
+ lines.forEach(l => process.stderr.write(l + "\n"));
56
+ }
57
+
36
58
  module.exports = function createListenMqtt(deps) {
37
59
  const {
38
60
  WebSocket, mqtt, HttpsProxyAgent, buildStream, buildProxy,
@@ -46,23 +68,17 @@ module.exports = function createListenMqtt(deps) {
46
68
  function scheduleReconnect(delayMs) {
47
69
  if (ctx._reconnectTimer) return;
48
70
  if (ctx._ending) return;
49
-
50
71
  if (ctx._reconnectAttempts >= MAX_RECONNECT) {
51
72
  logger(`[ AYMAN ] MQTT وصل الحد الأقصى (${MAX_RECONNECT}) — إيقاف`, "error");
52
73
  ctx._reconnectAttempts = 0;
53
74
  globalCallback({ type: "stop_listen", error: "max_reconnect_reached" }, null);
54
75
  return;
55
76
  }
56
-
57
- const d = ctx._mqttOpt?.reconnectDelayMs || DEFAULT_RECONNECT_MS;
58
- const ms = typeof delayMs === "number" ? delayMs : d;
77
+ const ms = typeof delayMs === "number" ? delayMs : (ctx._mqttOpt?.reconnectDelayMs || DEFAULT_RECONNECT_MS);
59
78
  ctx._reconnectAttempts++;
60
-
61
79
  logger(`[ AYMAN ] MQTT إعادة اتصال بعد ${ms}ms (${ctx._reconnectAttempts}/${MAX_RECONNECT})`, "warn");
62
-
63
80
  ctx._reconnectTimer = setTimeout(() => {
64
81
  ctx._reconnectTimer = null;
65
- // ✅ UUID جديد عند كل إعادة اتصال
66
82
  ctx.clientId = generateUUID();
67
83
  if (!ctx._ending) listenMqtt(defaultFuncs, api, ctx, globalCallback);
68
84
  }, ms);
@@ -94,29 +110,28 @@ module.exports = function createListenMqtt(deps) {
94
110
  protocolId: "MQIsdp",
95
111
  protocolVersion: 3,
96
112
  username: JSON.stringify(username),
97
- clean: true,
113
+ clean: false, // ✅ إصلاح puback error
98
114
  wsOptions: {
99
115
  headers: {
100
- Cookie: cookies,
101
- Origin: "https://www.facebook.com",
102
- "User-Agent": ua,
103
- Referer: "https://www.facebook.com/",
104
- Host: "edge-chat.facebook.com",
105
- Connection: "Upgrade",
106
- Pragma: "no-cache",
107
- "Cache-Control": "no-cache",
108
- Upgrade: "websocket",
109
- "Sec-WebSocket-Version": "13",
110
- "Accept-Encoding": "gzip, deflate, br",
111
- "Accept-Language": "ar,en-US;q=0.9,en;q=0.8",
116
+ Cookie: cookies,
117
+ Origin: "https://www.facebook.com",
118
+ "User-Agent": ua,
119
+ Referer: "https://www.facebook.com/",
120
+ Host: "edge-chat.facebook.com",
121
+ Connection: "Upgrade",
122
+ Pragma: "no-cache",
123
+ "Cache-Control": "no-cache",
124
+ Upgrade: "websocket",
125
+ "Sec-WebSocket-Version": "13",
126
+ "Accept-Encoding": "gzip, deflate, br",
127
+ "Accept-Language": "ar,en-US;q=0.9,en;q=0.8",
112
128
  "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits"
113
129
  },
114
- origin: "https://www.facebook.com",
115
- protocolVersion: 13,
116
- binaryType: "arraybuffer",
130
+ origin: "https://www.facebook.com",
131
+ protocolVersion: 13,
132
+ binaryType: "arraybuffer",
117
133
  handshakeTimeout: 15000
118
134
  },
119
- // ✅ keepalive 60s — أكثر استقراراً
120
135
  keepalive: 60,
121
136
  reschedulePings: true,
122
137
  reconnectPeriod: 0,
@@ -133,17 +148,13 @@ module.exports = function createListenMqtt(deps) {
133
148
  );
134
149
  const mqttClient = ctx.mqttClient;
135
150
 
136
- // ─── Error ───────────────────────────────────────────────
137
151
  mqttClient.on("error", function(err) {
138
152
  const msg = String(err?.message || err || "");
139
-
140
153
  if ((ctx._ending || ctx._cycling) && /No subscription existed|client disconnecting/i.test(msg)) return;
141
-
142
154
  if (/Not logged in|blocked the login|401|403/i.test(msg)) {
143
155
  try { if (mqttClient?.connected) mqttClient.end(true); } catch (_) {}
144
156
  return emitAuth(ctx, api, globalCallback, /blocked/i.test(msg) ? "login_blocked" : "not_logged_in", msg);
145
157
  }
146
-
147
158
  logger(`[ AYMAN ] MQTT خطأ: ${msg}`, "error");
148
159
  try { if (mqttClient?.connected) mqttClient.end(true); } catch (_) {}
149
160
  if (ctx._ending || ctx._cycling) return;
@@ -151,10 +162,9 @@ module.exports = function createListenMqtt(deps) {
151
162
  else globalCallback({ type: "stop_listen", error: msg }, null);
152
163
  });
153
164
 
154
- // ─── Connect ─────────────────────────────────────────────
155
165
  mqttClient.on("connect", function() {
156
166
  ctx._reconnectAttempts = 0;
157
-
167
+ showBanner();
158
168
  if (!process.env.AymanFcaOnline) {
159
169
  logger("[ AYMAN-FCA ] KIRA متصل بـ Facebook ✅", "info");
160
170
  process.env.AymanFcaOnline = "1";
@@ -177,7 +187,6 @@ module.exports = function createListenMqtt(deps) {
177
187
  mqttClient.publish("/foreground_state", JSON.stringify({ foreground: chatOn }), { qos: 1 });
178
188
  mqttClient.publish("/set_client_settings", JSON.stringify({ make_user_available_when_in_foreground: true }), { qos: 1 });
179
189
 
180
- // ✅ T_MS_WAIT timeout
181
190
  let rTimeout = setTimeout(() => {
182
191
  rTimeout = null;
183
192
  if (ctx._ending) return;
@@ -195,7 +204,6 @@ module.exports = function createListenMqtt(deps) {
195
204
  };
196
205
  });
197
206
 
198
- // ─── Message ─────────────────────────────────────────────
199
207
  mqttClient.on("message", function(topic, message) {
200
208
  if (ctx._ending) return;
201
209
  try {
@@ -239,7 +247,6 @@ module.exports = function createListenMqtt(deps) {
239
247
  }
240
248
  });
241
249
 
242
- // ─── Close / Offline / Disconnect ────────────────────────
243
250
  mqttClient.on("close", function() {
244
251
  if (ctx._ending || ctx._cycling) return;
245
252
  logger("[ AYMAN ] MQTT انقطع — إعادة اتصال", "warn");