Download bot.js from dima493/my-bot: direct link, hf CLI and curl.
- Browser
- Download file 3.99 kB
-
https://huggingface.co/spaces/dima493/my-bot/resolve/main/bot.js
- Command line
-
hf download hf://spaces/dima493/my-bot/bot.js
-
curl -L -o bot.js https://huggingface.co/spaces/dima493/my-bot/resolve/main/bot.js
3.99 kB
| process.on('uncaughtException', (err) => { | |
| console.error('=== КРИТИЧНИЙ ЗБІЙ ===\n', err); | |
| }); | |
| process.on('unhandledRejection', (reason, promise) => { | |
| console.error('=== НЕОБРОБЛЕНЕ ВІДХИЛЕННЯ ===\n', reason); | |
| }); | |
| const bedrock = require('bedrock-protocol'); | |
| const http = require('http'); | |
| // 1. Сервер Health Check для Hugging Face (ОБОВ'ЯЗКОВО ПОРТ 7860) | |
| http.createServer((req, res) => { | |
| res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
| res.end('Active\n'); | |
| }).listen(7860, '0.0.0.0', () => { | |
| console.log('[Система] HTTP сервер привязано до 0.0.0.0:7860'); | |
| }); | |
| // 2. Конфігурація підключення | |
| const HOST = 'steelhead.aternos.host'; | |
| const PORT = 27843; | |
| function createBot() { | |
| const botUsername = 'VNTU_Bot_' + Math.floor(Math.random() * 9000 + 1000); | |
| console.log(`\n[${new Date().toISOString()}] 🚀 Ініціалізація підключення: ${botUsername} до ${HOST}:${PORT}`); | |
| try { | |
| const client = bedrock.createClient({ | |
| host: HOST, | |
| port: PORT, | |
| username: botUsername, | |
| offline: true, | |
| skipPing: true, | |
| version: '1.21.50', | |
| raknetBackend: 'js', | |
| connectTimeout: 90000 | |
| }); | |
| // Діагностичні слухачі подій | |
| client.on('connect', () => console.log(`[${new Date().toISOString()}] З'єднання з хостом встановлено, очікування відповіді сервера...`)); | |
| client.on('join', () => console.log(`[${new Date().toISOString()}] Авторизація пройдена.`)); | |
| client.on('error', (err) => { | |
| console.log(`[${new Date().toISOString()}] Помилка протоколу: ${err.message}`); | |
| }); | |
| let afkInterval; | |
| client.on('spawn', () => { | |
| console.log(`[${new Date().toISOString()}] ✅ Бот успішно заспавнився на сервері.`); | |
| // 3. Система Anti-AFK (інтервал 30 секунд) | |
| afkInterval = setInterval(() => { | |
| if (client.status === 'open') { | |
| try { | |
| client.write('player_auth_input', { | |
| pitch: 0, yaw: 0, position: { x: 0, y: 64, z: 0 }, | |
| move_vector: { x: 0, z: 0 }, head_yaw: 0, | |
| input_data: { jump_down: false, sneak_down: true }, | |
| input_mode: 'mouse', play_mode: 'normal', interaction_model: 'touch', | |
| tick: 0n, delta: { x: 0, y: 0, z: 0 } | |
| }); | |
| console.log(`[${new Date().toISOString()}] 📡 Anti-AFK пакет надіслано.`); | |
| } catch (e) { | |
| console.log(`[${new Date().toISOString()}] ⚠️ Збій відправки Anti-AFK:`, e.message); | |
| } | |
| } | |
| }, 30000); | |
| }); | |
| client.on('error', (err) => { | |
| console.log(`[${new Date().toISOString()}] ❌ Помилка протоколу: ${err.message}`); | |
| }); | |
| client.on('disconnect', (packet) => { | |
| console.log(`[${new Date().toISOString()}] ⚠️ Відключено. Причина: ${packet.reason}`); | |
| }); | |
| client.on('close', () => { | |
| if (afkInterval) clearInterval(afkInterval); | |
| console.log(`[${new Date().toISOString()}] 🔄 З'єднання закрито. Виконується рестарт через 30 секунд...`); | |
| setTimeout(createBot, 30000); | |
| }); | |
| } catch (error) { | |
| console.log(`[${new Date().toISOString()}] 🛑 Критична помилка: ${error.message}`); | |
| setTimeout(createBot, 30000); | |
| } | |
| } | |
| createBot(); |