-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
403 lines (362 loc) · 13 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
const mineflayer = require('mineflayer')
const utils = require('./utils');
var colors = require('colors');
const fs = require('fs');
const { Client, EmbedBuilder } = require('discord.js')
const client = new Client({ intents: 3276799 });
require('dotenv').config();
let token = process.env.TOKEN;
let channel = process.env.CHANNEL;
client.login(token)
mineflayer.multiple = async (bots, constructor) => {
const { Worker, isMainThread, workerData } = require('worker_threads')
if (isMainThread) {
const threads = []
for (const i in bots) {
await utils.sleep(14000)
threads.push(new Worker(__filename, { workerData: bots[i] }))
}
} else {
constructor(workerData)
}
}
const accounts = []
const accountFile = 'accounts.txt';
const accountsFileData = fs.readFileSync(accountFile, 'utf8');
for (const account of accountsFileData.split('\r\n')) {
const splitted = account.split(':')
if (splitted.length === 4) {
accounts.push({ username: splitted[0], pass: splitted[1], home: splitted[2], auth: splitted[3] });
}
}
const bot_creator = ({ username, pass, home, auth }) => {
let bot = mineflayer.createBot({
username,
host: 'jogar.gladmc.com',
port: 25565,
checkTimeoutInterval: 60000,
version: '1.8.9',
auth,
pass,
home
})
client.on('ready', () => {
channel = client.channels.cache.get(channel)
return;
})
client.on('messageCreate', async (message) => {
if (message.channel.id !== channel.id) return
if (!(message.content.startsWith('!'))) return
// Manda MSG com o BOT
else if (message.content.startsWith(`!chat`)) {
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
if (bot.location !== 'home') {
channel.send(`${username} não está na home, aguarde um momento`)
return;
}
else {
let index = split.length - 2
split = split.splice(2, index)
split = split.join(' ')
bot.chat(split)
channel.send(`${username} mensagem enviada com sucesso.`)
}
}
}
// Para o BOT
else if (message.content.startsWith('!stop')) {
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
channel.send(`Desligando: ${username}`)
bot.disconnected = true
bot.quit()
return;
}
}
// Renicia o BOT
else if (message.content.startsWith(`!restart`)) {
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
channel.send(`Reiniciando: ${username}`)
bot.quit()
return;
}
}
// Verifica o moneytop
else if (message.content.startsWith(`!topmoney`)) {
let split = message.content.split(' ');
if (split.length !== 3) {
return;
}
let username = split[1];
let target = split[2];
if (bot.username.toLowerCase() !== username.toLowerCase()) {
return;
}
if (bot.location !== 'home') {
channel.send(`${username} Não está na home, aguarde um momento`);
return;
}
let messagesReceived = 0;
let gladmcDetected = false;
let collectedMessages = '';
bot.on('message', handleMessage);
function handleMessage(message) {
if (gladmcDetected) {
messagesReceived++;
if (messagesReceived > 1 && messagesReceived <= 11) {
collectedMessages += `[GladMC] ${message}\n`;
} else if (messagesReceived === 12) {
bot.removeListener('message', handleMessage);
const embed = new EmbedBuilder()
.setTitle('Jogadores com mais dinheiro do GladMC')
.setColor('#00FF00')
.setDescription(collectedMessages)
.setThumbnail('https://yt3.googleusercontent.com/F-mwc-JCMKxbvO_OnOUY2V8QGK4VsoBiUGV_4DHKBVUWUrqPoJJLBfau-XfxVtNbZx2dAl4r9Q=s900-c-k-c0x00ffffff-no-rj')
.setTimestamp()
.setFooter({ text: 'GladBOT by LukeTheNeko', iconURL: 'https://gladmc.com/uploads/logo_gladiador_gladmc.png' });
channel.send({ embeds: [embed] });
}
} else if (message.toString().startsWith('[GladMC] ')) {
gladmcDetected = true;
messagesReceived++;
if (messagesReceived > 1) {
collectedMessages += `[GladMC] ${message.toString().substring(8)}\n`;
}
}
}
bot.chat(`/money top`);
}
else if (message.content.startsWith(`!balance`)) {
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
if (bot.location !== 'home') {
channel.send(`${username} não está na home, aguarde um momento`)
return;
}
else {
let index = split.length - 2
split = split.splice(2, index)
split = split.join(' ')
bot.chat('/money balance')
bot.once('message', (message) => {
if (message.toString().startsWith('[GladMC] ')) {
const moneyMessage = message.toString().substring(8);
channel.send(` [GladMC] ${username}${moneyMessage}`);
}
});
}
}
}
// Verifica o money de outra pessoa
else if (message.content.startsWith(`!vermoney`)) {
let split = message.content.split(' ');
if (split.length !== 3) {
return;
}
let username = split[1];
let target = split[2];
if (bot.username.toLowerCase() !== username.toLowerCase()) {
return;
}
if (bot.location !== 'home') {
channel.send(`${username} Não está na home, aguarde um momento`);
return;
}
bot.chat(`/money ${target}`);
bot.once('message', (message) => {
if (message.toString().startsWith('[GladMC] ')) {
const moneyMessage = message.toString().substring(8);
channel.send(` [GladMC] ${moneyMessage}`);
}
});
}
// Abre caixas lendarias
else if (message.content.startsWith(`!len`)) {
let split = message.content.split(' ');
if (split[1] == bot.username || split[1] == 'all') {
if (bot.location !== 'home') {
channel.send(`${username} não está na home, aguarde um momento`);
return;
} else {
let index = split.length - 2;
split = split.splice(2, index);
split = split.join(' ');
channel.send(`${username} abriu uma caixa lendaria.`);
bot.chat('/caixas');
bot.once('windowOpen', () => {
if (bot.currentWindow) {
bot.clickWindow(7, 0, 0);
const filter = (gameMessage) => gameMessage.toString().startsWith("ERRO! Você precisa de uma chave da Caixa") || gameMessage.toString().startsWith("Parabéns! Você ganhou");
bot.once('message', (gameMessage) => {
if (filter(gameMessage)) {
if (gameMessage.toString().startsWith("ERRO! Você precisa de uma chave da Caixa")) {
channel.send(gameMessage.toString());
} else if (gameMessage.toString().startsWith("Parabéns! Você ganhou")) {
channel.send(gameMessage.toString());
}
}
});
}
});
}
}
}
// Abre caixas epicas
else if (message.content.startsWith(`!epic`)) {
let split = message.content.split(' ');
if (split[1] == bot.username || split[1] == 'all') {
if (bot.location !== 'home') {
channel.send(`${username} não está na home, aguarde um momento`);
return;
} else {
let index = split.length - 2;
split = split.splice(2, index);
split = split.join(' ');
channel.send(`${username} abriu uma caixa lendaria.`);
bot.chat('/caixas');
bot.once('windowOpen', () => {
if (bot.currentWindow) {
bot.clickWindow(5, 0, 0);
const filter = (gameMessage) => gameMessage.toString().startsWith("ERRO! Você precisa de uma chave da Caixa") || gameMessage.toString().startsWith("Parabéns! Você ganhou");
bot.once('message', (gameMessage) => {
if (filter(gameMessage)) {
if (gameMessage.toString().startsWith("ERRO! Você precisa de uma chave da Caixa")) {
channel.send(gameMessage.toString());
} else if (gameMessage.toString().startsWith("Parabéns! Você ganhou")) {
channel.send(gameMessage.toString());
}
}
});
}
});
}
}
}
// Compra boost de cacto 12%
else if (message.content.startsWith(`!cactus`)) {
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
if (bot.location !== 'home') {
channel.send(`${username} não está na home, aguarde um momento`)
return;
}
else {
let index = split.length - 2
split = split.splice(2, index)
split = split.join(' ')
channel.send(`${username} Comprou Boost de 12% para cactus.`)
bot.chat('/boost')
bot.on('windowOpen', function () {
bot.clickWindow(10, 0, 0);
});
}
}
}
// Drop todos os items
else if (message.content.startsWith('!drop')) {
const split = message.content.split(' ');
if (split[1] === bot.username || split[1] === 'all') {
if (bot.player.entity) {
if (bot.player.entity.onGround) {
const interval = setInterval(() => {
const inventory = bot.inventory;
const inventoryItems = inventory.items();
if (inventoryItems.length > 0) {
const itemStack = inventoryItems[0];
bot.tossStack(itemStack);
inventoryItems.shift();
} else {
clearInterval(interval);
channel.send(`${username} todos os itens do inventário foram descartados com sucesso.`);
}
}, 175);
} else {
channel.send(`${username} não está no chão, aguarde um momento.`);
}
}
}
}
// Compra boost de cana de açucar 12%
else if (message.content.startsWith(`!cana`)) {
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
if (bot.location !== 'home') {
channel.send(`${username} não está na home, aguarde um momento`)
return;
}
else {
let index = split.length - 2
split = split.splice(2, index)
split = split.join(' ')
channel.send(`${username} Comprou Boost de 12% para cana.`)
bot.chat('/boost')
bot.on('windowOpen', function () {
bot.clickWindow(12, 0, 0);
});
}
}
}
// Inicia o bot
else if (message.content.startsWith('!start')) {
console.log('test')
let split = message.content.split(' ')
if (split[1] == bot.username || split[1] == 'all') {
if (!bot.disconnected) return
channel.send(`Iniciando: ${username}`)
bot.disconnected = false
client.removeAllListeners()
bot.removeAllListeners()
bot._client.removeAllListeners()
bot_creator({ username, pass, home, auth });
return
}
}
})
bot.location = 'unknown'
bot.isRestarting = false
bot.disconnected = false
bot.once('login', async () => console.log("Conectando > ".brightMagenta + username))
bot.on('spawn', async () => {
await utils.sleep(6000)
await utils.getLocation(bot, home, async () => {
if (bot.location === 'home') {
channel.send(`${username} chegou na home (/pw${home})`)
}
else return;
})
})
bot.on('message', async (message) => {
console.log(message.toAnsi())
if (message.toString().includes(' Use o comando "/login <senha>" ')) bot.chat(`/login ${pass}`)
else if (message.toString().startsWith('Servidor está reiniciando')) {
console.log(`Servidor reiniciando, desconectando: ${bot.username}`.cyan)
bot.isRestarting = true
bot.quit()
}
})
bot.on('end', async (reason) => {
if (reason.includes('quitting') && bot.isRestarting) {
client.removeAllListeners()
bot.removeAllListeners()
bot._client.removeAllListeners()
utils.log(`${username} aguardando 5 min para reconectar`, 'brightMagenta')
await utils.sleep(60000 * 5)
bot.isRestarting = false
bot_creator({ username, pass, home, auth });
}
else if (reason.includes('quitting') && bot.disconnected) {
console.log('disconnected')
}
else {
client.removeAllListeners()
bot.removeAllListeners()
bot._client.removeAllListeners()
utils.log(`${username} foi desconectado, reconectando...`, 'brightRed');
await utils.sleep(14000);
bot_creator({ username, pass, home, auth });
}
})
}
mineflayer.multiple(accounts, bot_creator)