File size: 1,580 Bytes
0ee7b04 72ee6f0 0ee7b04 72ee6f0 0ee7b04 72ee6f0 0ee7b04 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
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(); |