@lazyneoaz/testfca 1.0.0
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.
- package/CHANGELOG.md +229 -0
- package/COOKIE_LOGIN.md +208 -0
- package/LICENSE +3 -0
- package/README.md +492 -0
- package/index.js +2 -0
- package/package.json +120 -0
- package/scripts/build-go.mjs +54 -0
- package/scripts/detect-platform.mjs +36 -0
- package/scripts/download-prebuilt.mjs +119 -0
- package/scripts/package.mjs +6 -0
- package/scripts/postinstall.mjs +113 -0
- package/src/apis/addExternalModule.js +24 -0
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/apis/changeThreadEmoji.js +53 -0
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +52 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/e2ee.js +170 -0
- package/src/apis/editMessage.js +78 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +82 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +95 -0
- package/src/apis/getThemeInfo.js +116 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +267 -0
- package/src/apis/getThreadList.js +232 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +117 -0
- package/src/apis/getUserInfo.js +513 -0
- package/src/apis/getUserInfoV2.js +146 -0
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +1236 -0
- package/src/apis/listenSpeed.js +179 -0
- package/src/apis/logout.js +93 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/apis/markAsRead.js +115 -0
- package/src/apis/markAsReadAll.js +40 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +250 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +150 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +182 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendMessage.js +346 -0
- package/src/apis/sendMessageMqtt.js +248 -0
- package/src/apis/sendTypingIndicator.js +105 -0
- package/src/apis/setMessageReaction.js +38 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setThreadTheme.js +260 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/share.js +107 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +25 -0
- package/src/database/appStateBackup.js +298 -0
- package/src/database/models/index.js +56 -0
- package/src/database/models/thread.js +31 -0
- package/src/database/models/user.js +32 -0
- package/src/database/threadData.js +101 -0
- package/src/database/userData.js +90 -0
- package/src/e2ee/bridge.js +275 -0
- package/src/e2ee/index.js +60 -0
- package/src/engine/client.js +95 -0
- package/src/engine/models/buildAPI.js +152 -0
- package/src/engine/models/loginHelper.js +574 -0
- package/src/engine/models/setOptions.js +88 -0
- package/src/types/index.d.ts +574 -0
- package/src/utils/antiSuspension.js +529 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +336 -0
- package/src/utils/axios.js +436 -0
- package/src/utils/cache.js +54 -0
- package/src/utils/clients.js +282 -0
- package/src/utils/constants.js +410 -0
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +109 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1373 -0
- package/src/utils/headers.js +235 -0
- package/src/utils/index.js +153 -0
- package/src/utils/monitoring.js +333 -0
- package/src/utils/rateLimiter.js +319 -0
- package/src/utils/tokenRefresh.js +680 -0
- package/src/utils/user-agents.js +238 -0
- package/src/utils/validation.js +157 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
/**
|
|
7
|
+
* Made by ChoruOfficial
|
|
8
|
+
* Mqtt
|
|
9
|
+
* Adds or removes members from a group chat with pre-checking.
|
|
10
|
+
*
|
|
11
|
+
* @param {"add" | "remove"} action The action to perform.
|
|
12
|
+
* @param {string|string[]} userIDs The user ID or array of user IDs.
|
|
13
|
+
* @param {string} threadID The ID of the group chat.
|
|
14
|
+
* @param {Function} [callback] Optional callback function.
|
|
15
|
+
* @returns {Promise<object>} A promise that resolves with information about the action.
|
|
16
|
+
*/
|
|
17
|
+
return async function gcmember(action, userIDs, threadID, callback) {
|
|
18
|
+
let _callback;
|
|
19
|
+
if (typeof threadID === 'function') {
|
|
20
|
+
_callback = threadID;
|
|
21
|
+
threadID = null;
|
|
22
|
+
} else if (typeof callback === 'function') {
|
|
23
|
+
_callback = callback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let resolvePromise, rejectPromise;
|
|
27
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
28
|
+
resolvePromise = resolve;
|
|
29
|
+
rejectPromise = reject;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (typeof _callback != "function") {
|
|
33
|
+
_callback = (err, data) => {
|
|
34
|
+
// Note: We will now rarely use the 'err' parameter for validation errors
|
|
35
|
+
if (err) return rejectPromise(err);
|
|
36
|
+
resolvePromise(data);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const validActions = ["add", "remove"];
|
|
42
|
+
action = action ? action.toLowerCase() : "";
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if (!validActions.includes(action)) {
|
|
46
|
+
return _callback(null, { type: "error_gc", error: `Invalid action. Must be one of: ${validActions.join(", ")}` });
|
|
47
|
+
}
|
|
48
|
+
if (!userIDs || userIDs.length === 0) {
|
|
49
|
+
return _callback(null, { type: "error_gc", error: "userIDs is required." });
|
|
50
|
+
}
|
|
51
|
+
if (!threadID) {
|
|
52
|
+
return _callback(null, { type: "error_gc", error: "threadID is required." });
|
|
53
|
+
}
|
|
54
|
+
if (!ctx.mqttClient) {
|
|
55
|
+
return _callback(null, { type: "error_gc", error: "Not connected to MQTT" });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const threadInfo = await api.getThreadInfo(threadID);
|
|
59
|
+
if (!threadInfo) {
|
|
60
|
+
return _callback(null, { type: "error_gc", error: "Could not retrieve thread information." });
|
|
61
|
+
}
|
|
62
|
+
if (threadInfo.isGroup === false) {
|
|
63
|
+
return _callback(null, { type: "error_gc", error: "This feature is only for group chats, not private messages." });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const currentMembers = threadInfo.participantIDs;
|
|
67
|
+
const usersToModify = Array.isArray(userIDs) ? userIDs : [userIDs];
|
|
68
|
+
let queryPayload, query;
|
|
69
|
+
let finalUsers = usersToModify;
|
|
70
|
+
|
|
71
|
+
ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
|
|
72
|
+
ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
|
|
73
|
+
|
|
74
|
+
if (action === 'add') {
|
|
75
|
+
const usersToAdd = usersToModify.filter(id => !currentMembers.includes(id));
|
|
76
|
+
if (usersToAdd.length === 0) {
|
|
77
|
+
return _callback(null, { type: "error_gc", error: "All specified users are already in the group." });
|
|
78
|
+
}
|
|
79
|
+
finalUsers = usersToAdd;
|
|
80
|
+
queryPayload = { thread_key: parseInt(threadID), contact_ids: finalUsers.map(id => parseInt(id)), sync_group: 1 };
|
|
81
|
+
query = { label: "23", payload: JSON.stringify(queryPayload), queue_name: threadID, task_id: ctx.wsTaskNumber };
|
|
82
|
+
|
|
83
|
+
} else { // action is 'remove'
|
|
84
|
+
const userToRemove = usersToModify[0];
|
|
85
|
+
if (!currentMembers.includes(userToRemove)) {
|
|
86
|
+
return _callback(null, { type: "error_gc", error: `User with ID ${userToRemove} is not in this group chat.` });
|
|
87
|
+
}
|
|
88
|
+
finalUsers = [userToRemove];
|
|
89
|
+
queryPayload = { thread_id: threadID, contact_id: userToRemove, sync_group: 1 };
|
|
90
|
+
query = { label: "140", payload: JSON.stringify(queryPayload), queue_name: "remove_participant_v2", task_id: ctx.wsTaskNumber };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const context = {
|
|
94
|
+
app_id: ctx.appID,
|
|
95
|
+
payload: { epoch_id: parseInt(utils.generateOfflineThreadingID()), tasks: [query], version_id: "24631415369801570" },
|
|
96
|
+
request_id: ctx.wsReqNumber,
|
|
97
|
+
type: 3
|
|
98
|
+
};
|
|
99
|
+
context.payload = JSON.stringify(context.payload);
|
|
100
|
+
|
|
101
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
|
|
102
|
+
if (err) return _callback(err);
|
|
103
|
+
|
|
104
|
+
const gcmemberInfo = {
|
|
105
|
+
type: "gc_member_update",
|
|
106
|
+
threadID: threadID,
|
|
107
|
+
userIDs: finalUsers,
|
|
108
|
+
action: action,
|
|
109
|
+
senderID: ctx.userID,
|
|
110
|
+
BotID: ctx.userID,
|
|
111
|
+
timestamp: Date.now(),
|
|
112
|
+
};
|
|
113
|
+
return _callback(null, gcmemberInfo);
|
|
114
|
+
});
|
|
115
|
+
} catch (err) {
|
|
116
|
+
|
|
117
|
+
return _callback(null, { type: "error_gc", error: err.message || "An unknown error occurred." });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return returnPromise;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
/**
|
|
7
|
+
* Made by Choru Official
|
|
8
|
+
* Mqtt
|
|
9
|
+
* Sets the name of a group chat thread via MQTT.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} newName The new name for the group chat.
|
|
12
|
+
* @param {string} threadID The ID of the group chat thread.
|
|
13
|
+
* @param {Function} [callback] Optional callback function to be invoked upon completion.
|
|
14
|
+
* @param {string} [initiatorID] The ID of the user who initiated the group name change (e.g., from event.senderID).
|
|
15
|
+
* @returns {Promise<object>} A promise that resolves with a structured event object on success or rejects on error.
|
|
16
|
+
*/
|
|
17
|
+
return function gcname(newName, threadID, callback, initiatorID) {
|
|
18
|
+
let _callback;
|
|
19
|
+
let _initiatorID;
|
|
20
|
+
|
|
21
|
+
let _resolvePromise;
|
|
22
|
+
let _rejectPromise;
|
|
23
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
24
|
+
_resolvePromise = resolve;
|
|
25
|
+
_rejectPromise = reject;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (utils.getType(callback) === "Function" || utils.getType(callback) === "AsyncFunction") {
|
|
29
|
+
_callback = callback;
|
|
30
|
+
_initiatorID = initiatorID;
|
|
31
|
+
} else if (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction") {
|
|
32
|
+
_callback = threadID;
|
|
33
|
+
threadID = null;
|
|
34
|
+
_initiatorID = callback;
|
|
35
|
+
} else if (utils.getType(callback) === "string") {
|
|
36
|
+
_initiatorID = callback;
|
|
37
|
+
_callback = undefined;
|
|
38
|
+
} else {
|
|
39
|
+
_callback = undefined;
|
|
40
|
+
_initiatorID = undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!_callback) {
|
|
44
|
+
_callback = function (__err, __data) {
|
|
45
|
+
if (__err) _rejectPromise(__err);
|
|
46
|
+
else _resolvePromise(__data);
|
|
47
|
+
};
|
|
48
|
+
} else {
|
|
49
|
+
const originalCallback = _callback;
|
|
50
|
+
_callback = function(__err, __data) {
|
|
51
|
+
if (__err) {
|
|
52
|
+
originalCallback(__err);
|
|
53
|
+
_rejectPromise(__err);
|
|
54
|
+
} else {
|
|
55
|
+
originalCallback(null, __data);
|
|
56
|
+
_resolvePromise(__data);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_initiatorID = _initiatorID || ctx.userID;
|
|
62
|
+
|
|
63
|
+
threadID = threadID || ctx.threadID;
|
|
64
|
+
|
|
65
|
+
if (!threadID) {
|
|
66
|
+
return _callback(new Error("threadID is required to change the group chat name."));
|
|
67
|
+
}
|
|
68
|
+
if (typeof newName !== 'string') {
|
|
69
|
+
return _callback(new Error("newName must be a string."));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!ctx.mqttClient) {
|
|
73
|
+
return _callback(new Error("Not connected to MQTT"));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ctx.wsReqNumber += 1;
|
|
77
|
+
ctx.wsTaskNumber += 1;
|
|
78
|
+
|
|
79
|
+
const queryPayload = {
|
|
80
|
+
thread_key: threadID.toString(),
|
|
81
|
+
thread_name: newName,
|
|
82
|
+
sync_group: 1,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const query = {
|
|
86
|
+
failure_count: null,
|
|
87
|
+
label: '32',
|
|
88
|
+
payload: JSON.stringify(queryPayload),
|
|
89
|
+
queue_name: threadID.toString(),
|
|
90
|
+
task_id: ctx.wsTaskNumber,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const context = {
|
|
94
|
+
app_id: ctx.appID,
|
|
95
|
+
payload: {
|
|
96
|
+
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
|
97
|
+
tasks: [query],
|
|
98
|
+
version_id: '24631415369801570',
|
|
99
|
+
},
|
|
100
|
+
request_id: ctx.wsReqNumber,
|
|
101
|
+
type: 3,
|
|
102
|
+
};
|
|
103
|
+
context.payload = JSON.stringify(context.payload);
|
|
104
|
+
|
|
105
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
|
|
106
|
+
if (err) {
|
|
107
|
+
return _callback(new Error(`MQTT publish failed for gcname: ${err.message || err}`));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const gcnameChangeEvent = {
|
|
111
|
+
type: "thread_name_update",
|
|
112
|
+
threadID: threadID,
|
|
113
|
+
newName: newName,
|
|
114
|
+
senderID: _initiatorID,
|
|
115
|
+
BotID: ctx.userID,
|
|
116
|
+
timestamp: Date.now(),
|
|
117
|
+
};
|
|
118
|
+
_callback(null, gcnameChangeEvent);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return returnPromise;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
/**
|
|
7
|
+
* Made by ChoruOfficial
|
|
8
|
+
* Mqtt
|
|
9
|
+
* Adds or removes an admin from a group chat with pre-checking.
|
|
10
|
+
*
|
|
11
|
+
* @param {"admin" | "unadmin"} action The action to perform.
|
|
12
|
+
* @param {string} userID The ID of the user to promote or demote.
|
|
13
|
+
* @param {string} threadID The ID of the group chat.
|
|
14
|
+
* @param {Function} [callback] Optional callback function.
|
|
15
|
+
* @returns {Promise<object>} A promise that resolves with information about the action.
|
|
16
|
+
*/
|
|
17
|
+
return async function gcrule(action, userID, threadID, callback) {
|
|
18
|
+
let _callback;
|
|
19
|
+
if (typeof threadID === 'function') {
|
|
20
|
+
_callback = threadID;
|
|
21
|
+
threadID = null;
|
|
22
|
+
} else if (typeof callback === 'function') {
|
|
23
|
+
_callback = callback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let resolvePromise, rejectPromise;
|
|
27
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
28
|
+
resolvePromise = resolve;
|
|
29
|
+
rejectPromise = reject;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (typeof _callback != "function") {
|
|
33
|
+
_callback = (err, data) => {
|
|
34
|
+
if (err) return rejectPromise(err);
|
|
35
|
+
resolvePromise(data);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const validActions = ["admin", "unadmin"];
|
|
41
|
+
action = action ? action.toLowerCase() : "";
|
|
42
|
+
|
|
43
|
+
if (!validActions.includes(action)) {
|
|
44
|
+
return _callback(null, { type: "error_gc_rule", error: `Invalid action. Must be one of: ${validActions.join(", ")}` });
|
|
45
|
+
}
|
|
46
|
+
if (!userID) return _callback(null, { type: "error_gc_rule", error: "userID is required." });
|
|
47
|
+
if (!threadID) return _callback(null, { type: "error_gc_rule", error: "threadID is required." });
|
|
48
|
+
if (!ctx.mqttClient) return _callback(null, { type: "error_gc_rule", error: "Not connected to MQTT" });
|
|
49
|
+
|
|
50
|
+
const threadInfo = await api.getThreadInfo(threadID);
|
|
51
|
+
if (!threadInfo) {
|
|
52
|
+
return _callback(null, { type: "error_gc_rule", error: "Could not retrieve thread information." });
|
|
53
|
+
}
|
|
54
|
+
if (threadInfo.isGroup === false) {
|
|
55
|
+
return _callback(null, { type: "error_gc_rule", error: "This feature is only for group chats." });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const adminIDs = threadInfo.adminIDs || [];
|
|
59
|
+
const isCurrentlyAdmin = adminIDs.some(admin => admin.id === userID);
|
|
60
|
+
|
|
61
|
+
if (action === 'admin') {
|
|
62
|
+
if (isCurrentlyAdmin) {
|
|
63
|
+
return _callback(null, { type: "error_gc_rule", error: `User is already an admin.` });
|
|
64
|
+
}
|
|
65
|
+
} else { // action is 'unadmin'
|
|
66
|
+
if (!isCurrentlyAdmin) {
|
|
67
|
+
return _callback(null, { type: "error_gc_rule", error: `User is not an admin.` });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const isAdminStatus = action === 'admin' ? 1 : 0;
|
|
72
|
+
ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
|
|
73
|
+
ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
|
|
74
|
+
|
|
75
|
+
const queryPayload = {
|
|
76
|
+
thread_key: parseInt(threadID),
|
|
77
|
+
contact_id: parseInt(userID),
|
|
78
|
+
is_admin: isAdminStatus
|
|
79
|
+
};
|
|
80
|
+
const query = {
|
|
81
|
+
failure_count: null,
|
|
82
|
+
label: "25",
|
|
83
|
+
payload: JSON.stringify(queryPayload),
|
|
84
|
+
queue_name: "admin_status",
|
|
85
|
+
task_id: ctx.wsTaskNumber
|
|
86
|
+
};
|
|
87
|
+
const context = {
|
|
88
|
+
app_id: ctx.appID,
|
|
89
|
+
payload: {
|
|
90
|
+
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
|
91
|
+
tasks: [query],
|
|
92
|
+
version_id: "24631415369801570"
|
|
93
|
+
},
|
|
94
|
+
request_id: ctx.wsReqNumber,
|
|
95
|
+
type: 3
|
|
96
|
+
};
|
|
97
|
+
context.payload = JSON.stringify(context.payload);
|
|
98
|
+
|
|
99
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
|
|
100
|
+
if (err) return _callback(err);
|
|
101
|
+
const gcruleInfo = {
|
|
102
|
+
type: "gc_rule_update",
|
|
103
|
+
threadID: threadID,
|
|
104
|
+
userID: userID,
|
|
105
|
+
action: action,
|
|
106
|
+
senderID: ctx.userID,
|
|
107
|
+
BotID: ctx.userID,
|
|
108
|
+
timestamp: Date.now(),
|
|
109
|
+
};
|
|
110
|
+
return _callback(null, gcruleInfo);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
} catch (err) {
|
|
114
|
+
return _callback(null, { type: "error_gc_rule", error: err.message || "An unknown error occurred." });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return returnPromise;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
return function getAccess(authCode = '', callback) {
|
|
7
|
+
var cb;
|
|
8
|
+
var url = 'https://business.facebook.com/';
|
|
9
|
+
var Referer = url + 'security/twofactor/reauth/?twofac_next=' + encodeURIComponent(url + 'content_management') + '&type=avoid_bypass&app_id=0&save_device=0';
|
|
10
|
+
var rt = new Promise(function (resolve, reject) {
|
|
11
|
+
cb = (error, token) => token ? resolve(token) : reject(error);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (typeof authCode == 'function') {
|
|
15
|
+
callback = authCode;
|
|
16
|
+
authCode = '';
|
|
17
|
+
}
|
|
18
|
+
if (typeof callback == 'function') cb = callback;
|
|
19
|
+
if (!!ctx.access_token)
|
|
20
|
+
cb(null, ctx.access_token);
|
|
21
|
+
else
|
|
22
|
+
utils
|
|
23
|
+
.get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, {
|
|
24
|
+
noRef: true,
|
|
25
|
+
Origin: url
|
|
26
|
+
})
|
|
27
|
+
.then(function (res) {
|
|
28
|
+
var html = res.body;
|
|
29
|
+
var lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
|
30
|
+
return lsd;
|
|
31
|
+
})
|
|
32
|
+
.then(function (lsd) {
|
|
33
|
+
function submitCode(code) {
|
|
34
|
+
var pCb;
|
|
35
|
+
var rtPromise = new Promise(function (resolve) {
|
|
36
|
+
pCb = (error, token) => resolve(cb(error, token));
|
|
37
|
+
});
|
|
38
|
+
if (typeof code != 'string')
|
|
39
|
+
pCb({
|
|
40
|
+
error: 'submitCode',
|
|
41
|
+
lerror: 'code must be string',
|
|
42
|
+
continue: submitCode
|
|
43
|
+
});
|
|
44
|
+
else
|
|
45
|
+
defaultFuncs
|
|
46
|
+
.post(url + 'security/twofactor/reauth/enter/', ctx.jar, {
|
|
47
|
+
approvals_code: code,
|
|
48
|
+
save_device: true,
|
|
49
|
+
lsd
|
|
50
|
+
}, ctx.globalOptions, null, {
|
|
51
|
+
Referer,
|
|
52
|
+
Origin: url
|
|
53
|
+
})
|
|
54
|
+
.then(function (res) {
|
|
55
|
+
var { payload } = JSON.parse(res.body.split(';').pop() || '{}');
|
|
56
|
+
if (payload && !payload.codeConfirmed)
|
|
57
|
+
throw {
|
|
58
|
+
error: 'submitCode',
|
|
59
|
+
lerror: payload.message,
|
|
60
|
+
continue: submitCode
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return;
|
|
64
|
+
})
|
|
65
|
+
.then(function () {
|
|
66
|
+
return utils
|
|
67
|
+
.get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, { noRef: true })
|
|
68
|
+
.then(function (res) {
|
|
69
|
+
var html = res.body;
|
|
70
|
+
var token = /"accessToken":"(\S+)","clientID":/g.exec(html);
|
|
71
|
+
|
|
72
|
+
return [html, token];
|
|
73
|
+
});
|
|
74
|
+
})
|
|
75
|
+
.then(function (res) {
|
|
76
|
+
if (!res[1])
|
|
77
|
+
throw {
|
|
78
|
+
error: 'token-undefined',
|
|
79
|
+
htmlData: res[0]
|
|
80
|
+
}
|
|
81
|
+
ctx.access_token = res[1][1];
|
|
82
|
+
return pCb(null, res[1][1]);
|
|
83
|
+
})
|
|
84
|
+
.catch(function (err) {
|
|
85
|
+
utils.error('getAccess', err.error || err);
|
|
86
|
+
return pCb(err);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return rtPromise;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (authCode.length == 6 && !isNaN(authCode))
|
|
93
|
+
submitCode(authCode.toString());
|
|
94
|
+
else if (typeof callback == 'function')
|
|
95
|
+
throw {
|
|
96
|
+
error: 'submitCode',
|
|
97
|
+
continue: submitCode
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
throw {
|
|
101
|
+
error: 'authentication code must be string or number or callback must be a function to continue'
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
.catch(function (err) {
|
|
105
|
+
utils.error('getAccess', typeof callback == 'function' ? (err.error || err) : err);
|
|
106
|
+
return cb(err);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return rt;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const utils = require('../utils');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} defaultFuncs
|
|
8
|
+
* @param {Object} api
|
|
9
|
+
* @param {Object} ctx
|
|
10
|
+
* @returns {function(netData: Array<Object>): Object | null}
|
|
11
|
+
*/
|
|
12
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
13
|
+
/**
|
|
14
|
+
* @param {Array<Object>} netData - The array of all extracted JSON objects from the HTML.
|
|
15
|
+
* @returns {Object|null} An object containing the bot's essential info, security tokens, and context accessor functions.
|
|
16
|
+
*/
|
|
17
|
+
return function getBotInfo(netData) {
|
|
18
|
+
if (!netData || !Array.isArray(netData)) {
|
|
19
|
+
utils.error("getBotInfo", "netData is not a valid array.");
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} key The configuration key to find (e.g., "MqttWebDeviceID").
|
|
25
|
+
* @returns {Object|null} The configuration object or null if not found.
|
|
26
|
+
*/
|
|
27
|
+
const findConfig = (key) => {
|
|
28
|
+
for (const scriptData of netData) {
|
|
29
|
+
if (scriptData.require) {
|
|
30
|
+
for (const req of scriptData.require) {
|
|
31
|
+
if (Array.isArray(req) && req[0] === key && req[2]) {
|
|
32
|
+
return req[2];
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(req) && req[3] && req[3][0]?.__bbox?.define) {
|
|
35
|
+
for (const def of req[3][0].__bbox.define) {
|
|
36
|
+
if (Array.isArray(def) && def[0].endsWith(key) && def[2]) {
|
|
37
|
+
return def[2];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const currentUserData = findConfig("CurrentUserInitialData");
|
|
48
|
+
const dtsgInitialData = findConfig("DTSGInitialData");
|
|
49
|
+
const dtsgInitData = findConfig("DTSGInitData");
|
|
50
|
+
const lsdData = findConfig("LSD");
|
|
51
|
+
|
|
52
|
+
if (!currentUserData || !dtsgInitialData) {
|
|
53
|
+
utils.error("getBotInfo", "Could not find critical data (CurrentUserInitialData or DTSGInitialData).");
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const botInfo = {
|
|
58
|
+
name: currentUserData.NAME,
|
|
59
|
+
firstName: currentUserData.SHORT_NAME,
|
|
60
|
+
uid: currentUserData.USER_ID,
|
|
61
|
+
appID: currentUserData.APP_ID,
|
|
62
|
+
dtsgToken: dtsgInitialData.token,
|
|
63
|
+
lsdToken: lsdData ? lsdData.token : undefined,
|
|
64
|
+
dtsgInit: dtsgInitData ? {
|
|
65
|
+
token: dtsgInitData.token,
|
|
66
|
+
async_get_token: dtsgInitData.async_get_token
|
|
67
|
+
} : undefined,
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} key The key of the value to retrieve.
|
|
71
|
+
* @returns {any} The value from the context.
|
|
72
|
+
*/
|
|
73
|
+
getCtx: (key) => ctx[key],
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {string} key The key of the option to retrieve.
|
|
77
|
+
* @returns {any} The value of the option.
|
|
78
|
+
*/
|
|
79
|
+
getOptions: (key) => ctx.globalOptions[key],
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @returns {string | undefined} The current region.
|
|
83
|
+
*/
|
|
84
|
+
getRegion: () => ctx?.region
|
|
85
|
+
};
|
|
86
|
+
return botInfo;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
|
|
5
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
6
|
+
return async (callback) => {
|
|
7
|
+
let resolveFunc = () => {};
|
|
8
|
+
let rejectFunc = () => {};
|
|
9
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
10
|
+
resolveFunc = resolve;
|
|
11
|
+
rejectFunc = reject;
|
|
12
|
+
});
|
|
13
|
+
if (!callback) {
|
|
14
|
+
callback = (err, data) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
return rejectFunc(err);
|
|
17
|
+
}
|
|
18
|
+
resolveFunc(data);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
utils.log("Fetching account info...");
|
|
22
|
+
api.httpGet(`https://www.facebook.com/profile.php?id=${ctx.userID}`, null, {
|
|
23
|
+
customUserAgent: utils.windowsUserAgent
|
|
24
|
+
}, (err, data) => {
|
|
25
|
+
|
|
26
|
+
if (err) throw err;
|
|
27
|
+
const profileMatch = data.match(/"CurrentUserInitialData",\[\],\{(.*?)\},(.*?)\]/);
|
|
28
|
+
if (profileMatch && profileMatch[1]){
|
|
29
|
+
const accountJson = JSON.parse(`{${profileMatch[1]}}`);
|
|
30
|
+
accountJson.name = accountJson.NAME;
|
|
31
|
+
accountJson.uid = accountJson.USER_ID;
|
|
32
|
+
delete accountJson.NAME;
|
|
33
|
+
delete accountJson.USER_ID;
|
|
34
|
+
return callback(null, {
|
|
35
|
+
...accountJson
|
|
36
|
+
});
|
|
37
|
+
} else return callback(null, { error: "Something went wrong. Maybe its possible that it has a limitation due to spam requests. You can try again later." });
|
|
38
|
+
}, true);
|
|
39
|
+
return returnPromise;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
const GENDERS = {
|
|
6
|
+
0: "unknown",
|
|
7
|
+
1: "female_singular",
|
|
8
|
+
2: "male_singular",
|
|
9
|
+
3: "female_singular_guess",
|
|
10
|
+
4: "male_singular_guess",
|
|
11
|
+
5: "mixed",
|
|
12
|
+
6: "neuter_singular",
|
|
13
|
+
7: "unknown_singular",
|
|
14
|
+
8: "female_plural",
|
|
15
|
+
9: "male_plural",
|
|
16
|
+
10: "neuter_plural",
|
|
17
|
+
11: "unknown_plural"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function formatData(obj) {
|
|
21
|
+
return Object.keys(obj).map(key => {
|
|
22
|
+
const user = obj[key];
|
|
23
|
+
return {
|
|
24
|
+
alternateName: user.alternateName,
|
|
25
|
+
firstName: user.firstName,
|
|
26
|
+
gender: GENDERS[user.gender],
|
|
27
|
+
userID: utils.formatID(user.id.toString()),
|
|
28
|
+
isFriend: user.is_friend != null && user.is_friend ? true : false,
|
|
29
|
+
fullName: user.name,
|
|
30
|
+
profilePicture: user.thumbSrc,
|
|
31
|
+
type: user.type,
|
|
32
|
+
profileUrl: user.uri,
|
|
33
|
+
vanity: user.vanity,
|
|
34
|
+
isBirthday: !!user.is_birthday
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
40
|
+
return async function getFriendsList(callback) {
|
|
41
|
+
let resolveFunc = () => {};
|
|
42
|
+
let rejectFunc = () => {};
|
|
43
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
44
|
+
resolveFunc = resolve;
|
|
45
|
+
rejectFunc = reject;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!callback) {
|
|
49
|
+
callback = (err, result) => {
|
|
50
|
+
if (err) return rejectFunc(err);
|
|
51
|
+
resolveFunc(result);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const res = await defaultFuncs.postFormData(
|
|
57
|
+
"https://www.facebook.com/chat/user_info_all",
|
|
58
|
+
ctx.jar,
|
|
59
|
+
{},
|
|
60
|
+
{ viewer: ctx.userID }
|
|
61
|
+
).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
62
|
+
|
|
63
|
+
if (!res) {
|
|
64
|
+
throw { error: "getFriendsList returned empty object." };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (res.error) {
|
|
68
|
+
throw res;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
callback(null, formatData(res.payload));
|
|
72
|
+
} catch (err) {
|
|
73
|
+
utils.error("getFriendsList", err);
|
|
74
|
+
callback(err);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return returnPromise;
|
|
78
|
+
};
|
|
79
|
+
};
|