-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBotHandler.js
118 lines (108 loc) · 3.13 KB
/
BotHandler.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
const minecraft = require('mineflayer');
const config = require('./config.json');
const chalk = require('chalk');
const hypixelapi = require('hypixel-api');
const Discord = require('discord.js');
const RegexHandler = require('./RegexHandler');
require('dotenv').config();
let bot = null;
let cd = [];
/**
*
* @param {Discord.Client} client
* @param {hypixelapi} api
*/
async function removeItemOnce(arr, value) {
var index = arr.indexOf(value);
if (index > -1) {
arr.splice(index, 1);
}
return arr;
}
async function createbot(client, api) {
console.log('Login in bot');
bot = minecraft.createBot({
host: 'mc.hypixel.net',
port: 25565,
username: process.env.minecraftusername,
password: process.env.minecraftpsw,
version: '1.13.2',
});
async function rejoinLimbo() {
console.log('Trying to send to Limbo');
bot.chat(`/ac \u00a7c<3`);
// Add a check if in Lobby -> HPAPI
console.log('In Limbo');
if (cd.includes('recon')) cd = await removeItemOnce(cd, 'recon');
}
bot.on('message', (message) => {});
bot.on('login', () => {
console.log('Logged in');
// replace Housing to Limbo | PR [29]
setTimeout(() => {
rejoinLimbo();
}, 15000);
});
bot.on('error', (err) => {
console.log(err);
});
bot.chatAddPattern(
// Guild > [VIP] Player: gBa1b2n3h4j5u6i7o4
RegexHandler.regex_guildchat,
'guild_chat',
'Custom chat event'
);
bot.chatAddPattern(
// Officer > [VIP] Player: gBa1b2n3h4j5u6i7o4
RegexHandler.regex_officerchat,
'officer_chat',
'Custom chat event'
);
bot.chatAddPattern(
// [VIP] Player joined the lobby!
RegexHandler.regex_lobbyjoin,
'in_lobby',
'Custom chat event'
);
bot.on('in_lobby', () => {
if (cd.includes('recon')) return;
cd.push('recon');
console.log(
chalk.redBright('Bot is outside of Limbo, trying to send to limbo again')
);
rejoinLimbo();
});
bot.on('guild_chat', (rank, username, grank, message) => {
sendGuildChatToDiscord(rank, username, grank, message);
});
bot.on('officer_chat', (rank, username, grank, message) => {
sendOfficerChatToDiscord(rank, username, grank, message);
});
async function sendGuildChatToDiscord(rank, username, grank, message) {
if (grank === '' || grank === undefined) {
client.guilds.cache
.get(config.guildid)
.channels.cache.get(config.guildchat)
.send(`Guild > ${rank} ${username}: ${message}`);
} else {
client.guilds.cache
.get(config.guildid)
.channels.cache.get(config.guildchat)
.send(`Guild > ${rank} ${username}${grank}: ${message}`);
}
}
async function sendOfficerChatToDiscord(rank, username, grank, message) {
if (grank === '' || grank === undefined) {
client.guilds.cache
.get(config.guildid)
.channels.cache.get(config.officerchat)
.send(`Officer > ${rank} ${username}: ${message}`);
} else {
client.guilds.cache
.get(config.guildid)
.channels.cache.get(config.officerchat)
.send(`Officer > ${rank} ${username}${grank}: ${message}`);
}
}
}
exports.createbot = createbot;