@langitdeveloper/baileys 2.1.6 → 2.1.7

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.
@@ -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;
@@ -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
- console.log(chalk.green(`
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.6",
3
+ "version": "2.1.7",
4
4
  "description": "WhatsApp API Modification By Langit",
5
5
  "keywords": [
6
6
  "whatsapp",