@dongdev/fca-unofficial 2.0.18 → 2.0.20
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
CHANGED
package/package.json
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
"use_strict";
|
2
|
+
|
3
|
+
const { generateOfflineThreadingID } = require("../../utils/format.js");
|
4
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
5
|
+
return (text, messageID, callback) => {
|
6
|
+
let reqID = ctx.wsReqNumber + 1;
|
7
|
+
var resolveFunc = () => { };
|
8
|
+
var rejectFunc = () => { };
|
9
|
+
var returnPromise = new Promise((resolve, reject) => {
|
10
|
+
resolveFunc = resolve;
|
11
|
+
rejectFunc = reject;
|
12
|
+
});
|
13
|
+
if (!callback) {
|
14
|
+
callback = (err, data) => {
|
15
|
+
if (err) {
|
16
|
+
return rejectFunc(err);
|
17
|
+
}
|
18
|
+
resolveFunc(data);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
const content = {
|
22
|
+
app_id: '2220391788200892',
|
23
|
+
payload: JSON.stringify({
|
24
|
+
data_trace_id: null,
|
25
|
+
epoch_id: parseInt(generateOfflineThreadingID()),
|
26
|
+
tasks: [{
|
27
|
+
failure_count: null,
|
28
|
+
label: '742',
|
29
|
+
payload: JSON.stringify({
|
30
|
+
message_id: messageID,
|
31
|
+
text: text,
|
32
|
+
}),
|
33
|
+
queue_name: 'edit_message',
|
34
|
+
task_id: ++ctx.wsTaskNumber,
|
35
|
+
}],
|
36
|
+
version_id: '6903494529735864',
|
37
|
+
}),
|
38
|
+
request_id: ++ctx.wsReqNumber,
|
39
|
+
type: 3
|
40
|
+
}
|
41
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), {
|
42
|
+
qos: 1,
|
43
|
+
retain: false
|
44
|
+
});
|
45
|
+
const handleRes = (topic, message) => {
|
46
|
+
if (topic === "/ls_resp") {
|
47
|
+
let jsonMsg = JSON.parse(message.toString());
|
48
|
+
jsonMsg.payload = JSON.parse(jsonMsg.payload);
|
49
|
+
if (jsonMsg.request_id != reqID) return;
|
50
|
+
ctx.mqttClient.removeListener('message', handleRes);
|
51
|
+
let msgID = jsonMsg.payload.step[1][2][2][1][2];
|
52
|
+
let msgReplace = jsonMsg.payload.step[1][2][2][1][4];
|
53
|
+
const bodies = {
|
54
|
+
body: msgReplace,
|
55
|
+
messageID: msgID
|
56
|
+
};
|
57
|
+
if (msgReplace != text) {
|
58
|
+
return callback({
|
59
|
+
error: "The message is too old or not from you!"
|
60
|
+
}, bodies);
|
61
|
+
}
|
62
|
+
return callback(undefined, bodies);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
ctx.mqttClient.on('message', handleRes);
|
66
|
+
return returnPromise;
|
67
|
+
};
|
68
|
+
}
|
@@ -178,10 +178,24 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
178
178
|
});
|
179
179
|
}
|
180
180
|
|
181
|
+
function sendOnce(baseForm, threadID, isSingleUser) {
|
182
|
+
const otid = generateOfflineThreadingID();
|
183
|
+
const form = { ...baseForm, offline_threading_id: otid, message_id: otid };
|
184
|
+
return new Promise((resolve, reject) => {
|
185
|
+
sendContent(form, threadID, isSingleUser, otid, (err, info) => (err ? reject(err) : resolve(info)));
|
186
|
+
});
|
187
|
+
}
|
188
|
+
|
181
189
|
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
182
190
|
if (getType(threadID) === "Array") return sendContent(form, threadID, false, messageAndOTID, callback);
|
183
|
-
if (getType(isGroup)
|
184
|
-
|
191
|
+
if (getType(isGroup) === "Boolean") return sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
192
|
+
sendOnce(form, threadID, false)
|
193
|
+
.then(info => callback(null, info))
|
194
|
+
.catch(() => {
|
195
|
+
sendOnce(form, threadID, true)
|
196
|
+
.then(info => callback(null, info))
|
197
|
+
.catch(err => callback(err));
|
198
|
+
});
|
185
199
|
}
|
186
200
|
|
187
201
|
function handleUrl(msg, form, callback, cb) {
|
@@ -362,5 +376,4 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
362
376
|
);
|
363
377
|
return returnPromise;
|
364
378
|
};
|
365
|
-
|
366
379
|
};
|
package/src/utils/client.js
CHANGED
@@ -99,10 +99,10 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
|
|
99
99
|
throw e;
|
100
100
|
}
|
101
101
|
ctx.auto_login = true;
|
102
|
-
|
102
|
+
logger("Login session expired", "warn");
|
103
103
|
const ok = await ctx.performAutoLogin();
|
104
104
|
if (ok) {
|
105
|
-
|
105
|
+
logger("Auto login successful! Restarting...");
|
106
106
|
ctx.auto_login = false;
|
107
107
|
process.exit(1);
|
108
108
|
} else {
|