|
|
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"; |
|
|
|
|
|
global.prefix = /^[°•π÷×¶∆£¢€¥®™+✓_=|/~!?@#%^&.©^]/i; |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
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(); |