@langitdeveloper/baileys 2.1.6 → 2.1.9
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/lib/Socket/messages-recv.js +35 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/bot-toolkit.js +165 -0
- package/lib/Utils/index.js +1 -0
- package/lib/index.js +1 -10
- package/package.json +2 -2
|
@@ -418,6 +418,30 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
418
418
|
const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
|
|
419
419
|
const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
|
|
420
420
|
let contentPath;
|
|
421
|
+
if (operation === Types_1.MexUpdatesOperations.GROUP_MEMBER_LINK) {
|
|
422
|
+
contentPath = content.data[Types_1.XWAPathsMexUpdates.GROUP_SHARING_CHANGE];
|
|
423
|
+
ev.emit('groups.update', [
|
|
424
|
+
{
|
|
425
|
+
id,
|
|
426
|
+
author: contentPath.updated_by.id,
|
|
427
|
+
member_link_mode: contentPath.properties.member_link_mode
|
|
428
|
+
}
|
|
429
|
+
]);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (operation === Types_1.MexUpdatesOperations.OWNER_COMMUNITY) {
|
|
433
|
+
contentPath = content.data[Types_1.XWAPathsMexUpdates.COMMUNITY_OWNER_CHANGE];
|
|
434
|
+
const updatedBy = contentPath.updated_by;
|
|
435
|
+
const roleUser = contentPath.role_updates[0].user;
|
|
436
|
+
ev.emit('community-owner.update', {
|
|
437
|
+
id,
|
|
438
|
+
author: (updatedBy === null || updatedBy === void 0 ? void 0 : updatedBy.pn) ? updatedBy.pn : updatedBy.id,
|
|
439
|
+
user: (roleUser === null || roleUser === void 0 ? void 0 : roleUser.pn) ? roleUser.pn : roleUser.jid,
|
|
440
|
+
new_role: contentPath.role_updates[0].new_role,
|
|
441
|
+
update_time: contentPath.update_time
|
|
442
|
+
});
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
421
445
|
if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
|
|
422
446
|
let action;
|
|
423
447
|
if (operation === Types_1.MexOperations.PROMOTE) {
|
|
@@ -1007,6 +1031,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1007
1031
|
.catch(err => onUnexpectedError(err, identifier));
|
|
1008
1032
|
}
|
|
1009
1033
|
};
|
|
1034
|
+
/** lets other queued microtasks/timers run before we process the next batch */
|
|
1035
|
+
const yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
|
|
1010
1036
|
const makeOfflineNodeProcessor = () => {
|
|
1011
1037
|
const nodeProcessorMap = new Map([
|
|
1012
1038
|
['message', handleMessage],
|
|
@@ -1016,6 +1042,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1016
1042
|
]);
|
|
1017
1043
|
const nodes = [];
|
|
1018
1044
|
let isProcessing = false;
|
|
1045
|
+
const BATCH_SIZE = 10;
|
|
1019
1046
|
const enqueue = (type, node) => {
|
|
1020
1047
|
nodes.push({ type, node });
|
|
1021
1048
|
if (isProcessing) {
|
|
@@ -1023,6 +1050,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1023
1050
|
}
|
|
1024
1051
|
isProcessing = true;
|
|
1025
1052
|
const promise = async () => {
|
|
1053
|
+
let processedInBatch = 0;
|
|
1026
1054
|
while (nodes.length && ws.isOpen) {
|
|
1027
1055
|
const { type, node } = nodes.shift();
|
|
1028
1056
|
const nodeProcessor = nodeProcessorMap.get(type);
|
|
@@ -1031,6 +1059,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1031
1059
|
continue;
|
|
1032
1060
|
}
|
|
1033
1061
|
await nodeProcessor(node);
|
|
1062
|
+
processedInBatch++;
|
|
1063
|
+
if (processedInBatch >= BATCH_SIZE) {
|
|
1064
|
+
processedInBatch = 0;
|
|
1065
|
+
// give the event loop room to breathe so a big offline
|
|
1066
|
+
// sync backlog doesn't make the bot look "frozen"
|
|
1067
|
+
await yieldToEventLoop();
|
|
1068
|
+
}
|
|
1034
1069
|
}
|
|
1035
1070
|
isProcessing = false;
|
|
1036
1071
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MexUpdatesOperations = {
|
|
4
|
+
OWNER_COMMUNITY: "NotificationCommunityOwnerUpdate",
|
|
5
|
+
GROUP_MEMBER_LINK: "NotificationGroupMemberLinkPropertyUpdate",
|
|
6
|
+
GROUP_LIMIT_SHARING: "NotificationGroupLimitSharingPropertyUpdate",
|
|
7
|
+
};
|
|
8
|
+
const XWAPathsMexUpdates = {
|
|
9
|
+
GROUP_SHARING_CHANGE: "xwa2_notify_group_on_prop_change",
|
|
10
|
+
COMMUNITY_OWNER_CHANGE: "xwa2_notify_group_on_participants_roles_change",
|
|
11
|
+
};
|
|
12
|
+
module.exports = {
|
|
13
|
+
MexUpdatesOperations: MexUpdatesOperations,
|
|
14
|
+
XWAPathsMexUpdates: XWAPathsMexUpdates,
|
|
15
|
+
};
|
package/lib/Types/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./Events"), exports);
|
|
|
27
27
|
__exportStar(require("./Product"), exports);
|
|
28
28
|
__exportStar(require("./Call"), exports);
|
|
29
29
|
__exportStar(require("./Signal"), exports);
|
|
30
|
+
__exportStar(require("./MexUpdates"), exports);
|
|
30
31
|
var DisconnectReason;
|
|
31
32
|
(function (DisconnectReason) {
|
|
32
33
|
DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBotToolkit = void 0;
|
|
4
|
+
const makeBotToolkit = (conn, logger) => {
|
|
5
|
+
const startedAt = Date.now();
|
|
6
|
+
const seenMessageIds = new Map(); // id -> timestamp, used for dedup
|
|
7
|
+
const rateLimitBuckets = new Map(); // `${jid}:${key}` -> last timestamp
|
|
8
|
+
const DEDUP_TTL_MS = 60 * 1000;
|
|
9
|
+
const dedupCleanupEvery = 200;
|
|
10
|
+
let dedupCounter = 0;
|
|
11
|
+
/** internal: drop old entries from the dedup map so it doesn't grow forever */
|
|
12
|
+
const cleanupDedup = () => {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
for (const [id, ts] of seenMessageIds) {
|
|
15
|
+
if (now - ts > DEDUP_TTL_MS) {
|
|
16
|
+
seenMessageIds.delete(id);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
resolveJid(jid) {
|
|
22
|
+
var _a;
|
|
23
|
+
const { isJidUser, isLidUser, isJidGroup, isJidBroadcast, isJidStatusBroadcast, isJidNewsLetter, isHostedPnUser, isHostedLidUser, jidDecode: decode } = require('../WABinary');
|
|
24
|
+
const decoded = decode(jid);
|
|
25
|
+
let kind = 'unknown';
|
|
26
|
+
if (isJidStatusBroadcast(jid)) {
|
|
27
|
+
kind = 'status';
|
|
28
|
+
}
|
|
29
|
+
else if (isJidNewsLetter(jid)) {
|
|
30
|
+
kind = 'newsletter';
|
|
31
|
+
}
|
|
32
|
+
else if (isJidGroup(jid)) {
|
|
33
|
+
kind = 'group';
|
|
34
|
+
}
|
|
35
|
+
else if (isJidBroadcast(jid)) {
|
|
36
|
+
kind = 'broadcast';
|
|
37
|
+
}
|
|
38
|
+
else if (isHostedLidUser(jid)) {
|
|
39
|
+
kind = 'hosted-lid';
|
|
40
|
+
}
|
|
41
|
+
else if (isLidUser(jid)) {
|
|
42
|
+
kind = 'lid';
|
|
43
|
+
}
|
|
44
|
+
else if (isHostedPnUser(jid)) {
|
|
45
|
+
kind = 'hosted-pn';
|
|
46
|
+
}
|
|
47
|
+
else if (isJidUser(jid)) {
|
|
48
|
+
kind = 'pn';
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
jid,
|
|
52
|
+
kind,
|
|
53
|
+
user: (_a = decoded === null || decoded === void 0 ? void 0 : decoded.user) !== null && _a !== void 0 ? _a : null,
|
|
54
|
+
device: (decoded === null || decoded === void 0 ? void 0 : decoded.device) !== undefined ? decoded.device : null,
|
|
55
|
+
server: (decoded === null || decoded === void 0 ? void 0 : decoded.server) || null,
|
|
56
|
+
isLid: kind === 'lid' || kind === 'hosted-lid',
|
|
57
|
+
isPn: kind === 'pn' || kind === 'hosted-pn'
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
healthCheck() {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f;
|
|
62
|
+
const wsState = (_b = (_a = conn.ws) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b.readyState;
|
|
63
|
+
const wsStateNames = { 0: 'CONNECTING', 1: 'OPEN', 2: 'CLOSING', 3: 'CLOSED' };
|
|
64
|
+
return {
|
|
65
|
+
uptimeMs: Date.now() - startedAt,
|
|
66
|
+
wsState: wsStateNames[wsState] || 'UNKNOWN',
|
|
67
|
+
isOnline: wsState === 1,
|
|
68
|
+
me: ((_c = conn.authState) === null || _c === void 0 ? void 0 : _c.creds.me) || null,
|
|
69
|
+
lidMappingCacheSize: (_f = (_e = (_d = conn.signalRepository) === null || _d === void 0 ? void 0 : _d.lidMapping) === null || _e === void 0 ? void 0 : _e.mappingCache) === null || _f === void 0 ? void 0 : _f.size,
|
|
70
|
+
dedupTracked: seenMessageIds.size,
|
|
71
|
+
rateLimitBucketsTracked: rateLimitBuckets.size
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
onSafe(event, handler, opts = {}) {
|
|
75
|
+
const { timeoutMs } = opts;
|
|
76
|
+
const wrapped = (data) => {
|
|
77
|
+
let timeoutHandle;
|
|
78
|
+
try {
|
|
79
|
+
const result = handler(data);
|
|
80
|
+
if (result && typeof result.then === 'function') {
|
|
81
|
+
if (timeoutMs) {
|
|
82
|
+
timeoutHandle = setTimeout(() => {
|
|
83
|
+
logger.warn({ event, timeoutMs }, 'onSafe handler is taking unusually long (still running)');
|
|
84
|
+
}, timeoutMs);
|
|
85
|
+
}
|
|
86
|
+
result
|
|
87
|
+
.catch((err) => {
|
|
88
|
+
logger.error({ err, event }, 'onSafe: unhandled async error, ignored');
|
|
89
|
+
})
|
|
90
|
+
.finally(() => {
|
|
91
|
+
if (timeoutHandle) {
|
|
92
|
+
clearTimeout(timeoutHandle);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
logger.error({ err, event }, 'onSafe: error, ignored');
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
conn.ev.on(event, wrapped);
|
|
102
|
+
return () => conn.ev.off(event, wrapped);
|
|
103
|
+
},
|
|
104
|
+
isDuplicateMessage(messageId) {
|
|
105
|
+
if (!messageId) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const seen = seenMessageIds.has(messageId);
|
|
109
|
+
seenMessageIds.set(messageId, Date.now());
|
|
110
|
+
dedupCounter += 1;
|
|
111
|
+
if (dedupCounter % dedupCleanupEvery === 0) {
|
|
112
|
+
cleanupDedup();
|
|
113
|
+
}
|
|
114
|
+
return seen;
|
|
115
|
+
},
|
|
116
|
+
isRateLimited(jid, key, windowMs) {
|
|
117
|
+
const bucketKey = `${jid}:${key}`;
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
const last = rateLimitBuckets.get(bucketKey);
|
|
120
|
+
if (last && now - last < windowMs) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
rateLimitBuckets.set(bucketKey, now);
|
|
124
|
+
return false;
|
|
125
|
+
},
|
|
126
|
+
async aiMahiru({ errorText, code, apiKey, model = 'claude-haiku-4-5-20251001' }) {
|
|
127
|
+
const key = apiKey || process.env.ANTHROPIC_API_KEY;
|
|
128
|
+
if (!key) {
|
|
129
|
+
throw new Error('aiMahiru: no Anthropic API key provided (pass apiKey or set ANTHROPIC_API_KEY)');
|
|
130
|
+
}
|
|
131
|
+
const promptParts = [
|
|
132
|
+
'Kamu adalah Mahiru, asisten debug buat fork Baileys bernama mahiru-bails/@langitdeveloper.',
|
|
133
|
+
'Jawab singkat, bahasa Indonesia santai, fokus ke: kemungkinan sebab error, dan baris/fungsi mana yang perlu dicek.',
|
|
134
|
+
'Jangan ngarang nama file/fungsi yang gak disebutkan user.'
|
|
135
|
+
];
|
|
136
|
+
if (errorText) {
|
|
137
|
+
promptParts.push(`Error yang dialami:\n${errorText}`);
|
|
138
|
+
}
|
|
139
|
+
if (code) {
|
|
140
|
+
promptParts.push(`Kode yang dipakai user:\n\`\`\`js\n${code}\n\`\`\``);
|
|
141
|
+
}
|
|
142
|
+
const res = await fetch('https://api.anthropic.com/v1/messages', {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: {
|
|
145
|
+
'content-type': 'application/json',
|
|
146
|
+
'x-api-key': key,
|
|
147
|
+
'anthropic-version': '2023-06-01'
|
|
148
|
+
},
|
|
149
|
+
body: JSON.stringify({
|
|
150
|
+
model,
|
|
151
|
+
max_tokens: 1000,
|
|
152
|
+
messages: [{ role: 'user', content: promptParts.join('\n\n') }]
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
if (!res.ok) {
|
|
156
|
+
const text = await res.text().catch(() => '');
|
|
157
|
+
throw new Error(`aiMahiru: Anthropic API error ${res.status}: ${text}`);
|
|
158
|
+
}
|
|
159
|
+
const data = await res.json();
|
|
160
|
+
const textBlock = (data.content || []).find((c) => c.type === 'text');
|
|
161
|
+
return (textBlock === null || textBlock === void 0 ? void 0 : textBlock.text) || '(no response)';
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
exports.makeBotToolkit = makeBotToolkit;
|
package/lib/Utils/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./crypto"), exports);
|
|
|
23
23
|
__exportStar(require("./signal"), exports);
|
|
24
24
|
__exportStar(require("./noise-handler"), exports);
|
|
25
25
|
__exportStar(require("./history"), exports);
|
|
26
|
+
__exportStar(require("./bot-toolkit"), exports);
|
|
26
27
|
__exportStar(require("./chat-utils"), exports);
|
|
27
28
|
__exportStar(require("./lt-hash"), exports);
|
|
28
29
|
__exportStar(require("./auth-utils"), exports);
|
package/lib/index.js
CHANGED
|
@@ -3,16 +3,7 @@
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
|
|
5
5
|
console.log(chalk.cyan("Thanks For Using My Baileys @Langit-Official"))
|
|
6
|
-
|
|
7
|
-
⣿⣿⣿⣿⣿⣷⣿⣿⣿⡅⡹⢿⠆⠙⠋⠉⠻⠿⣿⣿⣿⣿⣿⣿⣮⠻⣦⡙⢷⡑⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣌⠡⠌⠂⣙⠻⣛⠻⠷⠐⠈⠛⢱⣮⣷⣽⣿
|
|
8
|
-
⣿⣿⣿⣿⡇⢿⢹⣿⣶⠐⠁⠀⣀⣠⣤⠄⠀⠀⠈⠙⠻⣿⣿⣿⣦⣵⣌⠻⣷⢝⠦⠚⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢟⣻⣿⣊⡃⠀⣙⠿⣿⣿⣿⣎⢮⡀⢮⣽⣿⣿
|
|
9
|
-
⢿⣿⣿⣿⣧⡸⡎⡛⡩⠖⠀⣴⣿⣿⣿⠀⠀⠀⠀⠸⠇⠀⠙⢿⣿⣿⣿⣷⣌⢷⣑⢷⣄⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣫⠶⠛⠉⠀⠁⠀⠈⠈⠀⠠⠜⠻⣿⣆⢿⣼⣿⣿⣿
|
|
10
|
-
⢐⣿⣿⣿⣿⣧⢧⣧⢻⣦⢀⣹⣿⣿⣿⣇⠀⠄⠀⠀⠀⡀⠀⠈⢻⣿⣿⣿⣿⣷⣝⢦⡹⠷⡙⢿⣿⣿⣿⣿⣿⣿⣿⣿⠈⠁⠀⠀⠀⠁⠀⠀⠀⠱⣶⣄⡀⠀⠈⠛⠜⣿⣿⣿⣿
|
|
11
|
-
⠀⠊⢫⣿⣏⣿⡌⣼⣄⢫⡌⣿⣿⣿⣿⣿⣦⡈⠲⣄⣤⣤⡡⢀⣠⣿⣿⣿⣿⣿⣿⣷⣼⣍⢬⣦⡙⣿⣿⣿⣿⣿⣯⢁⡄⠀⡀⡀⠀⠄⢈⣠⢪⠀⣿⣿⣿⣦⠀⢉⢂⠹⡿⣿⣿
|
|
12
|
-
⠀⠀⠄⢹⢃⢻⣟⠙⣿⣦⠱⢻⣿⣿⣿⣿⣿⣿⣷⣬⣍⣭⣥⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⡙⢿⣼⡿⣿⣿⣿⣿⣿⣷⣄⠘⣱⢦⣤⡴⡿⢈⣼⣿⣿⣿⣇⣴⣶⣮⣅⢻⣿⡏
|
|
13
|
-
⠀⠀⠈⠹⣇⢡⢿⡆⠻⣿⣷⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣍⡻⣿⣟⣻⣿⣿⣿⣿⣷⣦⣥⣬⣤⣴⣾⣿⣿⣿⣿⣷⣿⣿⣿⣿⣷⡜⠃
|
|
14
|
-
⠀⠀⠀⢀⣘⠈⢂⠃⣧⡹⣿⣷⡄⠙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⣅⡙⢿⣟⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⡕⠂
|
|
15
|
-
⠀⠀⠀⠀⠀⠀⠛⢷⣜⢷⡌⠻⣿⣿⣦⣝⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣹⣷⣦⣹⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠉⠃⠀⠉`));
|
|
6
|
+
|
|
16
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
8
|
if (k2 === undefined) k2 = k;
|
|
18
9
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langitdeveloper/baileys",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"description": "WhatsApp API Modification By Langit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
],
|
|
9
9
|
"homepage": "https://github.com/langitdeveloper-official/mahiru-baileys",
|
|
10
10
|
"repository": {
|
|
11
|
-
"url": "https://github.com/langitdeveloper-
|
|
11
|
+
"url": "https://github.com/langitdeveloper-official/mahiru-baileys"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "Adhiraj Singh",
|