-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
83 lines (70 loc) · 2.27 KB
/
utils.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
const moment = require('moment')
const math = require('math');
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function enterRankup(bot) {
if (bot.currentWindow) bot.closeWindow(bot.currentWindow)
bot.setQuickBarSlot(4)
bot.activateItem()
bot.once('windowOpen', async (window) => {
if (window.title.includes('Modos de Jogo')) {
log(`Janela identificada: 'Modos de Jogo'`, 'grey')
await bot.clickWindow(10, 0, 0)
}
})
await sleep(5000)
if (bot.currentWindow?.title?.includes('Modos de Jogo')) {
console.log('Não entrou no fullpvp?')
enterRankup(bot)
}
}
async function getLocation(bot, home, cb) {
const onMessage = async (message) => {
if (message.includes('Teletransportado com sucesso')) {
log(`${bot.username} chegou na home com sucesso!`, 'brightGreen')
bot.location = 'home'
bot.removeListener('messagestr', onMessage)
}
else if (message.includes('Essa warp não')) {
log(`${bot.username} não conseguiu chegar na home`, 'brightRed')
bot.removeListener('messagestr', onMessage)
}
}
let coords = bot.entity.position
if (math.trunc(coords.z) === 0 && math.trunc(coords.x) === 0) {
const block = bot.blockAt(bot.entity.position.offset(0, -1, 0))
if (!block) return;
if (block.name === 'stone') {
bot.location = 'lobby'
console.log('Lobby identificado')
await enterRankup(bot)
}
else if (block.name === 'stained_hardened_clay') {
bot.location = 'rankup'
console.log('Fullpvp identificado!')
bot.on('messagestr', onMessage)
await sleep(1000)
log(`Indo até a home: ${home}`, 'grey')
bot.chat(`${home}`)
}
cb()
}
}
async function getCurrentTime() {
return (new moment()).format("HH:mm:ss");
}
async function log(message, color) {
let time = await getCurrentTime();
console.log(`[${time}] ${message}`[color]);
}
async function logAccount(user, message) {
log('[' + user + '] ' + message);
}
module.exports = {
sleep,
log,
logAccount,
getLocation,
getCurrentTime
}