-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathminechat.js
executable file
·53 lines (43 loc) · 1.08 KB
/
minechat.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
var readline = require('readline');
var mineflayer = require('mineflayer');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
function print_help() {
console.log("usage: PASSWORD=<password> node minechat.js <hostname>[:port] <user>");
}
if (process.argv.length < 4 || !("PASSWORD" in process.env)) {
console.log("Too few arguments!");
print_help();
process.exit(1);
}
process.argv.forEach(function(val, index, array) {
if (val == "-h") {
print_help();
process.exit(0);
}
});
var host = process.argv[2];
var port = 25565;
var user = process.argv[3];
var passwd = process.env.PASSWORD;
if (host.indexOf(':') != -1) {
port = host.substring(host.indexOf(':')+1);
host = host.substring(0, host.indexOf(':'));
}
console.log("connecting to " + host + ":" + port);
console.log("user: " + user);
var bot = mineflayer.createBot({
host: host,
port: port,
username: user,
password: passwd
});
rl.on('line', function(line) {
bot.chat(line);
});
bot.on('chat', function(username, message) {
console.log(username + ": " + message);
});