Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -4,372 +4,178 @@ const {
|
|
| 4 |
useMultiFileAuthState,
|
| 5 |
fetchLatestBaileysVersion
|
| 6 |
} = require('@whiskeysockets/baileys');
|
|
|
|
| 7 |
const qrcode = require('qrcode');
|
| 8 |
-
const axios = require('axios');
|
| 9 |
const fs = require('fs');
|
| 10 |
const path = require('path');
|
| 11 |
-
const express = require('express');
|
| 12 |
const http = require('http');
|
| 13 |
const pino = require('pino');
|
| 14 |
|
| 15 |
-
const
|
| 16 |
-
const
|
| 17 |
-
|
| 18 |
-
const PORT = process.env.PORT || 7860;
|
| 19 |
-
const HF_TOKEN = process.env.HF_TOKEN || '';
|
| 20 |
-
const AUTH_FOLDER = path.join(__dirname, 'auth');
|
| 21 |
|
| 22 |
let sock = null;
|
| 23 |
let qrCodeData = null;
|
| 24 |
let connectionStatus = 'disconnected';
|
| 25 |
-
let startTime = Date.now();
|
| 26 |
-
|
| 27 |
-
// ===== LOGGER YANG BENER =====
|
| 28 |
-
const logger = pino({
|
| 29 |
-
level: 'silent',
|
| 30 |
-
transport: {
|
| 31 |
-
target: 'pino-pretty',
|
| 32 |
-
options: { colorize: false }
|
| 33 |
-
}
|
| 34 |
-
}).child({ class: 'baileys' });
|
| 35 |
|
| 36 |
-
//
|
| 37 |
-
const
|
|
|
|
|
|
|
|
|
|
| 38 |
<!DOCTYPE html>
|
| 39 |
-
<html
|
| 40 |
<head>
|
| 41 |
-
<meta charset="UTF-8">
|
| 42 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 43 |
-
<title>
|
| 44 |
<style>
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
padding: 20px;
|
| 52 |
-
}
|
| 53 |
-
.container { max-width: 600px; margin: 0 auto; }
|
| 54 |
-
h1 { text-align: center; font-size: 2.5em; margin-bottom: 10px; }
|
| 55 |
-
.subtitle { text-align: center; opacity: 0.9; margin-bottom: 30px; }
|
| 56 |
-
.card {
|
| 57 |
-
background: rgba(255,255,255,0.1);
|
| 58 |
-
backdrop-filter: blur(10px);
|
| 59 |
-
border-radius: 20px;
|
| 60 |
-
padding: 25px;
|
| 61 |
-
margin-bottom: 20px;
|
| 62 |
-
border: 1px solid rgba(255,255,255,0.2);
|
| 63 |
-
}
|
| 64 |
-
.status-box {
|
| 65 |
-
display: flex;
|
| 66 |
-
align-items: center;
|
| 67 |
-
gap: 15px;
|
| 68 |
-
margin-bottom: 20px;
|
| 69 |
-
}
|
| 70 |
-
.status-icon {
|
| 71 |
-
width: 60px; height: 60px;
|
| 72 |
-
border-radius: 50%;
|
| 73 |
-
display: flex; align-items: center; justify-content: center;
|
| 74 |
-
font-size: 28px;
|
| 75 |
-
}
|
| 76 |
-
.online { background: #00b894; }
|
| 77 |
-
.offline { background: #e17055; }
|
| 78 |
-
.waiting { background: #fdcb6e; animation: pulse 2s infinite; }
|
| 79 |
-
@keyframes pulse {
|
| 80 |
-
0%, 100% { transform: scale(1); }
|
| 81 |
-
50% { transform: scale(1.05); }
|
| 82 |
}
|
| 83 |
-
.qr
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
border-radius: 15px;
|
| 88 |
display: inline-block;
|
| 89 |
-
margin:
|
| 90 |
}
|
| 91 |
-
.
|
| 92 |
-
.btn {
|
| 93 |
-
padding: 12px 25px;
|
| 94 |
-
border: none;
|
| 95 |
-
border-radius: 25px;
|
| 96 |
-
font-size: 14px;
|
| 97 |
-
font-weight: bold;
|
| 98 |
-
cursor: pointer;
|
| 99 |
-
margin: 5px;
|
| 100 |
-
background: rgba(255,255,255,0.2);
|
| 101 |
-
color: white;
|
| 102 |
-
border: 1px solid rgba(255,255,255,0.3);
|
| 103 |
-
}
|
| 104 |
-
.btn:hover { transform: translateY(-2px); }
|
| 105 |
-
.logs {
|
| 106 |
-
background: rgba(0,0,0,0.4);
|
| 107 |
-
border-radius: 10px;
|
| 108 |
padding: 15px;
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
overflow-y: auto;
|
| 112 |
-
font-family: monospace;
|
| 113 |
-
font-size: 12px;
|
| 114 |
}
|
| 115 |
-
.
|
|
|
|
|
|
|
| 116 |
</style>
|
| 117 |
</head>
|
| 118 |
<body>
|
| 119 |
-
<
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
<h2 id="statusTitle">Starting...</h2>
|
| 128 |
-
<span id="statusBadge" style="background:#e17055;padding:4px 12px;border-radius:12px;font-size:12px;">Offline</span>
|
| 129 |
-
</div>
|
| 130 |
-
</div>
|
| 131 |
-
|
| 132 |
-
<div id="loadingPanel">
|
| 133 |
-
<p>β³ Menyiapkan koneksi...</p>
|
| 134 |
-
<p style="font-size:12px;opacity:0.7;margin-top:10px;">Tunggu 10-30 detik</p>
|
| 135 |
-
</div>
|
| 136 |
-
|
| 137 |
-
<div id="qrPanel" class="qr-section hidden">
|
| 138 |
-
<h3>π· Scan QR Code</h3>
|
| 139 |
-
<div class="qr-box">
|
| 140 |
-
<img id="qrImage" src="" alt="QR">
|
| 141 |
-
</div>
|
| 142 |
-
<p style="font-size:14px;opacity:0.9;">WhatsApp β Menu β Linked Devices β Link</p>
|
| 143 |
-
<button class="btn" onclick="location.reload()">π Refresh QR</button>
|
| 144 |
-
</div>
|
| 145 |
-
|
| 146 |
-
<div id="connectedPanel" class="hidden" style="text-align:center;padding:30px;">
|
| 147 |
-
<div style="font-size:4em;margin-bottom:15px;">β
</div>
|
| 148 |
-
<h3 style="color:#00b894;">Terhubung!</h3>
|
| 149 |
-
<p style="margin:15px 0;">Bot siap menerima pesan</p>
|
| 150 |
-
<button class="btn" onclick="logout()">πͺ Logout</button>
|
| 151 |
-
</div>
|
| 152 |
-
|
| 153 |
-
<div class="logs" id="logs"></div>
|
| 154 |
</div>
|
|
|
|
| 155 |
</div>
|
| 156 |
-
|
| 157 |
<script>
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
async function checkStatus() {
|
| 166 |
-
try {
|
| 167 |
-
const res = await fetch('/api/status');
|
| 168 |
-
const data = await res.json();
|
| 169 |
-
|
| 170 |
-
const icon = document.getElementById('statusIcon');
|
| 171 |
-
const title = document.getElementById('statusTitle');
|
| 172 |
-
const badge = document.getElementById('statusBadge');
|
| 173 |
-
|
| 174 |
-
if (data.status === 'connected') {
|
| 175 |
-
icon.className = 'status-icon online';
|
| 176 |
-
icon.textContent = 'β';
|
| 177 |
-
title.textContent = 'Terhubung';
|
| 178 |
-
badge.style.background = '#00b894';
|
| 179 |
-
badge.textContent = 'Online';
|
| 180 |
-
document.getElementById('loadingPanel').classList.add('hidden');
|
| 181 |
-
document.getElementById('qrPanel').classList.add('hidden');
|
| 182 |
-
document.getElementById('connectedPanel').classList.remove('hidden');
|
| 183 |
-
}
|
| 184 |
-
else if (data.status === 'qr_ready') {
|
| 185 |
-
icon.className = 'status-icon waiting';
|
| 186 |
-
icon.textContent = 'π·';
|
| 187 |
-
title.textContent = 'Scan QR';
|
| 188 |
-
badge.style.background = '#fdcb6e';
|
| 189 |
-
badge.textContent = 'QR Ready';
|
| 190 |
-
document.getElementById('loadingPanel').classList.add('hidden');
|
| 191 |
-
document.getElementById('qrPanel').classList.remove('hidden');
|
| 192 |
-
document.getElementById('qrImage').src = '/api/qr?' + Date.now();
|
| 193 |
-
}
|
| 194 |
-
else if (data.status === 'error') {
|
| 195 |
-
title.textContent = 'Error: ' + data.error;
|
| 196 |
-
addLog('Error: ' + data.error);
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
} catch (e) {
|
| 200 |
-
addLog('Connection error');
|
| 201 |
-
}
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
async function logout() {
|
| 205 |
-
if (!confirm('Logout?')) return;
|
| 206 |
-
await fetch('/api/logout');
|
| 207 |
-
location.reload();
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
setInterval(checkStatus, 3000);
|
| 211 |
-
checkStatus();
|
| 212 |
-
addLog('Panel loaded');
|
| 213 |
</script>
|
| 214 |
</body>
|
| 215 |
</html>
|
| 216 |
-
`;
|
| 217 |
-
|
| 218 |
-
// ===== ROUTES =====
|
| 219 |
-
app.get('/', (req, res) => res.send(HTML_UI));
|
| 220 |
-
|
| 221 |
-
app.get('/api/status', (req, res) => {
|
| 222 |
-
res.json({
|
| 223 |
-
status: connectionStatus,
|
| 224 |
-
uptime: Math.floor((Date.now() - startTime) / 1000)
|
| 225 |
-
});
|
| 226 |
-
});
|
| 227 |
-
|
| 228 |
-
app.get('/api/qr', async (req, res) => {
|
| 229 |
-
if (!qrCodeData) return res.status(404).send('No QR');
|
| 230 |
-
try {
|
| 231 |
-
const buffer = await qrcode.toBuffer(qrCodeData, { type: 'png', width: 300 });
|
| 232 |
-
res.set('Content-Type', 'image/png');
|
| 233 |
-
res.send(buffer);
|
| 234 |
-
} catch (e) {
|
| 235 |
-
res.status(500).send('QR Error');
|
| 236 |
}
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
if (fs.existsSync(AUTH_FOLDER)) {
|
| 243 |
-
fs.rmSync(AUTH_FOLDER, { recursive: true, force: true });
|
| 244 |
}
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
}
|
| 250 |
});
|
| 251 |
|
| 252 |
-
//
|
| 253 |
async function startBot() {
|
| 254 |
-
console.log('π Starting...');
|
|
|
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
keepAliveIntervalMs: 30000,
|
| 269 |
-
connectTimeoutMs: 60000,
|
| 270 |
-
retryRequestDelayMs: 1000,
|
| 271 |
-
maxMsgRetryCount: 5,
|
| 272 |
-
// Tambahin agent biar gak kena block
|
| 273 |
-
agent: {
|
| 274 |
-
keepAlive: true,
|
| 275 |
-
maxSockets: 10
|
| 276 |
-
}
|
| 277 |
-
});
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
try {
|
| 295 |
-
await sock.sendMessage(sock.user.id, {
|
| 296 |
-
text: 'π€ Bot aktif!'
|
| 297 |
-
});
|
| 298 |
-
} catch (e) {}
|
| 299 |
-
}
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
// Error handling
|
| 316 |
-
sock.ev.on('creds.update', saveCreds);
|
| 317 |
-
|
| 318 |
-
sock.ws.on('error', (err) => {
|
| 319 |
-
console.log('WebSocket error:', err.message);
|
| 320 |
-
});
|
| 321 |
|
| 322 |
-
|
| 323 |
-
sock.ev.on('messages.upsert', async ({ messages, type }) => {
|
| 324 |
-
if (type !== 'notify') return;
|
| 325 |
-
const msg = messages[0];
|
| 326 |
-
if (!msg.message || msg.key.fromMe) return;
|
| 327 |
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
|
|
|
| 331 |
|
| 332 |
-
|
|
|
|
| 333 |
|
| 334 |
-
|
| 335 |
-
const args = text.slice(1).split(' ').slice(1).join(' ');
|
| 336 |
|
| 337 |
-
|
| 338 |
-
await sock.sendMessage(sender, {
|
| 339 |
-
text: '!ai [tanya] - Tanya AI\n!status - Status'
|
| 340 |
-
});
|
| 341 |
-
}
|
| 342 |
-
else if (cmd === 'status') {
|
| 343 |
-
await sock.sendMessage(sender, {
|
| 344 |
-
text: 'Status: ' + connectionStatus
|
| 345 |
-
});
|
| 346 |
-
}
|
| 347 |
-
else if (cmd === 'ai' && args) {
|
| 348 |
-
await sock.sendMessage(sender, { text: 'β³ AI mikir...' });
|
| 349 |
-
try {
|
| 350 |
-
const res = await axios.post(
|
| 351 |
-
'https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2',
|
| 352 |
-
{ inputs: `<s>[INST] ${args} [/INST]`, parameters: { max_new_tokens: 300 } },
|
| 353 |
-
{ headers: { 'Authorization': `Bearer ${HF_TOKEN}` }, timeout: 30000 }
|
| 354 |
-
);
|
| 355 |
-
let reply = res.data[0]?.generated_text || 'Gagal';
|
| 356 |
-
reply = reply.replace(/<s>\[INST\].*?\[\/INST\]\s*/, '');
|
| 357 |
-
await sock.sendMessage(sender, { text: reply.substring(0, 1000) });
|
| 358 |
-
} catch (e) {
|
| 359 |
-
await sock.sendMessage(sender, { text: 'β AI sibuk' });
|
| 360 |
-
}
|
| 361 |
-
}
|
| 362 |
-
});
|
| 363 |
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
}
|
| 370 |
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
console.log(`π
|
| 374 |
startBot();
|
| 375 |
});
|
|
|
|
| 4 |
useMultiFileAuthState,
|
| 5 |
fetchLatestBaileysVersion
|
| 6 |
} = require('@whiskeysockets/baileys');
|
| 7 |
+
const QRCode = require('qrcode-terminal');
|
| 8 |
const qrcode = require('qrcode');
|
|
|
|
| 9 |
const fs = require('fs');
|
| 10 |
const path = require('path');
|
|
|
|
| 11 |
const http = require('http');
|
| 12 |
const pino = require('pino');
|
| 13 |
|
| 14 |
+
const AUTH_FOLDER = './auth';
|
| 15 |
+
const PORT = 8080; // Localhost port
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
let sock = null;
|
| 18 |
let qrCodeData = null;
|
| 19 |
let connectionStatus = 'disconnected';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
// Simple HTTP server buat lihat QR di browser HP
|
| 22 |
+
const server = http.createServer(async (req, res) => {
|
| 23 |
+
if (req.url === '/') {
|
| 24 |
+
res.writeHead(200, {'Content-Type': 'text/html'});
|
| 25 |
+
res.end(`
|
| 26 |
<!DOCTYPE html>
|
| 27 |
+
<html>
|
| 28 |
<head>
|
|
|
|
| 29 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 30 |
+
<title>WA Bot - Termux</title>
|
| 31 |
<style>
|
| 32 |
+
body {
|
| 33 |
+
font-family: Arial;
|
| 34 |
+
background: #1a1a2e;
|
| 35 |
+
color: white;
|
| 36 |
+
text-align: center;
|
| 37 |
+
padding: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
+
.qr {
|
| 40 |
+
background: white;
|
| 41 |
+
padding: 20px;
|
| 42 |
+
border-radius: 10px;
|
|
|
|
| 43 |
display: inline-block;
|
| 44 |
+
margin: 20px 0;
|
| 45 |
}
|
| 46 |
+
.status {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
padding: 15px;
|
| 48 |
+
border-radius: 10px;
|
| 49 |
+
margin: 20px 0;
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
+
.connected { background: #00b894; }
|
| 52 |
+
.disconnected { background: #e17055; }
|
| 53 |
+
.waiting { background: #fdcb6e; color: black; }
|
| 54 |
</style>
|
| 55 |
</head>
|
| 56 |
<body>
|
| 57 |
+
<h1>π€ WhatsApp Bot (Termux)</h1>
|
| 58 |
+
<div class="status ${connectionStatus}" id="status">
|
| 59 |
+
Status: ${connectionStatus}
|
| 60 |
+
</div>
|
| 61 |
+
<div id="qrSection">
|
| 62 |
+
<p>Scan QR Code:</p>
|
| 63 |
+
<div class="qr">
|
| 64 |
+
<img id="qr" src="/qr" width="300" height="300" onerror="this.style.display='none'">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
</div>
|
| 66 |
+
<p>Atau lihat QR di terminal!</p>
|
| 67 |
</div>
|
|
|
|
| 68 |
<script>
|
| 69 |
+
setInterval(() => {
|
| 70 |
+
document.getElementById('qr').src = '/qr?' + Date.now();
|
| 71 |
+
fetch('/status').then(r => r.text()).then(s => {
|
| 72 |
+
document.getElementById('status').className = 'status ' + s;
|
| 73 |
+
document.getElementById('status').textContent = 'Status: ' + s;
|
| 74 |
+
});
|
| 75 |
+
}, 3000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
</script>
|
| 77 |
</body>
|
| 78 |
</html>
|
| 79 |
+
`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
+
else if (req.url === '/qr') {
|
| 82 |
+
if (!qrCodeData) {
|
| 83 |
+
res.writeHead(404);
|
| 84 |
+
res.end('No QR');
|
| 85 |
+
return;
|
|
|
|
|
|
|
| 86 |
}
|
| 87 |
+
const buffer = await qrcode.toBuffer(qrCodeData, { type: 'png', width: 300 });
|
| 88 |
+
res.writeHead(200, {'Content-Type': 'image/png'});
|
| 89 |
+
res.end(buffer);
|
| 90 |
+
}
|
| 91 |
+
else if (req.url === '/status') {
|
| 92 |
+
res.writeHead(200);
|
| 93 |
+
res.end(connectionStatus);
|
| 94 |
+
}
|
| 95 |
+
else {
|
| 96 |
+
res.writeHead(404);
|
| 97 |
+
res.end('Not found');
|
| 98 |
}
|
| 99 |
});
|
| 100 |
|
| 101 |
+
// WhatsApp Bot
|
| 102 |
async function startBot() {
|
| 103 |
+
console.log('π Starting WhatsApp Bot...');
|
| 104 |
+
console.log('π± Buka http://localhost:8080 di browser HP lu');
|
| 105 |
|
| 106 |
+
const { state, saveCreds } = await useMultiFileAuthState(AUTH_FOLDER);
|
| 107 |
+
const { version } = await fetchLatestBaileysVersion();
|
| 108 |
+
|
| 109 |
+
sock = makeWASocket({
|
| 110 |
+
version,
|
| 111 |
+
logger: pino({ level: 'silent' }),
|
| 112 |
+
printQRInTerminal: true, // Tampilkan QR di terminal juga
|
| 113 |
+
auth: state,
|
| 114 |
+
browser: ['Termux', 'Chrome', 'Android'],
|
| 115 |
+
syncFullHistory: false,
|
| 116 |
+
markOnlineOnConnect: true,
|
| 117 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
sock.ev.on('connection.update', async (update) => {
|
| 120 |
+
const { connection, lastDisconnect, qr } = update;
|
| 121 |
+
|
| 122 |
+
if (qr) {
|
| 123 |
+
console.log('\nπ₯ QR CODE (Scan ini):');
|
| 124 |
+
QRCode.generate(qr, { small: true });
|
| 125 |
+
qrCodeData = qr;
|
| 126 |
+
connectionStatus = 'waiting';
|
| 127 |
+
}
|
| 128 |
|
| 129 |
+
if (connection === 'open') {
|
| 130 |
+
connectionStatus = 'connected';
|
| 131 |
+
qrCodeData = null;
|
| 132 |
+
console.log('\nβ
BERHASIL! Bot terhubung.');
|
| 133 |
+
console.log('π± Nomor:', sock.user.id.split(':')[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
try {
|
| 136 |
+
await sock.sendMessage(sock.user.id, {
|
| 137 |
+
text: 'π€ Bot aktif di Termux!\n\nKetik !help'
|
| 138 |
+
});
|
| 139 |
+
} catch (e) {}
|
| 140 |
+
}
|
| 141 |
+
else if (connection === 'close') {
|
| 142 |
+
const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
|
| 143 |
+
connectionStatus = 'disconnected';
|
| 144 |
+
console.log('\nβ Terputus, reconnect...');
|
| 145 |
+
if (shouldReconnect) setTimeout(startBot, 5000);
|
| 146 |
+
}
|
| 147 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
+
sock.ev.on('creds.update', saveCreds);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
sock.ev.on('messages.upsert', async ({ messages, type }) => {
|
| 152 |
+
if (type !== 'notify') return;
|
| 153 |
+
const msg = messages[0];
|
| 154 |
+
if (!msg.message || msg.key.fromMe) return;
|
| 155 |
|
| 156 |
+
const sender = msg.key.remoteJid;
|
| 157 |
+
const text = msg.message.conversation || msg.message.extendedTextMessage?.text || '';
|
| 158 |
|
| 159 |
+
if (!text.startsWith('!')) return;
|
|
|
|
| 160 |
|
| 161 |
+
const cmd = text.slice(1).split(' ')[0].toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
+
if (cmd === 'help') {
|
| 164 |
+
await sock.sendMessage(sender, {
|
| 165 |
+
text: '*Command:*\n!ping - Test\n!status - Status'
|
| 166 |
+
});
|
| 167 |
+
}
|
| 168 |
+
else if (cmd === 'ping') {
|
| 169 |
+
await sock.sendMessage(sender, { text: 'π Pong!' });
|
| 170 |
+
}
|
| 171 |
+
else if (cmd === 'status') {
|
| 172 |
+
await sock.sendMessage(sender, { text: 'Status: ' + connectionStatus });
|
| 173 |
+
}
|
| 174 |
+
});
|
| 175 |
}
|
| 176 |
|
| 177 |
+
server.listen(PORT, '0.0.0.0', () => {
|
| 178 |
+
console.log(`π Web UI: http://localhost:${PORT}`);
|
| 179 |
+
console.log(`π Atau: http://127.0.0.1:${PORT}`);
|
| 180 |
startBot();
|
| 181 |
});
|