import fs from "fs"; import path from "path"; import makeWASocket, { useMultiFileAuthState, DisconnectReason, makeCacheableSignalKeyStore, } from "baileys"; import qrcode from "qrcode-terminal"; import { fileURLToPath } from "url"; import { loadCommands, handleCommand } from "./lib/handler.js"; // import { Client, Serialize } from "./lib/serialize.js"; global.prefix = /^[°•π÷×¶∆£¢€¥®™+✓_=|/~!?@#%^&.©^]/i; // __dirname untuk ESM const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function startBot() { const { state, saveCreds } = await useMultiFileAuthState("session"); const sock = makeWASocket({ printQRInTerminal: false, auth: { creds: state.creds, keys: makeCacheableSignalKeyStore(state.keys, undefined), }, browser: ["MyBot", "Chrome", "1.0.0"], }); sock.ev.on("creds.update", saveCreds); // global.conn = conn; sock.ev.on("connection.update", (update) => { const { connection, qr } = update; if (qr) { console.log("\n=== Scan QR ===\n"); qrcode.generate(qr, { small: true }); } if (connection === "open") console.log("✅ Bot tersambung!"); }); const commands = await loadCommands(path.join(__dirname, "command")); console.log(`${commands.size} command berhasil dimuat`); sock.ev.on("messages.upsert", async (message) => { if (!message.messages) return; const msg = message.messages[0]; if (!msg.message || msg.key.fromMe) return; await handleCommand(sock, msg, commands); }); } startBot();