This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
120 lines (107 loc) · 3.17 KB
/
index.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
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
const mineflayer = require('mineflayer');
const config = require('./config.json');
require('console-stamp')(console, {
format: ':date(mm/dd/yyyy HH:MM:ss)',
});
require('dotenv').config();
const env = process.env
const fs = require('fs');
let commands = {};
function loadCommands() {
commands = {};
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands[command.name] = command.execute;
}
}
loadCommands();
function wait(seconds) {
return new Promise((resolve) => {
setTimeout(resolve, seconds * 1000);
});
}
function createBot() {
const bot = mineflayer.createBot({
host: "proxy.hypixel.net",
version: '1.8.9',
username: process.env.EMAIL,
auth: 'microsoft',
});
let partyStatus = 'disbanded'
let queue = []
bot.once('spawn', () => {
console.log(`Connected.`);
bot.addChatPatternSet(
'PRIVATE_MESSAGE',
[/^From (?:\[(.+\+?\+?)\] )?(.+): (.+)$/],
{ parse: true }
);
bot.addChatPatternSet(
'PARTY_INVITE',
[/(?:\[(.+\+?\+?)\] )?(.+) has invited you to join their party!/],
{ parse: true }
)
});
bot.on('message', (msg) => {
if (msg.toString() == `The party was disbanded because all invites expired and the party was empty.`) {
partyStatus = 'disbanded'
}
})
bot.on('error', (error) => {
console.log(error)
})
bot.on('kicked', async (reason) => {
console.log(`Kicked for ${reason}. Not restarting.`)
process.exit();
})
bot.on('end', async (reason) => {
console.log(`Disconnected.`)
console.log(`${reason}`)
if (config.autoRestart) {
await wait(5)
createBot();
}
})
bot.on('chat:PRIVATE_MESSAGE', async ([
[rank, username, message]
]) => {
function reply(username, message) {
bot.chat(`/msg ${username} ${message}`);
}
const msg = message.toString();
if (msg.startsWith(`${config.prefix}`)) {
if (msg in commands) {
commands[msg](bot);
} else {
await wait(1)
reply(username, `Command ${msg} not found.`)
}
}
});
bot.on('chat:PARTY_INVITE', ([
[rank, username]
]) => {
async function joinParty(username) {
await wait(1)
bot.chat(`/p accept ${username}`)
partyStatus = "busy"
console.log(`Joined ${username}'s party.`)
await wait(config.timeInParty)
bot.chat(`/p leave`)
console.log(`Left ${username}'s party.`)
partyStatus = "disbanded"
if (queue.length > 0) {
await wait(1)
const nextPlayer = queue.shift();
joinParty(nextPlayer);
}
}
if (partyStatus === "busy") {
queue.push(username);
} else {
joinParty(username);
}
});
}
createBot();