king-boy 3.3.0 → 9.4.3

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.
@@ -57,5 +57,5 @@ module.exports = function(defaultFuncs, api, ctx) {
57
57
  return callback(err);
58
58
  });
59
59
  return returnPromise;
60
- }
60
+ };
61
61
  };
package/src/listenMqtt.js CHANGED
@@ -6,7 +6,6 @@ var mqtt = require('mqtt');
6
6
  var websocket = require('websocket-stream');
7
7
  var HttpsProxyAgent = require('https-proxy-agent');
8
8
  const EventEmitter = require('events');
9
- const { json } = require("body-parser");
10
9
  var identity = function () { };
11
10
  var form = {};
12
11
  var getSeqID = function () { };
@@ -38,7 +37,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
38
37
  if (ctx.mqttEndpoint) host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
39
38
  else if (ctx.region) host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLocaleLowerCase()}&sid=${sessionID}`;
40
39
  else host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
41
-
40
+
42
41
  var options = {
43
42
  clientId: "mqttwsclient",
44
43
  protocolId: 'MQIsdp',
@@ -56,23 +55,22 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
56
55
  origin: 'https://www.facebook.com',
57
56
  protocolVersion: 13
58
57
  },
59
- keepalive: 10,
58
+ keepalive: 60,
60
59
  reschedulePings: true,
61
- connectTimeout: 10000,
62
- reconnectPeriod: 1000
60
+ reconnectPeriod: 3
63
61
  };
64
62
 
65
63
  if (typeof ctx.globalOptions.proxy != "undefined") {
66
64
  var agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
67
65
  options.wsOptions.agent = agent;
68
66
  }
69
-
70
67
  ctx.mqttClient = new mqtt.Client(_ => websocket(host, options.wsOptions), options);
68
+ global.mqttClient = ctx.mqttClient;
71
69
 
72
- var mqttClient = ctx.mqttClient;
73
- mqttClient.on('error', function (err) {
70
+ global.mqttClient.on('error', function (err) {
74
71
  log.error("listenMqtt", err);
75
- mqttClient.end();
72
+ global.mqttClient.end();
73
+
76
74
  if (ctx.globalOptions.autoReconnect) getSeqID();
77
75
  else {
78
76
  globalCallback({ type: "stop_listen", error: "Server Đã Sập - Auto Restart" }, null);
@@ -80,10 +78,21 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
80
78
  }
81
79
  });
82
80
 
83
- mqttClient.on('connect', function () {
84
-
81
+ global.mqttClient.on('connect', function () {
82
+ if (!global.Fca.Data.Setup || global.Fca.Data.Setup == undefined) {
83
+ if (global.Fca.Require.FastConfig.RestartMQTT_Minutes != 0 && global.Fca.Data.StopListening != true) {
84
+ global.Fca.Data.Setup = true;
85
+ setTimeout(() => {
86
+ global.Fca.Require.logger.Warning("Closing MQTT Client...");
87
+ ctx.mqttClient.end();
88
+ global.Fca.Require.logger.Warning("Reconnecting MQTT Client...");
89
+ global.Fca.Data.Setup = false;
90
+ getSeqID();
91
+ }, Number(global.Fca.Require.FastConfig.RestartMQTT_Minutes) * 60 * 1000);
92
+ }
93
+ }
85
94
  if (process.env.OnStatus == undefined) {
86
- global.Fca.Require.logger.Normal(global.Fca.Data.PremText || "Hiện Status Lỗi :s")
95
+ global.Fca.Require.logger.Normal(global.Fca.Data.PremText || "Hiện Status Lỗi :s");
87
96
  if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) == 0) {
88
97
  // something
89
98
  }
@@ -95,6 +104,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
95
104
  }
96
105
  else {
97
106
  global.Fca.Require.logger.Normal(global.Fca.getText(global.Fca.Require.Language.Src.AutoRestart,global.Fca.Require.FastConfig.AutoRestartMinutes));
107
+ global.Fca.Require.logger.Normal("Auto Restart MQTT Client After: " + global.Fca.Require.FastConfig.RestartMQTT_Minutes + " Minutes");
98
108
  setInterval(() => {
99
109
  global.Fca.Require.logger.Normal(global.Fca.Require.Language.Src.OnRestart);
100
110
  process.exit(1);
@@ -104,7 +114,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
104
114
  process.env.OnStatus = true;
105
115
  }
106
116
 
107
- topics.forEach(topicsub => mqttClient.subscribe(topicsub));
117
+ topics.forEach(topicsub => global.mqttClient.subscribe(topicsub));
108
118
 
109
119
  var topic;
110
120
  var queue = {
@@ -115,23 +125,14 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
115
125
  entity_fbid: ctx.userID,
116
126
  };
117
127
 
118
- if (ctx.syncToken) {
119
- topic = "/messenger_sync_get_diffs";
120
- queue.last_seq_id = ctx.lastSeqId;
121
- queue.sync_token = ctx.syncToken;
122
- } else {
123
- topic = "/messenger_sync_create_queue";
124
- queue.initial_titan_sequence_id = ctx.lastSeqId;
125
- queue.device_params = null;
126
- }
127
- mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
128
+ topic = "/messenger_sync_create_queue";
129
+ queue.initial_titan_sequence_id = ctx.lastSeqId;
130
+ queue.device_params = null;
128
131
 
129
- // set status online
130
- // fix by NTKhang
131
- mqttClient.publish("/foreground_state", JSON.stringify({"foreground": chatOn}), {qos: 1});
132
+ global.mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
132
133
 
133
134
  var rTimeout = setTimeout(function () {
134
- mqttClient.end();
135
+ global.mqttClient.end();
135
136
  getSeqID();
136
137
  }, 3000);
137
138
 
@@ -142,8 +143,9 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
142
143
  };
143
144
  });
144
145
 
145
- mqttClient.on('message', function (topic, message, _packet) {
146
- const jsonMessage = JSON.parse(message.toString());
146
+ global.mqttClient.on('message', function (topic, message, _packet) {
147
+ const jsonMessage = JSON.parse(message.toString());
148
+
147
149
  if (topic === "/t_ms") {
148
150
  if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
149
151
 
@@ -190,17 +192,10 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
190
192
  LogUptime();process.kill(process.pid);
191
193
  });
192
194
 
193
- process.on('exit', (code) => {
195
+ process.on('exit', () => {
194
196
  LogUptime();
195
197
  });
196
198
 
197
- mqttClient.on('close', function () {
198
-
199
- });
200
-
201
- mqttClient.on('disconnect',function () {
202
- process.exit(1);
203
- });
204
199
  }
205
200
 
206
201
  function LogUptime() {
@@ -228,7 +223,7 @@ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
228
223
  } catch (err) {
229
224
  return log.error("Lỗi Nhẹ", err);
230
225
  }
231
- global.Fca.Data.event = fmtMsg;
226
+ global.Fca.Data.event = fmtMsg;
232
227
  try {
233
228
  if (process.env.HalzionVersion == 1973) {
234
229
  var { updateMessageCount,getData,hasData } = require('../Extra/ExtraGetThread');
@@ -621,25 +616,25 @@ module.exports = function (defaultFuncs, api, ctx) {
621
616
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
622
617
  .then((resData) => {
623
618
  if (utils.getType(resData) != "Array") {
624
- switch (global.Fca.Require.FastConfig.AutoLogin) {
625
- case true: {
626
- global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
627
- return global.Fca.AutoLogin();
628
- });
629
- break;
630
- }
631
- case false: {
632
- throw { error: global.Fca.Require.Language.Index.ErrAppState };
633
-
634
- }
619
+ if (global.Fca.Require.FastConfig.AutoLogin) {
620
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
621
+ return global.Fca.Action('AutoLogin');
622
+ });
623
+ }
624
+ else if (!global.Fca.Require.FastConfig.AutoLogin) {
625
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
635
626
  }
627
+ return;
628
+ }
629
+ else {
630
+ if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
631
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
632
+ if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
633
+ ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
634
+ listenMqtt(defaultFuncs, api, ctx, globalCallback);
635
+ }
636
+ else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
636
637
  }
637
- if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
638
- if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
639
- if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
640
- ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
641
- listenMqtt(defaultFuncs, api, ctx, globalCallback);
642
- } else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
643
638
  })
644
639
  .catch((err) => {
645
640
  log.error("getSeqId", err);
@@ -659,10 +654,10 @@ module.exports = function (defaultFuncs, api, ctx) {
659
654
  ctx.mqttClient.unsubscribe("/onevc");
660
655
  ctx.mqttClient.publish("/browser_close", "{}");
661
656
  ctx.mqttClient.end(false, function (...data) {
662
- callback(data);
663
657
  ctx.mqttClient = undefined;
664
658
  });
665
659
  }
660
+ global.Fca.Data.StopListening = true;
666
661
  }
667
662
  }
668
663
 
@@ -153,7 +153,7 @@ module.exports = function (defaultFuncs, api, ctx) {
153
153
  }
154
154
  else {
155
155
  sendContent(form, threadID, !isGroup, messageAndOTID, callback);
156
- global.Fca.isUser.push(threadID)
156
+ global.Fca.isUser.push(threadID);
157
157
  }
158
158
  }
159
159
  }
package/utils.js CHANGED
@@ -843,7 +843,7 @@ function formatHistoryMessage(m) {
843
843
  function getAdminTextMessageType(m) {
844
844
  switch (m.type) {
845
845
  case "joinable_group_link_mode_change":
846
- return "log:link-status"
846
+ return "log:link-status";
847
847
  case "magic_words":
848
848
  return "log:magic-words";
849
849
  case "change_thread_theme":
@@ -887,14 +887,14 @@ function getGenderByPhysicalMethod(name) {
887
887
  }
888
888
  break;
889
889
  case false: {
890
- if (!OtherName.includes(name.toUpperCase()) && !GirlName.includes(name.toUpperCase())) Name = "MALE"
890
+ if (!OtherName.includes(name.toUpperCase()) && !GirlName.includes(name.toUpperCase())) Name = "MALE";
891
891
  else Name = ['FEMALE','MALE'][Math.floor(Math.random() * 2)]; // just temp 🌚
892
892
  }
893
893
  break;
894
894
  }
895
895
  }
896
896
  catch (e) {
897
- return "UNKNOWN"
897
+ return "UNKNOWN";
898
898
  }
899
899
  return Name || "UNKNOWN";
900
900
  }
@@ -991,7 +991,7 @@ if (process.env.HalzionVersion == 1973) {
991
991
  id: o.userFbId,
992
992
  name: o.fullName,
993
993
  gender: getGenderByPhysicalMethod(o.fullName)
994
- })
994
+ });
995
995
  x.participantIDs.push(o.userFbId);
996
996
  }
997
997
  }
@@ -1041,23 +1041,6 @@ return {
1041
1041
  };
1042
1042
  }
1043
1043
 
1044
- /**
1045
- * @param {{ st: any; from: { toString: () => any; }; to: any; thread_fbid: any; hasOwnProperty: (arg0: string) => any; from_mobile: any; realtime_viewer_fbid: any; }} event
1046
- */
1047
-
1048
- function formatTyp(event) {
1049
- return {
1050
- isTyping: !!event.st,
1051
- from: event.from.toString(),
1052
- threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
1053
- // When receiving typ indication from mobile, `from_mobile` isn't set.
1054
- // If it is, we just use that value.
1055
- fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
1056
- userID: (event.realtime_viewer_fbid || event.from).toString(),
1057
- type: "typ"
1058
- };
1059
- }
1060
-
1061
1044
  /**
1062
1045
  * @param {{ threadKey: { otherUserFbId: any; threadFbId: any; }; actorFbId: any; actionTimestampMs: any; }} delta
1063
1046
  */
@@ -1361,18 +1344,15 @@ function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
1361
1344
  }
1362
1345
 
1363
1346
  if (res.error === 1357001) {
1364
- switch (globalThis.Fca.Require.FastConfig.AutoLogin) {
1365
- case true: {
1366
- globalThis.Fca.Require.logger.Warning(globalThis.Fca.Require.Language.Index.AutoLogin, function() {
1367
- return globalThis.Fca.AutoLogin();
1347
+ if (global.Fca.Require.FastConfig.AutoLogin) {
1348
+ return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
1349
+ return global.Fca.Action('AutoLogin');
1368
1350
  });
1369
- break;
1370
1351
  }
1371
- case false: {
1372
- throw { error: globalThis.Fca.Require.Language.Index.ErrAppState };
1373
-
1352
+ else if (!global.Fca.Require.FastConfig.AutoLogin) {
1353
+ return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
1374
1354
  }
1375
- }
1355
+ return;
1376
1356
  }
1377
1357
  else return res;
1378
1358
  });
@@ -1567,10 +1547,10 @@ function decodeClientPayload(payload) {
1567
1547
  */
1568
1548
 
1569
1549
  function getAppState(jar, Encode) {
1570
- var prettyMilliseconds = require('pretty-ms')
1550
+ var prettyMilliseconds = require('pretty-ms');
1571
1551
  var getText = globalThis.Fca.getText;
1572
- var Security = require('./Extra/Security/Index');
1573
- var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"))
1552
+ var Security = require("./Extra/Security/Index");
1553
+ var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1574
1554
  var logger = require('./logger'),languageFile = require('./Language/index.json');
1575
1555
  var Language = languageFile.find(i => i.Language == globalThis.Fca.Require.FastConfig.Language).Folder.Index;
1576
1556
  var data;
@@ -1600,7 +1580,7 @@ function getAppState(jar, Encode) {
1600
1580
  }
1601
1581
  }
1602
1582
  if(!globalThis.Fca.Setting.get('getAppState')) {
1603
- logger.Normal(getText(Language.ProcessDone,`${prettyMilliseconds(Date.now() - globalThis.Fca.startTime)}`),function() { globalThis.Fca.Setting.set('getAppState',true) });
1583
+ logger.Normal(getText(Language.ProcessDone,`${prettyMilliseconds(Date.now() - globalThis.Fca.startTime)}`),function() { globalThis.Fca.Setting.set('getAppState',true); });
1604
1584
  }
1605
1585
  return data;
1606
1586
  }
package/CountTime.json DELETED
@@ -1 +0,0 @@
1
- 6389156.211072815