@cexy/hoonfca 1.0.0 → 1.0.2

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 (98) hide show
  1. package/.travis.yml +6 -0
  2. package/LICENSE-MIT +21 -0
  3. package/index.d.ts +620 -0
  4. package/index.js +745 -433
  5. package/package.json +45 -6
  6. package/src/addExternalModule.js +14 -16
  7. package/src/addUserToGroup.js +45 -30
  8. package/src/changeAdminStatus.js +39 -42
  9. package/src/changeApprovalMode.js +79 -0
  10. package/src/changeArchivedStatus.js +19 -15
  11. package/src/changeBio.js +18 -16
  12. package/src/changeBlockedStatus.js +14 -12
  13. package/src/changeBlockedStatusMqtt.js +38 -17
  14. package/src/changeGroupImage.js +100 -77
  15. package/src/changeNickname.js +12 -11
  16. package/src/changeThreadColor.js +25 -16
  17. package/src/changeThreadEmoji.js +11 -10
  18. package/src/createNewGroup.js +21 -14
  19. package/src/createPoll.js +87 -21
  20. package/src/deleteMessage.js +18 -17
  21. package/src/deleteThread.js +18 -17
  22. package/src/editMessage.js +28 -31
  23. package/src/forwardAttachment.js +22 -19
  24. package/src/forwardMessage.js +63 -0
  25. package/src/getCurrentUserID.js +4 -2
  26. package/src/getEmojiUrl.js +20 -9
  27. package/src/getFriendsList.js +21 -18
  28. package/src/getGroupsList.js +83 -0
  29. package/src/getMarketplace.js +84 -0
  30. package/src/getNotifications.js +86 -0
  31. package/src/getPagesList.js +83 -0
  32. package/src/getStories.js +88 -0
  33. package/src/getThreadHistory.js +277 -126
  34. package/src/getThreadInfo.js +143 -115
  35. package/src/getThreadList.js +216 -143
  36. package/src/getThreadPictures.js +26 -32
  37. package/src/getUserID.js +13 -14
  38. package/src/getUserInfo.js +107 -68
  39. package/src/handleFriendRequest.js +16 -15
  40. package/src/handleMessageRequest.js +15 -15
  41. package/src/httpGet.js +36 -31
  42. package/src/httpPost.js +36 -31
  43. package/src/listenMqtt.js +705 -370
  44. package/src/logout.js +26 -28
  45. package/src/markAsDelivered.js +22 -17
  46. package/src/markAsRead.js +63 -49
  47. package/src/markAsReadAll.js +17 -13
  48. package/src/markAsSeen.js +23 -19
  49. package/src/muteThread.js +17 -14
  50. package/src/pinMessage.js +23 -22
  51. package/src/removeUserFromGroup.js +42 -22
  52. package/src/resolvePhotoUrl.js +15 -17
  53. package/src/searchForThread.js +18 -20
  54. package/src/searchUsers.js +89 -0
  55. package/src/sendComment.js +161 -0
  56. package/src/sendMessage.js +65 -52
  57. package/src/sendTypingIndicator.js +173 -48
  58. package/src/setBio.js +86 -0
  59. package/src/setMessageReaction.js +76 -16
  60. package/src/setPostReaction.js +29 -61
  61. package/src/setTheme.js +313 -0
  62. package/src/setTitle.js +27 -37
  63. package/src/shareContact.js +34 -82
  64. package/src/shareLink.js +56 -99
  65. package/src/threadColors.js +35 -97
  66. package/src/unfriend.js +15 -20
  67. package/src/unsendMessage.js +71 -18
  68. package/utils.js +1000 -472
  69. package/README.md +0 -83
  70. package/replit.nix +0 -3
  71. package/src/changeAvatar.js +0 -89
  72. package/src/changeCover.js +0 -92
  73. package/src/changeName.js +0 -106
  74. package/src/changeUsername.js +0 -80
  75. package/src/createCommentPost.js +0 -196
  76. package/src/createPost.js +0 -285
  77. package/src/data/getThreadInfo.json +0 -1
  78. package/src/follow.js +0 -71
  79. package/src/getAccess.js +0 -130
  80. package/src/getAvatarUser.js +0 -88
  81. package/src/getBotInitialData.js +0 -59
  82. package/src/getCtx.js +0 -5
  83. package/src/getMessage.js +0 -827
  84. package/src/getOptions.js +0 -5
  85. package/src/getRegion.js +0 -7
  86. package/src/getThreadHistoryDeprecated.js +0 -95
  87. package/src/getThreadInfoDeprecated.js +0 -77
  88. package/src/getThreadListDeprecated.js +0 -86
  89. package/src/httpPostFormData.js +0 -58
  90. package/src/listenNotification.js +0 -96
  91. package/src/refreshFb_dtsg.js +0 -75
  92. package/src/searchStickers.js +0 -59
  93. package/src/sendMessageMqtt.js +0 -326
  94. package/src/setMessageReactionMqtt.js +0 -74
  95. package/src/setProfileGuard.js +0 -66
  96. package/src/setStoryReaction.js +0 -97
  97. package/src/stopListenMqtt.js +0 -47
  98. package/src/uploadAttachment.js +0 -98
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID, getCurrentTimestamp } = require("../utils");
4
+
5
+ function isCallable(func) {
6
+ try {
7
+ Reflect.apply(func, null, []);
8
+ return true;
9
+ } catch (error) {
10
+ return false;
11
+ }
12
+ }
13
+
14
+ const themes = [
15
+ {
16
+ id: "3650637715209675",
17
+ name: "Besties",
18
+ },
19
+ {
20
+ id: "769656934577391",
21
+ name: "Women's History Month",
22
+ },
23
+ {
24
+ id: "702099018755409",
25
+ name: "Dune: Part Two",
26
+ },
27
+ {
28
+ id: "1480404512543552",
29
+ name: "Avatar: The Last Airbender",
30
+ },
31
+ {
32
+ id: "952656233130616",
33
+ name: "J.Lo",
34
+ },
35
+ {
36
+ id: "741311439775765",
37
+ name: "Love",
38
+ },
39
+ {
40
+ id: "215565958307259",
41
+ name: "Bob Marley: One Love",
42
+ },
43
+ {
44
+ id: "194982117007866",
45
+ name: "Football",
46
+ },
47
+ {
48
+ id: "1743641112805218",
49
+ name: "Soccer",
50
+ },
51
+ {
52
+ id: "730357905262632",
53
+ name: "Mean Girls",
54
+ },
55
+ {
56
+ id: "1270466356981452",
57
+ name: "Wonka",
58
+ },
59
+ {
60
+ id: "704702021720552",
61
+ name: "Pizza",
62
+ },
63
+ {
64
+ id: "1013083536414851",
65
+ name: "Wish",
66
+ },
67
+ {
68
+ id: "359537246600743",
69
+ name: "Trolls",
70
+ },
71
+ {
72
+ id: "173976782455615",
73
+ name: "The Marvels",
74
+ },
75
+ {
76
+ id: "2317258455139234",
77
+ name: "One Piece",
78
+ },
79
+ {
80
+ id: "6685081604943977",
81
+ name: "1989",
82
+ },
83
+ {
84
+ id: "1508524016651271",
85
+ name: "Avocado",
86
+ },
87
+ {
88
+ id: "265997946276694",
89
+ name: "Loki Season 2",
90
+ },
91
+ {
92
+ id: "6584393768293861",
93
+ name: "olivia rodrigo",
94
+ },
95
+ {
96
+ id: "845097890371902",
97
+ name: "Baseball",
98
+ },
99
+ {
100
+ id: "292955489929680",
101
+ name: "Lollipop",
102
+ },
103
+ {
104
+ id: "976389323536938",
105
+ name: "Loops",
106
+ },
107
+ {
108
+ id: "810978360551741",
109
+ name: "Parenthood",
110
+ },
111
+ {
112
+ id: "195296273246380",
113
+ name: "Bubble Tea",
114
+ },
115
+ {
116
+ id: "6026716157422736",
117
+ name: "Basketball",
118
+ },
119
+ {
120
+ id: "693996545771691",
121
+ name: "Elephants & Flowers",
122
+ },
123
+ {
124
+ id: "390127158985345",
125
+ name: "Chill",
126
+ },
127
+ {
128
+ id: "365557122117011",
129
+ name: "Support",
130
+ },
131
+ {
132
+ id: "339021464972092",
133
+ name: "Music",
134
+ },
135
+ {
136
+ id: "1060619084701625",
137
+ name: "Lo-Fi",
138
+ },
139
+ {
140
+ id: "3190514984517598",
141
+ name: "Sky",
142
+ },
143
+ {
144
+ id: "627144732056021",
145
+ name: "Celebration",
146
+ },
147
+ {
148
+ id: "275041734441112",
149
+ name: "Care",
150
+ },
151
+ {
152
+ id: "3082966625307060",
153
+ name: "Astrology",
154
+ },
155
+ {
156
+ id: "539927563794799",
157
+ name: "Cottagecore",
158
+ },
159
+ {
160
+ id: "527564631955494",
161
+ name: "Ocean",
162
+ },
163
+ {
164
+ id: "230032715012014",
165
+ name: "Tie-Dye",
166
+ },
167
+ {
168
+ id: "788274591712841",
169
+ name: "Monochrome",
170
+ },
171
+ {
172
+ id: "3259963564026002",
173
+ name: "Default",
174
+ },
175
+ {
176
+ id: "724096885023603",
177
+ name: "Berry",
178
+ },
179
+ {
180
+ id: "624266884847972",
181
+ name: "Candy",
182
+ },
183
+ {
184
+ id: "273728810607574",
185
+ name: "Unicorn",
186
+ },
187
+ {
188
+ id: "262191918210707",
189
+ name: "Tropical",
190
+ },
191
+ {
192
+ id: "2533652183614000",
193
+ name: "Maple",
194
+ },
195
+ {
196
+ id: "909695489504566",
197
+ name: "Sushi",
198
+ },
199
+ {
200
+ id: "582065306070020",
201
+ name: "Rocket",
202
+ },
203
+ {
204
+ id: "557344741607350",
205
+ name: "Citrus",
206
+ },
207
+ {
208
+ id: "280333826736184",
209
+ name: "Lollipop",
210
+ },
211
+ {
212
+ id: "271607034185782",
213
+ name: "Shadow",
214
+ },
215
+ {
216
+ id: "1257453361255152",
217
+ name: "Rose",
218
+ },
219
+ {
220
+ id: "571193503540759",
221
+ name: "Lavender",
222
+ },
223
+ {
224
+ id: "2873642949430623",
225
+ name: "Tulip",
226
+ },
227
+ {
228
+ id: "3273938616164733",
229
+ name: "Classic",
230
+ },
231
+ {
232
+ id: "403422283881973",
233
+ name: "Apple",
234
+ },
235
+ {
236
+ id: "3022526817824329",
237
+ name: "Peach",
238
+ },
239
+ {
240
+ id: "672058580051520",
241
+ name: "Honey",
242
+ },
243
+ {
244
+ id: "3151463484918004",
245
+ name: "Kiwi",
246
+ },
247
+ {
248
+ id: "736591620215564",
249
+ name: "Ocean",
250
+ },
251
+ {
252
+ id: "193497045377796",
253
+ name: "Grape",
254
+ },
255
+ ];
256
+
257
+ module.exports = function (defaultFuncs, api, ctx) {
258
+ return function setTheme(themeID, threadID, callback) {
259
+ if (!ctx.mqttClient) {
260
+ throw new Error("Not connected to MQTT");
261
+ }
262
+
263
+ ctx.wsReqNumber += 1;
264
+ ctx.wsTaskNumber += 1;
265
+
266
+ let selectedThemeID;
267
+
268
+ if (!themeID) {
269
+ // If no theme ID is provided, select a random theme from the themes array
270
+ const randomIndex = Math.floor(Math.random() * themes.length);
271
+ selectedThemeID = themes[randomIndex].id;
272
+ } else {
273
+ selectedThemeID = themeID;
274
+ }
275
+
276
+ const taskPayload = {
277
+ thread_key: threadID,
278
+ theme_fbid: selectedThemeID,
279
+ source: null,
280
+ sync_group: 1,
281
+ payload: null,
282
+ };
283
+
284
+ const task = {
285
+ failure_count: null,
286
+ label: "43",
287
+ payload: JSON.stringify(taskPayload),
288
+ queue_name: "thread_theme",
289
+ task_id: ctx.wsTaskNumber,
290
+ };
291
+
292
+ const content = {
293
+ app_id: "2220391788200892",
294
+ payload: JSON.stringify({
295
+ data_trace_id: null,
296
+ epoch_id: parseInt(generateOfflineThreadingID()),
297
+ tasks: [task],
298
+ version_id: "25095469420099952",
299
+ }),
300
+ request_id: ctx.wsReqNumber,
301
+ type: 3,
302
+ };
303
+
304
+ if (isCallable(callback)) {
305
+ // to be implemented
306
+ }
307
+
308
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), {
309
+ qos: 1,
310
+ retain: false,
311
+ });
312
+ };
313
+ };
package/src/setTitle.js CHANGED
@@ -1,45 +1,39 @@
1
1
  "use strict";
2
2
 
3
- const utils = require("../utils");
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
4
5
 
5
6
  module.exports = function (defaultFuncs, api, ctx) {
6
7
  return function setTitle(newTitle, threadID, callback) {
7
- let resolveFunc = function () {};
8
- let rejectFunc = function () {};
9
- const returnPromise = new Promise(function (resolve, reject) {
8
+ if (
9
+ !callback &&
10
+ (utils.getType(threadID) === "Function" ||
11
+ utils.getType(threadID) === "AsyncFunction")
12
+ ) {
13
+ throw { error: "please pass a threadID as a second argument." };
14
+ }
15
+
16
+ var resolveFunc = function () {};
17
+ var rejectFunc = function () {};
18
+ var returnPromise = new Promise(function (resolve, reject) {
10
19
  resolveFunc = resolve;
11
20
  rejectFunc = reject;
12
21
  });
13
22
 
14
23
  if (!callback) {
15
- if (
16
- utils.getType(threadID) === "Function" ||
17
- utils.getType(threadID) === "AsyncFunction"
18
- ) {
19
- callback = threadID;
20
- threadID = undefined;
21
- } else {
22
- callback = function (err, data) {
23
- if (err) {
24
- return rejectFunc(err);
25
- }
26
- resolveFunc(data);
27
- };
28
- }
29
- }
30
-
31
- if (!threadID) {
32
- return callback({ error: "Please pass a threadID as a second argument." });
24
+ callback = function (err, friendList) {
25
+ if (err) {
26
+ return rejectFunc(err);
27
+ }
28
+ resolveFunc(friendList);
29
+ };
33
30
  }
34
31
 
35
- const titleStr = newTitle !== null && newTitle !== undefined ? newTitle.toString() : "";
36
- const threadIDStr = threadID.toString();
37
- const messageAndOTID = utils.generateOfflineThreadingID();
38
-
39
- const form = {
32
+ var messageAndOTID = utils.generateOfflineThreadingID();
33
+ var form = {
40
34
  client: "mercury",
41
35
  action_type: "ma-type:log-message",
42
- author: "fbid:" + (ctx.userID),
36
+ author: "fbid:" + ctx.userID,
43
37
  author_email: "",
44
38
  coordinates: "",
45
39
  timestamp: Date.now(),
@@ -58,9 +52,9 @@ module.exports = function (defaultFuncs, api, ctx) {
58
52
  message_id: messageAndOTID,
59
53
  threading_id: utils.generateThreadingID(ctx.clientID),
60
54
  manual_retry_cnt: "0",
61
- thread_fbid: threadIDStr,
62
- thread_name: titleStr,
63
- thread_id: threadIDStr,
55
+ thread_fbid: threadID,
56
+ thread_name: newTitle,
57
+ thread_id: threadID,
64
58
  log_message_type: "log:thread-name",
65
59
  };
66
60
 
@@ -72,10 +66,6 @@ module.exports = function (defaultFuncs, api, ctx) {
72
66
  )
73
67
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
74
68
  .then(function (resData) {
75
- if (!resData) {
76
- throw { error: "setTitle returned empty response." };
77
- }
78
-
79
69
  if (resData.error && resData.error === 1545012) {
80
70
  throw { error: "Cannot change chat title: Not member of chat." };
81
71
  }
@@ -88,10 +78,10 @@ module.exports = function (defaultFuncs, api, ctx) {
88
78
  throw resData;
89
79
  }
90
80
 
91
- return callback(null);
81
+ return callback();
92
82
  })
93
83
  .catch(function (err) {
94
- utils.error("setTitle", err);
84
+ log.error("setTitle", err);
95
85
  return callback(err);
96
86
  });
97
87
 
@@ -1,100 +1,52 @@
1
1
  "use strict";
2
2
 
3
3
  var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return async function shareContact(text, senderID, threadID, callback) {
8
+ if (!ctx.mqttClient) {
9
+ throw new Error("Not connected to MQTT");
10
+ }
4
11
 
5
- module.exports = function(defaultFuncs, api, ctx) {
6
- return function shareContact(text, senderID, threadID, callback) {
7
12
  var resolveFunc = function () {};
8
13
  var rejectFunc = function () {};
9
- const returnPromise = new Promise(function (resolve, reject) {
14
+ var returnPromise = new Promise(function (resolve, reject) {
10
15
  resolveFunc = resolve;
11
16
  rejectFunc = reject;
12
17
  });
13
-
14
18
  if (!callback) {
15
19
  callback = function (err, data) {
16
- if (err) {
17
- return rejectFunc(err);
18
- }
20
+ if (err) return rejectFunc(err);
19
21
  resolveFunc(data);
22
+ data;
20
23
  };
21
24
  }
22
-
23
- if (!ctx.mqttClient) {
24
- return callback(new Error('Not connected to MQTT'));
25
- }
26
-
27
- if (!senderID || !threadID) {
28
- return callback({ error: "senderID and threadID are required." });
29
- }
30
-
31
- // safe initialization of request counters
32
- if (ctx.wsReqNumber === undefined || ctx.wsReqNumber === null) {
33
- ctx.wsReqNumber = 0;
34
- }
35
- if (ctx.wsTaskNumber === undefined || ctx.wsTaskNumber === null) {
36
- ctx.wsTaskNumber = 0;
37
- }
38
-
39
- ctx.wsReqNumber += 1;
40
- ctx.wsTaskNumber += 1;
41
-
42
- const queryPayload = {
43
- contact_id: senderID.toString(),
44
- sync_group: 1,
45
- text: text || "",
46
- thread_id: threadID.toString()
47
- };
48
-
49
- const query = {
50
- failure_count: null,
51
- label: '359',
52
- payload: JSON.stringify(queryPayload),
53
- queue_name: 'messenger_contact_sharing', // xma_open_contact_share
54
- task_id: Math.floor(Math.random() * 1001),
55
- };
56
-
57
- const context = {
58
- app_id: '2220391788200892',
59
- payload: {
60
- tasks: [query],
61
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
62
- version_id: '7214102258676893',
63
- },
64
- request_id: ctx.wsReqNumber,
25
+ let count_req = 0;
26
+ var form = JSON.stringify({
27
+ app_id: "2220391788200892",
28
+ payload: JSON.stringify({
29
+ tasks: [
30
+ {
31
+ label: "359",
32
+ payload: JSON.stringify({
33
+ contact_id: senderID,
34
+ sync_group: 1,
35
+ text: text || "",
36
+ thread_id: threadID,
37
+ }),
38
+ queue_name: "messenger_contact_sharing",
39
+ task_id: (Math.random() * 1001) << 0,
40
+ failure_count: null,
41
+ },
42
+ ],
43
+ epoch_id: utils.generateOfflineThreadingID(),
44
+ version_id: "7214102258676893",
45
+ }),
46
+ request_id: ++count_req,
65
47
  type: 3,
66
- };
67
-
68
- context.payload = JSON.stringify(context.payload);
69
-
70
- // safe callback mapping to prevent crashes
71
- if (typeof callback === 'function') {
72
- if (!ctx.callback_Task) {
73
- ctx.callback_Task = {};
74
- }
75
- ctx.callback_Task[ctx.wsReqNumber] = { callback, type: "shareContact" };
76
-
77
- // also fallback to reqCallbacks if your bot utilizes it
78
- if (ctx.reqCallbacks) {
79
- ctx.reqCallbacks[ctx.wsReqNumber] = callback;
80
- }
81
- }
82
-
83
- ctx.mqttClient.publish(
84
- '/ls_req',
85
- JSON.stringify(context),
86
- { qos: 1, retain: false },
87
- function (err, data) {
88
- if (err) {
89
- utils.error("shareContact", err);
90
- return callback(err);
91
- }
92
- // If not using callback listeners in state, trigger immediately
93
- if (!ctx.callback_Task && !ctx.reqCallbacks) {
94
- callback(null, data);
95
- }
96
- }
97
- );
48
+ });
49
+ ctx.mqttClient.publish("/ls_req", form);
98
50
 
99
51
  return returnPromise;
100
52
  };