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.
- package/CHANGELOG.md +220 -0
- package/LICENSE +26 -0
- package/README.md +346 -0
- package/THEME_FEATURES.md +137 -0
- package/examples/README.md +131 -0
- package/examples/apply-ai-theme.js +127 -0
- package/examples/check-current-theme.js +74 -0
- package/examples/simple-bot.js +114 -0
- package/examples/test-bot.js +752 -0
- package/examples/test-logging.js +85 -0
- package/examples/theme-usage-example.js +53 -0
- package/index.js +2 -0
- package/package.json +105 -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/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 +44 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/editMessage.js +70 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +65 -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 +104 -0
- package/src/apis/getThemeInfo.js +96 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +257 -0
- package/src/apis/getThreadList.js +222 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +83 -0
- package/src/apis/getUserInfo.js +495 -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 +796 -0
- package/src/apis/listenSpeed.js +170 -0
- package/src/apis/logout.js +63 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/apis/markAsRead.js +95 -0
- package/src/apis/markAsReadAll.js +41 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +330 -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 +141 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +161 -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 +281 -0
- package/src/apis/sendMessageMqtt.js +188 -0
- package/src/apis/sendTypingIndicator.js +41 -0
- package/src/apis/setMessageReaction.js +27 -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 +17 -0
- package/src/database/appStateBackup.js +189 -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/engine/client.js +91 -0
- package/src/engine/models/buildAPI.js +109 -0
- package/src/engine/models/loginHelper.js +326 -0
- package/src/engine/models/setOptions.js +53 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +169 -0
- package/src/utils/axios.js +290 -0
- package/src/utils/clients.js +270 -0
- package/src/utils/constants.js +396 -0
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +153 -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 +1067 -0
- package/src/utils/headers.js +199 -0
- package/src/utils/index.js +151 -0
- package/src/utils/monitoring.js +358 -0
- package/src/utils/rateLimiter.js +380 -0
- package/src/utils/tokenRefresh.js +311 -0
- package/src/utils/user-agents.js +238 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @ChoruOfficial
|
|
7
|
+
* @description A module for managing friend-related actions like listing friends, handling requests, and getting suggestions.
|
|
8
|
+
* @param {Object} defaultFuncs The default functions provided by the API wrapper.
|
|
9
|
+
* @param {Object} api The full API object.
|
|
10
|
+
* @param {Object} ctx The context object containing the user's session state (e.g., userID, jar, fb_dtsg).
|
|
11
|
+
* @returns {Object} A `friendModule` object with methods for friend interactions.
|
|
12
|
+
*/
|
|
13
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A private helper function to standardize friend data from various GraphQL endpoints.
|
|
17
|
+
* @private
|
|
18
|
+
* @param {Object} data The raw data object from a GraphQL response.
|
|
19
|
+
* @param {('requests'|'suggestions'|'list')} type The type of data to format, which determines the path to the user list.
|
|
20
|
+
* @returns {Array<Object>} An array of formatted friend objects, each containing `userID`, `name`, `profilePicture`, `socialContext`, and `url`.
|
|
21
|
+
*/
|
|
22
|
+
function formatFriends(data, type) {
|
|
23
|
+
const viewer = data?.data?.viewer;
|
|
24
|
+
let edges;
|
|
25
|
+
if (type === 'requests' && viewer?.friend_requests?.edges) {
|
|
26
|
+
edges = viewer.friend_requests.edges;
|
|
27
|
+
} else if (type === 'suggestions' && viewer?.people_you_may_know?.edges) {
|
|
28
|
+
edges = viewer.people_you_may_know.edges;
|
|
29
|
+
} else if (type === 'list' && data?.data?.node?.all_collections?.nodes[0]?.style_renderer?.collection?.pageItems?.edges) {
|
|
30
|
+
edges = data.data.node.all_collections.nodes[0].style_renderer.collection.pageItems.edges;
|
|
31
|
+
} else {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return edges.map(edge => {
|
|
35
|
+
const node = edge.node;
|
|
36
|
+
return {
|
|
37
|
+
userID: node.id || node.node?.id,
|
|
38
|
+
name: node.name || node.title?.text,
|
|
39
|
+
profilePicture: node.profile_picture?.uri || node.image?.uri,
|
|
40
|
+
socialContext: node.social_context?.text || node.subtitle_text?.text,
|
|
41
|
+
url: node.url
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const friendModule = {
|
|
47
|
+
/**
|
|
48
|
+
* @namespace api.friend
|
|
49
|
+
* @description A collection of functions for interacting with friends.
|
|
50
|
+
* @license Ex-it
|
|
51
|
+
* @author ChoruOfficial
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fetches the list of incoming friend requests.
|
|
56
|
+
* @async
|
|
57
|
+
* @returns {Promise<Array<Object>>} A promise that resolves to an array of friend request objects.
|
|
58
|
+
* @throws {Error} If the API request fails or returns an error.
|
|
59
|
+
*/
|
|
60
|
+
requests: async function() {
|
|
61
|
+
try {
|
|
62
|
+
const form = {
|
|
63
|
+
av: ctx.userID,
|
|
64
|
+
__user: ctx.userID,
|
|
65
|
+
__a: "1",
|
|
66
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
67
|
+
jazoest: ctx.jazoest,
|
|
68
|
+
lsd: ctx.lsd,
|
|
69
|
+
fb_api_caller_class: "RelayModern",
|
|
70
|
+
fb_api_req_friendly_name: "FriendingCometRootContentQuery",
|
|
71
|
+
variables: JSON.stringify({ scale: 3 }),
|
|
72
|
+
doc_id: "9103543533085580"
|
|
73
|
+
};
|
|
74
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
75
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
76
|
+
return formatFriends(res.data, 'requests');
|
|
77
|
+
} catch (err) {
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Accepts a friend request.
|
|
84
|
+
* @async
|
|
85
|
+
* @param {string} identifier The user ID or name of the person whose friend request is to be accepted. If a name is provided, the function will search through pending requests.
|
|
86
|
+
* @returns {Promise<Object>} A promise that resolves to the API response data upon successful acceptance.
|
|
87
|
+
* @throws {Error} If the identifier is missing, the user is not found in requests, or the API call fails.
|
|
88
|
+
*/
|
|
89
|
+
accept: async function(identifier) {
|
|
90
|
+
try {
|
|
91
|
+
if (!identifier) throw new Error("A name or user ID is required.");
|
|
92
|
+
let targetUserID = identifier;
|
|
93
|
+
if (isNaN(identifier)) {
|
|
94
|
+
const requests = await friendModule.requests();
|
|
95
|
+
const found = requests.find(req => req.name.toLowerCase().includes(identifier.toLowerCase()));
|
|
96
|
+
if (!found) throw new Error(`Could not find any friend request matching "${identifier}".`);
|
|
97
|
+
targetUserID = found.userID;
|
|
98
|
+
}
|
|
99
|
+
const variables = {
|
|
100
|
+
input: {
|
|
101
|
+
friend_requester_id: targetUserID,
|
|
102
|
+
friending_channel: "FRIENDS_HOME_MAIN",
|
|
103
|
+
actor_id: ctx.userID,
|
|
104
|
+
client_mutation_id: Math.floor(Math.random() * 10 + 1).toString()
|
|
105
|
+
},
|
|
106
|
+
scale: 3
|
|
107
|
+
};
|
|
108
|
+
const form = {
|
|
109
|
+
av: ctx.userID,
|
|
110
|
+
__user: ctx.userID,
|
|
111
|
+
__a: "1",
|
|
112
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
113
|
+
jazoest: ctx.jazoest,
|
|
114
|
+
lsd: ctx.lsd,
|
|
115
|
+
fb_api_caller_class: "RelayModern",
|
|
116
|
+
fb_api_req_friendly_name: "FriendingCometFriendRequestConfirmMutation",
|
|
117
|
+
variables: JSON.stringify(variables),
|
|
118
|
+
doc_id: "24630768433181357"
|
|
119
|
+
};
|
|
120
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
121
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
122
|
+
return res.data.data;
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if (err.message?.includes("1431004")) {
|
|
125
|
+
throw new Error("I cannot accept this friend request right now. There might be a problem with the account or you need to wait.");
|
|
126
|
+
}
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Fetches the friend list for a given user ID.
|
|
133
|
+
* @async
|
|
134
|
+
* @param {string} [userID=ctx.userID] The ID of the user whose friend list to fetch. Defaults to the logged-in user.
|
|
135
|
+
* @returns {Promise<Array<Object>>} A promise that resolves to an array of formatted friend objects.
|
|
136
|
+
* @throws {Error} If the API request fails.
|
|
137
|
+
*/
|
|
138
|
+
list: async function(userID = ctx.userID) {
|
|
139
|
+
try {
|
|
140
|
+
const sectionToken = Buffer.from(`app_section:${userID}:2356318349`).toString('base64');
|
|
141
|
+
const variables = {
|
|
142
|
+
collectionToken: null,
|
|
143
|
+
scale: 2,
|
|
144
|
+
sectionToken: sectionToken,
|
|
145
|
+
useDefaultActor: false,
|
|
146
|
+
userID: userID
|
|
147
|
+
};
|
|
148
|
+
const form = {
|
|
149
|
+
av: ctx.userID,
|
|
150
|
+
__user: ctx.userID,
|
|
151
|
+
__a: "1",
|
|
152
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
153
|
+
jazoest: ctx.jazoest,
|
|
154
|
+
lsd: ctx.lsd,
|
|
155
|
+
fb_api_caller_class: "RelayModern",
|
|
156
|
+
fb_api_req_friendly_name: "ProfileCometTopAppSectionQuery",
|
|
157
|
+
variables: JSON.stringify(variables),
|
|
158
|
+
doc_id: "24492266383698794"
|
|
159
|
+
};
|
|
160
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
161
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
162
|
+
return formatFriends(res.data, 'list');
|
|
163
|
+
} catch(err) {
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @namespace api.friend.suggest
|
|
170
|
+
* @description Functions for managing friend suggestions.
|
|
171
|
+
*/
|
|
172
|
+
suggest: {
|
|
173
|
+
/**
|
|
174
|
+
* Fetches a list of suggested friends (People You May Know).
|
|
175
|
+
* @async
|
|
176
|
+
* @param {number} [limit=30] The maximum number of suggestions to fetch.
|
|
177
|
+
* @returns {Promise<Array<Object>>} A promise that resolves to an array of suggested friend objects.
|
|
178
|
+
* @throws {Error} If the API request fails.
|
|
179
|
+
*/
|
|
180
|
+
list: async function(limit = 30) {
|
|
181
|
+
try {
|
|
182
|
+
const form = {
|
|
183
|
+
av: ctx.userID,
|
|
184
|
+
__user: ctx.userID,
|
|
185
|
+
__a: "1",
|
|
186
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
187
|
+
jazoest: ctx.jazoest,
|
|
188
|
+
lsd: ctx.lsd,
|
|
189
|
+
fb_api_caller_class: "RelayModern",
|
|
190
|
+
fb_api_req_friendly_name: "FriendingCometPYMKPanelPaginationQuery",
|
|
191
|
+
variables: JSON.stringify({ count: limit, cursor: null, scale: 3 }),
|
|
192
|
+
doc_id: "9917809191634193"
|
|
193
|
+
};
|
|
194
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
195
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
196
|
+
return formatFriends(res.data, 'suggestions');
|
|
197
|
+
} catch(err) {
|
|
198
|
+
throw err;
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
/**
|
|
202
|
+
* Sends a friend request to a user.
|
|
203
|
+
* @async
|
|
204
|
+
* @param {string} userID The ID of the user to send the friend request to.
|
|
205
|
+
* @returns {Promise<Object>} A promise that resolves to the API response data on success.
|
|
206
|
+
* @throws {Error} If the userID is missing or the API request fails.
|
|
207
|
+
*/
|
|
208
|
+
request: async function(userID) {
|
|
209
|
+
try {
|
|
210
|
+
if (!userID) throw new Error("userID is required.");
|
|
211
|
+
const variables = {
|
|
212
|
+
input: {
|
|
213
|
+
friend_requestee_ids: [userID],
|
|
214
|
+
friending_channel: "FRIENDS_HOME_MAIN",
|
|
215
|
+
actor_id: ctx.userID,
|
|
216
|
+
client_mutation_id: Math.floor(Math.random() * 10 + 1).toString()
|
|
217
|
+
},
|
|
218
|
+
scale: 3
|
|
219
|
+
};
|
|
220
|
+
const form = {
|
|
221
|
+
av: ctx.userID,
|
|
222
|
+
__user: ctx.userID,
|
|
223
|
+
__a: "1",
|
|
224
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
225
|
+
jazoest: ctx.jazoest,
|
|
226
|
+
lsd: ctx.lsd,
|
|
227
|
+
fb_api_caller_class: "RelayModern",
|
|
228
|
+
fb_api_req_friendly_name: "FriendingCometFriendRequestSendMutation",
|
|
229
|
+
variables: JSON.stringify(variables),
|
|
230
|
+
doc_id: "23982103144788355"
|
|
231
|
+
};
|
|
232
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
233
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
234
|
+
return res.data.data;
|
|
235
|
+
} catch(err) {
|
|
236
|
+
throw err;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return friendModule;
|
|
243
|
+
};
|
|
@@ -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
|
+
};
|