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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/editMessage.js +71 -53
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fca-priyansh",
3
- "version": "19.0.0",
3
+ "version": "19.0.1",
4
4
  "description": "Facebook-chat-api made by Priyansh rajput",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,53 +1,71 @@
1
- /* eslint-disable linebreak-style */
2
- "use strict";
3
-
4
- var utils = require("../utils");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function editMessage(messageID, changedText, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
-
11
- var returnPromise = new Promise(function (resolve, reject) {
12
- resolveFunc = resolve;
13
- rejectFunc = reject;
14
- });
15
-
16
- if (!callback) {
17
- callback = function (err, data) {
18
- if (err) return rejectFunc(err);
19
- resolveFunc(data);
20
- };
21
- }
22
- ctx.mqttClient.publish('/ls_req',
23
- JSON.stringify({
24
- app_id: "2220391788200892",
25
- payload: JSON.stringify({
26
- tasks: [{
27
- label: 742,
28
- payload: JSON.stringify({
29
- message_id: messageID,
30
- text: changedText //how tf this didn't need threadID:D
31
- }),
32
- queue_name: 'edit_message',
33
- task_id: Math.random() * 1001 << 0,
34
- failure_count: null,
35
- }],
36
- epoch_id: utils.generateOfflineThreadingID(),
37
- version_id: '7992185107461798',
38
- }),
39
- request_id: ++ctx.req_ID,
40
- type: 3
41
- }),
42
- {
43
- qos: 1,
44
- retain: false,
45
- }
46
- );
47
- ctx.callback_Task[ctx.req_ID] = new Object({
48
- callback,
49
- type: "editMessage"
50
- });
51
- return returnPromise;
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
+ }