fca-priyansh 19.0.0 → 19.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/package.json +1 -1
- package/src/editMessage.js +71 -53
package/package.json
CHANGED
package/src/editMessage.js
CHANGED
@@ -1,53 +1,71 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
"use_strict";
|
2
|
+
/**
|
3
|
+
* @author RFS-ADRENO
|
4
|
+
* @rewrittenBy Isai Ivanov
|
5
|
+
*/
|
6
|
+
const generateOfflineThreadingId = require('../utils');
|
7
|
+
|
8
|
+
function canBeCalled(func) {
|
9
|
+
try {
|
10
|
+
Reflect.apply(func, null, []);
|
11
|
+
return true;
|
12
|
+
} catch (error) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* A function for editing bot's messages.
|
19
|
+
* @param {string} text - The text with which the bot will edit its messages.
|
20
|
+
* @param {string} messageID - The message ID of the message the bot will edit.
|
21
|
+
* @param {Object} callback - Callback for the function.
|
22
|
+
*/
|
23
|
+
|
24
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
25
|
+
return function editMessage(text, messageID, callback) {
|
26
|
+
if (!ctx.mqttClient) {
|
27
|
+
throw new Error('Not connected to MQTT');
|
28
|
+
}
|
29
|
+
|
30
|
+
// modified and fix by kenneth panio the edit now works on secondary profile accounts
|
31
|
+
|
32
|
+
ctx.wsReqNumber ??= 0;
|
33
|
+
ctx.wsTaskNumber ??= 0;
|
34
|
+
|
35
|
+
ctx.wsReqNumber += 1;
|
36
|
+
ctx.wsTaskNumber += 1;
|
37
|
+
|
38
|
+
const queryPayload = {
|
39
|
+
message_id: messageID,
|
40
|
+
text: text,
|
41
|
+
};
|
42
|
+
|
43
|
+
const query = {
|
44
|
+
failure_count: null,
|
45
|
+
label: '742',
|
46
|
+
payload: JSON.stringify(queryPayload),
|
47
|
+
queue_name: 'edit_message',
|
48
|
+
task_id: ctx.wsTaskNumber,
|
49
|
+
};
|
50
|
+
|
51
|
+
const context = {
|
52
|
+
app_id: '2220391788200892',
|
53
|
+
payload: {
|
54
|
+
data_trace_id: null,
|
55
|
+
epoch_id: parseInt(generateOfflineThreadingId),
|
56
|
+
tasks: [query],
|
57
|
+
version_id: '6903494529735864',
|
58
|
+
},
|
59
|
+
request_id: ctx.wsReqNumber,
|
60
|
+
type: 3,
|
61
|
+
};
|
62
|
+
|
63
|
+
context.payload = JSON.stringify(context.payload);
|
64
|
+
|
65
|
+
if (canBeCalled(callback)) {
|
66
|
+
ctx.reqCallbacks[ctx.wsReqNumber] = callback;
|
67
|
+
}
|
68
|
+
|
69
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false });
|
70
|
+
}
|
71
|
+
}
|