aunubaileys 1.0.5 → 1.0.6
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/README.md +0 -5
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +6 -6
- package/lib/Utils/antiban.d.ts +0 -21
- package/lib/Utils/antiban.js +0 -170
package/README.md
CHANGED
|
@@ -61,11 +61,6 @@ Everything else is pure upstream. When upstream moves, we rebase the patch layer
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
### 🆕 What's new in 1.0.5 / Baru di 1.0.5
|
|
66
|
-
|
|
67
|
-
- 🛡️ **AunuAntiBan built in** — account-protection layer inspired by [baileys-antiban](https://github.com/kobie3717/baileys-antiban), reimplemented cleanly in-package: per-chat & global rate limiting with Gaussian jitter, 7-day warmup ramp for new accounts, group add/create guards, typing simulation, and `classifyDisconnect()` recovery advice. No telemetry, no extra network calls. Usage: `wrapAntiBan(sock)` or `new AunuAntiBan(opts).wrap(sock)`.
|
|
68
|
-
|
|
69
64
|
### 🆕 What's new in 1.0.4 / Baru di 1.0.4
|
|
70
65
|
|
|
71
66
|
- 🎨 **Rich builders** — `AIRich`, `Button`, `ButtonV2`, `Carousel`, `Toolkit` (+ aliases) for Meta AI-style rich responses, native-flow buttons and carousels; `aunuHandler.sendInteractive()` with automatic plain-text fallback on iOS-paired devices.
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aunubaileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"description": "AunuBaileys
|
|
4
|
+
"version": "1.0.6",
|
|
5
|
+
"description": "AunuBaileys — a WhatsApp Web API for bots that never sleep. Full upstream power with the beloved in-memory store restored and pairing that just works. Forged by AunuCore.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
8
8
|
"whatsapp-web",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"automation",
|
|
20
20
|
"nodejs"
|
|
21
21
|
],
|
|
22
|
-
"homepage": "https://
|
|
22
|
+
"homepage": "https://docsjs.aunucore.eu.cc",
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/AunuHost/AunuBaileys.git"
|
|
25
|
+
"url": "git+https://github.com/AunuHost/AunuBaileys-lib.git"
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"author": "AunuCore Creative Network",
|
|
@@ -101,9 +101,9 @@
|
|
|
101
101
|
"node": ">=20.0.0"
|
|
102
102
|
},
|
|
103
103
|
"bugs": {
|
|
104
|
-
"url": "https://github.com/AunuHost/AunuBaileys/issues"
|
|
104
|
+
"url": "https://github.com/AunuHost/AunuBaileys-lib/issues"
|
|
105
105
|
},
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|
|
108
108
|
}
|
|
109
|
-
}
|
|
109
|
+
}
|
package/lib/Utils/antiban.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { WASocket } from '../Types';
|
|
2
|
-
export declare const gaussianJitter: (mean?: number, sigma?: number) => number;
|
|
3
|
-
export declare class RateLimiter {
|
|
4
|
-
constructor(max: number, windowMs: number);
|
|
5
|
-
acquire(key: string): Promise<number>;
|
|
6
|
-
tryAcquire(key: string): boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface DisconnectClassification { category: string; action: 'stop' | 'restart' | 'reconnect' | 'backoff'; detail: string; }
|
|
9
|
-
export declare const classifyDisconnect: (error: unknown) => DisconnectClassification;
|
|
10
|
-
export interface AunuAntiBanOptions {
|
|
11
|
-
perChatPerMinute?: number; globalPerMinute?: number; minDelayMs?: number; jitterMs?: number;
|
|
12
|
-
warmupDays?: number; warmupStart?: number; typingSimulation?: boolean;
|
|
13
|
-
groupAddMax?: number; groupAddWindowMs?: number; groupCreateMax?: number; groupCreateWindowMs?: number;
|
|
14
|
-
}
|
|
15
|
-
export declare class AunuAntiBan {
|
|
16
|
-
constructor(options?: AunuAntiBanOptions);
|
|
17
|
-
warmupFactor(): number;
|
|
18
|
-
effectiveLimit(base: number): number;
|
|
19
|
-
wrap<T extends WASocket>(sock: T): T;
|
|
20
|
-
}
|
|
21
|
-
export declare const wrapAntiBan: (sock: WASocket, options?: AunuAntiBanOptions) => WASocket;
|
package/lib/Utils/antiban.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AunuAntiBan — lapisan perlindungan akun bawaan AunuBaileys.
|
|
3
|
-
* Konsep terinspirasi baileys-antiban (kobie3717), diimplementasikan ulang
|
|
4
|
-
* secara bersih di dalam paket: rate limiting dengan jitter Gaussian,
|
|
5
|
-
* jadwal warmup akun baru, penjaga operasi grup, simulasi mengetik,
|
|
6
|
-
* dan klasifikasi disconnect. Tanpa telemetri, tanpa jaringan tambahan.
|
|
7
|
-
*/
|
|
8
|
-
import { Boom } from '@hapi/boom';
|
|
9
|
-
import { DisconnectReason } from '../Types/index.js';
|
|
10
|
-
import { delay } from './generics.js';
|
|
11
|
-
|
|
12
|
-
/** Jitter Gaussian (Box-Muller), hasil dibatasi >= 0. */
|
|
13
|
-
export const gaussianJitter = (mean = 0, sigma = 1) => {
|
|
14
|
-
let u = 0;
|
|
15
|
-
let v = 0;
|
|
16
|
-
while (u === 0)
|
|
17
|
-
u = Math.random();
|
|
18
|
-
while (v === 0)
|
|
19
|
-
v = Math.random();
|
|
20
|
-
const n = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
|
|
21
|
-
return Math.max(0, mean + n * sigma);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/** Rate limiter jendela geser per kunci. */
|
|
25
|
-
export class RateLimiter {
|
|
26
|
-
constructor(max, windowMs) {
|
|
27
|
-
this.max = max;
|
|
28
|
-
this.windowMs = windowMs;
|
|
29
|
-
this.hits = new Map();
|
|
30
|
-
}
|
|
31
|
-
/** Tunggu sampai ada slot untuk key; kembalikan waktu tunggu (ms). */
|
|
32
|
-
async acquire(key) {
|
|
33
|
-
const now = Date.now();
|
|
34
|
-
let arr = this.hits.get(key);
|
|
35
|
-
if (!arr) {
|
|
36
|
-
arr = [];
|
|
37
|
-
this.hits.set(key, arr);
|
|
38
|
-
}
|
|
39
|
-
while (arr.length && now - arr[0] >= this.windowMs)
|
|
40
|
-
arr.shift();
|
|
41
|
-
if (arr.length >= this.max) {
|
|
42
|
-
const wait = this.windowMs - (now - arr[0]) + 5;
|
|
43
|
-
await delay(wait);
|
|
44
|
-
return this.acquire(key);
|
|
45
|
-
}
|
|
46
|
-
arr.push(Date.now());
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
/** Cek tanpa menunggu; true bila masih boleh. */
|
|
50
|
-
tryAcquire(key) {
|
|
51
|
-
const now = Date.now();
|
|
52
|
-
let arr = this.hits.get(key);
|
|
53
|
-
if (!arr) {
|
|
54
|
-
arr = [];
|
|
55
|
-
this.hits.set(key, arr);
|
|
56
|
-
}
|
|
57
|
-
while (arr.length && now - arr[0] >= this.windowMs)
|
|
58
|
-
arr.shift();
|
|
59
|
-
if (arr.length >= this.max) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
arr.push(now);
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Klasifikasi error disconnect -> kategori + tindakan yang disarankan. */
|
|
68
|
-
export const classifyDisconnect = (error) => {
|
|
69
|
-
const code = error?.output?.statusCode ?? error?.statusCode ?? error;
|
|
70
|
-
switch (code) {
|
|
71
|
-
case DisconnectReason.loggedOut:
|
|
72
|
-
return { category: 'logged_out', action: 'stop', detail: 'Sesi logout — perlu pairing ulang. Jangan auto-reconnect.' };
|
|
73
|
-
case DisconnectReason.restartRequired:
|
|
74
|
-
return { category: 'restart_required', action: 'restart', detail: 'Server meminta restart — hubungkan ulang sekali.' };
|
|
75
|
-
case DisconnectReason.connectionReplaced:
|
|
76
|
-
return { category: 'replaced', action: 'stop', detail: 'Sesi digantikan koneksi lain — periksa perangkat tertaut.' };
|
|
77
|
-
case DisconnectReason.badSession:
|
|
78
|
-
return { category: 'bad_session', action: 'stop', detail: 'Sesi rusak — hapus auth state dan pairing ulang.' };
|
|
79
|
-
case DisconnectReason.multideviceMismatch:
|
|
80
|
-
return { category: 'mismatch', action: 'stop', detail: 'Ketidakcocokan multidevice — pairing ulang.' };
|
|
81
|
-
case 403:
|
|
82
|
-
return { category: 'forbidden', action: 'stop', detail: '403 — kemungkinan dibatasi/diblokir. Berhenti dan periksa akun.' };
|
|
83
|
-
case 429:
|
|
84
|
-
return { category: 'rate_limited', action: 'backoff', detail: '429 — terlalu cepat. Mundur dan turunkan laju kirim.' };
|
|
85
|
-
case DisconnectReason.timedOut:
|
|
86
|
-
case DisconnectReason.connectionLost:
|
|
87
|
-
case DisconnectReason.connectionClosed:
|
|
88
|
-
default:
|
|
89
|
-
return { category: 'transient', action: 'reconnect', detail: 'Gangguan jaringan/server sementara — aman reconnect dengan jeda.' };
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export class AunuAntiBan {
|
|
94
|
-
constructor(options = {}) {
|
|
95
|
-
this.options = {
|
|
96
|
-
perChatPerMinute: 12,
|
|
97
|
-
globalPerMinute: 60,
|
|
98
|
-
minDelayMs: 700,
|
|
99
|
-
jitterMs: 900,
|
|
100
|
-
warmupDays: 7,
|
|
101
|
-
warmupStart: Date.now(),
|
|
102
|
-
typingSimulation: true,
|
|
103
|
-
groupAddMax: 3,
|
|
104
|
-
groupAddWindowMs: 600000,
|
|
105
|
-
groupCreateMax: 2,
|
|
106
|
-
groupCreateWindowMs: 600000,
|
|
107
|
-
...options
|
|
108
|
-
};
|
|
109
|
-
const o = this.options;
|
|
110
|
-
this.perChat = new RateLimiter(o.perChatPerMinute, 60000);
|
|
111
|
-
this.global = new RateLimiter(o.globalPerMinute, 60000);
|
|
112
|
-
this.groupAdd = new RateLimiter(o.groupAddMax, o.groupAddWindowMs);
|
|
113
|
-
this.groupCreate = new RateLimiter(o.groupCreateMax, o.groupCreateWindowMs);
|
|
114
|
-
}
|
|
115
|
-
/** Faktor warmup 0.3 -> 1.0 selama warmupDays sejak warmupStart. */
|
|
116
|
-
warmupFactor() {
|
|
117
|
-
const days = (Date.now() - this.options.warmupStart) / 86400000;
|
|
118
|
-
if (days >= this.options.warmupDays) {
|
|
119
|
-
return 1;
|
|
120
|
-
}
|
|
121
|
-
return 0.3 + 0.7 * Math.max(0, days / this.options.warmupDays);
|
|
122
|
-
}
|
|
123
|
-
/** Batasi laju efektif mengikuti warmup. */
|
|
124
|
-
effectiveLimit(base) {
|
|
125
|
-
return Math.max(1, Math.floor(base * this.warmupFactor()));
|
|
126
|
-
}
|
|
127
|
-
/** Terapkan perlindungan ke socket; socket yang sama dikembalikan. */
|
|
128
|
-
wrap(sock) {
|
|
129
|
-
const self = this;
|
|
130
|
-
const origSend = sock.sendMessage.bind(sock);
|
|
131
|
-
sock.sendMessage = async (jid, content, options) => {
|
|
132
|
-
await self.global.acquire('__global__');
|
|
133
|
-
await self.perChat.acquire(jid);
|
|
134
|
-
if (self.options.typingSimulation && (content?.text || content?.caption) && typeof sock.sendPresenceUpdate === 'function') {
|
|
135
|
-
try {
|
|
136
|
-
await sock.sendPresenceUpdate('composing', jid);
|
|
137
|
-
}
|
|
138
|
-
catch { }
|
|
139
|
-
}
|
|
140
|
-
const wait = self.options.minDelayMs * self.warmupFactor() + gaussianJitter(0, self.options.jitterMs / 2);
|
|
141
|
-
if (wait > 0) {
|
|
142
|
-
await delay(wait);
|
|
143
|
-
}
|
|
144
|
-
return origSend(jid, content, options);
|
|
145
|
-
};
|
|
146
|
-
if (typeof sock.groupParticipantsUpdate === 'function') {
|
|
147
|
-
const orig = sock.groupParticipantsUpdate.bind(sock);
|
|
148
|
-
sock.groupParticipantsUpdate = async (jid, participants, action, inviteMessage) => {
|
|
149
|
-
if (action === 'add' && !self.groupAdd.tryAcquire(jid)) {
|
|
150
|
-
throw new Boom('AunuAntiBan: batas tambah anggota grup tercapai — jeda dulu agar akun aman', { statusCode: 429 });
|
|
151
|
-
}
|
|
152
|
-
return orig(jid, participants, action, inviteMessage);
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
if (typeof sock.groupCreate === 'function') {
|
|
156
|
-
const origCreate = sock.groupCreate.bind(sock);
|
|
157
|
-
sock.groupCreate = async (subject, participants) => {
|
|
158
|
-
if (!self.groupCreate.tryAcquire('__create__')) {
|
|
159
|
-
throw new Boom('AunuAntiBan: batas buat grup tercapai — jeda dulu agar akun aman', { statusCode: 429 });
|
|
160
|
-
}
|
|
161
|
-
return origCreate(subject, participants);
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
sock.aunuAntiBan = self;
|
|
165
|
-
return sock;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Bungkus socket dengan AunuAntiBan (jalan pintas). */
|
|
170
|
-
export const wrapAntiBan = (sock, options) => new AunuAntiBan(options).wrap(sock);
|