bb-fca 2.0.9 → 2.0.11

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 (84) hide show
  1. package/dist/deltas/apis/messaging/editMessage.js +13 -24
  2. package/dist/deltas/apis/messaging/editMessage.js.map +1 -1
  3. package/dist/deltas/apis/messaging/emoji.js +34 -88
  4. package/dist/deltas/apis/messaging/emoji.js.map +1 -1
  5. package/dist/deltas/apis/messaging/gcmember.js +48 -101
  6. package/dist/deltas/apis/messaging/gcmember.js.map +1 -1
  7. package/dist/deltas/apis/messaging/gcname.js +28 -79
  8. package/dist/deltas/apis/messaging/gcname.js.map +1 -1
  9. package/dist/deltas/apis/messaging/gcrule.js +47 -105
  10. package/dist/deltas/apis/messaging/gcrule.js.map +1 -1
  11. package/dist/deltas/apis/messaging/markAsDelivered.js +10 -12
  12. package/dist/deltas/apis/messaging/markAsDelivered.js.map +1 -1
  13. package/dist/deltas/apis/messaging/markAsRead.js +25 -60
  14. package/dist/deltas/apis/messaging/markAsRead.js.map +1 -1
  15. package/dist/deltas/apis/messaging/markAsReadAll.js +9 -11
  16. package/dist/deltas/apis/messaging/markAsReadAll.js.map +1 -1
  17. package/dist/deltas/apis/messaging/markAsSeen.js +10 -37
  18. package/dist/deltas/apis/messaging/markAsSeen.js.map +1 -1
  19. package/dist/deltas/apis/messaging/nickname.js +38 -98
  20. package/dist/deltas/apis/messaging/nickname.js.map +1 -1
  21. package/dist/deltas/apis/messaging/notes.js +52 -90
  22. package/dist/deltas/apis/messaging/notes.js.map +1 -1
  23. package/dist/deltas/apis/messaging/resolvePhotoUrl.js +17 -42
  24. package/dist/deltas/apis/messaging/resolvePhotoUrl.js.map +1 -1
  25. package/dist/deltas/apis/messaging/sendMessage.js +14 -15
  26. package/dist/deltas/apis/messaging/sendMessage.js.map +1 -1
  27. package/dist/deltas/apis/messaging/sendTypingIndicator.js +7 -13
  28. package/dist/deltas/apis/messaging/sendTypingIndicator.js.map +1 -1
  29. package/dist/deltas/apis/messaging/setMessageReaction.js +24 -14
  30. package/dist/deltas/apis/messaging/setMessageReaction.js.map +1 -1
  31. package/dist/deltas/apis/messaging/shareContact.js +14 -12
  32. package/dist/deltas/apis/messaging/shareContact.js.map +1 -1
  33. package/dist/deltas/apis/messaging/stickers.js +4 -5
  34. package/dist/deltas/apis/messaging/stickers.js.map +1 -1
  35. package/dist/deltas/apis/messaging/theme.js +142 -213
  36. package/dist/deltas/apis/messaging/theme.js.map +1 -1
  37. package/dist/deltas/apis/messaging/unsendMessage.js +14 -7
  38. package/dist/deltas/apis/messaging/unsendMessage.js.map +1 -1
  39. package/dist/deltas/apis/posting/group.js +440 -11
  40. package/dist/deltas/apis/posting/group.js.map +1 -1
  41. package/dist/index.d.ts +18 -0
  42. package/dist/types/deltas/apis/messaging/editMessage.d.ts +4 -5
  43. package/dist/types/deltas/apis/messaging/emoji.d.ts +7 -1
  44. package/dist/types/deltas/apis/messaging/gcmember.d.ts +7 -1
  45. package/dist/types/deltas/apis/messaging/gcname.d.ts +9 -1
  46. package/dist/types/deltas/apis/messaging/gcrule.d.ts +7 -1
  47. package/dist/types/deltas/apis/messaging/markAsDelivered.d.ts +1 -2
  48. package/dist/types/deltas/apis/messaging/markAsRead.d.ts +1 -1
  49. package/dist/types/deltas/apis/messaging/markAsReadAll.d.ts +1 -2
  50. package/dist/types/deltas/apis/messaging/markAsSeen.d.ts +1 -1
  51. package/dist/types/deltas/apis/messaging/nickname.d.ts +7 -1
  52. package/dist/types/deltas/apis/messaging/notes.d.ts +13 -11
  53. package/dist/types/deltas/apis/messaging/resolvePhotoUrl.d.ts +4 -6
  54. package/dist/types/deltas/apis/messaging/sendMessage.d.ts +1 -1
  55. package/dist/types/deltas/apis/messaging/sendTypingIndicator.d.ts +1 -1
  56. package/dist/types/deltas/apis/messaging/setMessageReaction.d.ts +6 -1
  57. package/dist/types/deltas/apis/messaging/shareContact.d.ts +1 -2
  58. package/dist/types/deltas/apis/messaging/stickers.d.ts +1 -1
  59. package/dist/types/deltas/apis/messaging/theme.d.ts +8 -1
  60. package/dist/types/deltas/apis/messaging/unsendMessage.d.ts +6 -1
  61. package/dist/types/deltas/apis/posting/group.d.ts +88 -0
  62. package/package.json +1 -1
  63. package/src/deltas/apis/messaging/editMessage.ts +16 -26
  64. package/src/deltas/apis/messaging/emoji.ts +45 -97
  65. package/src/deltas/apis/messaging/gcmember.ts +68 -113
  66. package/src/deltas/apis/messaging/gcname.ts +42 -91
  67. package/src/deltas/apis/messaging/gcrule.ts +61 -111
  68. package/src/deltas/apis/messaging/markAsDelivered.ts +19 -14
  69. package/src/deltas/apis/messaging/markAsRead.ts +45 -72
  70. package/src/deltas/apis/messaging/markAsReadAll.ts +17 -17
  71. package/src/deltas/apis/messaging/markAsSeen.ts +17 -41
  72. package/src/deltas/apis/messaging/nickname.ts +50 -116
  73. package/src/deltas/apis/messaging/notes.ts +59 -95
  74. package/src/deltas/apis/messaging/resolvePhotoUrl.ts +27 -50
  75. package/src/deltas/apis/messaging/sendMessage.ts +28 -26
  76. package/src/deltas/apis/messaging/sendTypingIndicator.ts +13 -12
  77. package/src/deltas/apis/messaging/setMessageReaction.ts +45 -20
  78. package/src/deltas/apis/messaging/shareContact.ts +25 -15
  79. package/src/deltas/apis/messaging/stickers.ts +4 -4
  80. package/src/deltas/apis/messaging/theme.ts +172 -259
  81. package/src/deltas/apis/messaging/unsendMessage.ts +23 -7
  82. package/src/deltas/apis/posting/group.ts +516 -11
  83. package/src/types/index.d.ts +18 -0
  84. package/request.txt +0 -60
@@ -1,106 +1,71 @@
1
1
  import utils = require('../../../utils');
2
2
 
3
- export default function(defaultFuncs: any, api: any, ctx: any) {
3
+ /**
4
+ * @module gcmember
5
+ * @param {Object} defaultFuncs
6
+ * @param {Object} api
7
+ * @param {Object} ctx
8
+ */
9
+ export default function gcmember(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
4
14
  /**
5
- * Made by ChoruOfficial
6
- * Mqtt
7
- * Adds or removes members from a group chat with pre-checking.
8
- *
9
- * @param {"add" | "remove"} action The action to perform.
10
- * @param {string|string[]} userIDs The user ID or array of user IDs.
11
- * @param {string} threadID The ID of the group chat.
12
- * @param {Function} [callback] Optional callback function.
13
- * @returns {Promise<object>} A promise that resolves with information about the action.
15
+ * Made by ChoruOfficial — Adds or removes members from a group chat via MQTT.
16
+ * @param {"add" | "remove"} action - The action to perform.
17
+ * @param {string | string[]} userIDs - The user ID or array of user IDs.
18
+ * @param {string} threadID - The ID of the group chat.
19
+ * @returns {Promise<object>}
14
20
  */
15
- return async function gcmember(action, userIDs, threadID, callback) {
16
- let _callback;
17
- if (typeof threadID === 'function') {
18
- _callback = threadID;
19
- threadID = null;
20
- } else if (typeof callback === 'function') {
21
- _callback = callback;
22
- }
23
-
24
- let resolvePromise, rejectPromise;
25
- const returnPromise = new Promise<any>((resolve, reject) => {
26
- resolvePromise = resolve;
27
- rejectPromise = reject;
28
- });
21
+ return async function gcmember(
22
+ action: 'add' | 'remove',
23
+ userIDs: string | string[],
24
+ threadID: string,
25
+ ): Promise<any> {
26
+ const validActions = ['add', 'remove'];
27
+ const normalizedAction = (action || '').toLowerCase() as 'add' | 'remove';
29
28
 
30
- if (typeof _callback != 'function') {
31
- _callback = (err, data) => {
32
- // Note: We will now rarely use the 'err' parameter for validation errors
33
- if (err) return rejectPromise(err);
34
- resolvePromise(data);
35
- };
29
+ if (!validActions.includes(normalizedAction)) {
30
+ return { type: 'error_gc', error: `Invalid action. Must be one of: ${validActions.join(', ')}` };
31
+ }
32
+ if (!userIDs || (Array.isArray(userIDs) && userIDs.length === 0)) {
33
+ return { type: 'error_gc', error: 'userIDs is required.' };
34
+ }
35
+ if (!threadID) {
36
+ return { type: 'error_gc', error: 'threadID is required.' };
37
+ }
38
+ if (!ctx.mqttClient) {
39
+ return { type: 'error_gc', error: 'Not connected to MQTT' };
36
40
  }
37
41
 
38
42
  try {
39
- const validActions = ['add', 'remove'];
40
- action = action ? action.toLowerCase() : '';
41
-
42
- // --- ERROR CHECKS NOW RETURN AN OBJECT INSTEAD OF THROWING ---
43
- if (!validActions.includes(action)) {
44
- return _callback(null, {
45
- type: 'error_gc',
46
- error: `Invalid action. Must be one of: ${validActions.join(', ')}`,
47
- });
48
- }
49
- if (!userIDs || userIDs.length === 0) {
50
- return _callback(null, {
51
- type: 'error_gc',
52
- error: 'userIDs is required.',
53
- });
54
- }
55
- if (!threadID) {
56
- return _callback(null, {
57
- type: 'error_gc',
58
- error: 'threadID is required.',
59
- });
60
- }
61
- if (!ctx.mqttClient) {
62
- return _callback(null, {
63
- type: 'error_gc',
64
- error: 'Not connected to MQTT',
65
- });
66
- }
67
-
68
43
  const threadInfo = await api.getThreadInfo(threadID);
69
44
  if (!threadInfo) {
70
- return _callback(null, {
71
- type: 'error_gc',
72
- error: 'Could not retrieve thread information.',
73
- });
45
+ return { type: 'error_gc', error: 'Could not retrieve thread information.' };
74
46
  }
75
47
  if (threadInfo.isGroup === false) {
76
- return _callback(null, {
77
- type: 'error_gc',
78
- error: 'This feature is only for group chats, not private messages.',
79
- });
48
+ return { type: 'error_gc', error: 'This feature is only for group chats, not private messages.' };
80
49
  }
81
50
 
82
- const currentMembers = threadInfo.participantIDs;
51
+ const currentMembers: string[] = threadInfo.participantIDs;
83
52
  const usersToModify = Array.isArray(userIDs) ? userIDs : [userIDs];
84
- let queryPayload, query;
85
- let finalUsers = usersToModify;
86
53
 
87
54
  ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
88
55
  ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
89
56
 
90
- if (action === 'add') {
91
- const usersToAdd = usersToModify.filter(
92
- (id) => !currentMembers.includes(id),
93
- );
57
+ let query: any;
58
+ let finalUsers: string[];
59
+
60
+ if (normalizedAction === 'add') {
61
+ const usersToAdd = usersToModify.filter((id) => !currentMembers.includes(id));
94
62
  if (usersToAdd.length === 0) {
95
- return _callback(null, {
96
- type: 'error_gc',
97
- error: 'All specified users are already in the group.',
98
- });
63
+ return { type: 'error_gc', error: 'All specified users are already in the group.' };
99
64
  }
100
65
  finalUsers = usersToAdd;
101
- queryPayload = {
102
- thread_key: parseInt(threadID),
103
- contact_ids: finalUsers.map((id) => parseInt(id)),
66
+ const queryPayload = {
67
+ thread_key: Number.parseInt(threadID),
68
+ contact_ids: finalUsers.map((id) => Number.parseInt(id)),
104
69
  sync_group: 1,
105
70
  };
106
71
  query = {
@@ -110,16 +75,12 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
110
75
  task_id: ctx.wsTaskNumber,
111
76
  };
112
77
  } else {
113
- // action is 'remove'
114
78
  const userToRemove = usersToModify[0];
115
79
  if (!currentMembers.includes(userToRemove)) {
116
- return _callback(null, {
117
- type: 'error_gc',
118
- error: `User with ID ${userToRemove} is not in this group chat.`,
119
- });
80
+ return { type: 'error_gc', error: `User with ID ${userToRemove} is not in this group chat.` };
120
81
  }
121
82
  finalUsers = [userToRemove];
122
- queryPayload = {
83
+ const queryPayload = {
123
84
  thread_id: threadID,
124
85
  contact_id: userToRemove,
125
86
  sync_group: 1,
@@ -135,7 +96,7 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
135
96
  const context: any = {
136
97
  app_id: ctx.appID,
137
98
  payload: {
138
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
99
+ epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
139
100
  tasks: [query],
140
101
  version_id: '24631415369801570',
141
102
  },
@@ -144,32 +105,26 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
144
105
  };
145
106
  context.payload = JSON.stringify(context.payload);
146
107
 
147
- ctx.mqttClient.publish(
148
- '/ls_req',
149
- JSON.stringify(context),
150
- { qos: 1, retain: false },
151
- (err) => {
152
- if (err) return _callback(err); // For network errors, we still reject
153
-
154
- const gcmemberInfo = {
155
- type: 'gc_member_update',
156
- threadID: threadID,
157
- userIDs: finalUsers,
158
- action: action,
159
- senderID: ctx.userID,
160
- BotID: ctx.userID,
161
- timestamp: Date.now(),
162
- };
163
- return _callback(null, gcmemberInfo);
164
- },
108
+ await new Promise<void>((resolve, reject) =>
109
+ ctx.mqttClient.publish(
110
+ '/ls_req',
111
+ JSON.stringify(context),
112
+ { qos: 1, retain: false },
113
+ (err) => (err ? reject(err) : resolve()),
114
+ ),
165
115
  );
166
- } catch (err) {
167
- return _callback(null, {
168
- type: 'error_gc',
169
- error: err.message || 'An unknown error occurred.',
170
- });
171
- }
172
116
 
173
- return returnPromise;
117
+ return {
118
+ type: 'gc_member_update',
119
+ threadID,
120
+ userIDs: finalUsers,
121
+ action: normalizedAction,
122
+ senderID: ctx.userID,
123
+ BotID: ctx.userID,
124
+ timestamp: Date.now(),
125
+ };
126
+ } catch (err: any) {
127
+ return { type: 'error_gc', error: err.message || 'An unknown error occurred.' };
128
+ }
174
129
  };
175
130
  }
@@ -1,87 +1,45 @@
1
1
  import utils = require('../../../utils');
2
2
 
3
- export default function(defaultFuncs: any, api: any, ctx: any) {
3
+ /**
4
+ * Made by Choru Official
5
+ * Sets the name of a group chat thread via MQTT.
6
+ *
7
+ * @param {Object} defaultFuncs
8
+ * @param {Object} api
9
+ * @param {Object} ctx
10
+ */
11
+ export default function gcname(
12
+ defaultFuncs: any,
13
+ api: any,
14
+ ctx: any,
15
+ ): Function {
4
16
  /**
5
- * Made by Choru Official
6
- * Mqtt
7
17
  * Sets the name of a group chat thread via MQTT.
8
- *
9
- * @param {string} newName The new name for the group chat.
10
- * @param {string} threadID The ID of the group chat thread.
11
- * @param {Function} [callback] Optional callback function to be invoked upon completion.
12
- * @param {string} [initiatorID] The ID of the user who initiated the group name change (e.g., from event.senderID).
13
- * @returns {Promise<object>} A promise that resolves with a structured event object on success or rejects on error.
18
+ * @param {string} newName - The new name for the group chat.
19
+ * @param {string} threadID - The ID of the group chat thread.
20
+ * @param {string} [initiatorID] - The ID of the user who initiated the change.
21
+ * @returns {Promise<object>}
14
22
  */
15
- return function gcname(newName, threadID, callback, initiatorID) {
16
- let _callback;
17
- let _initiatorID;
18
-
19
- let _resolvePromise;
20
- let _rejectPromise;
21
- const returnPromise = new Promise<any>((resolve, reject) => {
22
- _resolvePromise = resolve;
23
- _rejectPromise = reject;
24
- });
25
-
26
- if (
27
- utils.getType(callback) === 'Function' ||
28
- utils.getType(callback) === 'AsyncFunction'
29
- ) {
30
- _callback = callback;
31
- _initiatorID = initiatorID;
32
- } else if (
33
- utils.getType(threadID) === 'Function' ||
34
- utils.getType(threadID) === 'AsyncFunction'
35
- ) {
36
- _callback = threadID;
37
- threadID = null;
38
- _initiatorID = callback;
39
- } else if (utils.getType(callback) === 'string') {
40
- _initiatorID = callback;
41
- _callback = undefined;
42
- } else {
43
- _callback = undefined;
44
- _initiatorID = undefined;
45
- }
46
-
47
- if (!_callback) {
48
- _callback = function(__err, __data) {
49
- if (__err) _rejectPromise(__err);
50
- else _resolvePromise(__data);
51
- };
52
- } else {
53
- const originalCallback = _callback;
54
- _callback = function(__err, __data) {
55
- if (__err) {
56
- originalCallback(__err);
57
- _rejectPromise(__err);
58
- } else {
59
- originalCallback(null, __data);
60
- _resolvePromise(__data);
61
- }
62
- };
63
- }
64
-
65
- _initiatorID = _initiatorID || ctx.userID;
66
-
67
- threadID = threadID || ctx.threadID;
68
-
23
+ return async function gcname(
24
+ newName: string,
25
+ threadID: string,
26
+ initiatorID?: string,
27
+ ): Promise<any> {
69
28
  if (!threadID) {
70
- return _callback(
71
- new Error('threadID is required to change the group chat name.'),
72
- );
29
+ throw new Error('threadID is required to change the group chat name.');
73
30
  }
74
31
  if (typeof newName !== 'string') {
75
- return _callback(new Error('newName must be a string.'));
32
+ throw new Error('newName must be a string.');
76
33
  }
77
-
78
34
  if (!ctx.mqttClient) {
79
- return _callback(new Error('Not connected to MQTT'));
35
+ throw new Error('Not connected to MQTT');
80
36
  }
81
37
 
82
38
  ctx.wsReqNumber += 1;
83
39
  ctx.wsTaskNumber += 1;
84
40
 
41
+ const _initiatorID = initiatorID || ctx.userID;
42
+
85
43
  const queryPayload = {
86
44
  thread_key: threadID.toString(),
87
45
  thread_name: newName,
@@ -108,29 +66,22 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
108
66
  };
109
67
  context.payload = JSON.stringify(context.payload);
110
68
 
111
- ctx.mqttClient.publish(
112
- '/ls_req',
113
- JSON.stringify(context),
114
- { qos: 1, retain: false },
115
- (err) => {
116
- if (err) {
117
- return _callback(
118
- new Error(`MQTT publish failed for gcname: ${err.message || err}`),
119
- );
120
- }
121
-
122
- const gcnameChangeEvent = {
123
- type: 'thread_name_update',
124
- threadID: threadID,
125
- newName: newName,
126
- senderID: _initiatorID,
127
- BotID: ctx.userID,
128
- timestamp: Date.now(),
129
- };
130
- _callback(null, gcnameChangeEvent);
131
- },
69
+ await new Promise<void>((resolve, reject) =>
70
+ ctx.mqttClient.publish(
71
+ '/ls_req',
72
+ JSON.stringify(context),
73
+ { qos: 1, retain: false },
74
+ (err) => (err ? reject(new Error(`MQTT publish failed for gcname: ${err.message || err}`)) : resolve()),
75
+ ),
132
76
  );
133
77
 
134
- return returnPromise;
78
+ return {
79
+ type: 'thread_name_update',
80
+ threadID,
81
+ newName,
82
+ senderID: _initiatorID,
83
+ BotID: ctx.userID,
84
+ timestamp: Date.now(),
85
+ };
135
86
  };
136
87
  }
@@ -1,108 +1,62 @@
1
1
  import utils = require('../../../utils');
2
2
 
3
- export default function(defaultFuncs: any, api: any, ctx: any) {
3
+ /**
4
+ * @module gcrule
5
+ * @param {Object} defaultFuncs
6
+ * @param {Object} api
7
+ * @param {Object} ctx
8
+ */
9
+ export default function gcrule(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
4
14
  /**
5
- * Made by ChoruOfficial
6
- * Mqtt
7
- * Adds or removes an admin from a group chat with pre-checking.
8
- *
9
- * @param {"admin" | "unadmin"} action The action to perform.
10
- * @param {string} userID The ID of the user to promote or demote.
11
- * @param {string} threadID The ID of the group chat.
12
- * @param {Function} [callback] Optional callback function.
13
- * @returns {Promise<object>} A promise that resolves with information about the action.
15
+ * Made by ChoruOfficial — Promotes or demotes a group chat member admin status via MQTT.
16
+ * @param {"admin" | "unadmin"} action - The action to perform.
17
+ * @param {string} userID - The user ID to promote or demote.
18
+ * @param {string} threadID - The ID of the group chat.
19
+ * @returns {Promise<object>}
14
20
  */
15
- return async function gcrule(action, userID, threadID, callback) {
16
- let _callback;
17
- if (typeof threadID === 'function') {
18
- _callback = threadID;
19
- threadID = null;
20
- } else if (typeof callback === 'function') {
21
- _callback = callback;
22
- }
23
-
24
- let resolvePromise, rejectPromise;
25
- const returnPromise = new Promise<any>((resolve, reject) => {
26
- resolvePromise = resolve;
27
- rejectPromise = reject;
28
- });
21
+ return async function gcrule(
22
+ action: 'admin' | 'unadmin',
23
+ userID: string,
24
+ threadID: string,
25
+ ): Promise<any> {
26
+ const validActions = ['admin', 'unadmin'];
27
+ const normalizedAction = (action || '').toLowerCase() as 'admin' | 'unadmin';
29
28
 
30
- if (typeof _callback != 'function') {
31
- _callback = (err, data) => {
32
- if (err) return rejectPromise(err);
33
- resolvePromise(data);
34
- };
29
+ if (!validActions.includes(normalizedAction)) {
30
+ return { type: 'error_gc_rule', error: `Invalid action. Must be one of: ${validActions.join(', ')}` };
35
31
  }
32
+ if (!userID) return { type: 'error_gc_rule', error: 'userID is required.' };
33
+ if (!threadID) return { type: 'error_gc_rule', error: 'threadID is required.' };
34
+ if (!ctx.mqttClient) return { type: 'error_gc_rule', error: 'Not connected to MQTT' };
36
35
 
37
36
  try {
38
- const validActions = ['admin', 'unadmin'];
39
- action = action ? action.toLowerCase() : '';
40
-
41
- if (!validActions.includes(action)) {
42
- return _callback(null, {
43
- type: 'error_gc_rule',
44
- error: `Invalid action. Must be one of: ${validActions.join(', ')}`,
45
- });
46
- }
47
- if (!userID)
48
- return _callback(null, {
49
- type: 'error_gc_rule',
50
- error: 'userID is required.',
51
- });
52
- if (!threadID)
53
- return _callback(null, {
54
- type: 'error_gc_rule',
55
- error: 'threadID is required.',
56
- });
57
- if (!ctx.mqttClient)
58
- return _callback(null, {
59
- type: 'error_gc_rule',
60
- error: 'Not connected to MQTT',
61
- });
62
-
63
37
  const threadInfo = await api.getThreadInfo(threadID);
64
- if (!threadInfo) {
65
- return _callback(null, {
66
- type: 'error_gc_rule',
67
- error: 'Could not retrieve thread information.',
68
- });
69
- }
70
- if (threadInfo.isGroup === false) {
71
- return _callback(null, {
72
- type: 'error_gc_rule',
73
- error: 'This feature is only for group chats.',
74
- });
75
- }
38
+ if (!threadInfo) return { type: 'error_gc_rule', error: 'Could not retrieve thread information.' };
39
+ if (threadInfo.isGroup === false) return { type: 'error_gc_rule', error: 'This feature is only for group chats.' };
76
40
 
77
- const adminIDs = threadInfo.adminIDs || [];
41
+ const adminIDs: { id: string }[] = threadInfo.adminIDs || [];
78
42
  const isCurrentlyAdmin = adminIDs.some((admin) => admin.id === userID);
79
43
 
80
- if (action === 'admin') {
81
- if (isCurrentlyAdmin) {
82
- return _callback(null, {
83
- type: 'error_gc_rule',
84
- error: `User is already an admin.`,
85
- });
86
- }
87
- } else {
88
- // action is 'unadmin'
89
- if (!isCurrentlyAdmin) {
90
- return _callback(null, {
91
- type: 'error_gc_rule',
92
- error: `User is not an admin.`,
93
- });
94
- }
44
+ if (normalizedAction === 'admin' && isCurrentlyAdmin) {
45
+ return { type: 'error_gc_rule', error: 'User is already an admin.' };
46
+ }
47
+ if (normalizedAction === 'unadmin' && !isCurrentlyAdmin) {
48
+ return { type: 'error_gc_rule', error: 'User is not an admin.' };
95
49
  }
96
50
 
97
- const isAdminStatus = action === 'admin' ? 1 : 0;
98
51
  ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
99
52
  ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
100
53
 
101
54
  const queryPayload = {
102
- thread_key: parseInt(threadID),
103
- contact_id: parseInt(userID),
104
- is_admin: isAdminStatus,
55
+ thread_key: Number.parseInt(threadID),
56
+ contact_id: Number.parseInt(userID),
57
+ is_admin: normalizedAction === 'admin' ? 1 : 0,
105
58
  };
59
+
106
60
  const query = {
107
61
  failure_count: null,
108
62
  label: '25',
@@ -110,10 +64,11 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
110
64
  queue_name: 'admin_status',
111
65
  task_id: ctx.wsTaskNumber,
112
66
  };
67
+
113
68
  const context: any = {
114
69
  app_id: ctx.appID,
115
70
  payload: {
116
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
71
+ epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
117
72
  tasks: [query],
118
73
  version_id: '24631415369801570',
119
74
  },
@@ -122,31 +77,26 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
122
77
  };
123
78
  context.payload = JSON.stringify(context.payload);
124
79
 
125
- ctx.mqttClient.publish(
126
- '/ls_req',
127
- JSON.stringify(context),
128
- { qos: 1, retain: false },
129
- (err) => {
130
- if (err) return _callback(err);
131
- const gcruleInfo = {
132
- type: 'gc_rule_update',
133
- threadID: threadID,
134
- userID: userID,
135
- action: action,
136
- senderID: ctx.userID,
137
- BotID: ctx.userID,
138
- timestamp: Date.now(),
139
- };
140
- return _callback(null, gcruleInfo);
141
- },
80
+ await new Promise<void>((resolve, reject) =>
81
+ ctx.mqttClient.publish(
82
+ '/ls_req',
83
+ JSON.stringify(context),
84
+ { qos: 1, retain: false },
85
+ (err) => (err ? reject(err) : resolve()),
86
+ ),
142
87
  );
143
- } catch (err) {
144
- return _callback(null, {
145
- type: 'error_gc_rule',
146
- error: err.message || 'An unknown error occurred.',
147
- });
148
- }
149
88
 
150
- return returnPromise;
89
+ return {
90
+ type: 'gc_rule_update',
91
+ threadID,
92
+ userID,
93
+ action: normalizedAction,
94
+ senderID: ctx.userID,
95
+ BotID: ctx.userID,
96
+ timestamp: Date.now(),
97
+ };
98
+ } catch (err: any) {
99
+ return { type: 'error_gc_rule', error: err.message || 'An unknown error occurred.' };
100
+ }
151
101
  };
152
102
  }
@@ -1,35 +1,40 @@
1
1
  // @ChoruOfficial
2
- "use strict";
2
+ import utils = require('../../../utils');
3
3
 
4
- import utils = require("../../../utils");
5
4
  /**
6
5
  * @param {Object} defaultFuncs
7
6
  * @param {Object} api
8
7
  * @param {Object} ctx
9
- * @returns {function(threadID: string, messageID: string): Promise<void>}
10
8
  */
11
- export default function(defaultFuncs: any, api: any, ctx: any) {
9
+ export default function markAsDelivered(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
12
14
  /**
13
15
  * Marks a message as delivered.
14
16
  * @param {string} threadID - The ID of the thread.
15
17
  * @param {string} messageID - The ID of the message to mark as delivered.
16
- * @returns {Promise<void>} A promise that resolves on success or rejects on error.
18
+ * @returns {Promise<void>}
17
19
  */
18
- return async function markAsDelivered(threadID, messageID) {
20
+ return async function markAsDelivered(
21
+ threadID: string,
22
+ messageID: string,
23
+ ): Promise<void> {
19
24
  if (!threadID || !messageID) {
20
- const err = "Error: messageID or threadID is not defined";
21
- utils.error("markAsDelivered", err);
25
+ const err = 'Error: messageID or threadID is not defined';
26
+ utils.error('markAsDelivered', err);
22
27
  throw new Error(err);
23
28
  }
24
29
 
25
- const form = {};
26
- form["message_ids[0]"] = messageID;
27
- form["thread_ids[" + threadID + "][0]"] = messageID;
30
+ const form: Record<string, any> = {};
31
+ form['message_ids[0]'] = messageID;
32
+ form['thread_ids[' + threadID + '][0]'] = messageID;
28
33
 
29
34
  try {
30
35
  const resData = await defaultFuncs
31
36
  .post(
32
- "https://www.facebook.com/ajax/mercury/delivery_receipts.php",
37
+ 'https://www.facebook.com/ajax/mercury/delivery_receipts.php',
33
38
  ctx.jar,
34
39
  form,
35
40
  )
@@ -40,8 +45,8 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
40
45
  throw resData;
41
46
  }
42
47
  } catch (err) {
43
- utils.error("markAsDelivered", err);
48
+ utils.error('markAsDelivered', err);
44
49
  throw err;
45
50
  }
46
51
  };
47
- };
52
+ }