stfca 1.0.2 → 1.0.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.
Files changed (141) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +45 -2
  3. package/checkUpdate.js +109 -0
  4. package/index.js +460 -1
  5. package/package.json +22 -46
  6. package/src/{api/action/addExternalModule.js → addExternalModule.js} +25 -25
  7. package/src/addUserToGroup.js +115 -0
  8. package/src/changeAdminStatus.js +103 -0
  9. package/src/changeArchivedStatus.js +55 -0
  10. package/src/{api/action/changeAvatar.js → changeAvatar.js} +136 -137
  11. package/src/changeAvatarV2.js +86 -0
  12. package/src/changeAvt.js +85 -0
  13. package/src/{api/action/changeBio.js → changeBio.js} +76 -75
  14. package/src/{api/messaging/changeBlockedStatus.js → changeBlockedStatus.js} +49 -48
  15. package/src/changeBlockedStatusMqtt.js +80 -0
  16. package/src/changeCover.js +72 -0
  17. package/src/changeGroupImage.js +135 -0
  18. package/src/changeName.js +79 -0
  19. package/src/changeNickname.js +59 -0
  20. package/src/changeThreadColor.js +65 -0
  21. package/src/changeThreadEmoji.js +55 -0
  22. package/src/changeUsername.js +59 -0
  23. package/src/createCommentPost.js +230 -0
  24. package/src/{api/messaging/createNewGroup.js → createNewGroup.js} +88 -88
  25. package/src/createPoll.js +71 -0
  26. package/src/createPost.js +276 -0
  27. package/src/{api/messaging/deleteMessage.js → deleteMessage.js} +56 -56
  28. package/src/{api/messaging/deleteThread.js → deleteThread.js} +56 -56
  29. package/src/editMessage.js +68 -0
  30. package/src/editMessageOld.js +67 -0
  31. package/src/follow.js +74 -0
  32. package/src/forwardAttachment.js +60 -0
  33. package/src/getAccess.js +112 -0
  34. package/src/getAvatarUser.js +78 -0
  35. package/src/{api/action/getCurrentUserID.js → getCurrentUserID.js} +7 -7
  36. package/src/{api/messaging/getEmojiUrl.js → getEmojiUrl.js} +2 -2
  37. package/src/{api/messaging/getFriendsList.js → getFriendsList.js} +83 -82
  38. package/src/{api/messaging/getMessage.js → getMessage.js} +847 -829
  39. package/src/getRegion.js +7 -0
  40. package/src/{api/threads/getThreadHistory.js → getThreadHistory.js} +680 -664
  41. package/src/getThreadHistoryDeprecated.js +71 -0
  42. package/src/getThreadInfo.js +232 -0
  43. package/src/getThreadInfoDeprecated.js +56 -0
  44. package/src/getThreadList.js +213 -0
  45. package/src/getThreadListDeprecated.js +46 -0
  46. package/src/getThreadPictures.js +59 -0
  47. package/src/getUID.js +119 -0
  48. package/src/{api/users/getUserID.js → getUserID.js} +61 -65
  49. package/src/getUserInfo.js +66 -0
  50. package/src/handleFriendRequest.js +46 -0
  51. package/src/handleMessageRequest.js +47 -0
  52. package/src/httpGet.js +49 -0
  53. package/src/httpPost.js +48 -0
  54. package/src/listenMqtt.js +833 -0
  55. package/src/logout.js +75 -0
  56. package/src/markAsDelivered.js +47 -0
  57. package/src/markAsRead.js +70 -0
  58. package/src/markAsReadAll.js +40 -0
  59. package/src/markAsSeen.js +48 -0
  60. package/src/muteThread.js +45 -0
  61. package/src/refreshFb_dtsg.js +89 -0
  62. package/src/removeUserFromGroup.js +79 -0
  63. package/src/{api/messaging/resolvePhotoUrl.js → resolvePhotoUrl.js} +45 -43
  64. package/src/{api/messaging/searchForThread.js → searchForThread.js} +53 -52
  65. package/src/searchStickers.js +53 -0
  66. package/src/sendMessage.js +379 -0
  67. package/src/{api/messaging/sendMessageMqtt.js → sendMessageMqtt.js} +322 -323
  68. package/src/sendTypingIndicator.js +101 -0
  69. package/src/sendTypingIndicatorV2.js +28 -0
  70. package/src/setMessageReaction.js +122 -0
  71. package/src/setMessageReactionMqtt.js +62 -0
  72. package/src/{api/action/setPostReaction.js → setPostReaction.js} +112 -106
  73. package/src/setStoryReaction.js +64 -0
  74. package/src/setTitle.js +90 -0
  75. package/src/shareContact.js +110 -0
  76. package/src/shareLink.js +59 -0
  77. package/src/stopListenMqtt.js +23 -0
  78. package/src/{api/messaging/threadColors.js → threadColors.js} +131 -128
  79. package/src/{api/action/unfriend.js → unfriend.js} +52 -54
  80. package/src/unsendMessage.js +45 -0
  81. package/src/{api/messaging/uploadAttachment.js → uploadAttachment.js} +93 -95
  82. package/utils.js +2876 -0
  83. package/LICENSE-MIT +0 -4
  84. package/index.d.ts +0 -615
  85. package/module/config.js +0 -33
  86. package/module/login.js +0 -48
  87. package/module/loginHelper.js +0 -722
  88. package/module/options.js +0 -44
  89. package/src/api/action/handleFriendRequest.js +0 -57
  90. package/src/api/action/logout.js +0 -76
  91. package/src/api/action/refreshFb_dtsg.js +0 -71
  92. package/src/api/http/httpGet.js +0 -46
  93. package/src/api/http/httpPost.js +0 -52
  94. package/src/api/http/postFormData.js +0 -47
  95. package/src/api/messaging/addUserToGroup.js +0 -68
  96. package/src/api/messaging/changeAdminStatus.js +0 -122
  97. package/src/api/messaging/changeArchivedStatus.js +0 -55
  98. package/src/api/messaging/changeGroupImage.js +0 -90
  99. package/src/api/messaging/changeNickname.js +0 -70
  100. package/src/api/messaging/changeThreadColor.js +0 -79
  101. package/src/api/messaging/changeThreadEmoji.js +0 -106
  102. package/src/api/messaging/createPoll.js +0 -43
  103. package/src/api/messaging/editMessage.js +0 -68
  104. package/src/api/messaging/forwardAttachment.js +0 -51
  105. package/src/api/messaging/handleMessageRequest.js +0 -65
  106. package/src/api/messaging/markAsDelivered.js +0 -57
  107. package/src/api/messaging/markAsRead.js +0 -88
  108. package/src/api/messaging/markAsReadAll.js +0 -49
  109. package/src/api/messaging/markAsSeen.js +0 -61
  110. package/src/api/messaging/muteThread.js +0 -50
  111. package/src/api/messaging/removeUserFromGroup.js +0 -105
  112. package/src/api/messaging/sendMessage.js +0 -379
  113. package/src/api/messaging/sendTypingIndicator.js +0 -67
  114. package/src/api/messaging/setMessageReaction.js +0 -75
  115. package/src/api/messaging/setTitle.js +0 -119
  116. package/src/api/messaging/shareContact.js +0 -49
  117. package/src/api/messaging/unsendMessage.js +0 -81
  118. package/src/api/socket/core/connectMqtt.js +0 -179
  119. package/src/api/socket/core/getSeqID.js +0 -25
  120. package/src/api/socket/core/getTaskResponseData.js +0 -22
  121. package/src/api/socket/core/markDelivery.js +0 -12
  122. package/src/api/socket/core/parseDelta.js +0 -351
  123. package/src/api/socket/detail/buildStream.js +0 -208
  124. package/src/api/socket/detail/constants.js +0 -24
  125. package/src/api/socket/listenMqtt.js +0 -133
  126. package/src/api/threads/getThreadInfo.js +0 -358
  127. package/src/api/threads/getThreadList.js +0 -248
  128. package/src/api/threads/getThreadPictures.js +0 -78
  129. package/src/api/users/getUserInfo.js +0 -319
  130. package/src/api/users/getUserInfoV2.js +0 -133
  131. package/src/core/sendReqMqtt.js +0 -63
  132. package/src/database/models/index.js +0 -49
  133. package/src/database/models/thread.js +0 -31
  134. package/src/database/models/user.js +0 -32
  135. package/src/database/threadData.js +0 -98
  136. package/src/database/userData.js +0 -89
  137. package/src/utils/client.js +0 -214
  138. package/src/utils/constants.js +0 -23
  139. package/src/utils/format.js +0 -1111
  140. package/src/utils/headers.js +0 -41
  141. package/src/utils/request.js +0 -215
@@ -1,98 +0,0 @@
1
- const { Thread } = require("./models");
2
-
3
- const validateThreadID = threadID => {
4
- if (typeof threadID !== "string" && typeof threadID !== "number") {
5
- throw new Error("Invalid threadID: must be a string or number.");
6
- }
7
- return String(threadID);
8
- };
9
- const validateData = data => {
10
- if (!data || typeof data !== "object" || Array.isArray(data)) {
11
- throw new Error("Invalid data: must be a non-empty object.");
12
- }
13
- };
14
-
15
- module.exports = function(bot) {
16
- return {
17
- async create(threadID, data) {
18
- try {
19
- let thread = await Thread.findOne({ where: { threadID } });
20
- if (thread) {
21
- return { thread: thread.get(), created: false };
22
- }
23
- thread = await Thread.create({ threadID, ...data });
24
- return { thread: thread.get(), created: true };
25
- } catch (error) {
26
- throw new Error(`Failed to create thread: ${error.message}`);
27
- }
28
- },
29
-
30
- async get(threadID) {
31
- try {
32
- threadID = validateThreadID(threadID);
33
- const thread = await Thread.findOne({ where: { threadID } });
34
- return thread ? thread.get() : null;
35
- } catch (error) {
36
- throw new Error(`Failed to get thread: ${error.message}`);
37
- }
38
- },
39
-
40
- async update(threadID, data) {
41
- try {
42
- threadID = validateThreadID(threadID);
43
- validateData(data);
44
- const thread = await Thread.findOne({ where: { threadID } });
45
-
46
- if (thread) {
47
- await thread.update(data);
48
- return { thread: thread.get(), created: false };
49
- } else {
50
- const newThread = await Thread.create({ ...data, threadID });
51
- return { thread: newThread.get(), created: true };
52
- }
53
- } catch (error) {
54
- throw new Error(`Failed to update thread: ${error.message}`);
55
- }
56
- },
57
-
58
- async del(threadID) {
59
- try {
60
- if (!threadID) {
61
- throw new Error("threadID is required and cannot be undefined");
62
- }
63
- threadID = validateThreadID(threadID);
64
- if (!threadID) {
65
- throw new Error("Invalid threadID");
66
- }
67
- const result = await Thread.destroy({ where: { threadID } });
68
- if (result === 0) {
69
- throw new Error("No thread found with the specified threadID");
70
- }
71
- return result;
72
- } catch (error) {
73
- throw new Error(`Failed to delete thread: ${error.message}`);
74
- }
75
- },
76
- async delAll() {
77
- try {
78
- return await Thread.destroy({ where: {} });
79
- } catch (error) {
80
- throw new Error(`Failed to delete all threads: ${error.message}`);
81
- }
82
- },
83
- async getAll(keys = null) {
84
- try {
85
- const attributes =
86
- typeof keys === "string"
87
- ? [keys]
88
- : Array.isArray(keys)
89
- ? keys
90
- : undefined;
91
- const threads = await Thread.findAll({ attributes });
92
- return threads.map(thread => thread.get());
93
- } catch (error) {
94
- throw new Error(`Failed to get all threads: ${error.message}`);
95
- }
96
- }
97
- };
98
- };
@@ -1,89 +0,0 @@
1
- const { User } = require("./models");
2
-
3
- const validateUserID = userID => {
4
- if (typeof userID !== "string" && typeof userID !== "number") {
5
- throw new Error("Invalid userID: must be a string or number.");
6
- }
7
- return String(userID);
8
- };
9
- const validateData = data => {
10
- if (!data || typeof data !== "object" || Array.isArray(data)) {
11
- throw new Error("Invalid data: must be a non-empty object.");
12
- }
13
- };
14
-
15
- module.exports = function (bot) {
16
- return {
17
- async create(userID, data) {
18
- try {
19
- userID = validateUserID(userID);
20
- validateData(data);
21
- let user = await User.findOne({ where: { userID } });
22
- if (user) return { user: user.get(), created: false };
23
- const payload = Object.prototype.hasOwnProperty.call(data, "data") ? data : { data };
24
- user = await User.create({ userID, ...payload });
25
- return { user: user.get(), created: true };
26
- } catch (error) {
27
- throw new Error(`Failed to create user: ${error.message}`);
28
- }
29
- },
30
-
31
- async get(userID) {
32
- try {
33
- userID = validateUserID(userID);
34
- const user = await User.findOne({ where: { userID } });
35
- return user ? user.get() : null;
36
- } catch (error) {
37
- throw new Error(`Failed to get user: ${error.message}`);
38
- }
39
- },
40
-
41
- async update(userID, data) {
42
- try {
43
- userID = validateUserID(userID);
44
- validateData(data);
45
- const payload = Object.prototype.hasOwnProperty.call(data, "data") ? data : { data };
46
- const user = await User.findOne({ where: { userID } });
47
- if (user) {
48
- await user.update(payload);
49
- return { user: user.get(), created: false };
50
- } else {
51
- const newUser = await User.create({ userID, ...payload });
52
- return { user: newUser.get(), created: true };
53
- }
54
- } catch (error) {
55
- throw new Error(`Failed to update user: ${error.message}`);
56
- }
57
- },
58
-
59
- async del(userID) {
60
- try {
61
- if (!userID) throw new Error("userID is required and cannot be undefined");
62
- userID = validateUserID(userID);
63
- const result = await User.destroy({ where: { userID } });
64
- if (result === 0) throw new Error("No user found with the specified userID");
65
- return result;
66
- } catch (error) {
67
- throw new Error(`Failed to delete user: ${error.message}`);
68
- }
69
- },
70
-
71
- async delAll() {
72
- try {
73
- return await User.destroy({ where: {} });
74
- } catch (error) {
75
- throw new Error(`Failed to delete all users: ${error.message}`);
76
- }
77
- },
78
-
79
- async getAll(keys = null) {
80
- try {
81
- const attributes = typeof keys === "string" ? [keys] : Array.isArray(keys) ? keys : undefined;
82
- const users = await User.findAll({ attributes });
83
- return users.map(u => u.get());
84
- } catch (error) {
85
- throw new Error(`Failed to get all users: ${error.message}`);
86
- }
87
- }
88
- };
89
- };
@@ -1,214 +0,0 @@
1
- "use strict";
2
-
3
- function saveCookies(jar) {
4
- return res => {
5
- try {
6
- const setCookie = res?.headers?.["set-cookie"];
7
- if (Array.isArray(setCookie) && setCookie.length) {
8
- const url = res?.request?.res?.responseUrl || (res?.config?.baseURL ? new URL(res.config.url || "/", res.config.baseURL).toString() : res?.config?.url || "https://www.facebook.com");
9
- for (const c of setCookie) {
10
- try {
11
- jar.setCookieSync(c, url);
12
- } catch { }
13
- }
14
- }
15
- } catch { }
16
- return res;
17
- };
18
- }
19
-
20
- function getAppState(jar) {
21
- if (!jar || typeof jar.getCookiesSync !== "function") return [];
22
- const urls = ["https://www.facebook.com", "https://www.messenger.com"];
23
- const all = urls.flatMap(u => {
24
- try { return jar.getCookiesSync(u) || []; } catch { return []; }
25
- });
26
- const seen = new Set();
27
- const out = [];
28
- for (const c of all) {
29
- const key = c.key || c.name;
30
- if (!key) continue;
31
- const id = key + "|" + (c.domain || "") + "|" + (c.path || "/");
32
- if (seen.has(id)) continue;
33
- seen.add(id);
34
- out.push({
35
- key,
36
- value: c.value,
37
- domain: c.domain || ".facebook.com",
38
- path: c.path || "/",
39
- hostOnly: !!c.hostOnly,
40
- creation: c.creation || new Date(),
41
- lastAccessed: c.lastAccessed || new Date(),
42
- secure: !!c.secure,
43
- httpOnly: !!c.httpOnly,
44
- expires: c.expires && c.expires !== "Infinity" ? c.expires : "Infinity"
45
- });
46
- }
47
- return out;
48
- }
49
-
50
- function makeParsable(html) {
51
- const raw = cleanXssi(String(html || ""));
52
- const split = raw.split(/\}\r?\n\s*\{/);
53
- if (split.length === 1) return raw;
54
- return "[" + split.join("},{") + "]";
55
- }
56
-
57
- function cleanXssi(t) {
58
- if (t == null) return "";
59
- let s = String(t);
60
- s = s.replace(/^[\uFEFF\xEF\xBB\xBF]+/, "");
61
- s = s.replace(/^\)\]\}',?\s*/, "");
62
- s = s.replace(/^\s*for\s*\(;;\);\s*/i, "");
63
- return s;
64
- }
65
-
66
- function parseAndCheckLogin(ctx, http, retryCount = 0) {
67
- const delay = ms => new Promise(r => setTimeout(r, ms));
68
- const headerOf = (headers, name) => {
69
- if (!headers) return;
70
- const k = Object.keys(headers).find(k => k.toLowerCase() === name.toLowerCase());
71
- return k ? headers[k] : undefined;
72
- };
73
- const buildUrl = cfg => {
74
- try {
75
- return cfg?.baseURL ? new URL(cfg.url || "/", cfg.baseURL).toString() : cfg?.url || "";
76
- } catch {
77
- return cfg?.url || "";
78
- }
79
- };
80
-
81
- const formatCookie = (arr, service) => {
82
- const n = String(arr?.[0] || "");
83
- const v = String(arr?.[1] || "");
84
- return `${n}=${v}; Domain=.${service}.com; Path=/; Secure`;
85
- };
86
-
87
- const maybeAutoLogin = async (resData) => {
88
- if (ctx.auto_login) {
89
- const e = new Error("Not logged in.");
90
- e.error = "Not logged in.";
91
- e.res = resData;
92
- throw e;
93
- }
94
- if (typeof ctx.performAutoLogin !== "function") {
95
- const e = new Error("Not logged in.");
96
- e.error = "Not logged in.";
97
- e.res = resData;
98
- throw e;
99
- }
100
- ctx.auto_login = true;
101
- console.warn("Login session expired");
102
- const ok = await ctx.performAutoLogin();
103
- if (ok) {
104
- console.log("Auto login successful! Restarting...");
105
- ctx.auto_login = false;
106
- process.exit(1);
107
- } else {
108
- ctx.auto_login = false;
109
- const e = new Error("Not logged in.");
110
- e.error = "Not logged in.";
111
- e.res = resData;
112
- throw e;
113
- }
114
- };
115
- return async (res) => {
116
- const status = res?.status ?? 0;
117
- if (status >= 500 && status < 600) {
118
- if (retryCount >= 5) {
119
- const err = new Error("Request retry failed. Check the `res` and `statusCode` property on this error.");
120
- err.statusCode = status;
121
- err.res = res?.data;
122
- err.error = "Request retry failed. Check the `res` and `statusCode` property on this error.";
123
- throw err;
124
- }
125
- const retryTime = Math.floor(Math.random() * 5000);
126
- await delay(retryTime);
127
- const url = buildUrl(res?.config);
128
- const method = String(res?.config?.method || "GET").toUpperCase();
129
- const ctype = String(headerOf(res?.config?.headers, "content-type") || "").toLowerCase();
130
- const isMultipart = ctype.includes("multipart/form-data");
131
- const payload = res?.config?.data;
132
- const params = res?.config?.params;
133
- retryCount += 1;
134
- if (method === "GET") {
135
- const newData = await http.get(url, ctx.jar, params || null, ctx.globalOptions, ctx);
136
- return await parseAndCheckLogin(ctx, http, retryCount)(newData);
137
- }
138
- if (isMultipart) {
139
- const newData = await http.postFormData(url, ctx.jar, payload, params, ctx.globalOptions, ctx);
140
- return await parseAndCheckLogin(ctx, http, retryCount)(newData);
141
- } else {
142
- const newData = await http.post(url, ctx.jar, payload, ctx.globalOptions, ctx);
143
- return await parseAndCheckLogin(ctx, http, retryCount)(newData);
144
- }
145
- }
146
- if (status === 404) return;
147
- if (status !== 200) {
148
- const err = new Error("parseAndCheckLogin got status code: " + status + ". Bailing out of trying to parse response.");
149
- err.statusCode = status;
150
- err.res = res?.data;
151
- throw err;
152
- }
153
- const resBodyRaw = res?.data;
154
- const body = typeof resBodyRaw === "string" ? makeParsable(resBodyRaw) : resBodyRaw;
155
- let parsed;
156
- try {
157
- parsed = typeof body === "object" && body !== null ? body : JSON.parse(body);
158
- } catch (e) {
159
- const err = new Error("JSON.parse error. Check the `detail` property on this error.");
160
- err.error = "JSON.parse error. Check the `detail` property on this error.";
161
- err.detail = e;
162
- err.res = resBodyRaw;
163
- throw err;
164
- }
165
- const method = String(res?.config?.method || "GET").toUpperCase();
166
- if (parsed?.redirect && method === "GET") {
167
- const redirectRes = await http.get(parsed.redirect, ctx.jar, null, ctx.globalOptions, ctx);
168
- return await parseAndCheckLogin(ctx, http)(redirectRes);
169
- }
170
- if (parsed?.jsmods && parsed.jsmods.require && Array.isArray(parsed.jsmods.require[0]) && parsed.jsmods.require[0][0] === "Cookie") {
171
- parsed.jsmods.require[0][3][0] = String(parsed.jsmods.require[0][3][0] || "").replace("_js_", "");
172
- const requireCookie = parsed.jsmods.require[0][3];
173
- await ctx.jar.setCookie(formatCookie(requireCookie, "facebook"), "https://www.facebook.com");
174
- await ctx.jar.setCookie(formatCookie(requireCookie, "messenger"), "https://www.messenger.com");
175
- }
176
- if (parsed?.jsmods && Array.isArray(parsed.jsmods.require)) {
177
- for (const item of parsed.jsmods.require) {
178
- if (item[0] === "DTSG" && item[1] === "setToken") {
179
- ctx.fb_dtsg = item[3][0];
180
- ctx.ttstamp = "2";
181
- for (let j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
182
- break;
183
- }
184
- }
185
- }
186
- if (parsed?.error === 1357001) {
187
- const err = new Error("Facebook blocked the login");
188
- err.error = "Not logged in.";
189
- throw err;
190
- }
191
- const resData = parsed;
192
- const resStr = JSON.stringify(resData);
193
- if (resStr.includes("XCheckpointFBScrapingWarningController") || resStr.includes("601051028565049")) {
194
- await maybeAutoLogin(resData);
195
- }
196
- if (resStr.includes("https://www.facebook.com/login.php?") || String(parsed?.redirect || "").includes("login.php?")) {
197
- await maybeAutoLogin(resData);
198
- }
199
- if (resStr.includes("1501092823525282")) {
200
- console.error("Bot checkpoint 282 detected, please check the account!");
201
- process.exit(0);
202
- }
203
- if (resStr.includes("828281030927956")) {
204
- console.error("Bot checkpoint 956 detected, please check the account!");
205
- }
206
- return parsed;
207
- };
208
- }
209
-
210
- module.exports = {
211
- saveCookies,
212
- getAppState,
213
- parseAndCheckLogin
214
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- const { getType } = require("./format");
3
- const stream = require("stream");
4
- function getFrom(html, a, b) {
5
- const i = html.indexOf(a);
6
- if (i < 0) return;
7
- const start = i + a.length;
8
- const j = html.indexOf(b, start);
9
- return j < 0 ? undefined : html.slice(start, j);
10
- }
11
- function isReadableStream(obj) {
12
- return (
13
- obj instanceof stream.Stream &&
14
- (getType(obj._read) === "Function" ||
15
- getType(obj._read) === "AsyncFunction") &&
16
- getType(obj._readableState) === "Object"
17
- );
18
- }
19
-
20
- module.exports = {
21
- getFrom,
22
- isReadableStream
23
- };