forked from urFate/Afk-Bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
117 lines (97 loc) · 3.48 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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', () => {
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(() => {
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;
setInterval(() => {
bot.chat(`${messages[i]}`);
if (i + 1 == messages.length) {
i = 0;
} else i++;
}, delay * 1000);
} else {
messages.forEach((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', (username, message) => {
if (config.utils['chat-log']) {
console.log(`[ChatLog] <${username}> ${message}`);
}
});
bot.on('goal_reached', () => {
console.log(
`\x1b[32m[BotLog] Bot arrived to target location. ${bot.entity.position}\x1b[0m`
);
});
bot.on('death', () => {
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', () => {
setTimeout(() => {
createBot();
}, config.utils['auto-recconect-delay']);
});
}
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();