meta-horizonn 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@
8
8
  "UID": "Đăng Nhập Tại ID: %1",
9
9
  "Area": "Vùng Của Tài Khoản Là: %1",
10
10
  "NoAreaData": "Không Thể Lấy Vùng Của Tài Khoản !",
11
+ "NoAreaDataBypass": "Không Thể Lấy Vùng Của Tài Khoản Tuy FCA Đã Bypass 😔",
11
12
  "OnLogin": "Đang Đăng Nhập ...",
12
13
  "InvaildAccount": "Sai Mật Khẩu Hoặc Tài Khoản !",
13
14
  "TwoAuth": "Bạn Đang Bật 2 Bảo Mật !",
@@ -122,6 +123,7 @@
122
123
  "UID": "Login as ID: %1",
123
124
  "Area": "Area Of Account Is: %1",
124
125
  "NoAreaData": "Can't Get Area Of Account !",
126
+ "NoAreaDataBypass": "Can't Get The Area Of The Account But FCA Bypass 😔",
125
127
  "OnLogin": "Currently logged ...",
126
128
  "InvaildAccount": "Wrong Password Or Account !",
127
129
  "TwoAuth": "You Currently On 2 Factor Security !",
package/Main.js CHANGED
@@ -20,7 +20,7 @@ var utils = global.Fca.Require.utils,
20
20
  express = require("express")(),
21
21
  { join } = require('path'),
22
22
  cheerio = require("cheerio"),
23
- { readFileSync } = require('fs-extra'),
23
+ { readFileSync, writeFileSync } = require('fs-extra'),
24
24
  Database = require("./Extra/Database"),
25
25
  readline = require("readline"),
26
26
  chalk = require("chalk"),
@@ -246,7 +246,7 @@ function setOptions(globalOptions, options) {
246
246
  break;
247
247
  }
248
248
  case 'userAgent': {
249
- globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36');
249
+ globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36');
250
250
  break;
251
251
  }
252
252
  case 'proxy': {
@@ -288,7 +288,7 @@ function setOptions(globalOptions, options) {
288
288
  * @param {{ getCookies: (arg0: string) => any[]; }} jar
289
289
  */
290
290
 
291
- function buildAPI(globalOptions, html, jar) {
291
+ function buildAPI(globalOptions, html, jar, bypass_region) {
292
292
  // var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(/** @type {{ cookieString: () => string; }} */val) { return val.cookieString().split("=")[0] === "c_user"; });
293
293
  //check tiktik
294
294
  var userID;
@@ -397,6 +397,12 @@ else userID = maybeUser[0].cookieString().split("=")[1].toString();
397
397
  log.warn("login", getText(Language.NoAreaData));
398
398
  api["htmlData"] = html;
399
399
  }
400
+ if (bypass_region) {
401
+ logger.Normal(Language.NoAreaDataBypass);
402
+ } else {
403
+ log.warn("login", getText(Language.NoAreaData));
404
+ api["htmlData"] = html;
405
+ }
400
406
 
401
407
  var defaultFuncs = utils.makeDefaults(html, userID, ctx);
402
408
 
@@ -996,19 +1002,56 @@ try {
996
1002
  console.log(e);
997
1003
  }
998
1004
 
999
-
1005
+ let redirect = [1, "https://m.facebook.com/"];
1006
+ let bypass_region_err = false;
1000
1007
  var ctx,api;
1001
1008
  mainPromise = mainPromise
1002
1009
  .then(function(res) {
1003
- var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/,redirect = reg.exec(res.body);
1010
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
1011
+ redirect = reg.exec(res.body);
1004
1012
  if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1005
1013
  return res;
1006
1014
  })
1007
1015
  .then(function(res) {
1008
- var html = res.body,Obj = buildAPI(globalOptions, html, jar);
1016
+ let reg_antierr = /This browser is not supported/gs; // =))))))
1017
+ if (reg_antierr.test(res.body)) {
1018
+ const Data = JSON.stringify(res.body);
1019
+ const Dt_Check = Data.split('2Fhome.php&amp;gfid=')[1];
1020
+ if (Dt_Check == undefined) return res
1021
+ const fid = Dt_Check.split("\\\\")[0];//fix sau
1022
+ if (Dt_Check == undefined || Dt_Check == "") return res
1023
+ const final_fid = fid.split(`\\`)[0];
1024
+ if (final_fid == undefined || final_fid == '') return res;
1025
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
1026
+ bypass_region_err = true;
1027
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
1028
+ }
1029
+ else return res
1030
+ })
1031
+ // .then(function(res) {
1032
+ // let reg_old_web = /Switch Default Site/gs;
1033
+ // if (reg_old_web.test(res.body)) {
1034
+ // let Data_Resp = JSON.stringify(res.body);
1035
+ // const link = Data_Resp.split('settings/site')[1].split("\"")[0].replace('\\', '')
1036
+ // const redirect_link2 = redirect[1] + "settings/site" + utils.cleanHTML(link)
1037
+ // console.log(redirect_link2)
1038
+ // return utils.get("https://www.facebook.com/", jar, null, globalOptions).then(utils.saveCookies(jar)); // try ag
1039
+ // }
1040
+ // else return res;
1041
+ // })
1042
+ // .then(function(res) {
1043
+ // var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
1044
+ // redirect = reg.exec(res.body);
1045
+ // if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
1046
+ // return res;
1047
+ // })
1048
+ .then(function(res){
1049
+ // console.log('okay');
1050
+ // global.Fca.Require.fs.writeFileSync('./AAAAA.html', JSON.stringify(res.body, null, 2));
1051
+ var html = res.body,Obj = buildAPI(globalOptions, html, jar, bypass_region_err);
1009
1052
  ctx = Obj.ctx;
1010
1053
  api = Obj.api;
1011
- process.env.api = Obj.api;
1054
+ // process.env.api = Obj.api;
1012
1055
  return res;
1013
1056
  });
1014
1057
  if (globalOptions.pageID) {
package/index.js CHANGED
@@ -466,7 +466,12 @@ module.exports = function(loginData, options, callback) {
466
466
  }
467
467
  }
468
468
  }
469
- return login(loginData, options, callback);
469
+ // return login(loginData, options, callback);
470
+ try {
471
+ login(loginData, options, callback);
472
+ } catch (e) {
473
+ console.log(e)
474
+ }
470
475
  }).catch(function(err) {
471
476
  console.log(err)
472
477
  log.error("[ FCA-UPDATE ] ➣", Language.UnableToConnect);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meta-horizonn",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Facebook-Chat-API Protect and Deploy by Kanzu and HZI Team. Kem is redeveloped. Rename package is Meta Horizonn and package supported ChatBot Messenger.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -145,12 +145,36 @@ function formatThreadGraphQLResponse(data) {
145
145
  };
146
146
  }
147
147
 
148
+ const MAX_ARRAY_LENGTH = 6; //safe
149
+ var Request_Update_Time = 0;
150
+ var updateInterval;
151
+ var updateTimeout;
152
+ let Queues = [];
153
+
154
+ let onetimecook = false
155
+
156
+ function addToQueues(num) {
157
+ const existingArray = Queues.some(subArr => subArr.some(obj => obj.threadID == num.threadID));
158
+
159
+ if (!existingArray) {
160
+ if (Queues.length > 0 && Queues[Queues.length - 1].length === MAX_ARRAY_LENGTH) {
161
+ Queues.push([num]);
162
+ } else {
163
+ const lastArray = Queues.length > 0 ? Queues[Queues.length - 1] : [];
164
+ lastArray.push(num);
165
+
166
+ if (Queues.length === 0) {
167
+ Queues.push(lastArray);
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+
148
174
  module.exports = function(defaultFuncs, api, ctx) {
149
175
 
150
- var { createData,getData,hasData,setLastRun,updateData, getAll } = require('../Extra/ExtraGetThread');
151
- var { capture } = require('../Extra/Src/Last-Run');
176
+ var { createData,getData,hasData,updateData, getAll } = require('../Extra/ExtraGetThread');
152
177
  var Database = require('../Extra/Database');
153
- global.Fca.Data.Userinfo = [];
154
178
 
155
179
  return async function getThreadInfoGraphQL(threadID, callback) {
156
180
  var resolveFunc = function(){};
@@ -168,248 +192,233 @@ module.exports = function(defaultFuncs, api, ctx) {
168
192
  resolveFunc(data);
169
193
  };
170
194
  }
195
+
196
+ if (utils.getType(threadID) !== "Array") threadID = [threadID];
171
197
 
172
- // được tìm thấy vào giữa tháng 8/2022 bởi @KanzuWakazaki - đã được chia sẻ cho @D-Jukie và Horizon Team Public group 🤴
173
- // những code tương tự muliti thread như này đều có thể là copy idea 🐧
174
- // đã áp dụng vào fca mới(cloud - fca(private)) vào cuối tháng 8/2022 bởi @IteralingCode(Hidden Member( always :) )) - Synthetic 4 - @Horizon Team
175
- //cập nhật dự án bị bỏ rơi này vào ngày 19/11/2022 bởi @KanzuWakazaki(Owner) - Synthetic 1 - @Horizon Team nhằm đáp ứng nhu cầu của client !
176
-
177
- if (utils.getType(threadID) !== "Array") threadID = [threadID];
178
198
 
199
+ if (utils.getType(global.Fca.Data.Userinfo) == "Array" || global.Fca.Data.Userinfo == undefined) global.Fca.Data.Userinfo = new Map();
179
200
 
180
- var SpecialMethod = function(TID) {
181
- const All = getAll();
182
- const Real = [];
183
- const Average = [];
184
- for (let i of All) {
185
- if (i.data.threadID != undefined) {
186
- if (i.data.TimeCreate + 900 * 1000 <= Date.now()) {
187
- Real.push(i.data.threadID);
188
- }
189
- else {
190
- Average.push({
191
- threadID: i.data.threadID,
192
- TimeCreate: i.data.TimeCreate
193
- });
194
- continue;
195
- }
196
- } else continue;
201
+ const updateUserInfo = (threadInfo) => {
202
+ if (!global.Fca.Data.Userinfo) {
203
+ global.Fca.Data.Userinfo = new Map();
197
204
  }
198
- const AllofThread = [];
199
- if (Average.length > 0) {
200
- var Time = 0;
201
- for (let i of Average) {
202
- Time += i.TimeCreate;
203
- }
204
- Time = Time / Average.length;
205
- if (Time + 900 * 1000 <= Date.now()) {
206
- for (let i of Average) {
207
- Real.push(i.threadID);
205
+
206
+ threadInfo.forEach(thread => {
207
+ const userInfo = thread.userInfo;
208
+
209
+ if (Array.isArray(userInfo)) {
210
+ const userInfoMap = new Map(userInfo.map(user => [user.id, user]));
211
+ for (const [id, user] of userInfoMap) {
212
+ global.Fca.Data.Userinfo.set(id, user);
213
+ }
208
214
  }
209
- } //can't =))
210
- else {
211
- setTimeout(function () {
212
- SpecialMethod(TID);
213
- }, Time + 900 * 1000 - Date.now());
214
- }
215
- }
216
- else {
217
- setTimeout(function () {
218
- SpecialMethod(TID);
219
- }, 900 * 1000);
220
- }
221
- if (Real.length == 0) return;
222
- else if (Real.length == 1) {
223
- return DefaultMethod(TID);
224
- }
225
- else if (All.length > 1) {
226
- for (let i of All) {
227
- if (i.data.threadID !== undefined) AllofThread.push(i.data.threadID);
228
- }
229
-
230
- const processChunk = (chunk) => {
231
- const Form = {};
232
- const ThreadInfo = [];
233
- chunk.forEach((x, y) => {
234
- Form["o" + y] = {
235
- doc_id: "3449967031715030",
236
- query_params: { id: x, message_limit: 0, load_messages: false, load_read_receipts: false, before: null }
237
- };
238
- });
239
-
240
- const form = { queries: JSON.stringify(Form), batch_name: "MessengerGraphQLThreadFetcher" };
241
-
242
- defaultFuncs
243
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
215
+ });
216
+ };
217
+
218
+ const getMultiInfo = async function (threadIDs) {
219
+ let form = {};
220
+ let tempThreadInf = [];
221
+ threadIDs.forEach((x,y) => {
222
+ form["o" + y] = {
223
+ doc_id: "3449967031715030",
224
+ query_params: { id: x, message_limit: 0, load_messages: false, load_read_receipts: false, before: null }
225
+ };
226
+ });
227
+ let Submit = { queries: JSON.stringify(form), batch_name: "MessengerGraphQLThreadFetcher" };
228
+
229
+ const promise = new Promise((resolve, reject) => {
230
+ defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, Submit)
244
231
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
245
232
  .then(resData => {
246
- if (resData.error || resData[resData.length - 1].error_results !== 0) throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều";
247
- resData = resData.slice(0, -1).sort((a, b) => Object.keys(a)[0].localeCompare(Object.keys(b)[0]));
248
- resData.forEach((x, y) => ThreadInfo.push(formatThreadGraphQLResponse(x["o" + y].data)));
249
- try {
250
- if (ThreadInfo.length === 1) {
251
- updateData(threadID, ThreadInfo[0]);
252
- if (utils.getType(ThreadInfo[0].userInfo) === "Array") {
253
- ThreadInfo[0].userInfo.forEach(i => {
254
- if (global.Fca.Data.Userinfo.some(ii => ii.id === i.id)) global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(ii => ii.id === i.id), 1);
255
- global.Fca.Data.Userinfo.push(i);
233
+ if (resData.error || resData[resData.length - 1].error_results !== 0) throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều";
234
+ resData = resData.slice(0, -1).sort((a, b) => Object.keys(a)[0].localeCompare(Object.keys(b)[0]));
235
+ resData.forEach((x, y) => tempThreadInf.push(formatThreadGraphQLResponse(x["o" + y].data)));
236
+ return resolve({
237
+ Success: true,
238
+ Data: tempThreadInf
256
239
  });
257
- }
258
- } else {
259
- ThreadInfo.forEach(i => {
260
- updateData(i.threadID, i);
261
- if (utils.getType(i.userInfo) === "Array") {
262
- i.userInfo.forEach(ii => {
263
- if (global.Fca.Data.Userinfo.some(iii => iii.id === ii.id)) global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(iii => iii.id === ii.id), 1);
264
- global.Fca.Data.Userinfo.push(ii);
265
- });
266
- }
267
- });
268
- }
269
- } catch (e) {
270
- console.log(e);
271
- }
272
240
  })
273
- .catch(() => { throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều"; });
274
- };
275
-
276
- if (AllofThread.length > 5) {
277
- const chunks = [];
278
- for (let i = 0; i < AllofThread.length; i += 5) {
279
- chunks.push(AllofThread.slice(i, i + 5));
280
- }
281
- chunks.forEach(processChunk);
282
- } else {
283
- processChunk(AllofThread);
284
- }
241
+ .catch(() => {
242
+ reject({ Success: false, Data: '' })
243
+ });
244
+ })
245
+
246
+ return await promise;
247
+ }
248
+
249
+ const formatAndUpdateData = (AllThreadInfo) => {
250
+ try {
251
+ AllThreadInfo.forEach(threadInf => { updateData(threadInf.threadID, threadInf); })
252
+ updateUserInfo(AllThreadInfo) // [ {}, {} ]
253
+
254
+ } catch (e) {
255
+ console.log(e);
285
256
  }
286
- };
257
+ }
287
258
 
288
- var DefaultMethod = function(TID) {
289
- var ThreadInfo = [];
290
- for (let i of TID) {
291
- ThreadInfo.push(getData(i));
292
- }
293
- if (ThreadInfo.length == 1) {
294
- callback(null,ThreadInfo[0]);
295
- if (utils.getType(ThreadInfo[0].userInfo) == "Array") {
296
- for (let i of ThreadInfo[0].userInfo) {
297
- if (global.Fca.Data.Userinfo.some(ii => ii.id == i.id)) {
298
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(ii => ii.id == i.id), 1);
299
- }
300
- global.Fca.Data.Userinfo.push(i);
259
+ const formatAndCreateData = (AllThreadInfo) => {
260
+ try {
261
+ AllThreadInfo.forEach(threadInf => { createData(threadInf.threadID, threadInf); })
262
+ updateUserInfo(AllThreadInfo) // [ {}, {} ]
263
+
264
+ } catch (e) {
265
+ console.log(e);
266
+ }
267
+ }
268
+
269
+ const checkAverageStaticTimestamp = function (avgTimeStamp) {
270
+ const DEFAULT_UPDATE_TIME = 900 * 1000; //thời gian cập nhật tối đa + với thời gian trung bình của tổng request 1 mảng
271
+ //khi request phút thứ 3, 1 req ở phút thứ 7, 1 req ở phút thứ 10, vậy trung bình là (3+7+1) / time.length (3) + với 15p = tg trung bình để cập nhật 1 mảng
272
+ const MAXIMUM_ERROR_TIME = 10 * 1000;
273
+ return { //khi check = false thì cần cập nhật vì đã hơn thời gian tb + 15p
274
+ Check: (parseInt(avgTimeStamp) + parseInt(DEFAULT_UPDATE_TIME)) + parseInt(MAXIMUM_ERROR_TIME) >= Date.now(), // ở đây avgTimeStamp là thời gian cố định của 1 mảng queue khi đầy
275
+ timeLeft: (parseInt(avgTimeStamp) + parseInt(DEFAULT_UPDATE_TIME)) - Date.now() + parseInt(MAXIMUM_ERROR_TIME)
276
+ }
277
+ }
278
+
279
+ const autoCheckAndUpdateRecallTime = () => {
280
+ let holdTime = [];
281
+ let oneTimeCall = false;
282
+ //lấy tất cả trung bình thời gian của tất cả mảng và tìm thời gian còn lại ngắn nhất, nếu có sẵn id cần cập nhật thì cập nhật ngày lập tức
283
+ Queues.forEach((i, index) => {
284
+ // [ { threadID, TimeCreate }, {} ]
285
+ const averageTimestamp = Math.round(i.reduce((acc, obj) => acc + obj.TimeCreate, 0) / i.length);
286
+ const DataAvg = checkAverageStaticTimestamp(averageTimestamp);
287
+ if (DataAvg.Check) {
288
+ //cần chờ
289
+ // holdTime.push(DataAvg.timeLeft);
290
+ //cho thi cho 10s sau check lai roi cho tiep nhe =))
301
291
  }
302
- } else {
303
- for (let i of ThreadInfo) {
304
- if (utils.getType(i.userInfo) == "Array") {
305
- for (let ii of i.userInfo) {
306
- if (global.Fca.Data.Userinfo.some(iii => iii.id == ii.id)) {
307
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(iii => iii.id == ii.id), 1);
308
- }
309
- global.Fca.Data.Userinfo.push(ii);
310
- }
292
+ else {
293
+ oneTimeCall = true;
311
294
  }
312
- }
313
- callback(null,ThreadInfo);
314
- }
315
- }
316
- };
317
- var CreateMethod = function(TID) {
318
- var Form = {};
319
- var ThreadInfo = [];
295
+ });
296
+
297
+ if (oneTimeCall) autoUpdateData(); // cập nhật ngay, nhin la biet tot hon hold roi =))
298
+
299
+ // if (holdTime.length >= 1) {
300
+ // holdTime.sort((a,b) => a - b) //low to high time
301
+ // if (holdTime[0] > Request_Update_Time) {
302
+ // Request_Update_Time = holdTime[0];
303
+ // clearInterval(updateInterval);
304
+ // updateInterval = setInterval(() => { autoUpdateData(); }, holdTime[0])
305
+ // }
306
+ // }
320
307
 
321
- TID.map(function (x,y) {
322
- Form["o" + y] = {
323
- doc_id: "3449967031715030",
324
- query_params: {
325
- id: x,
326
- message_limit: 0,
327
- load_messages: false,
328
- load_read_receipts: false,
329
- before: null
308
+ //hold lam cai cho gi khi ta co check lien tuc 10s 1 lan 😔
309
+
310
+ const MAXIMUM_RECALL_TIME = 30 * 1000;
311
+ clearTimeout(updateTimeout);
312
+ updateTimeout = setTimeout(() => { autoCheckAndUpdateRecallTime(); }, MAXIMUM_RECALL_TIME)
313
+ }
314
+
315
+ const autoUpdateData = async function() {
316
+ //[ [ {}, {} ], [ {}, {} ] ]
317
+ let doUpdate = [];
318
+ let holdTime = [];
319
+
320
+ Queues.forEach((i, index) => {
321
+ // [ {}, {} ]
322
+ const averageTimestamp = Math.round(i.reduce((acc, obj) => acc + obj.TimeCreate, 0) / i.length);
323
+ // thời gian trung bình của 1 mảng từ lúc bắt đầu request lần đầu, cần + thêm thời gian cố định là 15p !
324
+
325
+ const DataAvg = checkAverageStaticTimestamp(averageTimestamp)
326
+ if (DataAvg.Check) {
327
+ // chờ tiếp
328
+ }
329
+ else {
330
+ // đã hơn thời gian 15p
331
+ doUpdate.push(i) // [ {}, {} ]
332
+ Queues.splice(index, 1); //đạt điều kiện nên xoá để tý nó tự thêm 💀
330
333
  }
331
- };
334
+
332
335
  });
333
-
334
- var form = {
335
- queries: JSON.stringify(Form),
336
- batch_name: "MessengerGraphQLThreadFetcher"
337
- };
338
- defaultFuncs
339
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
340
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
341
- .then(function(resData) {
342
- if (resData.error) {
343
- throw resData.error;
344
- }
345
- if (resData[resData.length - 1].error_results !== 0) {
346
- throw resData.error;
347
- }
348
- resData = resData.splice(0, resData.length - 1);
349
- resData.sort((a, b) => { return Object.keys(a)[0].localeCompare(Object.keys(b)[0]); });
350
- resData.map(function (x,y) {
351
- ThreadInfo.push(formatThreadGraphQLResponse(x["o"+y].data));
352
- });
353
- if (Object.keys(resData).length == 1) {
354
- createData(threadID,ThreadInfo[0]);
355
- callback(null, ThreadInfo[0]);
356
- capture(callback);
357
- setLastRun('LastUpdate', callback);
358
- if (global.Fca.Data.Userinfo == undefined) global.Fca.Data.Userinfo = [];
359
- if (utils.getType(ThreadInfo[0].userInfo) == "Array") {
360
- for (let i of ThreadInfo[0].userInfo) {
361
- if (global.Fca.Data.Userinfo.some(ii => ii.id == i.id)) {
362
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(ii => ii.id == i.id), 1);
336
+
337
+ if (doUpdate.length >= 1) {
338
+ // maybe [ [ {}, {} ] [ {}, {} ] ]
339
+ let ids = []; // [ id, id ]
340
+ doUpdate.forEach(i => {
341
+ //[ {} {} ]
342
+ const onlyThreadID = [...new Set(i.map(obj => obj.threadID))]; // [ id1, id2 ]
343
+ ids.push(onlyThreadID) //[ [ id1, id2 ] ]
344
+ })
345
+
346
+ // [ [ id1, id2 ],[ id1, id2 ] ] 5 per arr
347
+
348
+ ids.forEach(async function(i) {
349
+ const dataResp = await getMultiInfo(i);
350
+ if (dataResp.Success == true) {
351
+ let MultiThread = dataResp.Data;
352
+ formatAndUpdateData(MultiThread)
363
353
  }
364
- global.Fca.Data.Userinfo.push(i);
365
- }
366
- }
367
- } else {
368
- // api.Horizon_Data([ThreadInfo], "Threads", "Post");
369
- for (let i of ThreadInfo) {
370
- createData(i.threadID,i);
371
- if (utils.getType(i.userInfo) == "Array") {
372
- for (let ii of i.userInfo) {
373
- if (global.Fca.Data.Userinfo.some(iii => iii.id == ii.id)) {
374
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(iii => iii.id == ii.id), 1);
375
- }
376
- global.Fca.Data.Userinfo.push(ii);
354
+ else {
355
+ global.Fca.Require.logger.Warning('CANT NOT GET THREADINFO 💀 MAYBE U HAS BEEN BLOCKED FROM FACEBOOK');
377
356
  }
378
- }
379
- }
380
- callback(null, ThreadInfo);
381
- }
382
- })
383
- .catch(function(err){
384
- throw err;
357
+ })
358
+ }
359
+ }
360
+
361
+ const createOrTakeDataFromDatabase = async (threadIDs) => {
362
+ let inDb = []; //NOTE: xử lý resp thành 1 mảng nếu có nhiều hơn 1 threadID và obj nếu 1 threadID
363
+ let inFastArr = [];
364
+ let createNow = [];
365
+ let cbThreadInfos = [];
366
+ // kiểm tra và phân ra 2 loại 1 là chưa có 2 là có =))
367
+ // kiểm tra
368
+
369
+ threadIDs.forEach(id => {
370
+ // id, id ,id
371
+ hasData(id) == true ? inDb.push(id) : createNow.push(id)
385
372
  });
386
- };
387
- if (global.Fca.Data.Already != true) { SpecialMethod(threadID); global.Fca.Data.Already = true; setInterval(function() {
388
- Database(true).set('UserInfo', global.Fca.Data.Userinfo);
389
- setTimeout(() => {
390
- delete global.Fca.Data.Userinfo;
391
- global.Fca.Data.Userinfo = [];
392
- }, 30 * 1000)
393
- }, 900 * 1000); }
394
-
373
+
374
+ if (inDb.length >= 1) {
375
+ let threadInfos = inDb.map(id => getData(id));
376
+ cbThreadInfos = cbThreadInfos.concat(threadInfos);
377
+ updateUserInfo(threadInfos);
378
+
379
+ //request update queue
380
+ threadInfos.forEach(i => addToQueues({ threadID: i.threadID, TimeCreate: Date.now() }));
381
+ }
382
+ if (createNow.length >= 1) {
383
+ //5 data per chunk []
384
+ const chunkSize = 5;
385
+ const totalChunk = []; // [ [ id, id ], [ id,id ] ]
386
+
387
+ for (let i = 0; i < createNow.length; i += chunkSize) {
388
+ const chunk = createNow.slice(i, i + chunkSize);
389
+ totalChunk.push(chunk);
390
+ }
391
+
392
+ for (let i of totalChunk) {
393
+ //i = [ id,id ]
394
+ const newThreadInf = await getMultiInfo(i); // always [ {} ] or [ {}, {} ]
395
+ if (newThreadInf.Success == true) {
396
+ let MultiThread = newThreadInf.Data;
397
+ formatAndCreateData(MultiThread)
398
+ cbThreadInfos = cbThreadInfos.concat(MultiThread)
395
399
 
396
- try {
397
- for (let i of threadID) {
398
- switch (hasData(i)) {
399
- case true: {
400
- DefaultMethod(threadID);
401
- break;
400
+ //request update queue
401
+ MultiThread.forEach(i => addToQueues({ threadID: i.threadID, TimeCreate: Date.now() }));
402
402
  }
403
- case false: {
404
- CreateMethod(threadID);
405
- break;
406
- }
407
- }
403
+ else {
404
+ global.Fca.Require.logger.Warning('CANT NOT GET THREADINFO 💀 MAYBE U HAS BEEN BLOCKED FROM FACEBOOK');
405
+ }
406
+ }
408
407
  }
409
- }
410
- catch (err) {
411
- console.log(err);
412
- }
408
+ return cbThreadInfos.length == 1 ? callback(null, cbThreadInfos[0]) : callback(null, cbThreadInfos)
409
+ }
410
+
411
+ if (global.Fca.Data.Already != true) {
412
+ global.Fca.Data.Already = true;
413
+ autoCheckAndUpdateRecallTime();
414
+ setInterval(function(){
415
+ const MapToArray = Array.from(global.Fca.Data.Userinfo, ([name, value]) => (value));
416
+ Database(true).set('UserInfo', MapToArray);
417
+ }, 420 * 1000);
418
+ }
419
+
420
+ await createOrTakeDataFromDatabase(threadID);
421
+
413
422
  return returnPromise;
414
423
  };
415
424
  };
@@ -45,35 +45,34 @@ module.exports = function (defaultFuncs, api, ctx) {
45
45
  }
46
46
 
47
47
  if (utils.getType(id) !== "Array") id = [id];
48
+ if (utils.getType(global.Fca.Data.Userinfo) == "Array" || global.Fca.Data.Userinfo == undefined) global.Fca.Data.Userinfo = new Map();
48
49
  if (global.Fca.Data.AlreadyGetInfo != true) {
49
50
  if (Database(true).has('UserInfo') == false) {
50
51
  Database(true).set('UserInfo', []);
51
52
  global.Fca.Data.AlreadyGetInfo = true;
52
53
  }
53
54
  }
54
-
55
- var NeedGet = [];
56
55
  var AlreadyGet = [];
57
-
58
- if (global.Fca.Data.Userinfo != undefined && global.Fca.Data.Userinfo.length != 0) {
59
- for (let i of id) {
60
- if (global.Fca.Data.Userinfo.some(ii => ii.id == i)) {
56
+ var NeedGet = [];
57
+ if (global.Fca.Data.Userinfo != undefined && global.Fca.Data.Userinfo.size != undefined) {
58
+ for (let idu of id) {
59
+ if (global.Fca.Data.Userinfo.has(idu)) {
61
60
  let Format = {};
62
- Format[i] = global.Fca.Data.Userinfo.find(ii => ii.id == i);
61
+ Format[idu] = global.Fca.Data.Userinfo.get(idu);
63
62
  AlreadyGet.push(Format);
64
- }
65
- else {
63
+ } else {
66
64
  const DatabaseUser = Database(true).get('UserInfo') || [];
67
- if (DatabaseUser.some(ii => ii.id == i)) {
68
- let Format = {};
69
- Format[i] = DatabaseUser.find(ii => ii.id == i);
65
+ const databaseUser = DatabaseUser.find(user => user.id === idu);
66
+ let Format = {};
67
+ Format[idu] = databaseUser;
68
+ if (databaseUser) {
70
69
  AlreadyGet.push(Format);
71
- }
72
- else {
73
- NeedGet.push(i);
70
+ } else {
71
+ NeedGet.push(idu);
74
72
  }
75
73
  }
76
74
  }
75
+
77
76
  }
78
77
 
79
78
  if (NeedGet.length > 0) {
@@ -103,11 +102,11 @@ module.exports = function (defaultFuncs, api, ctx) {
103
102
  });
104
103
  }
105
104
  else if (AlreadyGet.length == 1) {
106
- callback(null, AlreadyGet[0]);
105
+ callback(null,AlreadyGet[0]);
107
106
  }
108
107
  else if (AlreadyGet.length > 1) {
109
108
  callback(null, AlreadyGet);
110
109
  }
111
110
  return returnPromise;
112
111
  };
113
- };
112
+ };
@@ -53,7 +53,7 @@ module.exports = function(defaultFuncs, api, ctx) {
53
53
  callback(null, resData);
54
54
  })
55
55
  .catch(function(err) {
56
- log.error("getThreadInfoGraphQL", "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !");
56
+ log.error("getThreadInfoGraphQL", "Lỗi: getUserInfoV5 Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !");
57
57
  return callback(err);
58
58
  });
59
59
  return returnPromise;
package/src/listenMqtt.js CHANGED
@@ -91,12 +91,13 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
91
91
  const foreground = false;
92
92
 
93
93
  const sessionID = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
94
+ const GUID = utils.getGUID()
94
95
  const username = {
95
96
  u: ctx.userID,
96
97
  s: sessionID,
97
98
  chat_on: chatOn,
98
99
  fg: foreground,
99
- d: utils.getGUID(),
100
+ d: GUID,
100
101
  ct: 'websocket',
101
102
  aid: '219994525426954',
102
103
  aids: null,
@@ -117,11 +118,11 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
117
118
 
118
119
  let host;
119
120
  if (ctx.mqttEndpoint) {
120
- host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
121
+ host = `${ctx.mqttEndpoint}&sid=${sessionID}&cid=${GUID}`;
121
122
  } else if (ctx.region) {
122
- host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLowerCase()}&sid=${sessionID}`;
123
+ host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLowerCase()}&sid=${sessionID}&cid=${GUID}`;
123
124
  } else {
124
- host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
125
+ host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}&cid=${GUID}`;
125
126
  }
126
127
 
127
128
  const options = {
package/utils.js CHANGED
@@ -2972,8 +2972,40 @@ function getPaths(obj, parentPath = []) {
2972
2972
  }
2973
2973
  return paths;
2974
2974
  }
2975
+
2976
+ function cleanHTML (text) {
2977
+ text = text.replace(/(<br>)|(<\/?i>)|(<\/?em>)|(<\/?b>)|(!?~)|(&amp;)|(&#039;)|(&lt;)|(&gt;)|(&quot;)/g, (match) => {
2978
+ switch (match) {
2979
+ case "<br>":
2980
+ return "\n";
2981
+ case "<i>":
2982
+ case "<em>":
2983
+ case "</i>":
2984
+ case "</em>":
2985
+ return "*";
2986
+ case "<b>":
2987
+ case "</b>":
2988
+ return "**";
2989
+ case "~!":
2990
+ case "!~":
2991
+ return "||";
2992
+ case "&amp;":
2993
+ return "&";
2994
+ case "&#039;":
2995
+ return "'";
2996
+ case "&lt;":
2997
+ return "<";
2998
+ case "&gt;":
2999
+ return ">";
3000
+ case "&quot;":
3001
+ return '"';
3002
+ }
3003
+ });
3004
+ return text;
3005
+ }
2975
3006
 
2976
3007
  module.exports = {
3008
+ cleanHTML,
2977
3009
  isReadableStream:isReadableStream,
2978
3010
  get:get,
2979
3011
  post:post,