-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (94 loc) · 2.76 KB
/
index.js
File metadata and controls
108 lines (94 loc) · 2.76 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
99
100
101
102
103
104
105
106
107
108
const mineflayer = require("mineflayer");
const readline = require("readline");
const {MicrosoftAuthFlow} = require('prismarine-auth');
const port = process.env.PORT || 10000;
const keep_alive = require("./keep_alive");
const persist = require('node-persist');
const botConfigs = [
{
host: 'donutsmp.net',
username: 'abdoram999@gmail.com',
auth: 'microsoft'
}
/*{
host: 'T2eelYaBoody.aternos.me',
username: 'bot02',
//auth: 'offline'
}*/
];
const bots = [];
async function createBot(config, index) {
console.log(`Creating bot ${index} with config:`, config);
const bot = mineflayer.createBot(config);
bots[index] = bot;
// Handle anti-AFK measures
function antiAFK() {
if (!bot.entity) {
console.log(
`Bot ${index} entity is not available, skipping antiAFK action.`,
);
return;
}
bot.setControlState("jump", true);
setTimeout(() => bot.setControlState("jump", false), 200);
try {
bot.look(
Math.random() * 2 * Math.PI,
(Math.random() * Math.PI) / 2 - Math.PI / 4,
true,
);
} catch (err) {
console.log(`Error while looking around: ${err}`);
}
}
function sendPeriodicCommands() {
if (bot.entity) {
bot.chat("/shard");
setTimeout(() => {
bot.chat("/afk 3");
}, 3000);
} else {
console.log(`Bot ${index} is not ready to send commands.`);
}
}
bot.once("spawn", () => {
setInterval(antiAFK, 60000); // Jump and look around every minute
setInterval(sendPeriodicCommands, 60000); // Send /shard every 60 seconds and /afk 3 every 3 minutes
});
// Handle chat messages
bot.on("chat", (username, message) => {
if (username !== bot.username) {
const formattedMessage = message.replace(
/shards?/gi,
(match) => `<span style="color: purple">${match}</span>`,
);
console.log(`${username}: ${formattedMessage}`);
keep_alive.addMessage(username, formattedMessage);
}
});
// Input for sending messages
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", (input) => {
if (input.startsWith("/chat ")) {
const message = input.slice(6);
bots.forEach((b, i) => b.chat(message)); // Send message with both bots
} else {
console.log('Invalid command. Use "/chat <message>" to send a message.');
}
});
bot.on("error", (err) => {
console.error(`Bot ${index} Error:`, err);
});
bot.on("end", () => {
console.log(`Bot ${index} disconnected, attempting to reconnect...`);
setTimeout(() => {
createBot(config, index);
}, 10000);
});
}
// Create and manage both bots
botConfigs.forEach((config, index) => createBot(config, index));
// This is a big comment.