const { Client, LocalAuth, MessageMedia } = require('whatsapp-web.js'); const qrcode = require('qrcode-terminal'); const sharp = require('sharp'); const fs = require('fs'); const path = require('path'); const http = require('http'); http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('Bot WhatsApp Aktif!'); res.end(); }).listen(process.env.PORT || 8000); console.log('='.repeat(50)); console.log('šŸ¤– WA-BOT - Sticker, Smeme, Brat & Bratvid'); console.log('='.repeat(50)); // Konfigurasi const CONFIG = { MAX_SIZE: 8 * 1024 * 1024, // 8MB untuk gambar MAX_VIDEO_SIZE: 8 * 1024 * 1024, // 8MB untuk video (WhatsApp limit) STICKER_SIZE: 512, SMEME_COMMAND: '.smeme', STICKER_COMMAND: '.s', WATERMARK_COMMAND: '.wm', BRAT_COMMAND: '.brat', // Video to animated sticker BRATVID_COMMAND: '.bratvid', // Kirim video pendek HELP_COMMAND: '.help', PING_COMMAND: '.ping' }; // Client setup const client = new Client({ authStrategy: new LocalAuth({ dataPath: './.wwebjs_auth', clientId: 'wa-bot-ultimate' }), puppeteer: { headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'] } }); // ========== QR CODE HANDLER ========== client.on('qr', (qr) => { console.log('\nšŸ“± QR CODE READY!'); console.log('='.repeat(40)); qrcode.generate(qr, { small: true }); console.log('='.repeat(40)); console.log('\nšŸ“ CARA SCAN:'); console.log('1. WhatsApp HP > ⋯ > Linked Devices'); console.log('2. Link a Device > Scan QR'); console.log('='.repeat(50)); }); // ========== READY HANDLER ========== client.on('ready', () => { console.log('\nāœ… BOT READY!'); console.log(`šŸ¤– Name: ${client.info.pushname}`); console.log(`šŸ“± Number: ${client.info.wid.user}`); console.log(`šŸ• Connected: ${new Date().toLocaleString()}`); console.log('\nšŸŽ® COMMANDS:'); console.log('• .ping - Cek bot hidup'); console.log('• .help - Bantuan'); console.log('• .s - Sticker dari gambar'); console.log('• .smeme | - Buat meme'); console.log('• .wm - Ubah nama author sticker'); console.log('• .brat - Video jadi sticker (max 8MB, <10 detik)'); console.log('• .bratvid - Kirim video pendek'); console.log('\nā³ PROGRESS REACTIONS:'); console.log('• Sticker → ā³ → āœ… → šŸŽØ'); console.log('• Smeme → ā³ → āœ… → šŸ˜‚'); console.log('• Brat → ā³ → āœ… → šŸŽ¬'); console.log('• Bratvid → ā³ → āœ… → šŸ“¹'); console.log('='.repeat(50)); }); // ========== MESSAGE HANDLER ========== client.on('message', async message => { const text = message.body?.trim() || ''; try { // ========== AUTO REACTION ========== // Reaksi untuk sticker yang dikirim user if (message.hasMedia && message.type === 'sticker') { const stickerEmojis = ['šŸ˜', 'šŸ‘', 'šŸ˜‚', 'šŸ”„', 'šŸŽ‰', 'šŸ‘Œ', 'šŸ˜Ž', '✨']; const randomEmoji = stickerEmojis[Math.floor(Math.random() * stickerEmojis.length)]; await message.react(randomEmoji); console.log(`āœ… Reacted to sticker with: ${randomEmoji}`); } // Reaksi untuk video yang dikirim user if (message.hasMedia && message.type === 'video') { await message.react('šŸŽ¬'); console.log('āœ… Reacted to video with šŸŽ¬'); } // Reaksi untuk kata-kata tertentu await autoReactToKeywords(message, text); // ========== COMMANDS ========== const quotedMsg = message.hasQuotedMsg ? await message.getQuotedMessage() : null; // Sticker biasa (.s) if (text.toLowerCase() === CONFIG.STICKER_COMMAND) { await createSticker(message, 'Bot WA', 'Custom Sticker', quotedMsg); } // Smeme (.smeme ) else if (text.toLowerCase().startsWith(CONFIG.SMEME_COMMAND)) { await createSmeme(message, text, quotedMsg); } // Watermark (.wm ) else if (text.toLowerCase().startsWith(CONFIG.WATERMARK_COMMAND)) { await changeStickerAuthor(message, text); } // Brat - Video to animated sticker (.brat) else if (text.toLowerCase() === CONFIG.BRAT_COMMAND) { await createBratSticker(message, quotedMsg); } // Bratvid - Kirim video pendek (.bratvid) else if (text.toLowerCase() === CONFIG.BRATVID_COMMAND) { await sendBratVideo(message, quotedMsg); } // Ping (.ping) else if (text.toLowerCase() === CONFIG.PING_COMMAND) { const uptime = process.uptime(); const hours = Math.floor(uptime / 3600); const minutes = Math.floor((uptime % 3600) / 60); const seconds = Math.floor(uptime % 60); const uptimeStr = `${hours}h ${minutes}m ${seconds}s`; await message.reply(`šŸ“ Pong! Bot aktif!\nā³ Uptime: ${uptimeStr}`); await message.react('šŸ“'); } // Help (.help) else if (text.toLowerCase() === CONFIG.HELP_COMMAND) { await sendHelp(message); } // Jika kirim video tanpa command else if (message.hasMedia && message.type === 'video' && !text.includes('.')) { await message.reply('šŸ“¹ Kirim video dengan caption atau reply ke video:\n• .brat - Untuk sticker animasi\n• .bratvid - Untuk video pendek'); } } catch (error) { console.error('āŒ Error:', error); } }); // ========== FUNGSI UTAMA ========== // 1. Fungsi buat sticker biasa async function createSticker(message, author, stickerName, quotedMsg = null) { try { const targetMessage = message.hasMedia ? message : (quotedMsg && quotedMsg.hasMedia ? quotedMsg : null); if (!targetMessage || (targetMessage.type !== 'image' && targetMessage.type !== 'sticker')) { await message.reply('āŒ Kirim gambar atau reply ke gambar dengan caption .s'); return; } console.log('šŸ”„ Membuat sticker...'); await message.react('ā³'); const media = await targetMessage.downloadMedia(); if (!media || !media.data) throw new Error('Gambar tidak valid'); const buffer = Buffer.from(media.data, 'base64'); const processedBuffer = await sharp(buffer) .resize(CONFIG.STICKER_SIZE, CONFIG.STICKER_SIZE, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } }) .png() .toBuffer(); // Step 2: Kirim sticker await sendAsSticker(message.from, processedBuffer, author, stickerName); // Step 3: Hapus reaction jam, kasih centang (āœ…) await clearReaction(message); await message.react('āœ…'); await message.reply('āœ… Sticker berhasil dibuat! šŸŽ‰'); console.log('āœ… Sticker created with reactions'); } catch (error) { console.error('āŒ Sticker error:', error); // Hapus reaction jam, kasih X await clearReaction(message); await message.react('āŒ'); throw error; } } // 2. Fungsi buat smeme (dengan teks atas & bawah) async function createSmeme(message, text, quotedMsg = null) { try { const fullText = text.substring(CONFIG.SMEME_COMMAND.length).trim(); if (!fullText) { await message.reply('āŒ Format: .smeme \nContoh:\n• .smeme Lucu banget\n• .smeme TEKS ATAS | TEKS BAWAH'); return; } const targetMessage = message.hasMedia ? message : (quotedMsg && quotedMsg.hasMedia ? quotedMsg : null); if (!targetMessage || targetMessage.type !== 'image') { await message.reply('āŒ Kirim gambar dengan caption .smeme atau reply ke gambar!'); return; } let topText = ''; let bottomText = ''; if (fullText.includes('|')) { const parts = fullText.split('|').map(p => p.trim()); topText = parts[0] || ''; bottomText = parts[1] || ''; console.log(`šŸ”„ Membuat smeme: ATAS="${topText}" BAWAH="${bottomText}"`); // Step 1: Kasih reaction jam await message.react('ā³'); } else { topText = fullText; console.log(`šŸ”„ Membuat smeme: "${topText}"`); // Step 1: Kasih reaction jam await message.react('ā³'); } const media = await targetMessage.downloadMedia(); if (!media || !media.data) throw new Error('Gambar tidak valid'); const buffer = Buffer.from(media.data, 'base64'); const memeBuffer = await addTextToImage(buffer, topText, bottomText); const stickerName = bottomText ? `${topText} - ${bottomText}` : topText; // Step 2: Kirim sticker await sendAsSticker(message.from, memeBuffer, 'Smeme Bot', stickerName); // Step 3: Hapus reaction jam, kasih centang dan senyum await clearReaction(message); await message.react('āœ…'); await message.react('šŸ˜‚'); const successMsg = bottomText ? `āœ… Smeme "${topText} | ${bottomText}" berhasil dibuat! šŸ˜„` : `āœ… Smeme "${topText}" berhasil dibuat! šŸ˜„`; await message.reply(successMsg); console.log('āœ… Smeme created with reactions'); } catch (error) { console.error('āŒ Smeme error:', error); // Hapus reaction jam, kasih sedih await clearReaction(message); await message.react('😢'); throw error; } } // 3. Fungsi ubah nama author sticker (.wm) async function changeStickerAuthor(message, text) { try { const authorName = text.substring(CONFIG.WATERMARK_COMMAND.length).trim(); if (!authorName) { await message.reply('āŒ Format: .wm \nContoh: .wm Nama Kamu'); return; } if (!message.hasQuotedMsg) { await message.reply('āŒ Reply sticker yang mau diganti nama authornya!'); return; } const quotedMsg = await message.getQuotedMessage(); if (!quotedMsg.hasMedia || quotedMsg.type !== 'sticker') { await message.reply('āŒ Hanya bisa reply ke sticker!'); return; } console.log(`šŸ”„ Mengubah author sticker ke: "${authorName}"`); // Step 1: Kasih reaction jam await message.react('ā³'); const media = await quotedMsg.downloadMedia(); if (!media || !media.data) throw new Error('Sticker tidak valid'); const buffer = Buffer.from(media.data, 'base64'); const stickerName = quotedMsg.body || 'Custom Sticker'; // Step 2: Kirim sticker baru await sendAsSticker(message.from, buffer, authorName, stickerName); // Step 3: Hapus reaction jam, kasih centang dan glitter await clearReaction(message); await message.react('āœ…'); await message.react('✨'); await message.reply(`āœ… Sticker dengan author "${authorName}" berhasil dibuat! ✨`); console.log('āœ… Author changed with reactions'); } catch (error) { console.error('āŒ Watermark error:', error); // Hapus reaction jam, kasih warning await clearReaction(message); await message.react('āš ļø'); throw error; } } // 4. Fungsi BRAT - Video jadi sticker (FIXED) async function createBratSticker(message, quotedMsg = null) { try { const targetMessage = message.hasMedia ? message : (quotedMsg && quotedMsg.hasMedia ? quotedMsg : null); if (!targetMessage || !targetMessage.hasMedia || !targetMessage.mimetype.includes('video')) { await message.reply('āŒ Kirim video dengan caption .brat atau reply ke video!'); return; } console.log('šŸ”„ Memproses BRAT (video to sticker)...'); await message.react('ā³'); const media = await targetMessage.downloadMedia(); if (!media || !media.data) { throw new Error('Video tidak valid'); } // Cek ukuran const fileSize = (media.data.length * 3) / 4; if (fileSize > CONFIG.MAX_VIDEO_SIZE) { throw new Error(`Video terlalu besar! Maksimal ${CONFIG.MAX_VIDEO_SIZE / 1024 / 1024}MB`); } console.log(`šŸ“¹ Video size: ${(fileSize / 1024 / 1024).toFixed(2)}MB`); // Step 2: Kirim video sebagai media message // WhatsApp akan otomatis convert video pendek ke format yang sesuai const videoMedia = new MessageMedia(media.mimetype, media.data, 'video.mp4'); // Kirim video dengan opsi sendMediaAsSticker await client.sendMessage(message.from, videoMedia, { sendMediaAsSticker: true, stickerAuthor: 'Brat Bot', stickerName: 'Video Sticker' }); // Step 3: Hapus reaction jam, kasih centang dan film await clearReaction(message); await message.react('āœ…'); await message.react('šŸŽ¬'); await message.reply('āœ… Video berhasil dikonversi ke sticker! šŸŽ¬\n\nā„¹ļø WhatsApp akan otomatis convert video ke format sticker.'); console.log('āœ… Brat sticker sent with reactions'); } catch (error) { console.error('āŒ Brat error:', error); // Hapus reaction jam, kasih X await clearReaction(message); await message.react('āŒ'); if (error.message.includes('sticker')) { await message.reply('āŒ WhatsApp tidak bisa convert video ini ke sticker.\nšŸ’” Coba video yang lebih pendek (<10 detik) atau lebih kecil (<8MB)'); } else { await message.reply(`āŒ Error: ${error.message}`); } throw error; } } // 5. Fungsi BRATVID - Kirim video pendek async function sendBratVideo(message, quotedMsg = null) { try { const targetMessage = message.hasMedia ? message : (quotedMsg && quotedMsg.hasMedia ? quotedMsg : null); if (!targetMessage || !targetMessage.hasMedia || !targetMessage.mimetype.includes('video')) { await message.reply('āŒ Kirim video dengan caption .bratvid atau reply ke video!'); return; } console.log('šŸ”„ Memproses BRATVID (kirim video)...'); await message.react('ā³'); const media = await targetMessage.downloadMedia(); if (!media || !media.data) { throw new Error('Video tidak valid'); } // Cek ukuran const fileSize = (media.data.length * 3) / 4; if (fileSize > CONFIG.MAX_VIDEO_SIZE) { throw new Error(`Video terlalu besar! Maksimal ${CONFIG.MAX_VIDEO_SIZE / 1024 / 1024}MB`); } console.log(`šŸ“¹ Video size: ${(fileSize / 1024 / 1024).toFixed(2)}MB`); // Step 2: Kirim ulang video const videoMedia = new MessageMedia(media.mimetype, media.data, 'video.mp4'); await client.sendMessage(message.from, videoMedia, { caption: 'šŸ“¹ Video dari BRATVID' }); // Step 3: Hapus reaction jam, kasih centang dan kamera await clearReaction(message); await message.react('āœ…'); await message.react('šŸ“¹'); await message.reply('āœ… Video berhasil dikirim! šŸ“¹'); console.log('āœ… Bratvid sent with reactions'); } catch (error) { console.error('āŒ Bratvid error:', error); // Hapus reaction jam, kasih X await clearReaction(message); await message.react('āŒ'); throw error; } } // ========== HELPER FUNCTIONS ========== // Fungsi untuk auto react berdasarkan kata kunci async function autoReactToKeywords(message, text) { const lowerText = text.toLowerCase(); // Mapping kata kunci ke emoji const reactionMap = [ // Salam { keywords: ['hai', 'hi', 'hello', 'halo', 'p', 'assalamualaikum'], emoji: 'šŸ‘‹' }, { keywords: ['terima kasih', 'makasih', 'thanks', 'thank you'], emoji: 'šŸ™' }, { keywords: ['sama-sama', 'sama sama', 'youre welcome'], emoji: '😊' }, // Positif { keywords: ['ok', 'oke', 'okay', 'siap', 'roger', 'baik'], emoji: 'šŸ‘' }, { keywords: ['mantap', 'keren', 'bagus', 'hebat', 'wow'], emoji: 'šŸ”„' }, { keywords: ['lucu', 'funny', 'haha', 'wkwk', 'ngakak'], emoji: 'šŸ˜‚' }, { keywords: ['love', 'sayang', 'cinta'], emoji: 'ā¤ļø' }, // Command bot berhasil { keywords: ['berhasil', 'sukses', 'done', 'selesai'], emoji: 'āœ…' }, { keywords: ['gagal', 'error', 'failed'], emoji: 'āŒ' }, // Sticker related { keywords: ['sticker', 'stiker', 'stikernya', 'hasilnya'], emoji: 'šŸŽØ' }, { keywords: ['meme', 'smeme', 'memes'], emoji: '🤔' }, { keywords: ['brat', 'video sticker', 'animasi'], emoji: 'šŸŽ¬' }, { keywords: ['bratvid', 'video pendek'], emoji: 'šŸ“¹' }, // Bot command { keywords: ['bot', 'bang bot', 'bro bot'], emoji: 'šŸ¤–' }, { keywords: ['ping', 'test'], emoji: 'šŸ“' }, { keywords: ['help', 'bantuan'], emoji: 'ā„¹ļø' }, ]; // Cek setiap mapping for (const map of reactionMap) { for (const keyword of map.keywords) { if (lowerText.includes(keyword)) { try { await message.react(map.emoji); console.log(`āœ… Auto reacted with ${map.emoji} for keyword: ${keyword}`); return true; } catch (error) { console.log(`āŒ Failed to react: ${error.message}`); } } } } return false; } // Fungsi untuk clear reaction async function clearReaction(message) { try { // WhatsApp Web JS tidak punya clearReaction langsung // Kita coba hapus dengan mengirim empty reaction atau timpa try { // Coba hapus reaction kita sendiri await message.react(''); // Reaction kosong mungkin bisa hapus } catch (e) { // Jika tidak bisa, reaction baru akan timpa yang lama return true; } return true; } catch (error) { console.log('āš ļø Cannot clear reaction:', error.message); return false; } } // Fungsi untuk menambah teks ke gambar (smeme) async function addTextToImage(imageBuffer, topText, bottomText = '') { try { const imageWidth = 480; const imageHeight = 380; const resizedImage = await sharp(imageBuffer) .resize(imageWidth, imageHeight, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } }) .png() .toBuffer(); const padding = 16; const textHeight = 56; let svgElements = ''; if (topText) { svgElements += ` ${escapeHtml(topText)} `; } const imageY = topText ? textHeight + padding : padding; svgElements += ` `; if (bottomText) { const bottomY = 512 - textHeight; svgElements += ` ${escapeHtml(bottomText)} `; } const svgText = ` ${svgElements} `; const finalImage = await sharp(Buffer.from(svgText)) .png() .toBuffer(); return finalImage; } catch (error) { console.error('āŒ Add text error:', error); throw new Error('Gagal menambahkan teks ke gambar'); } } // Fungsi escape HTML function escapeHtml(text) { return text .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } // Fungsi untuk kirim sticker async function sendAsSticker(chatId, buffer, author, stickerName) { const stickerBase64 = buffer.toString('base64'); const stickerMedia = new MessageMedia('image/png', stickerBase64, 'sticker.png'); await client.sendMessage(chatId, stickerMedia, { sendMediaAsSticker: true, stickerAuthor: author, stickerName: stickerName.substring(0, 100) }); } // Fungsi bantuan async function sendHelp(message) { const helpText = ` šŸ¤– *WA-BOT COMMANDS* šŸ¤– *šŸŽØ STICKER:* • \`.s\` - Buat sticker (Caption/Reply gambar) • \`.wm \` - Ubah author (Reply sticker) *🤔 SMEME (MEME STICKER):* • \`.smeme \` - Teks atas (Caption/Reply gambar) • \`.smeme t1 | t2\` - Teks atas & bawah *šŸŽ¬ BRAT (VIDEO TO STICKER):* • \`.brat\` - Video ke sticker (Caption/Reply video) • āš ļø Max 8MB, <10 detik *šŸ“¹ BRATVID (SEND VIDEO):* • \`.bratvid\` - Kirim video pendek • Max 8MB *šŸ”„ PROGRESS INDICATOR:* • ā³ - Sedang diproses • āœ… - Berhasil • šŸŽØ - Sticker selesai • šŸ˜‚ - Smeme selesai • šŸŽ¬ - Brat selesai • šŸ“¹ - Bratvid selesai • ✨ - Watermark selesai • āŒ - Gagal *šŸ’” TIPS BRAT:* 1. Video harus pendek (<10 detik) 2. Ukuran kecil (<8MB) 3. WhatsApp auto convert ke format sticker 4. Jika gagal, coba video lain *šŸŽ­ AUTO REACTION:* • Sticker dari user → Random emoji • Video → šŸŽ¬ • Kata "makasih" → šŸ™ • Kata "mantap" → šŸ”„ • Kata "lucu" → šŸ˜‚ *šŸ› ļø LAINNYA:* • \`.ping\` - Cek bot hidup → šŸ“ • \`.help\` - Tampilkan bantuan ini → ā„¹ļø `; await message.reply(helpText); await message.react('ā„¹ļø'); console.log('āœ… Help sent with reaction'); } // ========== ERROR HANDLERS ========== client.on('auth_failure', (msg) => { console.log('āŒ AUTH FAILED:', msg); }); client.on('disconnected', (reason) => { console.log('šŸ”Œ Disconnected:', reason); console.log('šŸ”„ Reconnecting in 10s...'); setTimeout(() => client.initialize(), 10000); }); // ========== START BOT ========== client.initialize(); // Handle exit process.on('SIGINT', async () => { console.log('\nšŸ›‘ Stopping bot...'); await client.destroy(); console.log('āœ… Bot stopped'); process.exit(0); }); // ========== SERVER FOR HOSTING ========== const PORT = process.env.PORT || 8000; http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Bot is running!\n'); }).listen(PORT, () => { console.log(`šŸš€ Server listening on port ${PORT}`); });