fca-neokex-fix 1.0.1

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +220 -0
  2. package/LICENSE +26 -0
  3. package/README.md +346 -0
  4. package/THEME_FEATURES.md +137 -0
  5. package/examples/README.md +131 -0
  6. package/examples/apply-ai-theme.js +127 -0
  7. package/examples/check-current-theme.js +74 -0
  8. package/examples/simple-bot.js +114 -0
  9. package/examples/test-bot.js +752 -0
  10. package/examples/test-logging.js +85 -0
  11. package/examples/theme-usage-example.js +53 -0
  12. package/index.js +2 -0
  13. package/package.json +105 -0
  14. package/src/apis/addExternalModule.js +24 -0
  15. package/src/apis/addUserToGroup.js +108 -0
  16. package/src/apis/changeAdminStatus.js +148 -0
  17. package/src/apis/changeArchivedStatus.js +61 -0
  18. package/src/apis/changeAvatar.js +103 -0
  19. package/src/apis/changeBio.js +69 -0
  20. package/src/apis/changeBlockedStatus.js +54 -0
  21. package/src/apis/changeGroupImage.js +136 -0
  22. package/src/apis/changeThreadColor.js +116 -0
  23. package/src/apis/comment.js +207 -0
  24. package/src/apis/createAITheme.js +129 -0
  25. package/src/apis/createNewGroup.js +79 -0
  26. package/src/apis/createPoll.js +73 -0
  27. package/src/apis/deleteMessage.js +44 -0
  28. package/src/apis/deleteThread.js +52 -0
  29. package/src/apis/editMessage.js +70 -0
  30. package/src/apis/emoji.js +124 -0
  31. package/src/apis/fetchThemeData.js +65 -0
  32. package/src/apis/follow.js +81 -0
  33. package/src/apis/forwardMessage.js +52 -0
  34. package/src/apis/friend.js +243 -0
  35. package/src/apis/gcmember.js +122 -0
  36. package/src/apis/gcname.js +123 -0
  37. package/src/apis/gcrule.js +119 -0
  38. package/src/apis/getAccess.js +111 -0
  39. package/src/apis/getBotInfo.js +88 -0
  40. package/src/apis/getBotInitialData.js +43 -0
  41. package/src/apis/getFriendsList.js +79 -0
  42. package/src/apis/getMessage.js +423 -0
  43. package/src/apis/getTheme.js +104 -0
  44. package/src/apis/getThemeInfo.js +96 -0
  45. package/src/apis/getThreadHistory.js +239 -0
  46. package/src/apis/getThreadInfo.js +257 -0
  47. package/src/apis/getThreadList.js +222 -0
  48. package/src/apis/getThreadPictures.js +58 -0
  49. package/src/apis/getUserID.js +83 -0
  50. package/src/apis/getUserInfo.js +495 -0
  51. package/src/apis/getUserInfoV2.js +146 -0
  52. package/src/apis/handleMessageRequest.js +50 -0
  53. package/src/apis/httpGet.js +63 -0
  54. package/src/apis/httpPost.js +89 -0
  55. package/src/apis/httpPostFormData.js +69 -0
  56. package/src/apis/listenMqtt.js +796 -0
  57. package/src/apis/listenSpeed.js +170 -0
  58. package/src/apis/logout.js +63 -0
  59. package/src/apis/markAsDelivered.js +47 -0
  60. package/src/apis/markAsRead.js +95 -0
  61. package/src/apis/markAsReadAll.js +41 -0
  62. package/src/apis/markAsSeen.js +70 -0
  63. package/src/apis/mqttDeltaValue.js +330 -0
  64. package/src/apis/muteThread.js +45 -0
  65. package/src/apis/nickname.js +132 -0
  66. package/src/apis/notes.js +163 -0
  67. package/src/apis/pinMessage.js +141 -0
  68. package/src/apis/produceMetaTheme.js +180 -0
  69. package/src/apis/realtime.js +161 -0
  70. package/src/apis/removeUserFromGroup.js +117 -0
  71. package/src/apis/resolvePhotoUrl.js +58 -0
  72. package/src/apis/searchForThread.js +154 -0
  73. package/src/apis/sendMessage.js +281 -0
  74. package/src/apis/sendMessageMqtt.js +188 -0
  75. package/src/apis/sendTypingIndicator.js +41 -0
  76. package/src/apis/setMessageReaction.js +27 -0
  77. package/src/apis/setMessageReactionMqtt.js +61 -0
  78. package/src/apis/setThreadTheme.js +260 -0
  79. package/src/apis/setThreadThemeMqtt.js +94 -0
  80. package/src/apis/share.js +107 -0
  81. package/src/apis/shareContact.js +66 -0
  82. package/src/apis/stickers.js +257 -0
  83. package/src/apis/story.js +181 -0
  84. package/src/apis/theme.js +233 -0
  85. package/src/apis/unfriend.js +47 -0
  86. package/src/apis/unsendMessage.js +17 -0
  87. package/src/database/appStateBackup.js +189 -0
  88. package/src/database/models/index.js +56 -0
  89. package/src/database/models/thread.js +31 -0
  90. package/src/database/models/user.js +32 -0
  91. package/src/database/threadData.js +101 -0
  92. package/src/database/userData.js +90 -0
  93. package/src/engine/client.js +91 -0
  94. package/src/engine/models/buildAPI.js +109 -0
  95. package/src/engine/models/loginHelper.js +326 -0
  96. package/src/engine/models/setOptions.js +53 -0
  97. package/src/utils/auth-helpers.js +149 -0
  98. package/src/utils/autoReLogin.js +169 -0
  99. package/src/utils/axios.js +290 -0
  100. package/src/utils/clients.js +270 -0
  101. package/src/utils/constants.js +396 -0
  102. package/src/utils/formatters/data/formatAttachment.js +370 -0
  103. package/src/utils/formatters/data/formatDelta.js +153 -0
  104. package/src/utils/formatters/index.js +159 -0
  105. package/src/utils/formatters/value/formatCookie.js +91 -0
  106. package/src/utils/formatters/value/formatDate.js +36 -0
  107. package/src/utils/formatters/value/formatID.js +16 -0
  108. package/src/utils/formatters.js +1067 -0
  109. package/src/utils/headers.js +199 -0
  110. package/src/utils/index.js +151 -0
  111. package/src/utils/monitoring.js +358 -0
  112. package/src/utils/rateLimiter.js +380 -0
  113. package/src/utils/tokenRefresh.js +311 -0
  114. package/src/utils/user-agents.js +238 -0
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+ const mqtt = require('mqtt');
5
+ const websocket = require('websocket-stream');
6
+ const HttpsProxyAgent = require('https-proxy-agent');
7
+ const EventEmitter = require('events');
8
+
9
+ function connectLightspeed(ctx, globalCallback) {
10
+ let client;
11
+ let isStopped = false;
12
+
13
+ function startConnection(retryCount = 0) {
14
+ if (isStopped) return;
15
+
16
+ const chatOn = ctx.globalOptions.online;
17
+ const foreground = false;
18
+ const sessionID = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
19
+ const cookies = ctx.jar.getCookiesSync('https://www.facebook.com').join('; ');
20
+ const cid = ctx.clientID;
21
+
22
+ const username = {
23
+ u: ctx.userID,
24
+ s: sessionID,
25
+ chat_on: chatOn,
26
+ fg: foreground,
27
+ d: cid,
28
+ ct: 'websocket',
29
+ aid: '2220391788200892',
30
+ mqtt_sid: '',
31
+ cp: 3,
32
+ ecp: 10,
33
+ st: [],
34
+ pm: [],
35
+ dc: '',
36
+ no_auto_fg: true,
37
+ gas: null,
38
+ pack: [],
39
+ a: ctx.globalOptions.userAgent,
40
+ };
41
+
42
+ const queryParams = new URLSearchParams({
43
+ 'x-dgw-appid': '2220391788200892',
44
+ 'x-dgw-appversion': '0',
45
+ 'x-dgw-authtype': '1:0',
46
+ 'x-dgw-version': '5',
47
+ 'x-dgw-uuid': ctx.userID,
48
+ 'x-dgw-tier': 'prod',
49
+ 'x-dgw-loggingid': utils.getGUID(),
50
+ 'x-dgw-regionhint': ctx.region || 'PRN',
51
+ 'x-dgw-deviceid': ctx.clientID
52
+ });
53
+ const host = `wss://gateway.facebook.com/ws/lightspeed?${queryParams.toString()}`;
54
+
55
+ const options = {
56
+ clientId: 'mqttwsclient',
57
+ protocolId: 'MQIsdp',
58
+ protocolVersion: 3,
59
+ username: JSON.stringify(username),
60
+ clean: true,
61
+ wsOptions: {
62
+ headers: {
63
+ 'Cookie': cookies,
64
+ 'Origin': 'https://www.facebook.com',
65
+ 'User-Agent': username.a,
66
+ 'Referer': 'https://www.facebook.com/',
67
+ 'Host': new URL(host).hostname
68
+ }
69
+ },
70
+ keepalive: 10,
71
+ reconnectPeriod: 0
72
+ };
73
+
74
+ if (ctx.globalOptions.proxy) {
75
+ options.wsOptions.agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
76
+ }
77
+
78
+ try {
79
+ client = new mqtt.Client(_ => websocket(host, options.wsOptions), options);
80
+ utils.log("[Lightspeed] Attempting MQTT connection...");
81
+ } catch (err) {
82
+ utils.error("[Lightspeed] MQTT Client creation failed:", err.message);
83
+ reconnect(retryCount + 1);
84
+ return;
85
+ }
86
+
87
+ client.on('connect', () => {
88
+ utils.log("[Lightspeed] MQTT client connected. Attempting to subscribe to topics...");
89
+ retryCount = 0;
90
+
91
+
92
+ const topicsToSubscribe = [
93
+ "/t_ms", // Para sa mga messages at deltas
94
+ "/orca_presence", // Para sa online status
95
+ "/messaging_events" // Para sa ibang events
96
+ ];
97
+
98
+ topicsToSubscribe.forEach(topic => {
99
+ client.subscribe(topic, (err) => {
100
+ if (err) {
101
+ utils.error(`[Lightspeed] Failed to subscribe to topic ${topic}:`, err.message);
102
+ } else {
103
+ utils.log(`[Lightspeed] Subscribed to topic: ${topic}`);
104
+ }
105
+ });
106
+ });
107
+
108
+ });
109
+
110
+ client.on('message', (topic, payload) => {
111
+ utils.log(`[Lightspeed] Payload Received on topic ${topic}:`);
112
+ globalCallback(null, { type: 'lightspeed_message', topic: topic.toString(), payload: payload });
113
+ });
114
+
115
+ client.on('close', () => {
116
+ utils.warn(`[Lightspeed] Connection closed.`);
117
+ if (!isStopped) {
118
+ reconnect(retryCount + 1);
119
+ }
120
+ });
121
+
122
+ client.on('error', (err) => {
123
+ utils.error("[Lightspeed] MQTT Connection Error:", err.message);
124
+ });
125
+ }
126
+
127
+ function reconnect(retryCount) {
128
+ const delay = Math.min(3000 * Math.pow(2, retryCount), 60000);
129
+ utils.log(`[Lightspeed] Reconnecting in ${delay / 1000} seconds...`);
130
+ setTimeout(() => startConnection(retryCount), delay);
131
+ }
132
+
133
+ startConnection();
134
+
135
+ return {
136
+ stop: () => {
137
+ isStopped = true;
138
+ if (client) client.end(true);
139
+ utils.log("[Lightspeed] Listener has been manually stopped.");
140
+ }
141
+ };
142
+ }
143
+
144
+ module.exports = function (defaultFuncs, api, ctx) {
145
+ return (callback) => {
146
+ class MessageEmitter extends EventEmitter {
147
+ constructor() {
148
+ super();
149
+ this.listener = null;
150
+ }
151
+ stop() {
152
+ if (this.listener) {
153
+ this.listener.stop();
154
+ }
155
+ this.emit('stop');
156
+ }
157
+ }
158
+ const msgEmitter = new MessageEmitter();
159
+ const globalCallback = (error, message) => {
160
+ if (error) return msgEmitter.emit("error", error);
161
+ msgEmitter.emit("message", message);
162
+ };
163
+ if (typeof callback === 'function') {
164
+ msgEmitter.listener = connectLightspeed(ctx, callback);
165
+ } else {
166
+ msgEmitter.listener = connectLightspeed(ctx, globalCallback);
167
+ }
168
+ return msgEmitter;
169
+ };
170
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ /**
6
+ * @param {Object} defaultFuncs
7
+ * @param {Object} api
8
+ * @param {Object} ctx
9
+ * @returns {function(): Promise<void>}
10
+ */
11
+ module.exports = function (defaultFuncs, api, ctx) {
12
+ /**
13
+ * Logs the current user out of Facebook.
14
+ * @returns {Promise<void>} A promise that resolves when logout is successful or rejects on error.
15
+ */
16
+ return async function logout() {
17
+ const form = {
18
+ pmid: "0",
19
+ };
20
+
21
+ try {
22
+ const resData = await defaultFuncs
23
+ .post(
24
+ "https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
25
+ ctx.jar,
26
+ form,
27
+ )
28
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
29
+
30
+ const elem = resData.jsmods.instances[0][2][0].find(v => v.value === "logout");
31
+ if (!elem) {
32
+ throw { error: "Could not find logout form element." };
33
+ }
34
+
35
+ const html = resData.jsmods.markup.find(v => v[0] === elem.markup.__m)[1].__html;
36
+
37
+ const logoutForm = {
38
+ fb_dtsg: utils.getFrom(html, '"fb_dtsg" value="', '"'),
39
+ ref: utils.getFrom(html, '"ref" value="', '"'),
40
+ h: utils.getFrom(html, '"h" value="', '"'),
41
+ };
42
+
43
+ const logoutRes = await defaultFuncs
44
+ .post("https://www.facebook.com/logout.php", ctx.jar, logoutForm)
45
+ .then(utils.saveCookies(ctx.jar));
46
+
47
+ if (!logoutRes.headers || !logoutRes.headers.location) {
48
+ throw { error: "An error occurred when logging out." };
49
+ }
50
+
51
+ await defaultFuncs
52
+ .get(logoutRes.headers.location, ctx.jar)
53
+ .then(utils.saveCookies(ctx.jar));
54
+
55
+ ctx.loggedIn = false;
56
+ utils.log("logout", "Logged out successfully.");
57
+
58
+ } catch (err) {
59
+ utils.error("logout", err);
60
+ throw err;
61
+ }
62
+ };
63
+ };
@@ -0,0 +1,47 @@
1
+
2
+ "use strict";
3
+
4
+ const utils = require('../utils');
5
+ /**
6
+ * @param {Object} defaultFuncs
7
+ * @param {Object} api
8
+ * @param {Object} ctx
9
+ * @returns {function(threadID: string, messageID: string): Promise<void>}
10
+ */
11
+ module.exports = function (defaultFuncs, api, ctx) {
12
+ /**
13
+ * Marks a message as delivered.
14
+ * @param {string} threadID - The ID of the thread.
15
+ * @param {string} messageID - The ID of the message to mark as delivered.
16
+ * @returns {Promise<void>} A promise that resolves on success or rejects on error.
17
+ */
18
+ return async function markAsDelivered(threadID, messageID) {
19
+ if (!threadID || !messageID) {
20
+ const err = "Error: messageID or threadID is not defined";
21
+ utils.error("markAsDelivered", err);
22
+ throw new Error(err);
23
+ }
24
+
25
+ const form = {};
26
+ form["message_ids[0]"] = messageID;
27
+ form["thread_ids[" + threadID + "][0]"] = messageID;
28
+
29
+ try {
30
+ const resData = await defaultFuncs
31
+ .post(
32
+ "https://www.facebook.com/ajax/mercury/delivery_receipts.php",
33
+ ctx.jar,
34
+ form,
35
+ )
36
+ .then(utils.saveCookies(ctx.jar))
37
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
38
+
39
+ if (resData.error) {
40
+ throw resData;
41
+ }
42
+ } catch (err) {
43
+ utils.error("markAsDelivered", err);
44
+ throw err;
45
+ }
46
+ };
47
+ };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ /**
6
+ * @param {Object} defaultFuncs
7
+ * @param {Object} api
8
+ * @param {Object} ctx
9
+ */
10
+ module.exports = function (defaultFuncs, api, ctx) {
11
+ /**
12
+ * Marks a thread as read.
13
+ * @param {string} threadID - The ID of the thread to mark as read.
14
+ * @param {boolean} [read=true] - Whether to mark as read (true) or unread (false). Defaults to true.
15
+ * @param {Function} [callback] - The callback function.
16
+ * @returns {Promise<null|Error>} A Promise that resolves with null on success, or rejects with an Error.
17
+ */
18
+ return async function markAsRead(threadID, read, callback) {
19
+ if (
20
+ utils.getType(read) === "Function" ||
21
+ utils.getType(read) === "AsyncFunction"
22
+ ) {
23
+ callback = read;
24
+ read = true;
25
+ }
26
+ if (read == undefined) {
27
+ read = true;
28
+ }
29
+
30
+ if (!callback) {
31
+ callback = () => {};
32
+ }
33
+
34
+ const form = {};
35
+
36
+ if (typeof ctx.globalOptions.pageID !== "undefined") {
37
+ form["source"] = "PagesManagerMessagesInterface";
38
+ form["request_user_id"] = ctx.globalOptions.pageID;
39
+ form["ids[" + threadID + "]"] = read;
40
+ form["watermarkTimestamp"] = new Date().getTime();
41
+ form["shouldSendReadReceipt"] = true;
42
+ form["commerce_last_message_type"] = "";
43
+
44
+ let resData;
45
+ try {
46
+ resData = await defaultFuncs
47
+ .post(
48
+ "https://www.facebook.com/ajax/mercury/change_read_status.php",
49
+ ctx.jar,
50
+ form,
51
+ )
52
+ .then(utils.saveCookies(ctx.jar))
53
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
54
+ } catch (e) {
55
+ callback(e);
56
+ return e;
57
+ }
58
+
59
+ if (resData.error) {
60
+ const err = resData.error;
61
+ utils.error("markAsRead", err);
62
+ callback(err);
63
+ return err;
64
+ }
65
+
66
+ callback();
67
+ return null;
68
+ } else {
69
+ try {
70
+ if (ctx.mqttClient) {
71
+ const err = await new Promise((r) =>
72
+ ctx.mqttClient.publish(
73
+ "/mark_thread",
74
+ JSON.stringify({
75
+ threadID,
76
+ mark: "read",
77
+ state: read,
78
+ }),
79
+ { qos: 1, retain: false },
80
+ r,
81
+ ),
82
+ );
83
+ if (err) throw err;
84
+ } else {
85
+ throw {
86
+ error: "You can only use this function after you start listening.",
87
+ };
88
+ }
89
+ } catch (e) {
90
+ callback(e);
91
+ return e;
92
+ }
93
+ }
94
+ };
95
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+
6
+ /**
7
+ * @param {Object} defaultFuncs
8
+ * @param {Object} api
9
+ * @param {Object} ctx
10
+ * @returns {function(): Promise<void>}
11
+ */
12
+ module.exports = function (defaultFuncs, api, ctx) {
13
+ /**
14
+ * @returns {Promise<void>}
15
+ */
16
+ return async function markAsReadAll() {
17
+ const form = {
18
+ folder: "inbox",
19
+ };
20
+
21
+ try {
22
+ const resData = await defaultFuncs
23
+ .post(
24
+ "https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
25
+ ctx.jar,
26
+ form
27
+ );
28
+
29
+ const parsedData = utils.parseAndCheckLogin(resData, defaultFuncs);
30
+
31
+ if (parsedData.error) {
32
+ throw parsedData;
33
+ }
34
+
35
+ return;
36
+ } catch (err) {
37
+ utils.error("markAsReadAll", err);
38
+ throw err;
39
+ }
40
+ };
41
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ /**
6
+ * @param {Object} defaultFuncs
7
+ * @param {Object} api
8
+ * @param {Object} ctx
9
+ */
10
+ module.exports = function (defaultFuncs, api, ctx) {
11
+ /**
12
+ * Marks all messages as "seen" up to a specific timestamp.
13
+ * @param {number} [seen_timestamp=Date.now()] - The timestamp (in milliseconds) up to which messages should be marked as seen. If a function is provided, it's treated as the callback and the timestamp defaults to the current time.
14
+ * @param {Function} [callback] - The callback function.
15
+ * @returns {Promise<void>} A Promise that resolves on success or rejects with an error.
16
+ */
17
+ return async function markAsRead(seen_timestamp, callback) {
18
+ let resolveFunc = function () {};
19
+ let rejectFunc = function () {};
20
+ const returnPromise = new Promise(function (resolve, reject) {
21
+ resolveFunc = resolve;
22
+ rejectFunc = reject;
23
+ });
24
+
25
+ if (utils.getType(seen_timestamp) == "Function" || utils.getType(seen_timestamp) == "AsyncFunction") {
26
+ callback = seen_timestamp;
27
+ seen_timestamp = Date.now();
28
+ } else if (seen_timestamp === undefined) {
29
+ seen_timestamp = Date.now();
30
+ }
31
+
32
+ if (!callback) {
33
+ callback = function (err, friendList) {
34
+ if (err) {
35
+ return rejectFunc(err);
36
+ }
37
+ resolveFunc(friendList);
38
+ };
39
+ }
40
+
41
+ const form = {
42
+ seen_timestamp: seen_timestamp,
43
+ };
44
+
45
+ try {
46
+ const resData = await defaultFuncs
47
+ .post(
48
+ "https://www.facebook.com/ajax/mercury/mark_seen.php",
49
+ ctx.jar,
50
+ form,
51
+ )
52
+ .then(utils.saveCookies(ctx.jar))
53
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
54
+
55
+ if (resData.error) {
56
+ throw resData;
57
+ }
58
+
59
+ return callback();
60
+ } catch (err) {
61
+ utils.error("markAsSeen", err);
62
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
63
+ ctx.loggedIn = false;
64
+ }
65
+ return callback(err);
66
+ }
67
+
68
+ return returnPromise;
69
+ };
70
+ };