Create bot.js
Browse files
bot.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const mineflayer = require('mineflayer');
|
| 2 |
+
const fs = require('fs');
|
| 3 |
+
const pathfinder = require('mineflayer-pathfinder').pathfinder;
|
| 4 |
+
const { GoalNear } = require('mineflayer-pathfinder').goals;
|
| 5 |
+
|
| 6 |
+
const config = {
|
| 7 |
+
host: "minegens.id",
|
| 8 |
+
port: 25565,
|
| 9 |
+
version: "1.20.1"
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
// Daftar akun bot
|
| 13 |
+
const botAccounts = [
|
| 14 |
+
//{ username: "RenTakamori", password: "Kyouka19" },
|
| 15 |
+
// { username: "SenjoHutagi", password: "RenTakamori00", command: "/is" },
|
| 16 |
+
//{ username: "GunturKzy", password: "RenTakamori00", command: "/is" },
|
| 17 |
+
{ username: "KuroYamiis", password: "KuroID991", command: "/afk" },
|
| 18 |
+
];
|
| 19 |
+
|
| 20 |
+
const databaseFile = 'database.json';
|
| 21 |
+
let userDatabase = {};
|
| 22 |
+
|
| 23 |
+
if (fs.existsSync(databaseFile)) {
|
| 24 |
+
userDatabase = JSON.parse(fs.readFileSync(databaseFile, 'utf8'));
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function createBot(account, delay) {
|
| 28 |
+
setTimeout(() => {
|
| 29 |
+
const bot = mineflayer.createBot({
|
| 30 |
+
host: config.host,
|
| 31 |
+
port: config.port,
|
| 32 |
+
username: account.username,
|
| 33 |
+
version: config.version,
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
bot.loadPlugin(pathfinder);
|
| 37 |
+
|
| 38 |
+
bot.once('login', () => {
|
| 39 |
+
console.log(`Bot ${bot.username} berhasil masuk`);
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
bot.once('spawn', () => {
|
| 43 |
+
console.log(`Bot ${bot.username} telah spawn`);
|
| 44 |
+
|
| 45 |
+
setTimeout(() => {
|
| 46 |
+
if (!userDatabase[account.username]) {
|
| 47 |
+
bot.chat(`/register ${account.password}`);
|
| 48 |
+
userDatabase[account.username] = true;
|
| 49 |
+
fs.writeFileSync(databaseFile, JSON.stringify(userDatabase, null, 2));
|
| 50 |
+
console.log(`Mendaftarkan akun ${account.username}`);
|
| 51 |
+
} else {
|
| 52 |
+
bot.chat(`/login ${account.password}`);
|
| 53 |
+
console.log(`Login sebagai ${account.username}`);
|
| 54 |
+
}
|
| 55 |
+
}, 5000);
|
| 56 |
+
|
| 57 |
+
setTimeout(() => {
|
| 58 |
+
bot.chat('/server tycoon');
|
| 59 |
+
console.log(`Bot ${account.username} masuk ke realm Tycoon`);
|
| 60 |
+
}, 10000);
|
| 61 |
+
|
| 62 |
+
setTimeout(() => {
|
| 63 |
+
bot.chat(`${account.command}`);
|
| 64 |
+
console.log(`Bot ${account.username} command ${account.command}`);
|
| 65 |
+
}, 17000);
|
| 66 |
+
|
| 67 |
+
setTimeout(() => {
|
| 68 |
+
bot.chat('/spin');
|
| 69 |
+
console.log(`Bot ${account.username} Berputar`);
|
| 70 |
+
}, 19000);
|
| 71 |
+
|
| 72 |
+
const messages = [
|
| 73 |
+
"ヽ(・∀・)ノ",
|
| 74 |
+
"(^▽^)",
|
| 75 |
+
"(*^‿^*)",
|
| 76 |
+
"(≧◡≦)",
|
| 77 |
+
"(⁀ᗢ⁀)",
|
| 78 |
+
"╰(°▽°)╯",
|
| 79 |
+
"(✿◕‿◕)",
|
| 80 |
+
"(o^▽^o)",
|
| 81 |
+
"(。♥‿♥。)",
|
| 82 |
+
"(~‾▿‾)~"
|
| 83 |
+
];
|
| 84 |
+
|
| 85 |
+
function getRandomMessage() {
|
| 86 |
+
return messages[Math.floor(Math.random() * messages.length)];
|
| 87 |
+
}
|
| 88 |
+
// function randomChat() {
|
| 89 |
+
// bot.chat('/spin');
|
| 90 |
+
// }
|
| 91 |
+
// setInterval(randomChat, 420000);
|
| 92 |
+
});
|
| 93 |
+
bot.on('message', (message) => {
|
| 94 |
+
const text = message.toAnsi();
|
| 95 |
+
if (!text.includes("Level Progress:") && !text.includes("Next Rewards in")) {
|
| 96 |
+
console.log(`Bot ${bot.username} | ${text}`);
|
| 97 |
+
}
|
| 98 |
+
});
|
| 99 |
+
|
| 100 |
+
bot.once('kicked', (reason) => {
|
| 101 |
+
console.log(`Bot ${bot.username} dikeluarkan: ${reason}`);
|
| 102 |
+
reconnect(bot, account);
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
bot.once('error', (err) => {
|
| 106 |
+
console.error(`Terjadi kesalahan pada ${bot.username}: ${err}`);
|
| 107 |
+
reconnect(bot, account);
|
| 108 |
+
});
|
| 109 |
+
|
| 110 |
+
bot.once('death', () => {
|
| 111 |
+
console.log(`Bot ${bot.username} mati, respawning...`);
|
| 112 |
+
setTimeout(() => bot.chat('/respawn'), 5000);
|
| 113 |
+
});
|
| 114 |
+
}, delay);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function reconnect(bot, account) {
|
| 118 |
+
console.log(`Bot ${account.username} mencoba untuk masuk kembali...`);
|
| 119 |
+
bot.end(); // Pastikan instance lama dihentikan sebelum reconnect
|
| 120 |
+
setTimeout(() => createBot(account, 5000), 5000);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Jalankan semua bot dengan delay 15 detik antar akun
|
| 124 |
+
botAccounts.forEach((account, index) => {
|
| 125 |
+
createBot(account, index * 60000);
|
| 126 |
+
});
|