-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
194 lines (160 loc) · 7.71 KB
/
index.js
File metadata and controls
194 lines (160 loc) · 7.71 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const mineflayer = require('mineflayer');
var tpsPlugin = require('mineflayer-tps')(mineflayer)
const { username, prefix, password } = require('./config.json');
const ms = require('ms');
console.log('\x1b[33m%s\x1b[0m','[Console] Creating bot...');
const config = require('./botsettings.json');
// Mineflayer plugins sits here.
const pvp = require('mineflayer-pvp').plugin
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
var tpsPlugin = require('mineflayer-tps')(mineflayer)
const armorManager = require('mineflayer-armor-manager')
const mineflayerViewer = require('prismarine-viewer').mineflayer
const botArgs = { // Create bot
host: 'localhost', // 51.81.220.187 for 8b8t
port: '51922',
username: username,
version: '1.12.2'
};
const initBot = () => {
// Create the bot
let bot = mineflayer.createBot(botArgs);
// Load Mineflayer Plugins
bot.loadPlugin(tpsPlugin)
bot.loadPlugin(armorManager)
bot.loadPlugin(pathfinder)
bot.loadPlugin(pvp)
console.log('\x1b[33m%s\x1b[0m',`[Console] Logged in as ${username}`);
if (config.prismarineviewer.enabled) {
bot.once('spawn', () => {
console.log('\x1b[33m%s\x1b[0m','[Viewer] Viewer is listening to port 8080')
mineflayerViewer(bot, { port: 8080, firstPerson: true })
})
};
bot.on('message', message => { // logs messages to console + logins for the server
console.log('\x1b[36m%s\x1b[0m', '[CHAT]' + '\x1b[0m', '' + message.toString());
if (message.toString() === ("[8b8t] Please, login with the command: /login <password>")) {
bot.chat(`/login ` + password) } // Login (not gonna use .env, if you're using a public service like repl.it and you got hacked its your fault.)
if (message.toString() === ("[8b8t] Please register to play 8b8t /register <password>")) {
bot.chat(`/register ` + password) } // Registers into 8b. Might made this universal for servers that uses the same login concept.
if (message.toString() === ("Successful login!")) {
console.log('\x1b[33m%s\x1b[0m','[Console] Bot has joined the server!') } // Bot has joined the server
if (message.toString() === ("Successfully registered!")) {
console.log('\x1b[33m%s\x1b[0m','[Console] Bot has successfully registered to the server!') } // huhu
});
bot.armorManager.equipAll()
if (config.chatfeatures['spammer'].enabled) {
console.log('\x1b[33m%s\x1b[0m',`[Console] Spammer is enabled.`);
let messages = config.chatfeatures['spammer']['messages'];
if (config.chatfeatures['spammer'].repeat) {
let delay = config.chatfeatures['spammer']['delay']; // i don't know. but this code is too simular to urFate/Afk-Bot project.
let meow = 0;
setInterval(() => {
bot.chat(`${messages[meow]}`);
if (meow + 1 === messages.length) {
meow = 0;
} else meow++;
}, delay * 1000);
} else {
messages.forEach((msg) => {
bot.chat(msg);
});
}
}
if (config.friendlymode.enabled) { // Don't use friendlymode when PVP feature is enabled.
console.log('\x1b[33m%s\x1b[0m',`[Console] Friendly Mode enabled (DO NOT ENABLE PVP MODE IF THIS FEATURE IS ENABLED)`);
bot.on("move", ()=>{ // Tried this on 2b2t. A player kidnapped the bot.
const playerFilter = (entity) => entity.type === 'player' // filters out all entities except the player.
let player = bot.nearestEntity(playerFilter);
if (player) {
bot.lookAt(player.position.offset(0, player.height, 0))
bot.swingArm('right')
setInterval(() => {
bot.setControlState('sneak', true)
}, 450);
setInterval(() => {
bot.setControlState('sneak', false)
}, 200); // friendly got cool downs for anticheats
}
})
};
if (config.pvpmode.enabled) { // Don't use friendlymode when PVP feature is enabled.
console.log('\x1b[33m%s\x1b[0m',`[Console] PVP mode enabled (DO NOT ENABLE FRIENDLY MODE IF THIS FEATURE IS ENABLED)`);
bot.on('chat', (username, message) => {
if (message === prefix + 'pvp') {
bot.chat("youre dead :DD i will kil u!!")
const player = bot.players[username]
if (!player) {
bot.chat("You're not on my range, pls find me and give me armor and a sword and ask me to pvp again :D")
return
}
bot.pvp.attack(player.entity)
}
if (message === prefix + 'stoppvp') {
bot.chat("okay okay!! i will stop hurting you :(")
bot.pvp.stop()
}
})
};
bot.on('chat', (username, message) => {
if (username === bot.username) return
if (message === prefix + 'help') {
bot.chat('Commands : help, info, botstatus, ping, serverstatus, kill')
console.log('\x1b[33m%s\x1b[0m',`[Console] ${username} executed help command!`)
}
});
bot.on('chat', (username, message) => {
if (username === bot.username) return
if (message === prefix + 'info') {
bot.chat(`${bot.username} is using Thuy2y2c/bocchithebot source code.`)
console.log('\x1b[33m%s\x1b[0m',`[Console] ${username} executed info command!`)
}
});
bot.on('chat', (username, message) => {
if (username === bot.username) return
if (message === prefix + 'botstatus') {
bot.chat(`${bot.username} currently has ${bot.health}hp and ${bot.food} as hunger.`)
console.log('\x1b[33m%s\x1b[0m',`[Console] ${username} executed botstatus command!`)
}
});
bot.on('chat', (username, message) => {
if (username === bot.username) return
if (message === prefix + 'ping') {
bot.chat(`Your ping: ${bot.player.ping}ms`) // only checks for the player that executes the command. (might do the $ping (player) so other players can check their friend ping.)
console.log('\x1b[33m%s\x1b[0m',`[Console] ${username} executed ping command!`)
}
});
bot.on('chat', (username, message) => {
if (username === bot.username) return
if (message === prefix + 'kill') {
bot.chat(`/kill`)
console.log('\x1b[33m%s\x1b[0m',`[Console] ${username} executed kill command!`)
}
});
bot.on('chat', (username, message) => {
if (username === bot.username) return
if (message === prefix + 'serverstatus') {
bot.chat(`TPS: ${bot.getTps()} | Players: ${Object.values(bot.players).map(player => player.username).length}`)
console.log('\x1b[33m%s\x1b[0m',`[Console] ${username} executed serverstatus command!`)
}
});
bot.on('death', () => {
console.log('\x1b[33m%s\x1b[0m',
`Bot killed.. respawning..`
);
});
bot.on('end', () => { // Reconnect system when the bot is kicked
console.log('\x1b[33m%s\x1b[0m',`Bot got disconnected.. reconnecting`);
// Attempt to reconnect
setTimeout(initBot, 5000); // reconnect
});
bot.on('error', (err) => {
if (err.code === 'ECONNREFUSED') {
console.log('\x1b[33m%s\x1b[0m',`Can't connect to : ${err.address}:${err.port}`)
}
else {
console.log('\x1b[33m%s\x1b[0m',`Unhandled error: ${err}`);
}
});
};
initBot();