forked from urFate/Afk-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
102 lines (80 loc) · 3.26 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const mineflayer = require('mineflayer')
const Movements = require('mineflayer-pathfinder').Movements
const pathfinder = require('mineflayer-pathfinder').pathfinder
const { GoalBlock} = require('mineflayer-pathfinder').goals
const config = require('./settings.json');
function createBot () {
const bot = mineflayer.createBot({
username: config['bot-account']['username'],
password: config['bot-account']['password'],
auth: config['bot-account']['type'],
host: config.server.ip,
port: config.server.port,
version: config.server.version
})
bot.loadPlugin(pathfinder)
const mcData = require('minecraft-data')(bot.version)
const defaultMove = new Movements(bot, mcData)
bot.settings.colorsEnabled = false
bot.once("spawn", function(){
console.log("\x1b[33m[BotLog] Bot joined to the server", '\x1b[0m')
if(config.utils['auto-auth'].enabled){
console.log("[INFO] Started auto-auth module")
var password = config.utils['auto-auth'].password
setTimeout(function() {
bot.chat(`/register ${password} ${password}`)
bot.chat(`/login ${password}`)
}, 500);
console.log(`[Auth] Authentification commands executed.`)
}
if(config.utils['chat-messages'].enabled){
console.log("[INFO] Started chat-messages module")
var messages = config.utils['chat-messages']['messages']
if(config.utils['chat-messages'].repeat){
var delay = config.utils['chat-messages']['repeat-delay']
let i = 0
let msg_timer = setInterval(() => {
bot.chat(`${messages[i]}`)
if(i+1 == messages.length){
i = 0
} else i++
}, delay * 1000)
} else {
messages.forEach(function(msg){
bot.chat(msg)
})
}
}
const pos = config.position
if (config.position.enabled){
console.log(`\x1b[32m[BotLog] Starting moving to target location (${pos.x}, ${pos.y}, ${pos.z})\x1b[0m`)
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalBlock(pos.x, pos.y, pos.z))
}
if(config.utils['anti-afk'].enabled){
bot.setControlState('jump', true)
if(config.utils['anti-afk'].sneak){
bot.setControlState('sneak', true)
}
}
})
bot.on("chat", function(username, message){
if(config.utils['chat-log']){
console.log(`[ChatLog] <${username}> ${message}`)
}
})
bot.on("goal_reached", function(){
console.log(`\x1b[32m[BotLog] Bot arrived to target location. ${bot.entity.position}\x1b[0m`)
})
bot.on("death", function(){
console.log(`\x1b[33m[BotLog] Bot has been died and was respawned ${bot.entity.position}`, '\x1b[0m')
})
if(config.utils['auto-reconnect']){
bot.on('end', function(){
createBot()
})
}
bot.on('kicked', (reason) => console.log('\x1b[33m',`[BotLog] Bot was kicked from the server. Reason: \n${reason}`, '\x1b[0m'))
bot.on('error', err => console.log(`\x1b[31m[ERROR] ${err.message}`, '\x1b[0m'))
}
createBot()