alicezetion 1.3.5 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/Extra/Database/index.js +469 -0
  4. package/Extra/ExtraAddons.js +82 -0
  5. package/Extra/ExtraFindUID.js +62 -0
  6. package/Extra/ExtraGetThread.js +340 -0
  7. package/Extra/ExtraScreenShot.js +430 -0
  8. package/Extra/ExtraUptimeRobot.js +38 -0
  9. package/Extra/Html/Classic/script.js +119 -0
  10. package/Extra/Html/Classic/style.css +8 -0
  11. package/Extra/Security/AES_256_GCM/index.js +0 -0
  12. package/Extra/Security/Base/Step_1.js +6 -0
  13. package/Extra/Security/Base/Step_2.js +22 -0
  14. package/Extra/Security/Base/Step_3.js +22 -0
  15. package/Extra/Security/Base/index.js +173 -0
  16. package/Extra/Security/Index.js +5 -0
  17. package/Extra/Security/Step_1.js +6 -0
  18. package/Extra/Security/Step_2.js +22 -0
  19. package/Extra/Security/Step_3.js +22 -0
  20. package/Extra/Src/Change_Environment.js +24 -0
  21. package/Extra/Src/Check_Update.js +67 -0
  22. package/Extra/Src/History.js +115 -0
  23. package/Extra/Src/Instant_Update.js +65 -0
  24. package/Extra/Src/Last-Run.js +65 -0
  25. package/Extra/Src/Premium.js +81 -0
  26. package/Extra/Src/Release_Memory.js +41 -0
  27. package/Extra/Src/Websocket.js +213 -0
  28. package/Extra/Src/image/checkmate.jpg +0 -0
  29. package/Extra/Src/uuid.js +137 -0
  30. package/Func/AcceptAgreement.js +31 -0
  31. package/Func/ClearCache.js +64 -0
  32. package/Func/ReportV1.js +54 -0
  33. package/Language/index.json +217 -0
  34. package/Main.js +1211 -0
  35. package/broadcast.js +40 -0
  36. package/index.js +367 -560
  37. package/leiamnash/Dev_Horizon_Data.js +125 -0
  38. package/leiamnash/Premium.js +25 -0
  39. package/leiamnash/Screenshot.js +83 -0
  40. package/leiamnash/addExternalModule.js +7 -10
  41. package/leiamnash/addUserToGroup.js +17 -51
  42. package/leiamnash/changeAdminStatus.js +0 -0
  43. package/leiamnash/changeArchivedStatus.js +12 -26
  44. package/leiamnash/changeAvt.js +85 -0
  45. package/leiamnash/changeBio.js +6 -18
  46. package/leiamnash/changeBlockedStatus.js +3 -14
  47. package/leiamnash/changeGroupImage.js +16 -39
  48. package/leiamnash/changeNickname.js +11 -25
  49. package/leiamnash/changeThreadColor.js +10 -19
  50. package/leiamnash/changeThreadEmoji.js +10 -23
  51. package/leiamnash/chat.js +111 -196
  52. package/leiamnash/createNewGroup.js +12 -28
  53. package/leiamnash/createPoll.js +13 -24
  54. package/leiamnash/deleteMessage.js +12 -23
  55. package/leiamnash/deleteThread.js +11 -24
  56. package/leiamnash/forwardAttachment.js +13 -25
  57. package/leiamnash/getAccessToken.js +28 -0
  58. package/leiamnash/getCurrentUserID.js +1 -1
  59. package/leiamnash/getEmojiUrl.js +2 -4
  60. package/leiamnash/getFriendsList.js +11 -22
  61. package/leiamnash/getMessage.js +80 -0
  62. package/leiamnash/getThreadHistory.js +59 -167
  63. package/leiamnash/getThreadInfo.js +247 -28
  64. package/leiamnash/getThreadList.js +41 -66
  65. package/leiamnash/getThreadMain.js +220 -0
  66. package/leiamnash/getThreadPictures.js +17 -37
  67. package/leiamnash/getUID.js +59 -0
  68. package/leiamnash/getUserID.js +9 -13
  69. package/leiamnash/getUserInfo.js +67 -26
  70. package/leiamnash/getUserInfoMain.js +65 -0
  71. package/leiamnash/getUserInfoV2.js +32 -0
  72. package/leiamnash/getUserInfoV3.js +63 -0
  73. package/leiamnash/getUserInfoV4.js +55 -0
  74. package/leiamnash/getUserInfoV5.js +61 -0
  75. package/leiamnash/handleFriendRequest.js +12 -27
  76. package/leiamnash/handleMessageRequest.js +15 -31
  77. package/leiamnash/httpGet.js +13 -16
  78. package/leiamnash/httpPost.js +12 -16
  79. package/leiamnash/httpPostFormData.js +41 -0
  80. package/leiamnash/listenMqtt.js +301 -200
  81. package/leiamnash/logout.js +13 -20
  82. package/leiamnash/markAsDelivered.js +11 -21
  83. package/leiamnash/markAsRead.js +11 -21
  84. package/leiamnash/markAsReadAll.js +11 -18
  85. package/leiamnash/markAsSeen.js +9 -17
  86. package/leiamnash/muteThread.js +10 -15
  87. package/leiamnash/removeUserFromGroup.js +15 -45
  88. package/leiamnash/resolvePhotoUrl.js +8 -16
  89. package/leiamnash/searchForThread.js +10 -20
  90. package/leiamnash/sendMessage.js +379 -0
  91. package/leiamnash/sendTypingIndicator.js +9 -32
  92. package/leiamnash/setMessageReaction.js +12 -20
  93. package/leiamnash/setPostReaction.js +100 -74
  94. package/leiamnash/setTitle.js +13 -25
  95. package/leiamnash/threadColors.js +18 -36
  96. package/leiamnash/unfriend.js +9 -18
  97. package/leiamnash/unsendMessage.js +8 -17
  98. package/logger.js +66 -0
  99. package/package.json +49 -34
  100. package/replit.nix +1 -3
  101. package/utils.js +593 -108
  102. package/leiamnash/getThreadHistoryDeprecated.js +0 -93
  103. package/leiamnash/getThreadInfoDeprecated.js +0 -80
  104. package/leiamnash/getThreadListDeprecated.js +0 -75
@@ -1,169 +1,225 @@
1
- /*
1
+ /* eslint-disable no-redeclare */
2
+ "use strict";
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+ const mqtt = require('mqtt');
6
+ const Websocket = require('ws');
7
+ const HttpsProxyAgent = require('https-proxy-agent');
8
+ const EventEmitter = require('events');
9
+ const Duplexify = require('duplexify');
10
+ const Transform = require('readable-stream').Transform;
11
+ var identity = function () { };
12
+ var form = {};
13
+ var getSeqID = function () { };
2
14
 
3
- A L I C E » this project recode by one
4
- person LeiamNash
5
- this will only work on
6
- project alice
7
15
 
8
- */
16
+ var topics = ["/ls_req","/ls_resp","/legacy_web","/webrtc","/rtc_multi","/onevc","/br_sr","/sr_res","/t_ms","/thread_typing","/orca_typing_notifications","/notify_disconnect","/orca_presence","/inbox","/mercury", "/messaging_events", "/orca_message_notifications", "/pp","/webrtc_response"];
9
17
 
10
- "use strict";
18
+ /* [ Noti ? ]
19
+ ! "/br_sr", //Notification
20
+ * => Need to publish /br_sr right after this
21
+
22
+ ! "/notify_disconnect",
23
+ * => Need to publish /messenger_sync_create_queue right after this
11
24
 
12
- var utils = require("../utils");
13
- var log = require("npmlog");
14
- var mqtt = require('mqtt');
15
- var websocket = require('websocket-stream');
16
- var HttpsProxyAgent = require('https-proxy-agent');
17
- const EventEmitter = require('events');
25
+ ! "/orca_presence",
26
+ * => Will receive /sr_res right here.
27
+ */
28
+
29
+ var WebSocket_Global;
30
+
31
+ function buildProxy() {
32
+ var Proxy = new Transform({
33
+ objectMode: false
34
+ });
35
+
36
+ Proxy._write = function socketWriteNode(chunk, enc, next) {
37
+ if (WebSocket_Global.readyState !== WebSocket_Global.OPEN) {
38
+ return next();
39
+ }
40
+
41
+ if (typeof chunk === 'string') {
42
+ chunk = new Buffer.from(chunk, 'utf8');
43
+ }
44
+ WebSocket_Global.send(chunk, next);
45
+ };
46
+
47
+ Proxy._flush = function(done) {
48
+ WebSocket_Global.close();
49
+ done();
50
+ };
51
+
52
+ Proxy._writev = function(chunks, cb) {
53
+ var buffers = new Array(chunks.length);
54
+ for (var i = 0; i < chunks.length; i++) {
55
+ if (typeof chunks[i].chunk === 'string') {
56
+ buffers[i] = new Buffer.from(chunks[i], 'utf8');
57
+ } else {
58
+ buffers[i] = chunks[i].chunk;
59
+ }
60
+ }
61
+ this._write(new Buffer.concat(buffers), 'binary', cb);
62
+ };
63
+
64
+ return Proxy;
65
+ }
66
+
67
+ function buildStream(options, WebSocket, Proxy) {
68
+ const Stream = Duplexify(undefined, undefined, options);
69
+ Stream.socket = WebSocket;
70
+
71
+ WebSocket
72
+ .onclose = function() {
73
+ Stream.end();
74
+ Stream.destroy();
75
+ };
76
+ WebSocket
77
+ .onerror = function(err) {
78
+ Stream.destroy(err);
79
+ };
80
+ WebSocket
81
+ .onmessage = function(event) {
82
+ var data = event.data;
83
+ if (data instanceof ArrayBuffer) data = new Buffer.from(data);
84
+ else data = new Buffer.from(data, 'utf8');
85
+ Stream.push(data);
86
+ };
87
+ WebSocket
88
+ .onopen = function() {
89
+ Stream.setReadable(Proxy);
90
+ Stream.setWritable(Proxy);
91
+ Stream.emit('connect');
92
+ };
93
+ WebSocket_Global = WebSocket;
94
+ Proxy.on('close', function() { WebSocket.close(); });
95
+ return Stream;
96
+ }
18
97
 
19
- var identity = function() {};
20
- var form = {};
21
- var getSeqID = function() {};
22
-
23
- var topics = [
24
- "/legacy_web",
25
- "/webrtc",
26
- "/rtc_multi",
27
- "/onevc",
28
- "/br_sr", //Notification
29
- //Need to publish /br_sr right after this
30
- "/sr_res",
31
- "/t_ms",
32
- "/thread_typing",
33
- "/orca_typing_notifications",
34
- "/notify_disconnect",
35
- //Need to publish /messenger_sync_create_queue right after this
36
- "/orca_presence",
37
- //Will receive /sr_res right here.
38
-
39
- "/inbox",
40
- "/mercury",
41
- "/messaging_events",
42
- "/orca_message_notifications",
43
- "/pp",
44
- "/webrtc_response",
45
- ];
46
98
 
47
99
  function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
48
- //Don't really know what this does but I think it's for the active state?
100
+ //Don't really know what this does but I think it's for the act`ive state?
49
101
  //TODO: Move to ctx when implemented
50
102
  var chatOn = ctx.globalOptions.online;
51
103
  var foreground = false;
52
104
 
53
- var sessionID = Math.floor(Math.random() * 9007199254740991) + 1;
54
- var username = {
55
- u: ctx.userID,
56
- s: sessionID,
57
- chat_on: chatOn,
58
- fg: foreground,
59
- d: utils.getGUID(),
60
- ct: "websocket",
61
- //App id from facebook
62
- aid: "219994525426954",
63
- mqtt_sid: "",
64
- cp: 3,
65
- ecp: 10,
66
- st: [],
67
- pm: [],
68
- dc: "",
69
- no_auto_fg: true,
70
- gas: null,
71
- pack: []
72
- };
73
- var cookies = ctx.jar.getCookies("https://www.facebook.com").join("; ");
105
+ var sessionID = Math.floor((Math.random() * Number.MAX_SAFE_INTEGER)+1);
106
+ var username = {u: ctx.userID,s: sessionID,chat_on: chatOn,fg: foreground,d: utils.getGUID(),ct: "websocket",aid: "219994525426954", mqtt_sid: "",cp: 3,ecp: 10,st: [],pm: [],dc: "",no_auto_fg: true,gas: null,pack: []};
107
+ var cookies = ctx.jar.getCookies('https://www.facebook.com').join("; ");
74
108
 
75
109
  var host;
76
110
  if (ctx.mqttEndpoint) host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
77
111
  else if (ctx.region) host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLocaleLowerCase()}&sid=${sessionID}`;
78
112
  else host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
79
113
 
80
- var options = {
114
+ var options = {
81
115
  clientId: "mqttwsclient",
82
116
  protocolId: 'MQIsdp',
83
117
  protocolVersion: 3,
84
- username: JSON.stringify(username),
118
+ username: JSON.stringify(username),
85
119
  clean: true,
86
120
  wsOptions: {
87
121
  headers: {
88
122
  'Cookie': cookies,
89
123
  'Origin': 'https://www.facebook.com',
90
- 'User-Agent': ctx.globalOptions.userAgent,
124
+ 'User-Agent': (ctx.globalOptions.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36'),
91
125
  'Referer': 'https://www.facebook.com/',
92
126
  'Host': new URL(host).hostname //'edge-chat.facebook.com'
93
127
  },
94
128
  origin: 'https://www.facebook.com',
95
- protocolVersion: 13
129
+ protocolVersion: 13,
130
+ binaryType: 'arraybuffer',
96
131
  },
97
- keepalive: 10,
98
- reschedulePings: false
132
+ keepalive: 60,
133
+ reschedulePings: true,
134
+ reconnectPeriod: 3
99
135
  };
100
136
 
101
137
  if (typeof ctx.globalOptions.proxy != "undefined") {
102
138
  var agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
103
139
  options.wsOptions.agent = agent;
104
140
  }
141
+ ctx.mqttClient = new mqtt.Client(_ => buildStream(options, new Websocket(host, options.wsOptions), buildProxy()), options);
142
+ global.mqttClient = ctx.mqttClient;
105
143
 
106
- ctx.mqttClient = new mqtt.Client(_ => websocket(host, options.wsOptions), options);
107
-
108
- var mqttClient = ctx.mqttClient;
144
+ global.mqttClient.on('error', function (err) {
145
+ log.error("listenMqtt", err);
146
+ global.mqttClient.end();
109
147
 
110
- mqttClient.on('error', function(err) {
111
- log.error("listenMqtt", "Connection refused: Server unavailable. Exiting...");
112
- mqttClient.end();
113
- process.exit();
114
148
  if (ctx.globalOptions.autoReconnect) getSeqID();
115
149
  else {
116
- globalCallback({ type: "stop_listen", error: "Connection refused: Server unavailable" }, null);
150
+ globalCallback({ type: "stop_listen", error: "Server Đã Sập - Auto Restart" }, null);
151
+ return process.exit(1);
117
152
  }
118
153
  });
119
154
 
120
- mqttClient.on('connect', function() {
121
- topics.forEach(topicsub => mqttClient.subscribe(topicsub));
155
+ global.mqttClient.on('connect', function () {
156
+ if (!global.Fca.Data.Setup || global.Fca.Data.Setup == undefined) {
157
+ if (global.Fca.Require.FastConfig.RestartMQTT_Minutes != 0 && global.Fca.Data.StopListening != true) {
158
+ global.Fca.Data.Setup = true;
159
+ setTimeout(() => {
160
+ global.Fca.Require.logger.Warning("Closing MQTT Client...");
161
+ ctx.mqttClient.end();
162
+ global.Fca.Require.logger.Warning("Reconnecting MQTT Client...");
163
+ global.Fca.Data.Setup = false;
164
+ getSeqID();
165
+ }, Number(global.Fca.Require.FastConfig.RestartMQTT_Minutes) * 60 * 1000);
166
+ }
167
+ }
168
+ if (process.env.OnStatus == undefined) {
169
+ global.Fca.Require.logger.Normal("Bạn Đang Sài Phiên Bản: Premium Access");
170
+ if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) == 0) {
171
+ // something
172
+ }
173
+ else if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes < 10)) {
174
+ log.warn("AutoRestartMinutes","The number of minutes to automatically restart must be more than 10 minutes");
175
+ }
176
+ else if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) < 0) {
177
+ log.warn("AutoRestartMinutes","Invalid auto-restart minutes!");
178
+ }
179
+ else {
180
+ global.Fca.Require.logger.Normal(global.Fca.getText(global.Fca.Require.Language.Src.AutoRestart,global.Fca.Require.FastConfig.AutoRestartMinutes));
181
+ global.Fca.Require.logger.Normal("Auto Restart MQTT Client After: " + global.Fca.Require.FastConfig.RestartMQTT_Minutes + " Minutes");
182
+ setInterval(() => {
183
+ global.Fca.Require.logger.Normal(global.Fca.Require.Language.Src.OnRestart);
184
+ process.exit(1);
185
+ }, Number(global.Fca.Require.FastConfig.AutoRestartMinutes) * 60000);
186
+ }
187
+ require('../broadcast');
188
+ process.env.OnStatus = true;
189
+ }
190
+
191
+ topics.forEach(topicsub => global.mqttClient.subscribe(topicsub));
122
192
 
123
193
  var topic;
124
194
  var queue = {
125
- sync_api_version: 10,
126
- max_deltas_able_to_process: 1000,
195
+ sync_api_version: 11,
196
+ max_deltas_able_to_process: 100,
127
197
  delta_batch_size: 500,
128
198
  encoding: "JSON",
129
199
  entity_fbid: ctx.userID,
130
200
  };
131
201
 
132
- if (ctx.syncToken) {
133
- topic = "/messenger_sync_get_diffs";
134
- queue.last_seq_id = ctx.lastSeqId;
135
- queue.sync_token = ctx.syncToken;
136
- } else {
137
- topic = "/messenger_sync_create_queue";
138
- queue.initial_titan_sequence_id = ctx.lastSeqId;
139
- queue.device_params = null;
140
- }
202
+ topic = "/messenger_sync_create_queue";
203
+ queue.initial_titan_sequence_id = ctx.lastSeqId;
204
+ queue.device_params = null;
141
205
 
142
- mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
143
- //onbot
144
- mqttClient.publish("/foreground_state", JSON.stringify({"foreground": chatOn}), {qos: 1});
206
+ global.mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
145
207
 
146
- var rTimeout = setTimeout(function() {
147
- mqttClient.end();
208
+ var rTimeout = setTimeout(function () {
209
+ global.mqttClient.end();
148
210
  getSeqID();
149
- }, 5000);
211
+ }, 3000);
150
212
 
151
- ctx.tmsWait = function() {
213
+ ctx.tmsWait = function () {
152
214
  clearTimeout(rTimeout);
153
- ctx.globalOptions.emitReady ? globalCallback({
154
- type: "ready",
155
- error: null
156
- }) : "";
215
+ ctx.globalOptions.emitReady ? globalCallback({type: "ready",error: null}) : '';
157
216
  delete ctx.tmsWait;
158
217
  };
159
218
  });
160
219
 
161
- mqttClient.on('message', function(topic, message, _packet) {
162
- try {
163
- var jsonMessage = JSON.parse(message);
164
- } catch (ex) {
165
- return log.error("listenMqtt", "SyntaxError: Unexpected token in JSON at position 0");
166
- }
220
+ global.mqttClient.on('message', function (topic, message, _packet) {
221
+ const jsonMessage = JSON.parse(message.toString());
222
+
167
223
  if (topic === "/t_ms") {
168
224
  if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
169
225
 
@@ -173,7 +229,6 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
173
229
  }
174
230
 
175
231
  if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
176
-
177
232
  //If it contains more than 1 delta
178
233
  for (var i in jsonMessage.deltas) {
179
234
  var delta = jsonMessage.deltas[i];
@@ -186,7 +241,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
186
241
  from: jsonMessage.sender_fbid.toString(),
187
242
  threadID: utils.formatID((jsonMessage.thread || jsonMessage.sender_fbid).toString())
188
243
  };
189
- (function() { globalCallback(null, typ); })();
244
+ (function () { globalCallback(null, typ); })();
190
245
  } else if (topic === "/orca_presence") {
191
246
  if (!ctx.globalOptions.updatePresence) {
192
247
  for (var i in jsonMessage.list) {
@@ -200,41 +255,64 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
200
255
  timestamp: data["l"] * 1000,
201
256
  statuses: data["p"]
202
257
  };
203
- (function() { globalCallback(null, presence); })();
258
+ (function () { globalCallback(null, presence); })();
204
259
  }
205
260
  }
206
261
  }
207
262
 
208
263
  });
209
264
 
210
- mqttClient.on('close', function() {
211
- //(function () { globalCallback("Connection closed."); })();
212
- // client.end();
265
+ process.on('SIGINT', function () {
266
+ LogUptime();process.kill(process.pid);
267
+ });
268
+
269
+ process.on('exit', () => {
270
+ LogUptime();
213
271
  });
272
+
214
273
  }
215
274
 
275
+ function LogUptime() {
276
+ var uptime = process.uptime();
277
+ var { join } = require('path');
278
+ if (global.Fca.Require.fs.existsSync(join(__dirname, '../CountTime.json'))) {
279
+ var Time1 = (Number(global.Fca.Require.fs.readFileSync(join(__dirname, '../CountTime.json'), 'utf8')) || 0);
280
+ global.Fca.Require.fs.writeFileSync(join(__dirname, '../CountTime.json'), String(Number(uptime) + Time1), 'utf8');
281
+ }
282
+ else {
283
+ var Time1 = 0;
284
+ global.Fca.Require.fs.writeFileSync(join(__dirname, '../CountTime.json'), String(Number(uptime) + Time1), 'utf8');
285
+ }
286
+ }
216
287
  function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
217
288
  if (v.delta.class == "NewMessage") {
218
289
  //Not tested for pages
219
290
  if (ctx.globalOptions.pageID && ctx.globalOptions.pageID != v.queue) return;
220
291
 
221
292
  (function resolveAttachmentUrl(i) {
222
- if (v.delta.attachments && (i == v.delta.attachments.length)) {
293
+ if (v.delta.attachments && (i == v.delta.attachments.length) || utils.getType(v.delta.attachments) !== "Array") {
223
294
  var fmtMsg;
224
295
  try {
225
296
  fmtMsg = utils.formatDeltaMessage(v);
226
297
  } catch (err) {
227
- return globalCallback({
228
- error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
229
- detail: err,
230
- res: v,
231
- type: "parse_error"
232
- });
298
+ return log.error("Lỗi Nhẹ", err);
299
+ }
300
+ global.Fca.Data.event = fmtMsg;
301
+ try {
302
+ var { updateMessageCount,getData,hasData } = require('../Extra/ExtraGetThread');
303
+ if (hasData(fmtMsg.threadID)) {
304
+ var x = getData(fmtMsg.threadID);
305
+ x.messageCount+=1;
306
+ updateMessageCount(fmtMsg.threadID,x);
307
+ }
308
+ }
309
+ catch (e) {
310
+ //temp
233
311
  }
234
312
  if (fmtMsg)
235
313
  if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
236
314
 
237
- return !ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID ? undefined : (function() { globalCallback(null, fmtMsg); })();
315
+ return !ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID ? undefined : (function () { globalCallback(null, fmtMsg); })();
238
316
  } else {
239
317
  if (v.delta.attachments && (v.delta.attachments[i].mercury.attach_type == "photo")) {
240
318
  api.resolvePhotoUrl(v.delta.attachments[i].fbid, (err, url) => {
@@ -252,7 +330,7 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
252
330
  for (var i in clientPayload.deltas) {
253
331
  var delta = clientPayload.deltas[i];
254
332
  if (delta.deltaMessageReaction && !!ctx.globalOptions.listenEvents) {
255
- (function() {
333
+ (function () {
256
334
  globalCallback(null, {
257
335
  type: "message_reaction",
258
336
  threadID: (delta.deltaMessageReaction.threadKey.threadFbId ? delta.deltaMessageReaction.threadKey.threadFbId : delta.deltaMessageReaction.threadKey.otherUserFbId).toString(),
@@ -263,7 +341,7 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
263
341
  });
264
342
  })();
265
343
  } else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
266
- (function() {
344
+ (function () {
267
345
  globalCallback(null, {
268
346
  type: "message_unsend",
269
347
  threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
@@ -275,10 +353,11 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
275
353
  })();
276
354
  } else if (delta.deltaMessageReply) {
277
355
  //Mention block - #1
278
- var mdata = delta.deltaMessageReply.message === undefined ? [] :
279
- delta.deltaMessageReply.message.data === undefined ? [] :
280
- delta.deltaMessageReply.message.data.prng === undefined ? [] :
281
- JSON.parse(delta.deltaMessageReply.message.data.prng);
356
+ var mdata =
357
+ delta.deltaMessageReply.message === undefined ? [] :
358
+ delta.deltaMessageReply.message.data === undefined ? [] :
359
+ delta.deltaMessageReply.message.data.prng === undefined ? [] :
360
+ JSON.parse(delta.deltaMessageReply.message.data.prng);
282
361
  var m_id = mdata.map(u => u.i);
283
362
  var m_offset = mdata.map(u => u.o);
284
363
  var m_length = mdata.map(u => u.l);
@@ -292,7 +371,7 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
292
371
  threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
293
372
  messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
294
373
  senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
295
- attachments: delta.deltaMessageReply.message.attachments.map(function(att) {
374
+ attachments: delta.deltaMessageReply.message.attachments.map(function (att) {
296
375
  var mercury = JSON.parse(att.mercuryJSON);
297
376
  Object.assign(att, mercury);
298
377
  return att;
@@ -317,10 +396,11 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
317
396
 
318
397
  if (delta.deltaMessageReply.repliedToMessage) {
319
398
  //Mention block - #2
320
- mdata = delta.deltaMessageReply.repliedToMessage === undefined ? [] :
321
- delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
322
- delta.deltaMessageReply.repliedToMessage.data.prng === undefined ? [] :
323
- JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
399
+ mdata =
400
+ delta.deltaMessageReply.repliedToMessage === undefined ? [] :
401
+ delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
402
+ delta.deltaMessageReply.repliedToMessage.data.prng === undefined ? [] :
403
+ JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
324
404
  m_id = mdata.map(u => u.i);
325
405
  m_offset = mdata.map(u => u.o);
326
406
  m_length = mdata.map(u => u.l);
@@ -333,7 +413,7 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
333
413
  threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
334
414
  messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
335
415
  senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
336
- attachments: delta.deltaMessageReply.repliedToMessage.attachments.map(function(att) {
416
+ attachments: delta.deltaMessageReply.repliedToMessage.attachments.map(function (att) {
337
417
  var mercury = JSON.parse(att.mercuryJSON);
338
418
  Object.assign(att, mercury);
339
419
  return att;
@@ -381,6 +461,7 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
381
461
  for (var n in fetchData.message.ranges) mobj[fetchData.message.ranges[n].entity.id] = (fetchData.message.text || "").substr(fetchData.message.ranges[n].offset, fetchData.message.ranges[n].length);
382
462
 
383
463
  callbackToReturn.messageReply = {
464
+ type: "Message",
384
465
  threadID: callbackToReturn.threadID,
385
466
  messageID: fetchData.message_id,
386
467
  senderID: fetchData.message_sender.id.toString(),
@@ -403,38 +484,35 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
403
484
  };
404
485
  })
405
486
  .catch(err => log.error("forcedFetch", err))
406
- .finally(function() {
487
+ .finally(function () {
407
488
  if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
408
- !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function() { globalCallback(null, callbackToReturn); })();
489
+ !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
409
490
  });
410
491
  } else callbackToReturn.delta = delta;
411
-
492
+
412
493
  if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
413
494
 
414
- return !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function() { globalCallback(null, callbackToReturn); })();
495
+ return !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
415
496
  }
416
497
  }
417
498
  return;
418
499
  }
419
500
  }
420
-
421
- if (v.delta.class !== "NewMessage" && !ctx.globalOptions.listenEvents) return;
422
501
  switch (v.delta.class) {
423
- case "ReadReceipt":
502
+ case "ReadReceipt": {
424
503
  var fmtMsg;
425
504
  try {
426
505
  fmtMsg = utils.formatDeltaReadReceipt(v.delta);
427
506
  } catch (err) {
428
- return globalCallback({
429
- error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
430
- detail: err,
431
- res: v.delta,
432
- type: "parse_error"
433
- });
507
+ return log.error("Lỗi Nhẹ", err);
434
508
  }
435
- return (function() { globalCallback(null, fmtMsg); })();
436
- case "AdminTextMessage":
509
+ return (function () { globalCallback(null, fmtMsg); })();
510
+ }
511
+ case "AdminTextMessage": {
437
512
  switch (v.delta.type) {
513
+ case "joinable_group_link_mode_change":
514
+ case "magic_words":
515
+ case "pin_messages_v2":
438
516
  case "change_thread_theme":
439
517
  case "change_thread_icon":
440
518
  case "change_thread_nickname":
@@ -447,20 +525,15 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
447
525
  try {
448
526
  fmtMsg = utils.formatDeltaEvent(v.delta);
449
527
  } catch (err) {
450
- return globalCallback({
451
- error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
452
- detail: err,
453
- res: v.delta,
454
- type: "parse_error"
455
- });
528
+ console.log(v.delta)
529
+ return log.error("Lỗi Nhẹ", err);
456
530
  }
457
- return (function() { globalCallback(null, fmtMsg); })();
458
- default:
459
- return;
460
- }
531
+ return (function () { globalCallback(null, fmtMsg); })();
532
+ }
461
533
  break;
462
- //For group images
463
- case "ForcedFetch":
534
+ }
535
+ //For group images
536
+ case "ForcedFetch": {
464
537
  if (!v.delta.threadKey) return;
465
538
  var mid = v.delta.messageId;
466
539
  var tid = v.delta.threadKey.threadFbId;
@@ -495,22 +568,25 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
495
568
  log.info("forcedFetch", fetchData);
496
569
  switch (fetchData.__typename) {
497
570
  case "ThreadImageMessage":
498
- (!ctx.globalOptions.selfListen && fetchData.message_sender.id.toString() === ctx.userID) ||
499
- !ctx.loggedIn ? undefined : (function() {
500
- globalCallback(null, {
501
- type: "change_thread_image",
502
- threadID: utils.formatID(tid.toString()),
503
- snippet: fetchData.snippet,
504
- timestamp: fetchData.timestamp_precise,
505
- author: fetchData.message_sender.id,
506
- image: {
507
- attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
508
- width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
509
- height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
510
- url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri
511
- }
512
- });
513
- })();
571
+ (!ctx.globalOptions.selfListen &&
572
+ fetchData.message_sender.id.toString() === ctx.userID) ||
573
+ !ctx.loggedIn ?
574
+ undefined :
575
+ (function () {
576
+ globalCallback(null, {
577
+ type: "change_thread_image",
578
+ threadID: utils.formatID(tid.toString()),
579
+ snippet: fetchData.snippet,
580
+ timestamp: fetchData.timestamp_precise,
581
+ author: fetchData.message_sender.id,
582
+ image: {
583
+ attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
584
+ width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
585
+ height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
586
+ url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri
587
+ }
588
+ });
589
+ })();
514
590
  break;
515
591
  case "UserMessage":
516
592
  log.info("ff-Return", {
@@ -573,32 +649,44 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
573
649
  } else log.error("forcedFetch", fetchData);
574
650
  })
575
651
  .catch((err) => log.error("forcedFetch", err));
652
+ }
576
653
  }
577
654
  break;
578
655
  case "ThreadName":
579
656
  case "ParticipantsAddedToGroupThread":
580
- case "ParticipantLeftGroupThread":
657
+ case "ParticipantLeftGroupThread": {
581
658
  var formattedEvent;
582
659
  try {
583
660
  formattedEvent = utils.formatDeltaEvent(v.delta);
584
661
  } catch (err) {
585
- return globalCallback({
586
- error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
587
- detail: err,
588
- res: v.delta,
589
- type: "parse_error"
590
- });
662
+ console.log(err)
663
+ return log.error("Lỗi Nhẹ", err);
664
+ }
665
+ return (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) || !ctx.loggedIn ? undefined : (function () { globalCallback(null, formattedEvent); })();
666
+ }
667
+ case "NewMessage": {
668
+ if (v.delta.attachments != undefined && v.delta.attachments.length == 1 && v.delta.attachments[0].mercury.extensible_attachment != undefined && v.delta.attachments[0].mercury.extensible_attachment.story_attachment.style_list.includes("message_live_location")) {
669
+ v.delta.class = "UserLocation";
670
+ var fmtMsg;
671
+ try {
672
+ fmtMsg = utils.formatDeltaEvent(v.delta);
673
+ } catch (err) {
674
+ console.log(v.delta);
675
+ return log.error("Lỗi Nhẹ", err);
676
+ }
677
+ return (function () { globalCallback(null, fmtMsg); })();
591
678
  }
592
- return (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) || !ctx.loggedIn ? undefined : (function() { globalCallback(null, formattedEvent); })();
679
+ }
680
+ break;
593
681
  }
594
682
  }
595
683
 
684
+
596
685
  function markDelivery(ctx, api, threadID, messageID) {
597
686
  if (threadID && messageID) {
598
687
  api.markAsDelivered(threadID, messageID, (err) => {
599
- if (err) {
600
- log.error("markAsDelivered", err);
601
- } else {
688
+ if (err) log.error("markAsDelivered", err);
689
+ else {
602
690
  if (ctx.globalOptions.autoMarkRead) {
603
691
  api.markAsRead(threadID, (err) => {
604
692
  if (err) log.error("markAsDelivered", err);
@@ -609,7 +697,7 @@ function markDelivery(ctx, api, threadID, messageID) {
609
697
  }
610
698
  }
611
699
 
612
- module.exports = function(defaultFuncs, api, ctx) {
700
+ module.exports = function (defaultFuncs, api, ctx) {
613
701
  var globalCallback = identity;
614
702
  getSeqID = function getSeqID() {
615
703
  ctx.t_mqttCalled = false;
@@ -617,41 +705,54 @@ module.exports = function(defaultFuncs, api, ctx) {
617
705
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
618
706
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
619
707
  .then((resData) => {
620
- if (utils.getType(resData) != "Array") throw { error: "Not logged in", res: resData };
621
- if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
622
- if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
623
- if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
624
- ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
625
- listenMqtt(defaultFuncs, api, ctx, globalCallback);
626
- } else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
708
+ if (utils.getType(resData) != "Array") {
709
+ if (global.Fca.Require.FastConfig.AutoLogin) {
710
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
711
+ return global.Fca.Action('AutoLogin');
712
+ });
713
+ }
714
+ else if (!global.Fca.Require.FastConfig.AutoLogin) {
715
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
716
+ }
717
+ return;
718
+ }
719
+ else {
720
+ if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
721
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
722
+ if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
723
+ ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
724
+ listenMqtt(defaultFuncs, api, ctx, globalCallback);
725
+ }
726
+ else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
727
+ }
627
728
  })
628
729
  .catch((err) => {
629
730
  log.error("getSeqId", err);
630
- if (utils.getType(err) == "Object" && err.error === "Not logged in") ctx.loggedIn = false;
731
+ if (utils.getType(err) == "Object" && err.error === global.Fca.Require.Language.Index.ErrAppState) ctx.loggedIn = false;
631
732
  return globalCallback(err);
632
733
  });
633
734
  };
634
735
 
635
- return function(callback) {
736
+ return function (callback) {
636
737
  class MessageEmitter extends EventEmitter {
637
738
  stopListening(callback) {
638
- callback = callback || (() => {});
739
+ callback = callback || (() => { });
639
740
  globalCallback = identity;
640
741
  if (ctx.mqttClient) {
641
742
  ctx.mqttClient.unsubscribe("/webrtc");
642
743
  ctx.mqttClient.unsubscribe("/rtc_multi");
643
744
  ctx.mqttClient.unsubscribe("/onevc");
644
745
  ctx.mqttClient.publish("/browser_close", "{}");
645
- ctx.mqttClient.end(false, function(...data) {
646
- callback(data);
746
+ ctx.mqttClient.end(false, function (...data) {
647
747
  ctx.mqttClient = undefined;
648
748
  });
649
749
  }
750
+ global.Fca.Data.StopListening = true;
650
751
  }
651
752
  }
652
753
 
653
754
  var msgEmitter = new MessageEmitter();
654
- globalCallback = (callback || function(error, message) {
755
+ globalCallback = (callback || function (error, message) {
655
756
  if (error) return msgEmitter.emit("error", error);
656
757
  msgEmitter.emit("message", message);
657
758
  });