Spaces:
Running
Running
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const mineflayer = require('mineflayer')
|
| 2 |
+
|
| 3 |
+
function createBotInstance(cfg, log, onDisconnect) {
|
| 4 |
+
|
| 5 |
+
const bot = mineflayer.createBot({
|
| 6 |
+
host: cfg.host,
|
| 7 |
+
port: cfg.port,
|
| 8 |
+
username: cfg.name,
|
| 9 |
+
version: cfg.version || false,
|
| 10 |
+
auth: 'offline'
|
| 11 |
+
})
|
| 12 |
+
|
| 13 |
+
let auth = false
|
| 14 |
+
let login = false
|
| 15 |
+
let reg = false
|
| 16 |
+
|
| 17 |
+
bot.on('spawn', () => {
|
| 18 |
+
|
| 19 |
+
log(`[BOT] ${cfg.name} online`)
|
| 20 |
+
|
| 21 |
+
// AFK HUMAN SIM
|
| 22 |
+
setInterval(() => {
|
| 23 |
+
if (!bot.entity || !auth) return
|
| 24 |
+
|
| 25 |
+
bot.look(Math.random()*Math.PI*2, 0, true)
|
| 26 |
+
|
| 27 |
+
}, 6000)
|
| 28 |
+
|
| 29 |
+
setInterval(() => {
|
| 30 |
+
if (!bot.entity || !auth) return
|
| 31 |
+
|
| 32 |
+
if (Math.random() > 0.85) {
|
| 33 |
+
bot.setControlState('forward', true)
|
| 34 |
+
setTimeout(()=>bot.setControlState('forward',false),400)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
}, 8000)
|
| 38 |
+
|
| 39 |
+
})
|
| 40 |
+
|
| 41 |
+
bot.on('message', (msg) => {
|
| 42 |
+
|
| 43 |
+
const t = msg.toString().toLowerCase()
|
| 44 |
+
|
| 45 |
+
if (!auth) {
|
| 46 |
+
|
| 47 |
+
if (t.includes('login') && !login) {
|
| 48 |
+
login = true
|
| 49 |
+
setTimeout(()=>bot.chat(`/login ${cfg.password}`),2500)
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (t.includes('register') && !reg) {
|
| 53 |
+
reg = true
|
| 54 |
+
setTimeout(()=>bot.chat(`/register ${cfg.password} ${cfg.password}`),3000)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (t.includes('logged') || t.includes('success')) {
|
| 58 |
+
auth = true
|
| 59 |
+
log(`[AUTH] success`)
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
})
|
| 65 |
+
|
| 66 |
+
bot.on('kicked', r => log(`[KICK] ${r}`))
|
| 67 |
+
bot.on('error', e => log(`[ERR] ${e.message}`))
|
| 68 |
+
bot.on('end', onDisconnect)
|
| 69 |
+
|
| 70 |
+
return bot
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
module.exports = { createBotInstance }
|