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.
Files changed (74) hide show
  1. package/Extra/Balancer.js +49 -0
  2. package/Extra/Bypass/956/index.js +234 -0
  3. package/Extra/Bypass/test/aaaa.json +170 -0
  4. package/Extra/Bypass/test/index.js +188 -0
  5. package/Extra/Database/index.js +249 -140
  6. package/Extra/ExtraAddons.js +35 -33
  7. package/Extra/ExtraFindUID.js +3 -1
  8. package/Extra/ExtraGetThread.js +303 -56
  9. package/Extra/ExtraUptimeRobot.js +15 -3
  10. package/Extra/Html/Classic/script.js +3 -3
  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 +191 -0
  16. package/Extra/Security/Index.js +5 -146
  17. package/Extra/Security/Step_1.js +4 -9
  18. package/Extra/Security/Step_2.js +2 -0
  19. package/Extra/Security/Step_3.js +4 -2
  20. package/Extra/Src/Change_Environment.js +1 -1
  21. package/Extra/Src/Check_Update.js +67 -0
  22. package/Extra/Src/History.js +2 -2
  23. package/Extra/Src/Instant_Update.js +65 -0
  24. package/Extra/Src/Premium.js +35 -38
  25. package/Extra/Src/Release_Memory.js +160 -0
  26. package/Extra/Src/Websocket.js +213 -0
  27. package/Extra/Src/image/checkmate.jpg +0 -0
  28. package/Extra/Src/test.js +28 -0
  29. package/Extra/Src/uuid.js +1 -1
  30. package/Func/AcceptAgreement.js +4 -5
  31. package/Func/ClearCache.js +7 -7
  32. package/Func/ReportV1.js +5 -5
  33. package/LICENSE +1 -4
  34. package/Language/index.json +59 -8
  35. package/Main.js +1290 -0
  36. package/README.md +198 -1
  37. package/broadcast.js +43 -37
  38. package/index.js +303 -1704
  39. package/logger.js +4 -4
  40. package/package.json +16 -11
  41. package/src/Dev_Horizon_Data.js +3 -3
  42. package/src/Dev_getThreadInfoOLD.js +422 -0
  43. package/src/Dev_shareTest2.js +68 -0
  44. package/src/Dev_shareTest3.js +71 -0
  45. package/src/Premium.js +8 -13
  46. package/src/Screenshot.js +4 -6
  47. package/src/editMessage.js +53 -0
  48. package/src/getAccessToken.js +0 -4
  49. package/src/getFriendsList.js +1 -1
  50. package/src/getMessage.js +26 -3
  51. package/src/getThreadHistory.js +1 -1
  52. package/src/getThreadInfo.js +237 -161
  53. package/src/getThreadInfoOLD.js +422 -0
  54. package/src/getThreadMain.js +1 -1
  55. package/src/getUID.js +3 -3
  56. package/src/getUserInfo.js +56 -73
  57. package/src/getUserInfoMain.js +2 -2
  58. package/src/getUserInfoV2.js +0 -4
  59. package/src/getUserInfoV3.js +3 -3
  60. package/src/getUserInfoV4.js +5 -5
  61. package/src/getUserInfoV5.js +4 -4
  62. package/src/listenMqtt.js +905 -625
  63. package/src/listenMqttV1.js +846 -0
  64. package/src/sendMessage.js +54 -2
  65. package/src/sendMqttMessage.js +71 -0
  66. package/src/setPostReaction.js +3 -3
  67. package/src/shareContact.js +55 -0
  68. package/src/shareLink.js +58 -0
  69. package/src/unsendMessage.js +28 -20
  70. package/src/unsendMqttMessage.js +66 -0
  71. package/utils.js +1567 -138
  72. package/.gitattributes +0 -2
  73. package/gitattributes +0 -2
  74. package/gitignore.txt +0 -10
@@ -1,7 +1,7 @@
1
+ /* eslint-disable linebreak-style */
1
2
  "use strict";
2
3
 
3
4
  var utils = require("../utils");
4
- var log = require("npmlog");
5
5
  // tương lai đi rồi fix ahahha
6
6
  function formatEventReminders(reminder) {
7
7
  return {
@@ -145,13 +145,38 @@ 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,alreadyUpdate,setLastRun,updateData, getAll } = require('../Extra/ExtraGetThread');
151
- var { capture } = require('../Extra/Src/Last-Run');
152
- global.Fca.Data.Userinfo = [];
176
+ var { createData,getData,hasData,updateData, getAll } = require('../Extra/ExtraGetThread');
177
+ var Database = require('../Extra/Database');
153
178
 
154
- return function getThreadInfoGraphQL(threadID, callback) {
179
+ return async function getThreadInfoGraphQL(threadID, callback) {
155
180
  var resolveFunc = function(){};
156
181
  var rejectFunc = function(){};
157
182
  var returnPromise = new Promise(function (resolve, reject) {
@@ -167,182 +192,233 @@ module.exports = function(defaultFuncs, api, ctx) {
167
192
  resolveFunc(data);
168
193
  };
169
194
  }
195
+
196
+ if (utils.getType(threadID) !== "Array") threadID = [threadID];
170
197
 
171
- // đượ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 🤴
172
- // những code tương tự muliti thread như này đều có thể là copy idea 🐧
173
- // đã á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
174
- //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 !
175
198
 
176
- var time = new Date().toLocaleDateString('vi-VN', {minute: 'numeric' }).split(',')[0]
199
+ if (utils.getType(global.Fca.Data.Userinfo) == "Array" || global.Fca.Data.Userinfo == undefined) global.Fca.Data.Userinfo = new Map();
177
200
 
178
- if (utils.getType(threadID) !== "Array") threadID = [threadID];
179
-
180
-
181
- var SpecialMethod = function(TID) {
182
- var All = getAll();
183
- var AllofThread = []
184
- if (All.length < 1) {
185
- return DefaultMethod(TID);
186
- } else if (All.length > 1) {
187
- for (let i of All) {
188
- if (i.data.threadID != undefined) {
189
- AllofThread.push(i.data.threadID);
190
- } else continue;
201
+ const updateUserInfo = (threadInfo) => {
202
+ if (!global.Fca.Data.Userinfo) {
203
+ global.Fca.Data.Userinfo = new Map();
204
+ }
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
+ }
191
214
  }
192
- var Form = {};
193
- var ThreadInfo = [];
194
-
195
- AllofThread.map(function (x,y) {
196
- Form["o" + y] = {
197
- doc_id: "3449967031715030",
198
- query_params: {
199
- id: x,
200
- message_limit: 0,
201
- load_messages: false,
202
- load_read_receipts: false,
203
- before: null
204
- }
205
- };
206
- });
207
-
208
- var form = {
209
- queries: JSON.stringify(Form),
210
- batch_name: "MessengerGraphQLThreadFetcher"
211
- };
215
+ });
216
+ };
212
217
 
213
- defaultFuncs
214
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
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)
215
231
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
216
- .then(function(resData) {
217
- if (resData.error) {
218
- throw "Lỗi: getThreadInfoGraphQL Thể Do Bạn Spam Quá Nhiều"
219
- }
220
- if (resData[resData.length - 1].error_results !== 0) {
221
- throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều"
222
- }
223
- resData = resData.splice(0, resData.length - 1);
224
- resData.sort((a, b) => { return Object.keys(a)[0].localeCompare(Object.keys(b)[0]); });
225
- resData.map(function (x,y) {
226
- ThreadInfo.push(formatThreadGraphQLResponse(x["o"+y].data));
232
+ .then(resData => {
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
239
+ });
240
+ })
241
+ .catch(() => {
242
+ reject({ Success: false, Data: '' })
227
243
  });
228
- global.Fca.Data.Userinfo = []
229
- if (process.env.HalzionVersion == 1973) {
230
- if (Object.keys(resData).length == 1) {
231
- updateData(threadID,ThreadInfo[0]);
232
- global.Fca.Data.Userinfo.push(ThreadInfo[0].userInfo);
233
- } else {
234
- for (let i of ThreadInfo) {
235
- updateData(i.threadID,i);
236
- global.Fca.Data.Userinfo.push(i.userInfo);
237
- }
238
- }
239
- }
240
- })
241
- .catch(function(err){
242
- throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều"
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);
244
256
  }
257
+ }
258
+
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);
245
266
  }
246
- var DefaultMethod = function(TID) {
247
- var ThreadInfo = [];
248
- for (let i of TID) {
249
- ThreadInfo.push(getData(i));
250
- }
251
- if (ThreadInfo.length == 1) {
252
- callback(null,ThreadInfo[0]);
253
- global.Fca.Data.Userinfo.push(ThreadInfo[0].userInfo);
254
- } else {
255
- for (let i of ThreadInfo) {
256
- global.Fca.Data.Userinfo.push(i.userInfo);
257
- }
258
- callback(null,ThreadInfo);
259
- }
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)
260
276
  }
261
- var CreateMethod = function(TID) {
262
- var Form = {}
263
- var ThreadInfo = [];
264
-
265
- TID.map(function (x,y) {
266
- Form["o" + y] = {
267
- doc_id: "3449967031715030",
268
- query_params: {
269
- id: x,
270
- message_limit: 0,
271
- load_messages: false,
272
- load_read_receipts: false,
273
- before: null
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 =))
291
+ }
292
+ else {
293
+ oneTimeCall = true;
274
294
  }
275
- };
276
295
  });
277
296
 
278
- var form = {
279
- queries: JSON.stringify(Form),
280
- batch_name: "MessengerGraphQLThreadFetcher"
281
- };
297
+ if (oneTimeCall) autoUpdateData(); // cập nhật ngay, nhin la biet tot hon hold roi =))
282
298
 
283
- defaultFuncs
284
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
285
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
286
- .then(function(resData) {
287
- if (resData.error) {
288
- callback(null,{threadID:"5011501735554963",threadName:"TempThreadInfo",participantIDs:["100042817150429","100077059530660"],userInfo:[{id:"100042817150429",name:"Nguyễn Th\xe1i Hảo",firstName:"Hảo",vanity:"Lazic.Kanzu",thumbSrc:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t39.30808-1/311136459_774539707316594_357342861145224378_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=101&ccb=1-7&_nc_sid=f67be1&_nc_ohc=0y9pN1XSiVIAX8HS5P6&_nc_ht=scontent.fsgn5-10.fna&oh=00_AfCBYmeKDgLZLWDMRBmBZj8zRLboVA096bkbsC4a1Q0DUQ&oe=637E5939",profileUrl:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t39.30808-1/311136459_774539707316594_357342861145224378_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=101&ccb=1-7&_nc_sid=f67be1&_nc_ohc=0y9pN1XSiVIAX8HS5P6&_nc_ht=scontent.fsgn5-10.fna&oh=00_AfCBYmeKDgLZLWDMRBmBZj8zRLboVA096bkbsC4a1Q0DUQ&oe=637E5939",gender:"MALE",type:"User",isFriend:!0,isBirthday:!1},{id:"100077059530660",name:"Lucius Hori",firstName:"Lucius",vanity:"Horizon.Lucius.Synthesis.III",thumbSrc:"https://scontent.fsgn5-3.fna.fbcdn.net/v/t39.30808-1/309709623_179304871314830_1479186956574752444_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=104&ccb=1-7&_nc_sid=7206a8&_nc_ohc=rXiLw0_ID7MAX-q4wYv&_nc_ht=scontent.fsgn5-3.fna&oh=00_AfD8Wl_EQLLBCZOWxmBdcIP9Nc1iyLQY9qsMTIN4Sf5H8w&oe=637D35E0",profileUrl:"https://scontent.fsgn5-3.fna.fbcdn.net/v/t39.30808-1/309709623_179304871314830_1479186956574752444_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=104&ccb=1-7&_nc_sid=7206a8&_nc_ohc=rXiLw0_ID7MAX-q4wYv&_nc_ht=scontent.fsgn5-3.fna&oh=00_AfD8Wl_EQLLBCZOWxmBdcIP9Nc1iyLQY9qsMTIN4Sf5H8w&oe=637D35E0",gender:"MALE",type:"User",isFriend:!1,isBirthday:!1}],unreadCount:38357,messageCount:39288,timestamp:"1668862170994",muteUntil:null,isGroup:!0,isSubscribed:!0,isArchived:!1,folder:"INBOX",cannotReplyReason:null,eventReminders:[],emoji:"\uD83D\uDE0F",color:"DD8800",nicknames:{"100042817150429":"Bla bla"},adminIDs:[{id:"100042817150429"}],approvalMode:!0,approvalQueue:[],reactionsMuteMode:"reactions_not_muted",mentionsMuteMode:"mentions_not_muted",isPinProtected:!1,relatedPageThread:null,name:"Temp ThreadInfo GraphQL",snippet:"/getthreadtest",snippetSender:"100042817150429",snippetAttachments:[],serverTimestamp:"1668862170994",imageSrc:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t1.15752-9/278020824_345766417524223_6790288127531819759_n.jpg?_nc_cat=101&ccb=1-7&_nc_sid=02e273&_nc_ohc=kOr9K5TWwDMAX-4qPH1&_nc_ht=scontent.fsgn5-10.fna&oh=03_AdRQSwLyIGJ-zrgyQj1IIQAFO3IC-4_Qq_qMd58ZtMCI0A&oe=63A02D7A",isCanonicalUser:!1,isCanonical:!1,recipientsLoadable:!0,hasEmailParticipant:!1,readOnly:!1,canReply:!0,lastMessageType:"message",lastReadTimestamp:"1649756873571",threadType:2,TimeCreate:1668862173440,TimeUpdate:1668862173440});
289
- throw resData.error
290
- }
291
- if (resData[resData.length - 1].error_results !== 0) {
292
- callback(null,{threadID:"5011501735554963",threadName:"TempThreadInfo",participantIDs:["100042817150429","100077059530660"],userInfo:[{id:"100042817150429",name:"Nguyễn Th\xe1i Hảo",firstName:"Hảo",vanity:"Lazic.Kanzu",thumbSrc:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t39.30808-1/311136459_774539707316594_357342861145224378_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=101&ccb=1-7&_nc_sid=f67be1&_nc_ohc=0y9pN1XSiVIAX8HS5P6&_nc_ht=scontent.fsgn5-10.fna&oh=00_AfCBYmeKDgLZLWDMRBmBZj8zRLboVA096bkbsC4a1Q0DUQ&oe=637E5939",profileUrl:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t39.30808-1/311136459_774539707316594_357342861145224378_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=101&ccb=1-7&_nc_sid=f67be1&_nc_ohc=0y9pN1XSiVIAX8HS5P6&_nc_ht=scontent.fsgn5-10.fna&oh=00_AfCBYmeKDgLZLWDMRBmBZj8zRLboVA096bkbsC4a1Q0DUQ&oe=637E5939",gender:"MALE",type:"User",isFriend:!0,isBirthday:!1},{id:"100077059530660",name:"Lucius Hori",firstName:"Lucius",vanity:"Horizon.Lucius.Synthesis.III",thumbSrc:"https://scontent.fsgn5-3.fna.fbcdn.net/v/t39.30808-1/309709623_179304871314830_1479186956574752444_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=104&ccb=1-7&_nc_sid=7206a8&_nc_ohc=rXiLw0_ID7MAX-q4wYv&_nc_ht=scontent.fsgn5-3.fna&oh=00_AfD8Wl_EQLLBCZOWxmBdcIP9Nc1iyLQY9qsMTIN4Sf5H8w&oe=637D35E0",profileUrl:"https://scontent.fsgn5-3.fna.fbcdn.net/v/t39.30808-1/309709623_179304871314830_1479186956574752444_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=104&ccb=1-7&_nc_sid=7206a8&_nc_ohc=rXiLw0_ID7MAX-q4wYv&_nc_ht=scontent.fsgn5-3.fna&oh=00_AfD8Wl_EQLLBCZOWxmBdcIP9Nc1iyLQY9qsMTIN4Sf5H8w&oe=637D35E0",gender:"MALE",type:"User",isFriend:!1,isBirthday:!1}],unreadCount:38357,messageCount:39288,timestamp:"1668862170994",muteUntil:null,isGroup:!0,isSubscribed:!0,isArchived:!1,folder:"INBOX",cannotReplyReason:null,eventReminders:[],emoji:"\uD83D\uDE0F",color:"DD8800",nicknames:{"100042817150429":"Bla bla"},adminIDs:[{id:"100042817150429"}],approvalMode:!0,approvalQueue:[],reactionsMuteMode:"reactions_not_muted",mentionsMuteMode:"mentions_not_muted",isPinProtected:!1,relatedPageThread:null,name:"Temp ThreadInfo GraphQL",snippet:"/getthreadtest",snippetSender:"100042817150429",snippetAttachments:[],serverTimestamp:"1668862170994",imageSrc:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t1.15752-9/278020824_345766417524223_6790288127531819759_n.jpg?_nc_cat=101&ccb=1-7&_nc_sid=02e273&_nc_ohc=kOr9K5TWwDMAX-4qPH1&_nc_ht=scontent.fsgn5-10.fna&oh=03_AdRQSwLyIGJ-zrgyQj1IIQAFO3IC-4_Qq_qMd58ZtMCI0A&oe=63A02D7A",isCanonicalUser:!1,isCanonical:!1,recipientsLoadable:!0,hasEmailParticipant:!1,readOnly:!1,canReply:!0,lastMessageType:"message",lastReadTimestamp:"1649756873571",threadType:2,TimeCreate:1668862173440,TimeUpdate:1668862173440});
293
- throw resData.error
294
- }
295
- resData = resData.splice(0, resData.length - 1);
296
- resData.sort((a, b) => { return Object.keys(a)[0].localeCompare(Object.keys(b)[0]); });
297
- resData.map(function (x,y) {
298
- ThreadInfo.push(formatThreadGraphQLResponse(x["o"+y].data));
299
- });
300
- if (process.env.HalzionVersion == 1973) {
301
- if (Object.keys(resData).length == 1) {
302
- // api.Horizon_Data([ThreadInfo], "Threads", "Post");
303
- createData(threadID,ThreadInfo[0]);
304
- callback(null, ThreadInfo[0]);
305
- capture(callback);
306
- setLastRun('LastUpdate', callback);
307
- } else {
308
- // api.Horizon_Data([ThreadInfo], "Threads", "Post");
309
- for (let i of ThreadInfo) {
310
- createData(i.threadID,i);
311
- global.Fca.Data.Userinfo.push(i.userInfo);
312
- }
313
- callback(null, ThreadInfo);
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
+ // }
307
+
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
314
328
  }
315
- }
316
329
  else {
317
- callback(null, ThreadInfo[0]);
318
- global.Fca.Data.Userinfo.push(ThreadInfo[0].userInfo);
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 💀
319
333
  }
320
- })
321
- .catch(function(err){
322
- callback(null,{threadID:"5011501735554963",threadName:"TempThreadInfo",participantIDs:["100042817150429","100077059530660"],userInfo:[{id:"100042817150429",name:"Nguyễn Th\xe1i Hảo",firstName:"Hảo",vanity:"Lazic.Kanzu",thumbSrc:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t39.30808-1/311136459_774539707316594_357342861145224378_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=101&ccb=1-7&_nc_sid=f67be1&_nc_ohc=0y9pN1XSiVIAX8HS5P6&_nc_ht=scontent.fsgn5-10.fna&oh=00_AfCBYmeKDgLZLWDMRBmBZj8zRLboVA096bkbsC4a1Q0DUQ&oe=637E5939",profileUrl:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t39.30808-1/311136459_774539707316594_357342861145224378_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=101&ccb=1-7&_nc_sid=f67be1&_nc_ohc=0y9pN1XSiVIAX8HS5P6&_nc_ht=scontent.fsgn5-10.fna&oh=00_AfCBYmeKDgLZLWDMRBmBZj8zRLboVA096bkbsC4a1Q0DUQ&oe=637E5939",gender:"MALE",type:"User",isFriend:!0,isBirthday:!1},{id:"100077059530660",name:"Lucius Hori",firstName:"Lucius",vanity:"Horizon.Lucius.Synthesis.III",thumbSrc:"https://scontent.fsgn5-3.fna.fbcdn.net/v/t39.30808-1/309709623_179304871314830_1479186956574752444_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=104&ccb=1-7&_nc_sid=7206a8&_nc_ohc=rXiLw0_ID7MAX-q4wYv&_nc_ht=scontent.fsgn5-3.fna&oh=00_AfD8Wl_EQLLBCZOWxmBdcIP9Nc1iyLQY9qsMTIN4Sf5H8w&oe=637D35E0",profileUrl:"https://scontent.fsgn5-3.fna.fbcdn.net/v/t39.30808-1/309709623_179304871314830_1479186956574752444_n.jpg?stp=cp0_dst-jpg_p60x60&_nc_cat=104&ccb=1-7&_nc_sid=7206a8&_nc_ohc=rXiLw0_ID7MAX-q4wYv&_nc_ht=scontent.fsgn5-3.fna&oh=00_AfD8Wl_EQLLBCZOWxmBdcIP9Nc1iyLQY9qsMTIN4Sf5H8w&oe=637D35E0",gender:"MALE",type:"User",isFriend:!1,isBirthday:!1}],unreadCount:38357,messageCount:39288,timestamp:"1668862170994",muteUntil:null,isGroup:!0,isSubscribed:!0,isArchived:!1,folder:"INBOX",cannotReplyReason:null,eventReminders:[],emoji:"\uD83D\uDE0F",color:"DD8800",nicknames:{"100042817150429":"Bla bla"},adminIDs:[{id:"100042817150429"}],approvalMode:!0,approvalQueue:[],reactionsMuteMode:"reactions_not_muted",mentionsMuteMode:"mentions_not_muted",isPinProtected:!1,relatedPageThread:null,name:"Temp ThreadInfo GraphQL",snippet:"/getthreadtest",snippetSender:"100042817150429",snippetAttachments:[],serverTimestamp:"1668862170994",imageSrc:"https://scontent.fsgn5-10.fna.fbcdn.net/v/t1.15752-9/278020824_345766417524223_6790288127531819759_n.jpg?_nc_cat=101&ccb=1-7&_nc_sid=02e273&_nc_ohc=kOr9K5TWwDMAX-4qPH1&_nc_ht=scontent.fsgn5-10.fna&oh=03_AdRQSwLyIGJ-zrgyQj1IIQAFO3IC-4_Qq_qMd58ZtMCI0A&oe=63A02D7A",isCanonicalUser:!1,isCanonical:!1,recipientsLoadable:!0,hasEmailParticipant:!1,readOnly:!1,canReply:!0,lastMessageType:"message",lastReadTimestamp:"1649756873571",threadType:2,TimeCreate:1668862173440,TimeUpdate:1668862173440});
323
- throw err;
334
+
335
+ });
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)
353
+ }
354
+ else {
355
+ global.Fca.Require.logger.Warning('CANT NOT GET THREADINFO 💀 MAYBE U HAS BEEN BLOCKED FROM FACEBOOK');
356
+ }
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)
324
372
  });
325
- }
326
- if (global.Fca.Data.Already != true) SpecialMethod(threadID);
327
- global.Fca.Data.Already = true;
328
-
329
-
330
- setInterval(function(){
331
- SpecialMethod(threadID);
332
- }, 900 * 1000);
333
373
 
334
- for (let i of threadID) {
335
- switch (hasData(i)) {
336
- case true: {
337
- DefaultMethod(threadID);
338
- break;
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);
339
390
  }
340
- case false: {
341
- CreateMethod(threadID);
342
- break;
343
- }
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)
399
+
400
+ //request update queue
401
+ MultiThread.forEach(i => addToQueues({ threadID: i.threadID, TimeCreate: Date.now() }));
402
+ }
403
+ else {
404
+ global.Fca.Require.logger.Warning('CANT NOT GET THREADINFO 💀 MAYBE U HAS BEEN BLOCKED FROM FACEBOOK');
405
+ }
406
+ }
344
407
  }
345
- }
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
+
346
422
  return returnPromise;
347
423
  };
348
- };
424
+ };