@isaxn/bailyes 1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 isanamd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @isan/bailyes
2
+
3
+ 🚀 **Modern WhatsApp Bot Framework** built on top of
4
+ [`@whiskeysockets/baileys`](https://github.com/WhiskeySockets/Baileys)
5
+
6
+ `@isan/bailyes` menyediakan **engine WhatsApp bot yang ringan, stabil, dan mudah dipakai**, cocok untuk:
7
+ - Bot pribadi
8
+ - Bot grup
9
+ - Framework bot lanjutan
10
+ - Project npm / open-source
11
+
12
+ ---
13
+
14
+ ## ✨ Features
15
+
16
+ - ✅ Built on **Baileys (Multi-Device)**
17
+ - 🔐 **QR Login only** (aman & stabil)
18
+ - ⚡ Fast & lightweight
19
+ - 🧩 Easy to integrate into any bot
20
+ - 📦 Ready for **ESM & CommonJS**
21
+ - 🔁 Auto reconnect
22
+ - 🧠 Clean & minimal API
23
+ - 🚫 No forced pairing / aggressive login
24
+
25
+ ---
26
+
27
+ support in my channel:
28
+ https://whatsapp.com/channel/0029Vb7M8VA05MUkehrqcl3J
29
+
30
+ ## 📦 Installation
31
+
32
+ ```bash
33
+ npm install @isan/bailyes
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ const makeWASocket = require("@whiskeysockets/baileys").default;
4
+ const {
5
+ useMultiFileAuthState,
6
+ DisconnectReason,
7
+ fetchLatestBaileysVersion
8
+ } = require("@whiskeysockets/baileys");
9
+
10
+ const qrcode = require("qrcode-terminal");
11
+ const pino = require("pino");
12
+
13
+ class WAClient {
14
+ async connect(authFolder = "./auth") {
15
+ const { state, saveCreds } =
16
+ await useMultiFileAuthState(authFolder);
17
+
18
+ const { version } =
19
+ await fetchLatestBaileysVersion();
20
+
21
+ const sock = makeWASocket({
22
+ version,
23
+ auth: state,
24
+ printQRInTerminal: false,
25
+ logger: pino({ level: "silent" }),
26
+ browser: ["Bailyes", "Chrome", "1.0.0"]
27
+ });
28
+ sock.ev.on("creds.update", saveCreds);
29
+
30
+ sock.ev.on("connection.update", (update) => {
31
+ const { connection, lastDisconnect, qr } = update;
32
+
33
+ if (qr) {
34
+ console.clear();
35
+ console.log("📱 Scan QR Code:\n");
36
+ qrcode.generate(qr, { small: true });
37
+ }
38
+
39
+ if (connection === "open") {
40
+ console.log("✅ WhatsApp Connected");
41
+ }
42
+
43
+ if (connection === "close") {
44
+ const code =
45
+ lastDisconnect?.error?.output?.statusCode;
46
+
47
+ if (code !== DisconnectReason.loggedOut) {
48
+ setTimeout(() => {
49
+ this.connect(authFolder);
50
+ }, 3000);
51
+ } else {
52
+ console.log(
53
+ "❌ Logged out. Delete auth folder to re-login."
54
+ );
55
+ }
56
+ }
57
+ });
58
+
59
+ return sock;
60
+ }
61
+ }
62
+
63
+ module.exports = {
64
+ WAClient
65
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ //cjs
2
+ "use strict";
3
+ const { WAClient } = require("./core/client.cjs");
4
+ module.exports = {
5
+ WAClient
6
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@isaxn/bailyes",
3
+ "version": "1.0.0",
4
+ "description": "WhatsApp Bot Framework built on Baileys",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./src/index.js",
8
+ "exports": {
9
+ "import": "./src/index.js",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "files": [
13
+ "src",
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "author": "isan",
19
+ "license": "MIT",
20
+ "keywords": [
21
+ "whatsapp",
22
+ "bot",
23
+ "baileys",
24
+ "whatsapp-bot",
25
+ "framework"
26
+ ],
27
+ "dependencies": {
28
+ "@whiskeysockets/baileys": "^6.7.0",
29
+ "pino": "^9.0.0",
30
+ "qrcode-terminal": "^0.12.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }
@@ -0,0 +1,55 @@
1
+ //isanamd code dont delete
2
+ import makeWASocket, {
3
+ useMultiFileAuthState,
4
+ DisconnectReason,
5
+ fetchLatestBaileysVersion
6
+ } from "@whiskeysockets/baileys";
7
+
8
+ import qrcode from "qrcode-terminal";
9
+ import pino from "pino";
10
+
11
+ export class WAClient {
12
+ async connect(authFolder = "./auth") {
13
+ const { state, saveCreds } =
14
+ await useMultiFileAuthState(authFolder);
15
+
16
+ const { version } =
17
+ await fetchLatestBaileysVersion();
18
+
19
+ const sock = makeWASocket({
20
+ version,
21
+ auth: state,
22
+ printQRInTerminal: false,
23
+ logger: pino({ level: "silent" }),
24
+ browser: ["Bailyes", "Chrome", "1.0.0"]
25
+ });
26
+
27
+ sock.ev.on("creds.update", saveCreds);
28
+
29
+ sock.ev.on("connection.update", (update) => {
30
+ const { connection, lastDisconnect, qr } = update;
31
+
32
+ if (qr) {
33
+ console.clear();
34
+ qrcode.generate(qr, { small: true });
35
+ }
36
+
37
+ if (connection === "open") {
38
+ console.log("✅ WhatsApp Connected");
39
+ }
40
+
41
+ if (connection === "close") {
42
+ const code =
43
+ lastDisconnect?.error?.output?.statusCode;
44
+
45
+ if (code !== DisconnectReason.loggedOut) {
46
+ setTimeout(() => {
47
+ this.connect(authFolder);
48
+ }, 3000);
49
+ }
50
+ }
51
+ });
52
+
53
+ return sock;
54
+ }
55
+ }
@@ -0,0 +1,78 @@
1
+ import {
2
+ downloadContentFromMessage
3
+ } from "@whiskeysockets/baileys";
4
+ import fs from "fs";
5
+ import path from "path";
6
+
7
+ export class Context {
8
+ constructor(sock, msg) {
9
+ this.sock = sock;
10
+ this.msg = msg;
11
+
12
+ this.chat = msg.key.remoteJid;
13
+ this.sender =
14
+ msg.key.participant ||
15
+ msg.participant ||
16
+ msg.key.remoteJid;
17
+
18
+ this.isGroup = this.chat.endsWith("@g.us");
19
+ this.message = msg.message;
20
+
21
+ this.text =
22
+ this.message?.conversation ||
23
+ this.message?.extendedTextMessage?.text ||
24
+ "";
25
+ }
26
+
27
+ // ===== MEDIA =====
28
+ get isImage() { return !!this.message?.imageMessage; }
29
+ get isVideo() { return !!this.message?.videoMessage; }
30
+ get isAudio() { return !!this.message?.audioMessage; }
31
+ get isVN() {
32
+ return this.isAudio && this.message.audioMessage?.ptt;
33
+ }
34
+
35
+ async downloadMedia(folder = "media") {
36
+ let type, msg;
37
+
38
+ if (this.isImage) type = "image", msg = this.message.imageMessage;
39
+ else if (this.isVideo) type = "video", msg = this.message.videoMessage;
40
+ else if (this.isAudio) type = "audio", msg = this.message.audioMessage;
41
+ else return null;
42
+
43
+ const stream = await downloadContentFromMessage(msg, type);
44
+ const buffer = [];
45
+
46
+ for await (const chunk of stream) buffer.push(chunk);
47
+
48
+ if (!fs.existsSync(folder)) fs.mkdirSync(folder);
49
+
50
+ const ext = type === "image" ? "jpg" : type === "video" ? "mp4" : "mp3";
51
+ const filePath = path.join(folder, `${Date.now()}.${ext}`);
52
+
53
+ fs.writeFileSync(filePath, Buffer.concat(buffer));
54
+ return filePath;
55
+ }
56
+
57
+ // ===== SEND =====
58
+ reply(text) {
59
+ return this.sock.sendMessage(this.chat, { text }, { quoted: this.msg });
60
+ }
61
+
62
+ replyButtons(text, buttons, footer = "") {
63
+ return this.sock.sendMessage(
64
+ this.chat,
65
+ {
66
+ text,
67
+ footer,
68
+ buttons: buttons.map((b, i) => ({
69
+ buttonId: b.id || String(i + 1),
70
+ buttonText: { displayText: b.text },
71
+ type: 1
72
+ })),
73
+ headerType: 1
74
+ },
75
+ { quoted: this.msg }
76
+ );
77
+ }
78
+ }
@@ -0,0 +1,15 @@
1
+ export class Events {
2
+ constructor() {
3
+ this.events = {};
4
+ }
5
+
6
+ on(event, fn) {
7
+ (this.events[event] ||= []).push(fn);
8
+ }
9
+
10
+ emit(event, data) {
11
+ for (const fn of this.events[event] || []) {
12
+ fn(data);
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,40 @@
1
+ export class Handler {
2
+ constructor(prefix = ["!","."]) {
3
+ this.prefix = prefix;
4
+ this.commands = new Map();
5
+ this.hears = [];
6
+ }
7
+
8
+ command(name, fn) {
9
+ this.commands.set(name, fn);
10
+ }
11
+
12
+ hear(pattern, fn) {
13
+ this.hears.push({ pattern, fn });
14
+ }
15
+
16
+ handle(ctx) {
17
+ const text = ctx.text.trim();
18
+ if (!text) return;
19
+
20
+ for (const p of this.prefix) {
21
+ if (text.startsWith(p)) {
22
+ const [cmd, ...args] = text.slice(p.length).split(/\s+/);
23
+ if (this.commands.has(cmd)) {
24
+ ctx.command = cmd;
25
+ ctx.args = args;
26
+ return this.commands.get(cmd)(ctx);
27
+ }
28
+ }
29
+ }
30
+
31
+ for (const h of this.hears) {
32
+ if (
33
+ typeof h.pattern === "string" && text === h.pattern ||
34
+ h.pattern instanceof RegExp && h.pattern.test(text)
35
+ ) {
36
+ return h.fn(ctx);
37
+ }
38
+ }
39
+ }
40
+ }
package/src/index.js ADDED
@@ -0,0 +1,56 @@
1
+ //isanamd code dont delete
2
+ export { WAClient } from "./core/client.js";
3
+ import { Context } from "./core/context.js";
4
+ import { Events } from "./core/events.js";
5
+ import { Handler } from "./core/handler.js";
6
+
7
+ const cooldown = new Map();
8
+
9
+ function canReply(jid, delay = 3000) {
10
+ const now = Date.now();
11
+ if (cooldown.has(jid) && now - cooldown.get(jid) < delay) {
12
+ return false;
13
+ }
14
+ cooldown.set(jid, now);
15
+ return true;
16
+ }
17
+
18
+ export class Bailyes {
19
+ constructor(options = {}) {
20
+ this.auth = options.auth || "auth";
21
+ this.prefix = options.prefix || ["!"];
22
+ this.client = new WAClient();
23
+ this.events = new Events();
24
+ this.handler = new Handler(this.prefix);
25
+ }
26
+
27
+
28
+ on(event, fn) {
29
+ this.events.on(event, fn);
30
+ }
31
+
32
+ command(name, fn) {
33
+ this.handler.command(name, fn);
34
+ }
35
+
36
+ hear(pattern, fn) {
37
+ this.handler.hear(pattern, fn);
38
+ }
39
+
40
+ async start() {
41
+ const sock = await this.client.connect(this.auth);
42
+
43
+ sock.ev.on("messages.upsert", ({ messages }) => {
44
+ const msg = messages?.[0];
45
+ if (!msg || !msg.message || msg.key.fromMe) return;
46
+
47
+ const ctx = new Context(sock, msg);
48
+
49
+ if (!canReply(ctx.chat)) return;
50
+
51
+ this.events.emit("message", ctx);
52
+
53
+ this.handler.handle(ctx);
54
+ });
55
+ }
56
+ }