fca-priyansh 16.0.0 → 18.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Extra/Balancer.js +49 -0
- package/Extra/Bypass/956/index.js +234 -0
- package/Extra/Bypass/test/aaaa.json +170 -0
- package/Extra/Bypass/test/index.js +188 -0
- package/Extra/Database/index.js +249 -140
- package/Extra/ExtraAddons.js +35 -33
- package/Extra/ExtraFindUID.js +3 -1
- package/Extra/ExtraGetThread.js +303 -56
- package/Extra/ExtraUptimeRobot.js +15 -3
- package/Extra/Html/Classic/script.js +3 -3
- package/Extra/Security/AES_256_GCM/index.js +0 -0
- package/Extra/Security/Base/Step_1.js +6 -0
- package/Extra/Security/Base/Step_2.js +22 -0
- package/Extra/Security/Base/Step_3.js +22 -0
- package/Extra/Security/Base/index.js +191 -0
- package/Extra/Security/Index.js +5 -146
- package/Extra/Security/Step_1.js +4 -9
- package/Extra/Security/Step_2.js +2 -0
- package/Extra/Security/Step_3.js +4 -2
- package/Extra/Src/Change_Environment.js +1 -1
- package/Extra/Src/Check_Update.js +67 -0
- package/Extra/Src/History.js +2 -2
- package/Extra/Src/Instant_Update.js +65 -0
- package/Extra/Src/Premium.js +35 -38
- package/Extra/Src/Release_Memory.js +160 -0
- package/Extra/Src/Websocket.js +213 -0
- package/Extra/Src/image/checkmate.jpg +0 -0
- package/Extra/Src/test.js +28 -0
- package/Extra/Src/uuid.js +1 -1
- package/Func/AcceptAgreement.js +4 -5
- package/Func/ClearCache.js +7 -7
- package/Func/ReportV1.js +5 -5
- package/LICENSE +1 -4
- package/Language/index.json +59 -8
- package/Main.js +1290 -0
- package/README.md +198 -1
- package/broadcast.js +43 -37
- package/index.js +303 -1704
- package/logger.js +4 -4
- package/package.json +16 -11
- package/src/Dev_Horizon_Data.js +3 -3
- package/src/Dev_getThreadInfoOLD.js +422 -0
- package/src/Dev_shareTest2.js +68 -0
- package/src/Dev_shareTest3.js +71 -0
- package/src/Premium.js +8 -13
- package/src/Screenshot.js +4 -6
- package/src/editMessage.js +53 -0
- package/src/getAccessToken.js +0 -4
- package/src/getFriendsList.js +1 -1
- package/src/getMessage.js +26 -3
- package/src/getThreadHistory.js +1 -1
- package/src/getThreadInfo.js +237 -161
- package/src/getThreadInfoOLD.js +422 -0
- package/src/getThreadMain.js +1 -1
- package/src/getUID.js +3 -3
- package/src/getUserInfo.js +56 -73
- package/src/getUserInfoMain.js +2 -2
- package/src/getUserInfoV2.js +0 -4
- package/src/getUserInfoV3.js +3 -3
- package/src/getUserInfoV4.js +5 -5
- package/src/getUserInfoV5.js +4 -4
- package/src/listenMqtt.js +905 -625
- package/src/listenMqttV1.js +846 -0
- package/src/sendMessage.js +54 -2
- package/src/sendMqttMessage.js +71 -0
- package/src/setPostReaction.js +3 -3
- package/src/shareContact.js +55 -0
- package/src/shareLink.js +58 -0
- package/src/unsendMessage.js +28 -20
- package/src/unsendMqttMessage.js +66 -0
- package/utils.js +1567 -138
- package/.gitattributes +0 -2
- package/gitattributes +0 -2
- package/gitignore.txt +0 -10
package/src/listenMqtt.js
CHANGED
@@ -1,676 +1,956 @@
|
|
1
|
-
/* eslint-disable
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
/* eslint-disable linebreak-style */
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const utils = require('../utils');
|
5
|
+
const log = require('npmlog');
|
6
|
+
const mqtt = require('mqtt');
|
7
|
+
const WebSocket = require('ws');
|
8
|
+
const HttpsProxyAgent = require('https-proxy-agent');
|
8
9
|
const EventEmitter = require('events');
|
9
|
-
|
10
|
-
|
10
|
+
const Duplexify = require('duplexify');
|
11
|
+
const {
|
12
|
+
Transform
|
13
|
+
} = require('stream');
|
14
|
+
var identity = function() {};
|
11
15
|
var form = {};
|
12
|
-
var getSeqID = function
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
16
|
+
var getSeqID = function() {};
|
17
|
+
global.Fca.Data.MsgCount = new Map();
|
18
|
+
global.Fca.Data.event = new Map();
|
19
|
+
|
20
|
+
const 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'];
|
21
|
+
|
22
|
+
let WebSocket_Global;
|
23
|
+
|
24
|
+
function buildProxy() {
|
25
|
+
const Proxy = new Transform({
|
26
|
+
objectMode: false,
|
27
|
+
transform(chunk, enc, next) {
|
28
|
+
if (WebSocket_Global.readyState !== WebSocket_Global.OPEN) {
|
29
|
+
return next();
|
30
|
+
}
|
31
|
+
|
32
|
+
let data;
|
33
|
+
if (typeof chunk === 'string') {
|
34
|
+
data = Buffer.from(chunk, 'utf8');
|
35
|
+
} else {
|
36
|
+
data = chunk;
|
37
|
+
}
|
38
|
+
|
39
|
+
WebSocket_Global.send(data);
|
40
|
+
next();
|
41
|
+
},
|
42
|
+
flush(done) {
|
43
|
+
WebSocket_Global.close();
|
44
|
+
done();
|
45
|
+
},
|
46
|
+
writev(chunks, cb) {
|
47
|
+
const buffers = chunks.map(({ chunk }) => {
|
48
|
+
if (typeof chunk === 'string') {
|
49
|
+
return Buffer.from(chunk, 'utf8');
|
50
|
+
}
|
51
|
+
return chunk;
|
52
|
+
});
|
53
|
+
this._write(Buffer.concat(buffers), 'binary', cb);
|
54
|
+
},
|
55
|
+
});
|
56
|
+
return Proxy;
|
57
|
+
}
|
58
|
+
|
59
|
+
function buildStream(options, WebSocket, Proxy) {
|
60
|
+
const Stream = Duplexify(undefined, undefined, options);
|
61
|
+
Stream.socket = WebSocket;
|
62
|
+
|
63
|
+
WebSocket.onclose = () => {
|
64
|
+
Stream.end();
|
65
|
+
Stream.destroy();
|
66
|
+
};
|
67
|
+
|
68
|
+
WebSocket.onerror = (err) => {
|
69
|
+
Stream.destroy(err);
|
70
|
+
};
|
71
|
+
|
72
|
+
WebSocket.onmessage = (event) => {
|
73
|
+
const data = event.data instanceof ArrayBuffer ? Buffer.from(event.data) : Buffer.from(event.data, 'utf8');
|
74
|
+
Stream.push(data);
|
75
|
+
};
|
76
|
+
|
77
|
+
WebSocket.onopen = () => {
|
78
|
+
Stream.setReadable(Proxy);
|
79
|
+
Stream.setWritable(Proxy);
|
80
|
+
Stream.emit('connect');
|
81
|
+
};
|
82
|
+
|
83
|
+
WebSocket_Global = WebSocket;
|
84
|
+
Proxy.on('close', () => WebSocket.close());
|
85
|
+
|
86
|
+
return Stream;
|
87
|
+
}
|
37
88
|
|
38
89
|
function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
const chatOn = ctx.globalOptions.online;
|
91
|
+
const foreground = false;
|
92
|
+
|
93
|
+
const sessionID = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
|
94
|
+
const GUID = utils.getGUID()
|
95
|
+
const username = {
|
96
|
+
u: ctx.userID,
|
97
|
+
s: sessionID,
|
98
|
+
chat_on: chatOn,
|
99
|
+
fg: foreground,
|
100
|
+
d: GUID,
|
101
|
+
ct: 'websocket',
|
102
|
+
aid: '219994525426954',
|
103
|
+
aids: null,
|
104
|
+
mqtt_sid: '',
|
105
|
+
cp: 3,
|
106
|
+
ecp: 10,
|
107
|
+
st: [],
|
108
|
+
pm: [],
|
109
|
+
dc: '',
|
110
|
+
no_auto_fg: true,
|
111
|
+
gas: null,
|
112
|
+
pack: [],
|
113
|
+
p: null,
|
114
|
+
php_override: ""
|
115
|
+
};
|
116
|
+
|
117
|
+
const cookies = ctx.jar.getCookies('https://www.facebook.com').join('; ');
|
118
|
+
|
119
|
+
let host;
|
120
|
+
if (ctx.mqttEndpoint) {
|
121
|
+
host = `${ctx.mqttEndpoint}&sid=${sessionID}&cid=${GUID}`;
|
122
|
+
} else if (ctx.region) {
|
123
|
+
host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLowerCase()}&sid=${sessionID}&cid=${GUID}`;
|
124
|
+
} else {
|
125
|
+
host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}&cid=${GUID}`;
|
126
|
+
}
|
127
|
+
|
128
|
+
const options = {
|
129
|
+
clientId: 'mqttwsclient',
|
130
|
+
protocolId: 'MQIsdp',
|
131
|
+
protocolVersion: 3,
|
132
|
+
username: JSON.stringify(username),
|
133
|
+
clean: true,
|
134
|
+
wsOptions: {
|
135
|
+
headers: {
|
136
|
+
Cookie: cookies,
|
137
|
+
Origin: 'https://www.facebook.com',
|
138
|
+
'User-Agent': ctx.globalOptions.userAgent,
|
139
|
+
Referer: 'https://www.facebook.com/',
|
140
|
+
Host: new URL(host).hostname,
|
141
|
+
},
|
142
|
+
origin: 'https://www.facebook.com',
|
143
|
+
protocolVersion: 13,
|
144
|
+
binaryType: 'arraybuffer',
|
145
|
+
},
|
146
|
+
keepalive: 60,
|
147
|
+
reschedulePings: true,
|
148
|
+
reconnectPeriod: 3,
|
149
|
+
};
|
150
|
+
|
151
|
+
if (ctx.globalOptions.proxy !== undefined) {
|
152
|
+
const agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
|
153
|
+
options.wsOptions.agent = agent;
|
154
|
+
}
|
155
|
+
|
156
|
+
ctx.mqttClient = new mqtt.Client(() => buildStream(options, new WebSocket(host, options.wsOptions), buildProxy()), options);
|
157
|
+
global.mqttClient = ctx.mqttClient;
|
158
|
+
|
159
|
+
global.mqttClient.on('error', (err) => {
|
160
|
+
log.error('listenMqtt', err);
|
161
|
+
global.mqttClient.end();
|
162
|
+
|
163
|
+
if (ctx.globalOptions.autoReconnect) {
|
164
|
+
getSeqID();
|
165
|
+
} else {
|
166
|
+
globalCallback({
|
167
|
+
type: 'stop_listen',
|
168
|
+
error: 'Server Đã Sập - Auto Restart'
|
169
|
+
}, null);
|
170
|
+
return process.exit(1);
|
171
|
+
}
|
172
|
+
});
|
173
|
+
|
174
|
+
global.mqttClient.on('connect', () => {
|
175
|
+
if (!global.Fca.Data.Setup || global.Fca.Data.Setup === undefined) {
|
176
|
+
if (global.Fca.Require.Priyansh.RestartMQTT_Minutes !== 0 && global.Fca.Data.StopListening !== true) {
|
177
|
+
global.Fca.Data.Setup = true;
|
178
|
+
setTimeout(() => {
|
179
|
+
global.Fca.Require.logger.Warning('Closing MQTT Client...');
|
180
|
+
ctx.mqttClient.end();
|
181
|
+
global.Fca.Require.logger.Warning('Reconnecting MQTT Client...');
|
182
|
+
global.Fca.Data.Setup = false;
|
183
|
+
getSeqID();
|
184
|
+
}, Number(global.Fca.Require.Priyansh.RestartMQTT_Minutes) * 60 * 1000);
|
185
|
+
}
|
186
|
+
}
|
91
187
|
|
92
|
-
if (
|
93
|
-
|
94
|
-
|
188
|
+
if (process.env.OnStatus === undefined) {
|
189
|
+
global.Fca.Require.logger.Normal('Bạn Đang Sài Phiên Bản: Premium Access');
|
190
|
+
|
191
|
+
if (Number(global.Fca.Require.Priyansh.AutoRestartMinutes) === 0) {
|
192
|
+
// something
|
193
|
+
} else if (Number(global.Fca.Require.Priyansh.AutoRestartMinutes) < 10) {
|
194
|
+
log.warn('AutoRestartMinutes', 'The number of minutes to automatically restart must be more than 10 minutes');
|
195
|
+
} else if (Number(global.Fca.Require.Priyansh.AutoRestartMinutes) < 0) {
|
196
|
+
log.warn('AutoRestartMinutes', 'Invalid auto-restart minutes!');
|
197
|
+
} else {
|
198
|
+
global.Fca.Require.logger.Normal(global.Fca.getText(global.Fca.Require.Language.Src.AutoRestart, global.Fca.Require.Priyansh.AutoRestartMinutes));
|
199
|
+
global.Fca.Require.logger.Normal(`Auto Restart MQTT Client After: ${global.Fca.Require.Priyansh.RestartMQTT_Minutes} Minutes`);
|
200
|
+
setTimeout(() => {
|
201
|
+
global.Fca.Require.logger.Normal(global.Fca.Require.Language.Src.OnRestart);
|
202
|
+
process.exit(1);
|
203
|
+
}, Number(global.Fca.Require.Priyansh.AutoRestartMinutes) * 60000);
|
204
|
+
}
|
205
|
+
require('../broadcast').startBroadcasting();
|
206
|
+
const MemoryManager = require('../Extra/Src/Release_Memory');
|
207
|
+
const path = require('path');
|
208
|
+
|
209
|
+
const SettingMemoryManager = {
|
210
|
+
warningThreshold: 0.7,
|
211
|
+
releaseThreshold: 0.8,
|
212
|
+
maxThreshold: 0.9,
|
213
|
+
interval: 300 * 1000,
|
214
|
+
logLevel: 'warn',
|
215
|
+
logFile: path.join(process.cwd(), 'Horizon_Database' ,'memory.log'),
|
216
|
+
smartReleaseEnabled: true,
|
217
|
+
allowLog: (global.Fca.Require.Priyansh.AntiStuckAndMemoryLeak.LogFile.Use || false)
|
218
|
+
};
|
219
|
+
|
220
|
+
const memoryManager = new MemoryManager(SettingMemoryManager);
|
221
|
+
|
222
|
+
memoryManager.autoStart(60 * 60 * 1000);
|
223
|
+
|
224
|
+
if (global.Fca.Require.Priyansh.AntiStuckAndMemoryLeak.AutoRestart.Use) {
|
225
|
+
memoryManager.onMaxMemory(function() {
|
226
|
+
global.Fca.Require.logger.Warning('Memory Usage >= 90% - Auto Restart Avoid Crash');
|
227
|
+
process.exit(1);
|
228
|
+
});
|
229
|
+
}
|
230
|
+
process.env.OnStatus = true;
|
95
231
|
}
|
96
232
|
|
97
|
-
|
233
|
+
topics.forEach((topicsub) => global.mqttClient.subscribe(topicsub));
|
98
234
|
|
99
|
-
var mqttClient = ctx.mqttClient;
|
100
235
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
236
|
+
let topic;
|
237
|
+
const queue = {
|
238
|
+
sync_api_version: 11,
|
239
|
+
max_deltas_able_to_process: 100,
|
240
|
+
delta_batch_size: 500,
|
241
|
+
encoding: 'JSON',
|
242
|
+
entity_fbid: ctx.userID,
|
243
|
+
};
|
107
244
|
|
108
|
-
|
109
|
-
|
245
|
+
topic = "/messenger_sync_create_queue";
|
246
|
+
queue.initial_titan_sequence_id = ctx.lastSeqId;
|
247
|
+
queue.device_params = null;
|
110
248
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
delta_batch_size: 500,
|
116
|
-
encoding: "JSON",
|
117
|
-
entity_fbid: ctx.userID,
|
118
|
-
};
|
249
|
+
global.mqttClient.publish(topic, JSON.stringify(queue), {
|
250
|
+
qos: 1,
|
251
|
+
retain: false
|
252
|
+
});
|
119
253
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
254
|
+
var rTimeout = setTimeout(function() {
|
255
|
+
global.mqttClient.end();
|
256
|
+
getSeqID();
|
257
|
+
}, 3000);
|
258
|
+
|
259
|
+
ctx.tmsWait = function() {
|
260
|
+
clearTimeout(rTimeout);
|
261
|
+
ctx.globalOptions.emitReady ? globalCallback({
|
262
|
+
type: "ready",
|
263
|
+
error: null
|
264
|
+
}) : '';
|
265
|
+
delete ctx.tmsWait;
|
266
|
+
};
|
267
|
+
});
|
268
|
+
|
269
|
+
const HandleMessage = function(topic, message, _packet) {
|
270
|
+
const jsonMessage = JSON.parse(message.toString());
|
271
|
+
if (topic === "/t_ms") {
|
272
|
+
if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
|
273
|
+
|
274
|
+
if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
|
275
|
+
ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
|
276
|
+
ctx.syncToken = jsonMessage.syncToken;
|
277
|
+
}
|
278
|
+
|
279
|
+
if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
|
280
|
+
//If it contains more than 1 delta
|
281
|
+
for (var i in jsonMessage.deltas) {
|
282
|
+
var delta = jsonMessage.deltas[i];
|
283
|
+
parseDelta(defaultFuncs, api, ctx, globalCallback, {
|
284
|
+
"delta": delta
|
285
|
+
});
|
286
|
+
}
|
287
|
+
} else if (topic === "/ls_resp") {
|
288
|
+
const payload = JSON.parse(jsonMessage.payload); //'{"name":null,"step":[1,[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"replaceOptimsiticMessage","7192532113093667880","mid.$gABfX5li9LA6VdUymnWPRAdlkiawo"]]]],[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"mailboxTaskCompletionApiOnTaskCompletion",[19,"415"],true]]]],[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"removeTask",[19,"415"],[9]]]]]]}'
|
289
|
+
const request_ID = jsonMessage.request_id;
|
290
|
+
|
291
|
+
if (ctx.callback_Task[request_ID] != undefined && ctx.callback_Task[request_ID].type != undefined) {
|
292
|
+
const {
|
293
|
+
callback,
|
294
|
+
type
|
295
|
+
} = ctx.callback_Task[request_ID];
|
296
|
+
const Data = new getRespData(type, payload);
|
297
|
+
if (!callback) {
|
298
|
+
return;
|
299
|
+
}
|
300
|
+
else if (!Data) {
|
301
|
+
callback("Something went wrong 🐳", null);
|
124
302
|
} else {
|
125
|
-
|
126
|
-
|
127
|
-
|
303
|
+
callback(null, Data);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
} else if (topic === "/thread_typing" || topic === "/orca_typing_notifications") {
|
307
|
+
var typ = {
|
308
|
+
type: "typ",
|
309
|
+
isTyping: !!jsonMessage.state,
|
310
|
+
from: jsonMessage.sender_fbid.toString(),
|
311
|
+
threadID: utils.formatID((jsonMessage.thread || jsonMessage.sender_fbid).toString())
|
312
|
+
};
|
313
|
+
(function() {
|
314
|
+
globalCallback(null, typ);
|
315
|
+
})();
|
316
|
+
} else if (topic === "/orca_presence") {
|
317
|
+
if (!ctx.globalOptions.updatePresence) {
|
318
|
+
for (var i in jsonMessage.list) {
|
319
|
+
var data = jsonMessage.list[i];
|
320
|
+
var userID = data["u"];
|
321
|
+
|
322
|
+
var presence = {
|
323
|
+
type: "presence",
|
324
|
+
userID: userID.toString(),
|
325
|
+
//Convert to ms
|
326
|
+
timestamp: data["l"] * 1000,
|
327
|
+
statuses: data["p"]
|
328
|
+
};
|
329
|
+
(function() {
|
330
|
+
globalCallback(null, presence);
|
331
|
+
})();
|
128
332
|
}
|
333
|
+
}
|
334
|
+
}
|
129
335
|
|
130
|
-
|
336
|
+
};
|
131
337
|
|
132
|
-
|
133
|
-
mqttClient.end();
|
134
|
-
getSeqID();
|
135
|
-
}, 5000);
|
338
|
+
global.mqttClient.on('message', HandleMessage);
|
136
339
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
error: null
|
142
|
-
}) : "";
|
143
|
-
delete ctx.tmsWait;
|
144
|
-
};
|
145
|
-
});
|
340
|
+
process.on('SIGINT', () => {
|
341
|
+
LogUptime();
|
342
|
+
process.kill(process.pid);
|
343
|
+
});
|
146
344
|
|
147
|
-
|
148
|
-
try {
|
149
|
-
var jsonMessage = JSON.parse(message);
|
150
|
-
} catch (ex) {
|
151
|
-
return log.error("listenMqtt", ex);
|
152
|
-
}
|
153
|
-
if (topic === "/t_ms") {
|
154
|
-
if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
|
345
|
+
process.on('exit', LogUptime);
|
155
346
|
|
156
|
-
if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
|
157
|
-
ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
|
158
|
-
ctx.syncToken = jsonMessage.syncToken;
|
159
|
-
}
|
160
347
|
|
161
|
-
|
348
|
+
}
|
162
349
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
350
|
+
function getRespData(Type, payload) {
|
351
|
+
try {
|
352
|
+
switch (Type) {
|
353
|
+
case "sendMqttMessage": {
|
354
|
+
return {
|
355
|
+
type: Type,
|
356
|
+
threadID: payload.step[1][2][2][1][2], //this is sick bro
|
357
|
+
messageID: payload.step[1][2][2][1][3],
|
358
|
+
payload: payload.step[1][2]
|
359
|
+
};
|
360
|
+
}
|
361
|
+
default: { //!very LAZY :> cook yourself
|
362
|
+
return {
|
363
|
+
Data: payload.step[1][2][2][1],
|
364
|
+
type: Type,
|
365
|
+
payload: payload.step[1][2]
|
366
|
+
};
|
367
|
+
}
|
368
|
+
}
|
369
|
+
} catch (e) {
|
370
|
+
return null;
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
function LogUptime() {
|
375
|
+
const uptime = process.uptime();
|
376
|
+
const {
|
377
|
+
join
|
378
|
+
} = require('path');
|
379
|
+
const filePath = join(__dirname, '../CountTime.json');
|
380
|
+
|
381
|
+
let time1;
|
382
|
+
if (global.Fca.Require.fs.existsSync(filePath)) {
|
383
|
+
time1 = Number(global.Fca.Require.fs.readFileSync(filePath, 'utf8')) || 0;
|
384
|
+
} else {
|
385
|
+
time1 = 0;
|
386
|
+
}
|
387
|
+
|
388
|
+
global.Fca.Require.fs.writeFileSync(filePath, String(Number(uptime) + time1), 'utf8');
|
389
|
+
}
|
390
|
+
|
391
|
+
if (global.Fca.Require.Priyansh.AntiGetInfo.AntiGetThreadInfo) {
|
392
|
+
setInterval(() => {
|
393
|
+
try {
|
394
|
+
const { updateMessageCount, getData, hasData } = require('../Extra/ExtraGetThread');
|
395
|
+
const Data = global.Fca.Data.MsgCount;
|
396
|
+
const Arr = Array.from(Data.keys());
|
397
|
+
for (let i of Arr) {
|
398
|
+
const Count = parseInt(Data.get(i));
|
399
|
+
if (hasData(i)) {
|
400
|
+
let x = getData(i);
|
401
|
+
x.messageCount += Count;
|
402
|
+
updateMessageCount(i, x);
|
403
|
+
Data.delete(i);
|
190
404
|
}
|
191
405
|
}
|
406
|
+
|
407
|
+
} catch (e) {
|
408
|
+
console.log(e);
|
192
409
|
}
|
410
|
+
}, 30 * 1000);
|
411
|
+
}
|
193
412
|
|
194
|
-
|
413
|
+
function parseDelta(defaultFuncs, api, ctx, globalCallback, {
|
414
|
+
delta
|
415
|
+
}) {
|
416
|
+
if (delta.class === 'NewMessage') {
|
417
|
+
if (ctx.globalOptions.pageID && ctx.globalOptions.pageID !== delta.queue) return;
|
195
418
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
419
|
+
const resolveAttachmentUrl = (i) => {
|
420
|
+
if (!delta.attachments || i === delta.attachments.length || utils.getType(delta.attachments) !== 'Array') {
|
421
|
+
let fmtMsg;
|
422
|
+
try {
|
423
|
+
fmtMsg = utils.formatDeltaMessage(delta);
|
424
|
+
} catch (err) {
|
425
|
+
return log.error('Lỗi Nhẹ', err);
|
426
|
+
}
|
427
|
+
|
428
|
+
if (fmtMsg) {
|
429
|
+
const isGroup = fmtMsg.isGroup;
|
430
|
+
const threadID = fmtMsg.threadID;
|
431
|
+
const messageID = fmtMsg.messageID;
|
432
|
+
|
433
|
+
global.Fca.Data.event.set("Data", {
|
434
|
+
isGroup,
|
435
|
+
threadID,
|
436
|
+
messageID
|
437
|
+
});
|
438
|
+
|
439
|
+
if (global.Fca.Require.Priyansh.AntiGetInfo.AntiGetThreadInfo) {
|
440
|
+
global.Fca.Data.MsgCount.set(fmtMsg.threadID, ((global.Fca.Data.MsgCount.get(fmtMsg.threadID)) + 1 || 1));
|
441
|
+
}
|
201
442
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
if (ctx.globalOptions.pageID && ctx.globalOptions.pageID != v.queue) return;
|
443
|
+
if (ctx.globalOptions.autoMarkDelivery) {
|
444
|
+
markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
|
445
|
+
}
|
206
446
|
|
207
|
-
|
208
|
-
|
209
|
-
|
447
|
+
if (!ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID) return;
|
448
|
+
globalCallback(null, fmtMsg);
|
449
|
+
}
|
450
|
+
} else {
|
451
|
+
const attachment = delta.attachments[i];
|
452
|
+
if (attachment.mercury.attach_type === 'photo') {
|
453
|
+
api.resolvePhotoUrl(attachment.fbid, (err, url) => {
|
454
|
+
if (!err) attachment.mercury.metadata.url = url;
|
455
|
+
resolveAttachmentUrl(i + 1);
|
456
|
+
});
|
457
|
+
} else {
|
458
|
+
resolveAttachmentUrl(i + 1);
|
459
|
+
}
|
460
|
+
}
|
461
|
+
};
|
462
|
+
|
463
|
+
resolveAttachmentUrl(0);
|
464
|
+
} else if (delta.class === 'ClientPayload') {
|
465
|
+
const clientPayload = utils.decodeClientPayload(delta.payload);
|
466
|
+
if (clientPayload && clientPayload.deltas) {
|
467
|
+
for (const delta of clientPayload.deltas) {
|
468
|
+
if (delta.deltaMessageReaction && !!ctx.globalOptions.listenEvents) {
|
469
|
+
const messageReaction = {
|
470
|
+
type: 'message_reaction',
|
471
|
+
threadID: (delta.deltaMessageReaction.threadKey.threadFbId ? delta.deltaMessageReaction.threadKey.threadFbId : delta.deltaMessageReaction.threadKey.otherUserFbId).toString(),
|
472
|
+
messageID: delta.deltaMessageReaction.messageId,
|
473
|
+
reaction: delta.deltaMessageReaction.reaction,
|
474
|
+
senderID: delta.deltaMessageReaction.senderId.toString(),
|
475
|
+
userID: delta.deltaMessageReaction.userId.toString(),
|
476
|
+
};
|
477
|
+
globalCallback(null, messageReaction);
|
478
|
+
} else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
|
479
|
+
const messageUnsend = {
|
480
|
+
type: 'message_unsend',
|
481
|
+
threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
|
482
|
+
messageID: delta.deltaRecallMessageData.messageID,
|
483
|
+
senderID: delta.deltaRecallMessageData.senderID.toString(),
|
484
|
+
deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
|
485
|
+
timestamp: delta.deltaRecallMessageData.timestamp,
|
486
|
+
};
|
487
|
+
globalCallback(null, messageUnsend);
|
488
|
+
} else if (delta.deltaMessageReply) {
|
489
|
+
const mdata =
|
490
|
+
delta.deltaMessageReply.message === undefined ?
|
491
|
+
[] :
|
492
|
+
delta.deltaMessageReply.message.data === undefined ?
|
493
|
+
[] :
|
494
|
+
delta.deltaMessageReply.message.data.prng === undefined ?
|
495
|
+
[] :
|
496
|
+
JSON.parse(delta.deltaMessageReply.message.data.prng);
|
497
|
+
|
498
|
+
const m_id = mdata.map((u) => u.i);
|
499
|
+
const m_offset = mdata.map((u) => u.o);
|
500
|
+
const m_length = mdata.map((u) => u.l);
|
501
|
+
|
502
|
+
const mentions = {};
|
503
|
+
for (let i = 0; i < m_id.length; i++) {
|
504
|
+
mentions[m_id[i]] = (delta.deltaMessageReply.message.body || '').substring(m_offset[i], m_offset[i] + m_length[i]);
|
505
|
+
}
|
506
|
+
|
507
|
+
const callbackToReturn = {
|
508
|
+
type: 'message_reply',
|
509
|
+
threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
|
510
|
+
messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
|
511
|
+
senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
|
512
|
+
attachments: ( delta.deltaMessageReply.message.attachments || [] )
|
513
|
+
.map((att) => {
|
514
|
+
const mercury = JSON.parse(att.mercuryJSON);
|
515
|
+
Object.assign(att, mercury);
|
516
|
+
return att;
|
517
|
+
})
|
518
|
+
.map((att) => {
|
519
|
+
let x;
|
210
520
|
try {
|
211
|
-
|
212
|
-
} catch (
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
res: v,
|
217
|
-
type: "parse_error"
|
218
|
-
});
|
521
|
+
x = utils._formatAttachment(att);
|
522
|
+
} catch (ex) {
|
523
|
+
x = att;
|
524
|
+
x.error = ex;
|
525
|
+
x.type = 'unknown';
|
219
526
|
}
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
527
|
+
return x;
|
528
|
+
}),
|
529
|
+
args: (delta.deltaMessageReply.message.body || '').trim().split(/\s+/),
|
530
|
+
body: delta.deltaMessageReply.message.body || '',
|
531
|
+
isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,
|
532
|
+
mentions,
|
533
|
+
timestamp: parseInt(delta.deltaMessageReply.message.messageMetadata.timestamp),
|
534
|
+
participantIDs: (delta.deltaMessageReply.message.participants || []).map((e) => e.toString()),
|
535
|
+
};
|
536
|
+
|
537
|
+
if (delta.deltaMessageReply.repliedToMessage) {
|
538
|
+
const mdata =
|
539
|
+
delta.deltaMessageReply.repliedToMessage === undefined ?
|
540
|
+
[] :
|
541
|
+
delta.deltaMessageReply.repliedToMessage.data === undefined ?
|
542
|
+
[] :
|
543
|
+
delta.deltaMessageReply.repliedToMessage.data.prng === undefined ?
|
544
|
+
[] :
|
545
|
+
JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
|
546
|
+
|
547
|
+
const m_id = mdata.map((u) => u.i);
|
548
|
+
const m_offset = mdata.map((u) => u.o);
|
549
|
+
const m_length = mdata.map((u) => u.l);
|
550
|
+
|
551
|
+
const rmentions = {};
|
552
|
+
for (let i = 0; i < m_id.length; i++) {
|
553
|
+
rmentions[m_id[i]] = (delta.deltaMessageReply.repliedToMessage.body || '').substring(m_offset[i], m_offset[i] + m_length[i]);
|
231
554
|
}
|
232
|
-
})(0);
|
233
|
-
}
|
234
555
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
senderID: delta.deltaMessageReaction.senderId.toString(),
|
248
|
-
userID: delta.deltaMessageReaction.userId.toString()
|
249
|
-
});
|
250
|
-
})();
|
251
|
-
} else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
|
252
|
-
(function () {
|
253
|
-
globalCallback(null, {
|
254
|
-
type: "message_unsend",
|
255
|
-
threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
|
256
|
-
messageID: delta.deltaRecallMessageData.messageID,
|
257
|
-
senderID: delta.deltaRecallMessageData.senderID.toString(),
|
258
|
-
deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
|
259
|
-
timestamp: delta.deltaRecallMessageData.timestamp
|
260
|
-
});
|
261
|
-
})();
|
262
|
-
} else if (delta.deltaMessageReply) {
|
263
|
-
//Mention block - #1
|
264
|
-
var mdata =
|
265
|
-
delta.deltaMessageReply.message === undefined ? [] :
|
266
|
-
delta.deltaMessageReply.message.data === undefined ? [] :
|
267
|
-
delta.deltaMessageReply.message.data.prng === undefined ? [] :
|
268
|
-
JSON.parse(delta.deltaMessageReply.message.data.prng);
|
269
|
-
var m_id = mdata.map(u => u.i);
|
270
|
-
var m_offset = mdata.map(u => u.o);
|
271
|
-
var m_length = mdata.map(u => u.l);
|
272
|
-
|
273
|
-
var mentions = {};
|
274
|
-
|
275
|
-
for (var i = 0; i < m_id.length; i++) mentions[m_id[i]] = (delta.deltaMessageReply.message.body || "").substring(m_offset[i], m_offset[i] + m_length[i]);
|
276
|
-
//Mention block - 1#
|
277
|
-
var callbackToReturn = {
|
278
|
-
type: "message_reply",
|
279
|
-
threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
|
280
|
-
messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
|
281
|
-
senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
|
282
|
-
attachments: delta.deltaMessageReply.message.attachments.map(function (att) {
|
283
|
-
var mercury = JSON.parse(att.mercuryJSON);
|
284
|
-
Object.assign(att, mercury);
|
285
|
-
return att;
|
286
|
-
}).map(att => {
|
287
|
-
var x;
|
288
|
-
try {
|
289
|
-
x = utils._formatAttachment(att);
|
290
|
-
} catch (ex) {
|
291
|
-
x = att;
|
292
|
-
x.error = ex;
|
293
|
-
x.type = "unknown";
|
294
|
-
}
|
295
|
-
return x;
|
296
|
-
}),
|
297
|
-
args: (delta.deltaMessageReply.message.body || "").trim().split(/\s+/),
|
298
|
-
body: (delta.deltaMessageReply.message.body || ""),
|
299
|
-
isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,
|
300
|
-
mentions: mentions,
|
301
|
-
timestamp: delta.deltaMessageReply.message.messageMetadata.timestamp,
|
302
|
-
participantIDs: (delta.deltaMessageReply.message.participants || []).map(e => e.toString())
|
303
|
-
};
|
304
|
-
|
305
|
-
if (delta.deltaMessageReply.repliedToMessage) {
|
306
|
-
//Mention block - #2
|
307
|
-
mdata =
|
308
|
-
delta.deltaMessageReply.repliedToMessage === undefined ? [] :
|
309
|
-
delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
|
310
|
-
delta.deltaMessageReply.repliedToMessage.data.prng === undefined ? [] :
|
311
|
-
JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
|
312
|
-
m_id = mdata.map(u => u.i);
|
313
|
-
m_offset = mdata.map(u => u.o);
|
314
|
-
m_length = mdata.map(u => u.l);
|
315
|
-
|
316
|
-
var rmentions = {};
|
317
|
-
|
318
|
-
for (var i = 0; i < m_id.length; i++) rmentions[m_id[i]] = (delta.deltaMessageReply.repliedToMessage.body || "").substring(m_offset[i], m_offset[i] + m_length[i]);
|
319
|
-
//Mention block - 2#
|
320
|
-
callbackToReturn.messageReply = {
|
321
|
-
threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
|
322
|
-
messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
|
323
|
-
senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
|
324
|
-
attachments: delta.deltaMessageReply.repliedToMessage.attachments.map(function (att) {
|
325
|
-
var mercury = JSON.parse(att.mercuryJSON);
|
326
|
-
Object.assign(att, mercury);
|
327
|
-
return att;
|
328
|
-
}).map(att => {
|
329
|
-
var x;
|
330
|
-
try {
|
331
|
-
x = utils._formatAttachment(att);
|
332
|
-
} catch (ex) {
|
333
|
-
x = att;
|
334
|
-
x.error = ex;
|
335
|
-
x.type = "unknown";
|
336
|
-
}
|
337
|
-
return x;
|
338
|
-
}),
|
339
|
-
args: (delta.deltaMessageReply.repliedToMessage.body || "").trim().split(/\s+/),
|
340
|
-
body: delta.deltaMessageReply.repliedToMessage.body || "",
|
341
|
-
isGroup: !!delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,
|
342
|
-
mentions: rmentions,
|
343
|
-
timestamp: delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp,
|
344
|
-
participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map(e => e.toString())
|
345
|
-
};
|
346
|
-
} else if (delta.deltaMessageReply.replyToMessageId) {
|
347
|
-
return defaultFuncs
|
348
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, {
|
349
|
-
"av": ctx.globalOptions.pageID,
|
350
|
-
"queries": JSON.stringify({
|
351
|
-
"o0": {
|
352
|
-
//Using the same doc_id as forcedFetch
|
353
|
-
"doc_id": "2848441488556444",
|
354
|
-
"query_params": {
|
355
|
-
"thread_and_message_id": {
|
356
|
-
"thread_id": callbackToReturn.threadID,
|
357
|
-
"message_id": delta.deltaMessageReply.replyToMessageId.id,
|
358
|
-
}
|
359
|
-
}
|
360
|
-
}
|
361
|
-
})
|
362
|
-
})
|
363
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
364
|
-
.then((resData) => {
|
365
|
-
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
366
|
-
if (resData[resData.length - 1].successful_results === 0) throw { error: "forcedFetch: there was no successful_results", res: resData };
|
367
|
-
var fetchData = resData[0].o0.data.message;
|
368
|
-
var mobj = {};
|
369
|
-
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);
|
370
|
-
|
371
|
-
callbackToReturn.messageReply = {
|
372
|
-
threadID: callbackToReturn.threadID,
|
373
|
-
messageID: fetchData.message_id,
|
374
|
-
senderID: fetchData.message_sender.id.toString(),
|
375
|
-
attachments: fetchData.message.blob_attachment.map(att => {
|
376
|
-
var x;
|
377
|
-
try {
|
378
|
-
x = utils._formatAttachment({ blob_attachment: att });
|
379
|
-
} catch (ex) {
|
380
|
-
x = att;
|
381
|
-
x.error = ex;
|
382
|
-
x.type = "unknown";
|
383
|
-
}
|
384
|
-
return x;
|
385
|
-
}),
|
386
|
-
args: (fetchData.message.text || "").trim().split(/\s+/) || [],
|
387
|
-
body: fetchData.message.text || "",
|
388
|
-
isGroup: callbackToReturn.isGroup,
|
389
|
-
mentions: mobj,
|
390
|
-
timestamp: parseInt(fetchData.timestamp_precise)
|
391
|
-
};
|
392
|
-
})
|
393
|
-
.catch(err => log.error("forcedFetch", err))
|
394
|
-
.finally(function () {
|
395
|
-
if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
396
|
-
!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
|
397
|
-
});
|
398
|
-
} else callbackToReturn.delta = delta;
|
399
|
-
|
400
|
-
if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
401
|
-
|
402
|
-
return !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
|
556
|
+
callbackToReturn.messageReply = {
|
557
|
+
threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
|
558
|
+
messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
|
559
|
+
senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
|
560
|
+
attachments: delta.deltaMessageReply.repliedToMessage.attachments
|
561
|
+
.map((att) => {
|
562
|
+
let mercury;
|
563
|
+
try {
|
564
|
+
mercury = JSON.parse(att.mercuryJSON);
|
565
|
+
Object.assign(att, mercury);
|
566
|
+
} catch (ex) {
|
567
|
+
mercury = {};
|
403
568
|
}
|
404
|
-
|
405
|
-
|
569
|
+
return att;
|
570
|
+
})
|
571
|
+
.map((att) => {
|
572
|
+
let x;
|
573
|
+
try {
|
574
|
+
x = utils._formatAttachment(att);
|
575
|
+
} catch (ex) {
|
576
|
+
x = att;
|
577
|
+
x.error = ex;
|
578
|
+
x.type = 'unknown';
|
579
|
+
}
|
580
|
+
return x;
|
581
|
+
}),
|
582
|
+
args: (delta.deltaMessageReply.repliedToMessage.body || '').trim().split(/\s+/),
|
583
|
+
body: delta.deltaMessageReply.repliedToMessage.body || '',
|
584
|
+
isGroup: !!delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,
|
585
|
+
mentions: rmentions,
|
586
|
+
timestamp: parseInt(delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp),
|
587
|
+
participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map((e) => e.toString()),
|
588
|
+
};
|
589
|
+
} else if (delta.deltaMessageReply.replyToMessageId) {
|
590
|
+
return defaultFuncs
|
591
|
+
.post('https://www.facebook.com/api/graphqlbatch/', ctx.jar, {
|
592
|
+
av: ctx.globalOptions.pageID,
|
593
|
+
queries: JSON.stringify({
|
594
|
+
o0: {
|
595
|
+
doc_id: '2848441488556444',
|
596
|
+
query_params: {
|
597
|
+
thread_and_message_id: {
|
598
|
+
thread_id: callbackToReturn.threadID,
|
599
|
+
message_id: delta.deltaMessageReply.replyToMessageId.id,
|
600
|
+
},
|
601
|
+
},
|
602
|
+
},
|
603
|
+
}),
|
604
|
+
})
|
605
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
606
|
+
.then((resData) => {
|
607
|
+
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
608
|
+
if (resData[resData.length - 1].successful_results === 0) throw {
|
609
|
+
error: 'forcedFetch: there was no successful_results',
|
610
|
+
res: resData
|
611
|
+
};
|
612
|
+
const fetchData = resData[0].o0.data.message;
|
613
|
+
const mobj = {};
|
614
|
+
|
615
|
+
for (const n in fetchData.message.ranges) {
|
616
|
+
mobj[fetchData.message.ranges[n].entity.id] = (fetchData.message.text || '').substr(fetchData.message.ranges[n].offset, fetchData.message.ranges[n].length);
|
617
|
+
}
|
618
|
+
callbackToReturn.messageReply = {
|
619
|
+
type: 'Message',
|
620
|
+
threadID: callbackToReturn.threadID,
|
621
|
+
messageID: fetchData.message_id,
|
622
|
+
senderID: fetchData.message_sender.id.toString(),
|
623
|
+
attachments: fetchData.message.blob_attachment.map((att) => utils._formatAttachment({
|
624
|
+
blob_attachment: att
|
625
|
+
})),
|
626
|
+
args: (fetchData.message.text || '').trim().split(/\s+/) || [],
|
627
|
+
body: fetchData.message.text || '',
|
628
|
+
isGroup: callbackToReturn.isGroup,
|
629
|
+
mentions: mobj,
|
630
|
+
timestamp: parseInt(fetchData.timestamp_precise),
|
631
|
+
};
|
632
|
+
})
|
633
|
+
|
634
|
+
.catch((err) => log.error('forcedFetch', err))
|
635
|
+
.finally(() => {
|
636
|
+
if (ctx.globalOptions.autoMarkDelivery) {
|
637
|
+
markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
638
|
+
}
|
639
|
+
|
640
|
+
if (!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID) return;
|
641
|
+
globalCallback(null, callbackToReturn);
|
642
|
+
});
|
643
|
+
} else {
|
644
|
+
callbackToReturn.delta = delta;
|
645
|
+
}
|
646
|
+
if (ctx.globalOptions.autoMarkDelivery) {
|
647
|
+
markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
648
|
+
}
|
649
|
+
|
650
|
+
if (!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID) return;
|
651
|
+
globalCallback(null, callbackToReturn);
|
406
652
|
}
|
653
|
+
}
|
654
|
+
|
655
|
+
return;
|
656
|
+
}
|
657
|
+
}
|
658
|
+
switch (delta.class) {
|
659
|
+
case 'ReadReceipt': {
|
660
|
+
let fmtMsg;
|
661
|
+
try {
|
662
|
+
fmtMsg = utils.formatDeltaReadReceipt(delta);
|
663
|
+
} catch (err) {
|
664
|
+
return log.error('Lỗi Nhẹ', err);
|
665
|
+
}
|
666
|
+
globalCallback(null, fmtMsg);
|
667
|
+
break;
|
668
|
+
}
|
669
|
+
case 'AdminTextMessage': {
|
670
|
+
switch (delta.type) {
|
671
|
+
case 'joinable_group_link_mode_change':
|
672
|
+
case 'magic_words':
|
673
|
+
case 'pin_messages_v2':
|
674
|
+
case 'change_thread_theme':
|
675
|
+
case 'change_thread_icon':
|
676
|
+
case 'change_thread_nickname':
|
677
|
+
case 'change_thread_admins':
|
678
|
+
case 'change_thread_approval_mode':
|
679
|
+
case 'group_poll':
|
680
|
+
case 'messenger_call_log':
|
681
|
+
case 'participant_joined_group_call': {
|
682
|
+
let fmtMsg;
|
683
|
+
try {
|
684
|
+
fmtMsg = utils.formatDeltaEvent(delta);
|
685
|
+
} catch (err) {
|
686
|
+
console.log(delta);
|
687
|
+
return log.error('Lỗi Nhẹ', err);
|
688
|
+
}
|
689
|
+
globalCallback(null, fmtMsg);
|
690
|
+
break;
|
691
|
+
}
|
692
|
+
}
|
693
|
+
break;
|
407
694
|
}
|
408
695
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
detail: err,
|
441
|
-
res: v.delta,
|
442
|
-
type: "parse_error"
|
443
|
-
});
|
444
|
-
}
|
445
|
-
return (function () { globalCallback(null, fmtMsg); })();
|
446
|
-
default:
|
447
|
-
return;
|
448
|
-
}
|
449
|
-
break;
|
450
|
-
//For group images
|
451
|
-
case "ForcedFetch":
|
452
|
-
if (!v.delta.threadKey) return;
|
453
|
-
var mid = v.delta.messageId;
|
454
|
-
var tid = v.delta.threadKey.threadFbId;
|
455
|
-
if (mid && tid) {
|
456
|
-
const form = {
|
457
|
-
"av": ctx.globalOptions.pageID,
|
458
|
-
"queries": JSON.stringify({
|
459
|
-
"o0": {
|
460
|
-
//This doc_id is valid as of March 25, 2020
|
461
|
-
"doc_id": "2848441488556444",
|
462
|
-
"query_params": {
|
463
|
-
"thread_and_message_id": {
|
464
|
-
"thread_id": tid.toString(),
|
465
|
-
"message_id": mid,
|
466
|
-
}
|
467
|
-
}
|
468
|
-
}
|
469
|
-
})
|
470
|
-
};
|
696
|
+
//For group images
|
697
|
+
case 'ForcedFetch': {
|
698
|
+
if (!delta.threadKey) return;
|
699
|
+
const mid = delta.messageId;
|
700
|
+
const tid = delta.threadKey.threadFbId;
|
701
|
+
|
702
|
+
if (mid && tid) {
|
703
|
+
const form = {
|
704
|
+
av: ctx.globalOptions.pageID,
|
705
|
+
queries: JSON.stringify({
|
706
|
+
o0: {
|
707
|
+
doc_id: '2848441488556444',
|
708
|
+
query_params: {
|
709
|
+
thread_and_message_id: {
|
710
|
+
thread_id: tid.toString(),
|
711
|
+
message_id: mid,
|
712
|
+
},
|
713
|
+
},
|
714
|
+
},
|
715
|
+
}),
|
716
|
+
};
|
717
|
+
defaultFuncs
|
718
|
+
.post('https://www.facebook.com/api/graphqlbatch/', ctx.jar, form)
|
719
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
720
|
+
.then((resData) => {
|
721
|
+
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
722
|
+
|
723
|
+
if (resData[resData.length - 1].successful_results === 0) throw {
|
724
|
+
error: 'forcedFetch: there was no successful_results',
|
725
|
+
res: resData
|
726
|
+
};
|
471
727
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
mentions: {},
|
532
|
-
timestamp: parseInt(fetchData.timestamp_precise),
|
533
|
-
isGroup: (fetchData.message_sender.id != tid.toString())
|
534
|
-
});
|
535
|
-
globalCallback(null, {
|
536
|
-
type: "message",
|
537
|
-
senderID: utils.formatID(fetchData.message_sender.id),
|
538
|
-
body: fetchData.message.text || "",
|
539
|
-
threadID: utils.formatID(tid.toString()),
|
540
|
-
messageID: fetchData.message_id,
|
541
|
-
attachments: [{
|
542
|
-
type: "share",
|
543
|
-
ID: fetchData.extensible_attachment.legacy_attachment_id,
|
544
|
-
url: fetchData.extensible_attachment.story_attachment.url,
|
545
|
-
|
546
|
-
title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
|
547
|
-
description: fetchData.extensible_attachment.story_attachment.description.text,
|
548
|
-
source: fetchData.extensible_attachment.story_attachment.source,
|
549
|
-
|
550
|
-
image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
|
551
|
-
width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
|
552
|
-
height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
|
553
|
-
playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
|
554
|
-
duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
|
555
|
-
|
556
|
-
subattachments: fetchData.extensible_attachment.subattachments,
|
557
|
-
properties: fetchData.extensible_attachment.story_attachment.properties,
|
558
|
-
}],
|
559
|
-
mentions: {},
|
560
|
-
timestamp: parseInt(fetchData.timestamp_precise),
|
561
|
-
isGroup: (fetchData.message_sender.id != tid.toString())
|
562
|
-
});
|
563
|
-
}
|
564
|
-
} else log.error("forcedFetch", fetchData);
|
565
|
-
})
|
566
|
-
.catch((err) => log.error("forcedFetch", err));
|
567
|
-
}
|
568
|
-
break;
|
569
|
-
case "ThreadName":
|
570
|
-
case "ParticipantsAddedToGroupThread":
|
571
|
-
case "ParticipantLeftGroupThread":
|
572
|
-
var formattedEvent;
|
573
|
-
try {
|
574
|
-
formattedEvent = utils.formatDeltaEvent(v.delta);
|
575
|
-
} catch (err) {
|
576
|
-
return globalCallback({
|
577
|
-
error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
|
578
|
-
detail: err,
|
579
|
-
res: v.delta,
|
580
|
-
type: "parse_error"
|
581
|
-
});
|
728
|
+
const fetchData = resData[0].o0.data.message;
|
729
|
+
|
730
|
+
if (utils.getType(fetchData) === 'Object') {
|
731
|
+
log.info('forcedFetch', fetchData);
|
732
|
+
switch (fetchData.__typename) {
|
733
|
+
case 'ThreadImageMessage':
|
734
|
+
if (!ctx.globalOptions.selfListen && fetchData.message_sender.id.toString() === ctx.userID) return;
|
735
|
+
if (!ctx.loggedIn) return;
|
736
|
+
|
737
|
+
globalCallback(null, {
|
738
|
+
type: 'change_thread_image',
|
739
|
+
threadID: utils.formatID(tid.toString()),
|
740
|
+
snippet: fetchData.snippet,
|
741
|
+
timestamp: fetchData.timestamp_precise,
|
742
|
+
author: fetchData.message_sender.id,
|
743
|
+
image: {
|
744
|
+
attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
|
745
|
+
width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
|
746
|
+
height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
|
747
|
+
url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri,
|
748
|
+
},
|
749
|
+
});
|
750
|
+
break;
|
751
|
+
case 'UserMessage': {
|
752
|
+
const event = {
|
753
|
+
type: 'message',
|
754
|
+
senderID: utils.formatID(fetchData.message_sender.id),
|
755
|
+
body: fetchData.message.text || '',
|
756
|
+
threadID: utils.formatID(tid.toString()),
|
757
|
+
messageID: fetchData.message_id,
|
758
|
+
attachments: [{
|
759
|
+
type: 'share',
|
760
|
+
ID: fetchData.extensible_attachment.legacy_attachment_id,
|
761
|
+
url: fetchData.extensible_attachment.story_attachment.url,
|
762
|
+
title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
|
763
|
+
description: fetchData.extensible_attachment.story_attachment.description.text,
|
764
|
+
source: fetchData.extensible_attachment.story_attachment.source,
|
765
|
+
image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
|
766
|
+
width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
|
767
|
+
height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
|
768
|
+
playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
|
769
|
+
duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
|
770
|
+
subattachments: fetchData.extensible_attachment.subattachments,
|
771
|
+
properties: fetchData.extensible_attachment.story_attachment.properties,
|
772
|
+
}],
|
773
|
+
mentions: {},
|
774
|
+
timestamp: parseInt(fetchData.timestamp_precise),
|
775
|
+
isGroup: (fetchData.message_sender.id !== tid.toString()),
|
776
|
+
};
|
777
|
+
|
778
|
+
log.info('ff-Return', event);
|
779
|
+
globalCallback(null, event);
|
780
|
+
break;
|
781
|
+
}
|
782
|
+
default:
|
783
|
+
log.error('forcedFetch', fetchData);
|
784
|
+
}
|
785
|
+
} else {
|
786
|
+
log.error('forcedFetch', fetchData);
|
582
787
|
}
|
583
|
-
|
788
|
+
})
|
789
|
+
.catch((err) => log.error('forcedFetch', err));
|
790
|
+
}
|
791
|
+
break;
|
584
792
|
}
|
793
|
+
case 'ThreadName':
|
794
|
+
case 'ParticipantsAddedToGroupThread':
|
795
|
+
case 'ParticipantLeftGroupThread': {
|
796
|
+
let formattedEvent;
|
797
|
+
try {
|
798
|
+
formattedEvent = utils.formatDeltaEvent(delta);
|
799
|
+
} catch (err) {
|
800
|
+
console.log(err);
|
801
|
+
return log.error('Lỗi Nhẹ', err);
|
802
|
+
}
|
803
|
+
|
804
|
+
if (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) return;
|
805
|
+
if (!ctx.loggedIn) return;
|
806
|
+
globalCallback(null, formattedEvent);
|
807
|
+
break;
|
808
|
+
}
|
809
|
+
case 'NewMessage': {
|
810
|
+
const hasLiveLocation = delta => {
|
811
|
+
const attachment = delta.attachments?.[0]?.mercury?.extensible_attachment;
|
812
|
+
const storyAttachment = attachment?.story_attachment;
|
813
|
+
return storyAttachment?.style_list?.includes('message_live_location');
|
814
|
+
};
|
815
|
+
|
816
|
+
if (delta.attachments?.length === 1 && hasLiveLocation(delta)) {
|
817
|
+
delta.class = 'UserLocation';
|
818
|
+
|
819
|
+
try {
|
820
|
+
const fmtMsg = utils.formatDeltaEvent(delta);
|
821
|
+
globalCallback(null, fmtMsg);
|
822
|
+
} catch (err) {
|
823
|
+
console.log(delta);
|
824
|
+
log.error('Lỗi Nhẹ', err);
|
825
|
+
}
|
826
|
+
}
|
827
|
+
break;
|
828
|
+
}
|
829
|
+
}
|
585
830
|
}
|
586
831
|
|
587
832
|
function markDelivery(ctx, api, threadID, messageID) {
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
833
|
+
if (threadID && messageID) {
|
834
|
+
api.markAsDelivered(threadID, messageID, (err) => {
|
835
|
+
if (err) log.error('markAsDelivered', err);
|
836
|
+
else {
|
837
|
+
if (ctx.globalOptions.autoMarkRead) {
|
838
|
+
api.markAsRead(threadID, (err) => {
|
839
|
+
if (err) log.error('markAsDelivered', err);
|
840
|
+
});
|
841
|
+
}
|
842
|
+
}
|
843
|
+
});
|
844
|
+
}
|
600
845
|
}
|
601
846
|
|
602
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
603
|
-
var globalCallback = identity;
|
604
|
-
getSeqID = function getSeqID() {
|
605
|
-
ctx.t_mqttCalled = false;
|
606
|
-
defaultFuncs
|
607
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
608
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
609
|
-
.then((resData) => {
|
610
|
-
if (utils.getType(resData) != "Array") throw { error: "Not logged in", res: resData };
|
611
|
-
if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
612
|
-
if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
|
613
|
-
if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
|
614
|
-
ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
|
615
|
-
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
616
|
-
} else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
|
617
|
-
})
|
618
|
-
.catch((err) => {
|
619
|
-
log.error("getSeqId", err);
|
620
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in") ctx.loggedIn = false;
|
621
|
-
return globalCallback(err);
|
622
|
-
});
|
623
|
-
};
|
624
847
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
848
|
+
|
849
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
850
|
+
var globalCallback = identity;
|
851
|
+
var okeoke;
|
852
|
+
getSeqID = function getSeqID() {
|
853
|
+
ctx.t_mqttCalled = false;
|
854
|
+
defaultFuncs
|
855
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
856
|
+
.then(res => {
|
857
|
+
okeoke = res;
|
858
|
+
return res;
|
859
|
+
})
|
860
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
861
|
+
.then((resData) => {
|
862
|
+
if (utils.getType(resData) != "Array") {
|
863
|
+
if (okeoke.request.uri && okeoke.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
|
864
|
+
if (okeoke.request.uri.href.includes('601051028565049')) {
|
865
|
+
return global.Fca.BypassAutomationNotification(undefined, ctx.jar, ctx.globalOptions, undefined ,process.env.UID)
|
640
866
|
}
|
867
|
+
}
|
868
|
+
if (global.Fca.Require.Priyansh.AutoLogin) {
|
869
|
+
return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
|
870
|
+
return global.Fca.Action('AutoLogin');
|
871
|
+
});
|
872
|
+
} else if (!global.Fca.Require.Priyansh.AutoLogin) {
|
873
|
+
return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
|
874
|
+
}
|
875
|
+
return;
|
876
|
+
} else {
|
877
|
+
if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
878
|
+
if (resData[resData.length - 1].successful_results === 0) throw {
|
879
|
+
error: "getSeqId: there was no successful_results",
|
880
|
+
res: resData
|
881
|
+
};
|
882
|
+
if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
|
883
|
+
ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
|
884
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
885
|
+
} else throw {
|
886
|
+
error: "getSeqId: no sync_sequence_id found.",
|
887
|
+
res: resData
|
888
|
+
};
|
641
889
|
}
|
890
|
+
})
|
891
|
+
.catch((err) => {
|
892
|
+
log.error("getSeqId", err);
|
893
|
+
if (okeoke.request.uri && okeoke.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
|
894
|
+
if (okeoke.request.uri.href.includes('601051028565049')) {
|
895
|
+
return global.Fca.BypassAutomationNotification(undefined, ctx.jar, ctx.globalOptions, undefined ,process.env.UID)
|
896
|
+
}
|
897
|
+
}
|
898
|
+
if (utils.getType(err) == "Object" && err.error === global.Fca.Require.Language.Index.ErrAppState) ctx.loggedIn = false;
|
899
|
+
return globalCallback(err);
|
900
|
+
});
|
901
|
+
};
|
902
|
+
|
903
|
+
return function(callback) {
|
904
|
+
class MessageEmitter extends EventEmitter {
|
905
|
+
stopListening(callback) {
|
906
|
+
callback = callback || (() => {});
|
907
|
+
globalCallback = identity;
|
908
|
+
if (ctx.mqttClient) {
|
909
|
+
ctx.mqttClient.unsubscribe("/webrtc");
|
910
|
+
ctx.mqttClient.unsubscribe("/rtc_multi");
|
911
|
+
ctx.mqttClient.unsubscribe("/onevc");
|
912
|
+
ctx.mqttClient.publish("/browser_close", "{}");
|
913
|
+
ctx.mqttClient.end(false, function(...data) {
|
914
|
+
ctx.mqttClient = undefined;
|
915
|
+
});
|
916
|
+
}
|
917
|
+
global.Fca.Data.StopListening = true;
|
918
|
+
}
|
919
|
+
}
|
642
920
|
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
//Reset some stuff
|
650
|
-
if (!ctx.firstListen) ctx.lastSeqId = null;
|
651
|
-
ctx.syncToken = undefined;
|
652
|
-
ctx.t_mqttCalled = false;
|
653
|
-
|
654
|
-
//Same request as getThreadList
|
655
|
-
form = {
|
656
|
-
"av": ctx.globalOptions.pageID,
|
657
|
-
"queries": JSON.stringify({
|
658
|
-
"o0": {
|
659
|
-
"doc_id": "3336396659757871",
|
660
|
-
"query_params": {
|
661
|
-
"limit": 1,
|
662
|
-
"before": null,
|
663
|
-
"tags": ["INBOX"],
|
664
|
-
"includeDeliveryReceipts": false,
|
665
|
-
"includeSeqID": true
|
666
|
-
}
|
667
|
-
}
|
668
|
-
})
|
669
|
-
};
|
921
|
+
var msgEmitter = new MessageEmitter();
|
922
|
+
globalCallback = (callback || function(error, message) {
|
923
|
+
if (error) return msgEmitter.emit("error", error);
|
924
|
+
msgEmitter.emit("message", message);
|
925
|
+
});
|
670
926
|
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
927
|
+
//Reset some stuff
|
928
|
+
if (!ctx.firstListen) ctx.lastSeqId = null;
|
929
|
+
ctx.syncToken = undefined;
|
930
|
+
ctx.t_mqttCalled = false;
|
931
|
+
|
932
|
+
//Same request as getThreadList
|
933
|
+
form = {
|
934
|
+
av: ctx.globalOptions.pageID,
|
935
|
+
queries: JSON.stringify({
|
936
|
+
o0: {
|
937
|
+
doc_id: '3336396659757871',
|
938
|
+
query_params: {
|
939
|
+
limit: 1,
|
940
|
+
before: null,
|
941
|
+
tags: ['INBOX'],
|
942
|
+
includeDeliveryReceipts: false,
|
943
|
+
includeSeqID: true,
|
944
|
+
},
|
945
|
+
},
|
946
|
+
}),
|
675
947
|
};
|
948
|
+
|
949
|
+
|
950
|
+
if (!ctx.firstListen || !ctx.lastSeqId) getSeqID();
|
951
|
+
else listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
952
|
+
ctx.firstListen = false;
|
953
|
+
|
954
|
+
return msgEmitter;
|
955
|
+
};
|
676
956
|
};
|