-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.js
More file actions
98 lines (86 loc) · 2.42 KB
/
bot.js
File metadata and controls
98 lines (86 loc) · 2.42 KB
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
const fs = require("fs");
const colors = require('colors');
const mineflayer = require("mineflayer");
let bot;
const config = JSON.parse(fs.readFileSync("./config.json", "utf-8"));
function getRandomMessage() {
return config.messages[Math.floor(Math.random() * config.messages.length)];
}
function isInLobby() {
if (!bot || !bot.game || bot.game.difficulty != "hard") {
return true;
} else {
return false;
}
}
const main = () => {
let forceStop = false;
bot = mineflayer.createBot({
host: config.ip,
username: config.username,
version: config.version,
skipValidation: true,
});
bot.once("spawn", async () => {
let lobbyCount = 0;
while (!forceStop) {
await bot.waitForTicks(20);
if (lobbyCount > 30) {
bot.end();
break;
}
if (!bot.entity) continue;
if (!bot.entity.position) continue;
if (isInLobby()) lobbyCount++;
}
});
bot.once("login", async () => {
await bot.waitForTicks(100);
bot.chat("/register " + config.password);
await bot.waitForTicks(100);
bot.chat("/login " + config.password);
while (!forceStop) {
if (!isInLobby()) {
for (player in bot.players) {
const targetUsername = bot.players[player].username;
if (config.blacklist.includes(targetUsername.toLowerCase()) || bot.entity.username == targetUsername) continue;
if (forceStop) return;
bot.chat("/msg " + targetUsername + " " + config.prefix + getRandomMessage());
if(config.log.sends) {
console.log(`Sent message to: ${targetUsername}`.yellow)
}
await bot.waitForTicks(config.delay);
}
}
await bot.waitForTicks(2);
}
});
bot.on("error", (err) => {
if(config.log.errors) {
console.log(err.red);
}
bot.end();
});
bot.on('chat', (username, message) => {
if(config.log.messages) return
if (username === bot.username) return
console.log(`${username}`.brightBlue.bold+` » ` +message.blue)
})
bot.on('whisper', (username, message) => {
if(config.log.whispers) return
if (username === bot.username) return
console.log(`${username}`.cyan+` whispers: `.cyan + message.cyan)
})
bot.on("kicked", (err) => {
if(config.log.kicks) {
console.log(err.red);
}
bot.end();
});
bot.on("end", () => {
bot.removeAllListeners();
forceStop = true;
setTimeout(main, 5000);
});
};
main();