-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
60 lines (47 loc) · 1.79 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
const mineflayer = require('mineflayer');
require('dotenv').config();
const chalk = require('chalk');
const fs = require('fs');
const { setTimeout } = require('timers/promises');
console.log(chalk.blueBright.bold(`Logging into ${process.env.playername}...`));
// Create the bot
const bot = mineflayer.createBot({
host: process.env.host || 'localhost',
port: parseInt(process.env.port) || '25565',
username: process.env.playername || 'aternos-afk',
});
module.exports = bot;
// Chat message
bot.once('spawn', () => {
bot.chat(`Started the script.`);
});
// Reconnect
bot.on('end', () => {
console.log(chalk.redBright('warn') + chalk.red(' The bot disconnected. Attempting to reconnect...'));
setTimeout(bot, 5000);
});
// Command handler
const files = fs.readdirSync("./src/functions").filter(file => file.endsWith(".js"));
for (const file of files) {
const eventName = file.split(".")[0];
// eslint-disable-next-line no-unused-vars
const event = require(`./src/functions/${file}`);
console.log(chalk.cyanBright(`Function ${eventName}.js`) + chalk.greenBright(` has been loaded.`));
}
// Events folder
const eFiles = fs.readdirSync("./src/events").filter(file => file.endsWith(".js"));
for (const file of eFiles) {
const eventName = file.split(".")[0];
// eslint-disable-next-line no-unused-vars
const event = require(`./src/events/${file}`);
console.log(chalk.magentaBright(`Event ${eventName}.js`) + chalk.blue(` has been loaded.`));
}
const utilFiles = fs.readdirSync("./src/utils").filter(file => file.endsWith(".js"));
// Utils
for (const file of utilFiles) {
const eventName = file.split(".")[0];
// eslint-disable-next-line no-unused-vars
const event = require(`./src/utils/${file}`);
console.log(chalk.yellowBright(`UtiltyFile ${eventName}.js`) + chalk.blue(` has been loaded.`));
}
// 0x26e