@dongdev/fca-unofficial 3.0.31 → 4.0.0

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 (127) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +224 -406
  3. package/dist/index.d.mts +1241 -0
  4. package/dist/index.d.ts +1241 -0
  5. package/dist/index.js +27749 -0
  6. package/dist/index.mjs +27713 -0
  7. package/docs/ARCHITECTURE.md +467 -0
  8. package/docs/DOCS.md +686 -0
  9. package/fca-config.example.json +33 -0
  10. package/package.json +32 -22
  11. package/test/fca.test.cjs +533 -0
  12. package/CHANGELOG.md +0 -296
  13. package/DOCS.md +0 -2712
  14. package/func/checkUpdate.js +0 -222
  15. package/func/logAdapter.js +0 -33
  16. package/func/logger.js +0 -48
  17. package/index.d.ts +0 -751
  18. package/index.js +0 -8
  19. package/module/config.js +0 -40
  20. package/module/login.js +0 -133
  21. package/module/loginHelper.js +0 -1296
  22. package/module/options.js +0 -44
  23. package/src/api/action/addExternalModule.js +0 -25
  24. package/src/api/action/changeAvatar.js +0 -137
  25. package/src/api/action/changeBio.js +0 -75
  26. package/src/api/action/enableAutoSaveAppState.js +0 -73
  27. package/src/api/action/getCurrentUserID.js +0 -7
  28. package/src/api/action/handleFriendRequest.js +0 -57
  29. package/src/api/action/logout.js +0 -76
  30. package/src/api/action/refreshFb_dtsg.js +0 -48
  31. package/src/api/action/setPostReaction.js +0 -106
  32. package/src/api/action/unfriend.js +0 -54
  33. package/src/api/http/httpGet.js +0 -46
  34. package/src/api/http/httpPost.js +0 -52
  35. package/src/api/http/postFormData.js +0 -47
  36. package/src/api/messaging/addUserToGroup.js +0 -68
  37. package/src/api/messaging/changeAdminStatus.js +0 -126
  38. package/src/api/messaging/changeArchivedStatus.js +0 -55
  39. package/src/api/messaging/changeBlockedStatus.js +0 -48
  40. package/src/api/messaging/changeGroupImage.js +0 -91
  41. package/src/api/messaging/changeNickname.js +0 -70
  42. package/src/api/messaging/changeThreadColor.js +0 -79
  43. package/src/api/messaging/changeThreadEmoji.js +0 -111
  44. package/src/api/messaging/createNewGroup.js +0 -88
  45. package/src/api/messaging/createPoll.js +0 -46
  46. package/src/api/messaging/createThemeAI.js +0 -98
  47. package/src/api/messaging/deleteMessage.js +0 -136
  48. package/src/api/messaging/deleteThread.js +0 -56
  49. package/src/api/messaging/editMessage.js +0 -68
  50. package/src/api/messaging/forwardAttachment.js +0 -57
  51. package/src/api/messaging/getEmojiUrl.js +0 -29
  52. package/src/api/messaging/getFriendsList.js +0 -82
  53. package/src/api/messaging/getMessage.js +0 -829
  54. package/src/api/messaging/getThemePictures.js +0 -62
  55. package/src/api/messaging/handleMessageRequest.js +0 -65
  56. package/src/api/messaging/markAsDelivered.js +0 -57
  57. package/src/api/messaging/markAsRead.js +0 -88
  58. package/src/api/messaging/markAsReadAll.js +0 -49
  59. package/src/api/messaging/markAsSeen.js +0 -61
  60. package/src/api/messaging/muteThread.js +0 -50
  61. package/src/api/messaging/removeUserFromGroup.js +0 -62
  62. package/src/api/messaging/resolvePhotoUrl.js +0 -43
  63. package/src/api/messaging/scheduler.js +0 -264
  64. package/src/api/messaging/searchForThread.js +0 -53
  65. package/src/api/messaging/sendMessage.js +0 -270
  66. package/src/api/messaging/sendTypingIndicator.js +0 -74
  67. package/src/api/messaging/setMessageReaction.js +0 -90
  68. package/src/api/messaging/setTitle.js +0 -124
  69. package/src/api/messaging/shareContact.js +0 -49
  70. package/src/api/messaging/threadColors.js +0 -128
  71. package/src/api/messaging/unsendMessage.js +0 -81
  72. package/src/api/messaging/uploadAttachment.js +0 -492
  73. package/src/api/socket/core/connectMqtt.js +0 -258
  74. package/src/api/socket/core/emitAuth.js +0 -103
  75. package/src/api/socket/core/getSeqID.js +0 -320
  76. package/src/api/socket/core/getTaskResponseData.js +0 -25
  77. package/src/api/socket/core/parseDelta.js +0 -377
  78. package/src/api/socket/detail/buildStream.js +0 -215
  79. package/src/api/socket/detail/constants.js +0 -28
  80. package/src/api/socket/listenMqtt.js +0 -377
  81. package/src/api/socket/middleware/index.js +0 -216
  82. package/src/api/threads/getThreadHistory.js +0 -664
  83. package/src/api/threads/getThreadInfo.js +0 -296
  84. package/src/api/threads/getThreadList.js +0 -293
  85. package/src/api/threads/getThreadPictures.js +0 -78
  86. package/src/api/users/getUserID.js +0 -65
  87. package/src/api/users/getUserInfo.js +0 -402
  88. package/src/api/users/getUserInfoV2.js +0 -134
  89. package/src/core/sendReqMqtt.js +0 -96
  90. package/src/database/helpers.js +0 -53
  91. package/src/database/models/index.js +0 -88
  92. package/src/database/models/thread.js +0 -50
  93. package/src/database/models/user.js +0 -46
  94. package/src/database/threadData.js +0 -94
  95. package/src/database/userData.js +0 -98
  96. package/src/remote/remoteClient.js +0 -123
  97. package/src/utils/broadcast.js +0 -51
  98. package/src/utils/client.js +0 -10
  99. package/src/utils/constants.js +0 -23
  100. package/src/utils/cookies.js +0 -68
  101. package/src/utils/format/attachment.js +0 -357
  102. package/src/utils/format/cookie.js +0 -9
  103. package/src/utils/format/date.js +0 -50
  104. package/src/utils/format/decode.js +0 -44
  105. package/src/utils/format/delta.js +0 -194
  106. package/src/utils/format/ids.js +0 -64
  107. package/src/utils/format/index.js +0 -64
  108. package/src/utils/format/message.js +0 -88
  109. package/src/utils/format/presence.js +0 -132
  110. package/src/utils/format/readTyp.js +0 -44
  111. package/src/utils/format/thread.js +0 -42
  112. package/src/utils/format/utils.js +0 -141
  113. package/src/utils/headers.js +0 -115
  114. package/src/utils/loginParser/autoLogin.js +0 -125
  115. package/src/utils/loginParser/helpers.js +0 -43
  116. package/src/utils/loginParser/index.js +0 -10
  117. package/src/utils/loginParser/parseAndCheckLogin.js +0 -220
  118. package/src/utils/loginParser/textUtils.js +0 -28
  119. package/src/utils/request/client.js +0 -26
  120. package/src/utils/request/config.js +0 -23
  121. package/src/utils/request/defaults.js +0 -46
  122. package/src/utils/request/helpers.js +0 -46
  123. package/src/utils/request/index.js +0 -17
  124. package/src/utils/request/methods.js +0 -163
  125. package/src/utils/request/proxy.js +0 -21
  126. package/src/utils/request/retry.js +0 -77
  127. package/src/utils/request/sanitize.js +0 -49
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Shared helpers for database layer (userData, threadData).
5
- * Keeps validation and payload normalization in one place.
6
- */
7
-
8
- const DB_NOT_INIT = "Database not initialized";
9
-
10
- function validateId(value, fieldName = "id") {
11
- if (value == null) {
12
- throw new Error(`${fieldName} is required and cannot be undefined`);
13
- }
14
- if (typeof value !== "string" && typeof value !== "number") {
15
- throw new Error(`Invalid ${fieldName}: must be a string or number`);
16
- }
17
- return String(value);
18
- }
19
-
20
- function validateData(data) {
21
- if (!data || typeof data !== "object" || Array.isArray(data)) {
22
- throw new Error("Invalid data: must be a non-empty object");
23
- }
24
- }
25
-
26
- /**
27
- * @param {string|string[]|null} keys - "userID" | ["userID","data"] | null
28
- * @returns {string[]|undefined}
29
- */
30
- function normalizeAttributes(keys) {
31
- if (keys == null) return undefined;
32
- return typeof keys === "string" ? [keys] : Array.isArray(keys) ? keys : undefined;
33
- }
34
-
35
- /**
36
- * Normalize payload: accept either { data } or raw object.
37
- */
38
- function normalizePayload(data, key = "data") {
39
- return Object.prototype.hasOwnProperty.call(data, key) ? data : { [key]: data };
40
- }
41
-
42
- function wrapError(message, cause) {
43
- return new Error(`${message}: ${cause && cause.message ? cause.message : cause}`);
44
- }
45
-
46
- module.exports = {
47
- DB_NOT_INIT,
48
- validateId,
49
- validateData,
50
- normalizeAttributes,
51
- normalizePayload,
52
- wrapError
53
- };
@@ -1,88 +0,0 @@
1
- const { Sequelize } = require("sequelize");
2
- const fs = require("fs");
3
- const path = require("path");
4
-
5
- let sequelize = null;
6
- let models = {};
7
-
8
- try {
9
- const databasePath = path.join(process.cwd(), "Fca_Database");
10
- if (!fs.existsSync(databasePath)) {
11
- fs.mkdirSync(databasePath, { recursive: true });
12
- }
13
-
14
- sequelize = new Sequelize({
15
- dialect: "sqlite",
16
- storage: path.join(databasePath, "database.sqlite"),
17
- logging: false,
18
- pool: {
19
- max: 5,
20
- min: 0,
21
- acquire: 30000,
22
- idle: 10000
23
- },
24
- retry: {
25
- max: 3
26
- },
27
- dialectOptions: {
28
- timeout: 5000
29
- },
30
- isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
31
- });
32
-
33
- // Load models with error handling
34
- try {
35
- const modelFiles = fs.readdirSync(__dirname)
36
- .filter(file => file.endsWith(".js") && file !== "index.js");
37
-
38
- for (const file of modelFiles) {
39
- try {
40
- const model = require(path.join(__dirname, file))(sequelize);
41
- if (model && model.name) {
42
- models[model.name] = model;
43
- }
44
- } catch (modelError) {
45
- // Log but continue loading other models
46
- console.error(`Failed to load model ${file}:`, modelError && modelError.message ? modelError.message : String(modelError));
47
- }
48
- }
49
-
50
- // Associate models
51
- Object.keys(models).forEach(modelName => {
52
- try {
53
- if (models[modelName].associate) {
54
- models[modelName].associate(models);
55
- }
56
- } catch (assocError) {
57
- console.error(`Failed to associate model ${modelName}:`, assocError && assocError.message ? assocError.message : String(assocError));
58
- }
59
- });
60
- } catch (loadError) {
61
- console.error("Failed to load models:", loadError && loadError.message ? loadError.message : String(loadError));
62
- }
63
-
64
- models.sequelize = sequelize;
65
- models.Sequelize = Sequelize;
66
- models.isReady = true;
67
- models.syncAll = async () => {
68
- try {
69
- if (!sequelize) {
70
- throw new Error("Sequelize instance not initialized");
71
- }
72
- await sequelize.sync({ force: false });
73
- } catch (error) {
74
- console.error("Failed to synchronize models:", error && error.message ? error.message : String(error));
75
- throw error;
76
- }
77
- };
78
- } catch (initError) {
79
- console.error("Database initialization error:", initError && initError.message ? initError.message : String(initError));
80
- models.sequelize = null;
81
- models.Sequelize = Sequelize;
82
- models.isReady = false;
83
- models.syncAll = async () => {
84
- throw new Error("Database not initialized");
85
- };
86
- }
87
-
88
- module.exports = models;
@@ -1,50 +0,0 @@
1
- module.exports = function(sequelize) {
2
- const { Model, DataTypes } = require("sequelize");
3
-
4
- class Thread extends Model {}
5
-
6
- Thread.init(
7
- {
8
- num: {
9
- type: DataTypes.INTEGER,
10
- allowNull: false,
11
- autoIncrement: true,
12
- primaryKey: true
13
- },
14
- threadID: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true
18
- },
19
- messageCount: {
20
- type: DataTypes.INTEGER,
21
- allowNull: false,
22
- defaultValue: 0
23
- },
24
- data: {
25
- type: DataTypes.TEXT,
26
- allowNull: true,
27
- get() {
28
- const value = this.getDataValue('data');
29
- if (typeof value === 'string') {
30
- try {
31
- return JSON.parse(value);
32
- } catch {
33
- return value;
34
- }
35
- }
36
- return value;
37
- },
38
- set(value) {
39
- this.setDataValue('data', typeof value === 'string' ? value : JSON.stringify(value));
40
- }
41
- }
42
- },
43
- {
44
- sequelize,
45
- modelName: "Thread",
46
- timestamps: true
47
- }
48
- );
49
- return Thread;
50
- };
@@ -1,46 +0,0 @@
1
- module.exports = function (sequelize) {
2
- const { Model, DataTypes } = require("sequelize");
3
-
4
- class User extends Model { }
5
-
6
- User.init(
7
- {
8
- num: {
9
- type: DataTypes.INTEGER,
10
- allowNull: false,
11
- autoIncrement: true,
12
- primaryKey: true
13
- },
14
- userID: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true
18
- },
19
- data: {
20
- type: DataTypes.TEXT,
21
- allowNull: true,
22
- get() {
23
- const value = this.getDataValue('data');
24
- if (typeof value === 'string') {
25
- try {
26
- return JSON.parse(value);
27
- } catch {
28
- return value;
29
- }
30
- }
31
- return value;
32
- },
33
- set(value) {
34
- this.setDataValue('data', typeof value === 'string' ? value : JSON.stringify(value));
35
- }
36
- }
37
- },
38
- {
39
- sequelize,
40
- modelName: "User",
41
- timestamps: true
42
- }
43
- );
44
-
45
- return User;
46
- };
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- const models = require("./models");
4
- const {
5
- DB_NOT_INIT,
6
- validateId,
7
- validateData,
8
- normalizeAttributes,
9
- wrapError
10
- } = require("./helpers");
11
-
12
- const Thread = models.Thread;
13
- const ID_FIELD = "threadID";
14
-
15
- module.exports = function (bot) {
16
- return {
17
- async create(threadID, data) {
18
- if (!Thread) {
19
- return { thread: { threadID: validateId(threadID, ID_FIELD), ...(data || {}) }, created: true };
20
- }
21
- try {
22
- threadID = validateId(threadID, ID_FIELD);
23
- let thread = await Thread.findOne({ where: { threadID } });
24
- if (thread) return { thread: thread.get(), created: false };
25
- thread = await Thread.create({ threadID, ...(data || {}) });
26
- return { thread: thread.get(), created: true };
27
- } catch (err) {
28
- throw wrapError("Failed to create thread", err);
29
- }
30
- },
31
-
32
- async get(threadID) {
33
- if (!Thread) return null;
34
- try {
35
- threadID = validateId(threadID, ID_FIELD);
36
- const thread = await Thread.findOne({ where: { threadID } });
37
- return thread ? thread.get() : null;
38
- } catch (err) {
39
- throw wrapError("Failed to get thread", err);
40
- }
41
- },
42
-
43
- async update(threadID, data) {
44
- if (!Thread) {
45
- return { thread: { threadID: validateId(threadID, ID_FIELD), ...(data || {}) }, created: false };
46
- }
47
- try {
48
- threadID = validateId(threadID, ID_FIELD);
49
- validateData(data);
50
- const thread = await Thread.findOne({ where: { threadID } });
51
- if (thread) {
52
- await thread.update(data);
53
- return { thread: thread.get(), created: false };
54
- }
55
- const newThread = await Thread.create({ ...data, threadID });
56
- return { thread: newThread.get(), created: true };
57
- } catch (err) {
58
- throw wrapError("Failed to update thread", err);
59
- }
60
- },
61
-
62
- async del(threadID) {
63
- if (!Thread) throw new Error(DB_NOT_INIT);
64
- try {
65
- threadID = validateId(threadID, ID_FIELD);
66
- const result = await Thread.destroy({ where: { threadID } });
67
- if (result === 0) throw new Error("No thread found with the specified threadID");
68
- return result;
69
- } catch (err) {
70
- throw wrapError("Failed to delete thread", err);
71
- }
72
- },
73
-
74
- async delAll() {
75
- if (!Thread) return 0;
76
- try {
77
- return await Thread.destroy({ where: {} });
78
- } catch (err) {
79
- throw wrapError("Failed to delete all threads", err);
80
- }
81
- },
82
-
83
- async getAll(keys = null) {
84
- if (!Thread) return [];
85
- try {
86
- const attributes = normalizeAttributes(keys);
87
- const rows = await Thread.findAll({ attributes });
88
- return rows.map((t) => t.get());
89
- } catch (err) {
90
- throw wrapError("Failed to get all threads", err);
91
- }
92
- }
93
- };
94
- };
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- const models = require("./models");
4
- const {
5
- DB_NOT_INIT,
6
- validateId,
7
- validateData,
8
- normalizeAttributes,
9
- normalizePayload,
10
- wrapError
11
- } = require("./helpers");
12
-
13
- const User = models.User;
14
- const ID_FIELD = "userID";
15
-
16
- function stubUser(userID, data) {
17
- return { user: { userID, ...normalizePayload(data || {}, "data") }, created: true };
18
- }
19
-
20
- module.exports = function (bot) {
21
- return {
22
- async create(userID, data) {
23
- if (!User) return stubUser(validateId(userID, ID_FIELD), data);
24
- try {
25
- userID = validateId(userID, ID_FIELD);
26
- validateData(data);
27
- const payload = normalizePayload(data, "data");
28
- let user = await User.findOne({ where: { userID } });
29
- if (user) return { user: user.get(), created: false };
30
- user = await User.create({ userID, ...payload });
31
- return { user: user.get(), created: true };
32
- } catch (err) {
33
- throw wrapError("Failed to create user", err);
34
- }
35
- },
36
-
37
- async get(userID) {
38
- if (!User) return null;
39
- try {
40
- userID = validateId(userID, ID_FIELD);
41
- const user = await User.findOne({ where: { userID } });
42
- return user ? user.get() : null;
43
- } catch (err) {
44
- throw wrapError("Failed to get user", err);
45
- }
46
- },
47
-
48
- async update(userID, data) {
49
- if (!User) return { user: { userID: validateId(userID, ID_FIELD), ...normalizePayload(data || {}, "data") }, created: false };
50
- try {
51
- userID = validateId(userID, ID_FIELD);
52
- validateData(data);
53
- const payload = normalizePayload(data, "data");
54
- const user = await User.findOne({ where: { userID } });
55
- if (user) {
56
- await user.update(payload);
57
- return { user: user.get(), created: false };
58
- }
59
- const newUser = await User.create({ userID, ...payload });
60
- return { user: newUser.get(), created: true };
61
- } catch (err) {
62
- throw wrapError("Failed to update user", err);
63
- }
64
- },
65
-
66
- async del(userID) {
67
- if (!User) throw new Error(DB_NOT_INIT);
68
- try {
69
- userID = validateId(userID, ID_FIELD);
70
- const result = await User.destroy({ where: { userID } });
71
- if (result === 0) throw new Error("No user found with the specified userID");
72
- return result;
73
- } catch (err) {
74
- throw wrapError("Failed to delete user", err);
75
- }
76
- },
77
-
78
- async delAll() {
79
- if (!User) return 0;
80
- try {
81
- return await User.destroy({ where: {} });
82
- } catch (err) {
83
- throw wrapError("Failed to delete all users", err);
84
- }
85
- },
86
-
87
- async getAll(keys = null) {
88
- if (!User) return [];
89
- try {
90
- const attributes = normalizeAttributes(keys);
91
- const rows = await User.findAll({ attributes });
92
- return rows.map((u) => u.get());
93
- } catch (err) {
94
- throw wrapError("Failed to get all users", err);
95
- }
96
- }
97
- };
98
- };
@@ -1,123 +0,0 @@
1
- "use strict";
2
-
3
- const WebSocket = require("ws");
4
- const logger = require("../../func/logger");
5
-
6
- function createRemoteClient(api, ctx, cfg) {
7
- if (!cfg || !cfg.enabled || !cfg.url) return null;
8
-
9
- const url = String(cfg.url);
10
- const token = cfg.token ? String(cfg.token) : null;
11
- const autoReconnect = cfg.autoReconnect !== false;
12
- const emitter = ctx && ctx._emitter;
13
-
14
- let ws = null;
15
- let closed = false;
16
- let reconnectTimer = null;
17
-
18
- function log(message, level = "info") {
19
- logger(`[remote] ${message}`, level);
20
- }
21
-
22
- function scheduleReconnect() {
23
- if (!autoReconnect || closed) return;
24
- if (reconnectTimer) return;
25
- reconnectTimer = setTimeout(() => {
26
- reconnectTimer = null;
27
- if (!closed) connect();
28
- }, 5000);
29
- }
30
-
31
- function safeEmit(event, payload) {
32
- try {
33
- if (emitter && typeof emitter.emit === "function") {
34
- emitter.emit(event, payload);
35
- }
36
- } catch { }
37
- }
38
-
39
- function connect() {
40
- try {
41
- ws = new WebSocket(url, {
42
- headers: token ? { Authorization: `Bearer ${token}` } : undefined
43
- });
44
- } catch (e) {
45
- log(`connect error: ${e && e.message ? e.message : String(e)}`, "warn");
46
- scheduleReconnect();
47
- return;
48
- }
49
-
50
- ws.on("open", () => {
51
- log("connected", "info");
52
- const payload = {
53
- type: "hello",
54
- userID: ctx && ctx.userID,
55
- region: ctx && ctx.region,
56
- version: require("../../package.json").version
57
- };
58
- try {
59
- ws.send(JSON.stringify(payload));
60
- } catch { }
61
- safeEmit("remoteConnected", payload);
62
- });
63
-
64
- ws.on("message", data => {
65
- let msg;
66
- try {
67
- msg = JSON.parse(data.toString());
68
- } catch {
69
- return;
70
- }
71
- if (!msg || typeof msg !== "object") return;
72
-
73
- switch (msg.type) {
74
- case "ping":
75
- try {
76
- ws.send(JSON.stringify({ type: "pong" }));
77
- } catch { }
78
- break;
79
- case "stop":
80
- safeEmit("remoteStop", msg);
81
- break;
82
- case "broadcast":
83
- safeEmit("remoteBroadcast", msg.payload || {});
84
- break;
85
- default:
86
- safeEmit("remoteMessage", msg);
87
- break;
88
- }
89
- });
90
-
91
- ws.on("close", () => {
92
- log("disconnected", "warn");
93
- safeEmit("remoteDisconnected");
94
- if (!closed) scheduleReconnect();
95
- });
96
-
97
- ws.on("error", err => {
98
- log(`error: ${err && err.message ? err.message : String(err)}`, "warn");
99
- });
100
- }
101
-
102
- connect();
103
-
104
- return {
105
- close() {
106
- closed = true;
107
- if (reconnectTimer) {
108
- clearTimeout(reconnectTimer);
109
- reconnectTimer = null;
110
- }
111
- try {
112
- if (ws && ws.readyState === WebSocket.OPEN) {
113
- ws.close();
114
- }
115
- } catch { }
116
- }
117
- };
118
- }
119
-
120
- module.exports = {
121
- createRemoteClient
122
- };
123
-
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- const logger = require("../../func/logger");
4
-
5
- function delay(ms) {
6
- return new Promise(resolve => setTimeout(resolve, ms));
7
- }
8
-
9
- async function broadcast(api, threadIDs, message, options) {
10
- const opts = options || {};
11
- const delayMs = typeof opts.delayMs === "number" ? opts.delayMs : 1000;
12
- const skipBlocked = opts.skipBlocked !== false;
13
- const onResult = typeof opts.onResult === "function" ? opts.onResult : null;
14
-
15
- if (!api || typeof api.sendMessage !== "function") {
16
- throw new Error("broadcast: api.sendMessage is required.");
17
- }
18
-
19
- const ids = Array.isArray(threadIDs) ? threadIDs : [threadIDs];
20
- const results = [];
21
-
22
- for (const id of ids) {
23
- try {
24
- const res = await api.sendMessage(message, id);
25
- const item = { threadID: id, ok: true, res };
26
- results.push(item);
27
- if (onResult) onResult(null, item);
28
- } catch (e) {
29
- const msg = e && e.error ? e.error : e && e.message ? e.message : String(e);
30
- logger(`broadcast: failed for ${id}: ${msg}`, "warn");
31
- const item = { threadID: id, ok: false, error: e };
32
- results.push(item);
33
- if (onResult) onResult(e, item);
34
-
35
- if (
36
- skipBlocked &&
37
- /permission|blocked|not allowed|cannot send message|not authorized/i.test(msg)
38
- ) {
39
- // Skip only this target, continue with others
40
- }
41
- }
42
- if (delayMs > 0) {
43
- await delay(delayMs);
44
- }
45
- }
46
-
47
- return results;
48
- }
49
-
50
- module.exports = broadcast;
51
-
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- const { saveCookies, getAppState } = require("./cookies");
4
- const { parseAndCheckLogin } = require("./loginParser");
5
-
6
- module.exports = {
7
- saveCookies,
8
- getAppState,
9
- parseAndCheckLogin
10
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- const { getType } = require("./format");
3
- const stream = require("stream");
4
- function getFrom(html, a, b) {
5
- const i = html.indexOf(a);
6
- if (i < 0) return;
7
- const start = i + a.length;
8
- const j = html.indexOf(b, start);
9
- return j < 0 ? undefined : html.slice(start, j);
10
- }
11
- function isReadableStream(obj) {
12
- return (
13
- obj instanceof stream.Stream &&
14
- (getType(obj._read) === "Function" ||
15
- getType(obj._read) === "AsyncFunction") &&
16
- getType(obj._readableState) === "Object"
17
- );
18
- }
19
-
20
- module.exports = {
21
- getFrom,
22
- isReadableStream
23
- };