-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
99 lines (81 loc) · 2.48 KB
/
app.js
File metadata and controls
99 lines (81 loc) · 2.48 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
const mineflayer = require('mineflayer');
require('dotenv').config();
const express = require('express');
const app = express();
app.set('view engine', 'ejs');
app.use(express.urlencoded({ extended: true }));
app.use(express.static(__dirname + '/assets'));
let accounts = (process.env.name).split(',');
let timeout = 0;
accounts.forEach(username => {
setTimeout(() => {
initBot(username, process.env.host, process.env.port);
}, timeout);
timeout += 1000;
});
app.listen(8080);
function initBot(username, host, port) {
const chatlog = [];
const log = (msg) => {
chatlog.push(msg);
console.log(`[${username}] ${msg}`);
};
log(`Creating new bot...`);
const bot = mineflayer.createBot({
version: '1.18.2',
host: host,
port: port,
username: username,
});
bot.once("spawn", () => {
console.log("We're alive!")
});
bot.on("messagestr", (message) => {
log(message);
if (message == ("LOGIN » Please login with /login <password>")) {
log("[SYSTEM] Logging in...");
bot.chat(`/login ${process.env.password}`);
} else if (message.startsWith("JartexNetwork » You are connected to Lobby")) {
log("[SYSTEM] Opening server selector...");
bot.chat(`/server`);
bot.on("windowOpen", (window) => {
setTimeout(() => {
log("[SYSTEM] Clicking on survival icon...");
bot.simpleClick.leftMouse(19);
}, 1000);
});
}
});
bot.on("kicked", (reason) => {
log(`The bot has been kicked: ${reason}`);
});
bot.once('end', reason => {
log('Connection lost: ' + reason);
log('ATTEMPTING RECONNECT IN 5 SECONDS...')
setTimeout(() => {
initBot(username, host, port);
}, 5000);
});
// http
const router = express.Router();
app.use(`/${username}/`, router);
router.get(`/`, (req, res) => {
res.render('index', {
status: 'online',
account: {
username: username
}
});
});
router.get(`/chatlogs`, (req, res) => {
res.json(chatlog);
});
router.post(`/chat`, (req, res) => {
bot.chat(req.body.message);
res.sendStatus(200);
});
router.post(`/restart`, (req, res) => {
bot.end('Restarting...');
res.sendStatus(200);
});
}