Update bot.js
Browse files
bot.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
const mineflayer = require("mineflayer");
|
| 2 |
const Movements = require("mineflayer-pathfinder").Movements;
|
| 3 |
const pathfinder = require("mineflayer-pathfinder").pathfinder;
|
| 4 |
-
const { GoalBlock, GoalXZ
|
| 5 |
|
| 6 |
const config = require("./settings.json");
|
| 7 |
|
|
@@ -9,240 +9,303 @@ const loggers = require("./logging.js");
|
|
| 9 |
const logger = loggers.logger;
|
| 10 |
|
| 11 |
function createBot() {
|
| 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 |
bot.chat(`/skyblock`);
|
| 38 |
-
logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`);
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
|
| 43 |
-
}, 10000);
|
| 44 |
-
setInterval(async () => {
|
| 45 |
bot.chat(`/home`);
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
}, 5000);
|
| 57 |
-
setTimeout(async () => {
|
| 58 |
-
bot.chat(`/home`);
|
| 59 |
-
logger.info(`[${config["bot-account"]["username"]}] Bölgede besleyici minyon bulunamadı.Home konumuna ışınlanma komutu kullanıldı.`);
|
| 60 |
-
}, 10000);
|
| 61 |
-
setInterval(async () => {
|
| 62 |
-
|
| 63 |
-
if(Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("Besleyici ")).length > 0){
|
| 64 |
-
bot.activateEntityAt(bot.entities[Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("Besleyici "))[0]], bot.entities[Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("Besleyici "))[0]].position)
|
| 65 |
-
};
|
| 66 |
}, 13000);
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
}, 16000);
|
| 70 |
-
};
|
| 71 |
-
}, 2000);
|
| 72 |
-
}, 300000);
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
} else i++;
|
| 91 |
-
}, delay * 1000);
|
| 92 |
-
} else {
|
| 93 |
-
messages.forEach((msg) => {
|
| 94 |
-
bot.chat(msg);
|
| 95 |
-
});
|
| 96 |
-
}
|
| 97 |
}
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
if (config.
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
bot.pathfinder.setGoal(new GoalBlock(pos.x, pos.y, pos.z));
|
| 106 |
}
|
| 107 |
|
| 108 |
-
if (config.utils["anti-afk"].enabled) {
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
if (config.utils["anti-afk"].jump) {
|
| 114 |
-
bot.setControlState("jump", true);
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
if (config.utils["anti-afk"]["hit"].enabled) {
|
| 118 |
-
let delay = config.utils["anti-afk"]["hit"]["delay"];
|
| 119 |
-
let attackMobs = config.utils["anti-afk"]["hit"]["attack-mobs"];
|
| 120 |
-
|
| 121 |
-
setInterval(() => {
|
| 122 |
-
if (attackMobs) {
|
| 123 |
-
let entity = bot.nearestEntity(
|
| 124 |
-
(e) =>
|
| 125 |
-
e.type !== "object" &&
|
| 126 |
-
e.type !== "player" &&
|
| 127 |
-
e.type !== "global" &&
|
| 128 |
-
e.type !== "orb" &&
|
| 129 |
-
e.type !== "other",
|
| 130 |
-
);
|
| 131 |
-
|
| 132 |
-
if (entity) {
|
| 133 |
-
bot.attack(entity);
|
| 134 |
-
return;
|
| 135 |
-
}
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
bot.swingArm("right", true);
|
| 139 |
-
}, delay);
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
if (config.utils["anti-afk"].rotate) {
|
| 143 |
-
setInterval(() => {
|
| 144 |
-
bot.look(bot.entity.yaw + 1, bot.entity.pitch, true);
|
| 145 |
-
}, 100);
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
if (config.utils["anti-afk"]["circle-walk"].enabled) {
|
| 149 |
-
let radius = config.utils["anti-afk"]["circle-walk"]["radius"];
|
| 150 |
-
setInterval(() => {
|
| 151 |
-
circleWalk(bot, radius);
|
| 152 |
-
}, 30000);
|
| 153 |
-
}
|
| 154 |
}
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
|
| 165 |
bot.closeWindow(window);
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
bot.closeWindow(window);
|
| 169 |
-
}
|
| 170 |
-
}else{
|
| 171 |
bot.closeWindow(window);
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
| 175 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
});
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
`Bot has been died and was respawned at ${bot.entity.position}`,
|
| 193 |
-
);
|
| 194 |
-
});
|
| 195 |
-
|
| 196 |
-
if (config.utils["auto-reconnect"]) {
|
| 197 |
-
bot.on("end", () => {
|
| 198 |
-
setTimeout(() => {
|
| 199 |
-
createBot();
|
| 200 |
-
}, config.utils["auto-reconnect-delay"]);
|
| 201 |
-
});
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
bot.on("kicked", (reason) => {
|
| 205 |
-
let reasonText = JSON.parse(reason).text;
|
| 206 |
-
if (reasonText === "") {
|
| 207 |
-
reasonText = JSON.parse(reason).extra[0].text;
|
| 208 |
-
}
|
| 209 |
-
try{
|
| 210 |
-
reasonText = reasonText?.replace(/§./g, "");
|
| 211 |
-
logger.warn(`Bot sunucudan atıldı.Sebep: ${reasonText}`);
|
| 212 |
-
}catch{
|
| 213 |
-
logger.warn(`Bot sunucudan atıldı.Sebep: Bulunamadı.`);
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
});
|
| 217 |
-
|
| 218 |
-
bot.on("error", (err) => logger.error(`${err.message}`));
|
| 219 |
}
|
| 220 |
|
| 221 |
-
|
| 222 |
function circleWalk(bot, radius) {
|
| 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 |
createBot();
|
|
@@ -254,12 +317,12 @@ const port = process.env.PORT || 7860; //buraya karışmayın.
|
|
| 254 |
app.get("/", (req, res) => res.send("Pinglendi")); //değiştirebilirsiniz.
|
| 255 |
|
| 256 |
app.listen(
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
);
|
| 261 |
|
| 262 |
process.on('uncaughtException', function (err) {
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
|
|
|
| 1 |
const mineflayer = require("mineflayer");
|
| 2 |
const Movements = require("mineflayer-pathfinder").Movements;
|
| 3 |
const pathfinder = require("mineflayer-pathfinder").pathfinder;
|
| 4 |
+
const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
|
| 5 |
|
| 6 |
const config = require("./settings.json");
|
| 7 |
|
|
|
|
| 9 |
const logger = loggers.logger;
|
| 10 |
|
| 11 |
function createBot() {
|
| 12 |
+
const bot = mineflayer.createBot({
|
| 13 |
+
username: config["bot-account"]["username"],
|
| 14 |
+
auth: config["bot-account"]["type"],
|
| 15 |
+
host: config.server.ip,
|
| 16 |
+
port: config.server.port,
|
| 17 |
+
version: config.server.version,
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
bot.loadPlugin(pathfinder);
|
| 21 |
+
|
| 22 |
+
// Güvenli "Besleyici" tespiti için yardımcı fonksiyon
|
| 23 |
+
function isBesleyiciEntity(e) {
|
| 24 |
+
try {
|
| 25 |
+
if (!e) return false;
|
| 26 |
+
// displayName objesi varsa toString ile al
|
| 27 |
+
const display = e.displayName && typeof e.displayName.toString === "function"
|
| 28 |
+
? e.displayName.toString()
|
| 29 |
+
: null;
|
| 30 |
+
const name = e.name || display || e.username || "";
|
| 31 |
+
return typeof name === "string" && name.includes("Besleyici ");
|
| 32 |
+
} catch (err) {
|
| 33 |
+
return false;
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// Tek bir tekrar eden görev: her 5 dakika / 2s gibi orijinal mantığı koruyarak
|
| 38 |
+
let besleyiciCheckInterval = null;
|
| 39 |
+
let periodicIsHomeInterval = null;
|
| 40 |
+
|
| 41 |
+
bot.once("spawn", async () => {
|
| 42 |
+
const defaultMove = new Movements(bot);
|
| 43 |
+
bot.pathfinder.setMovements(defaultMove);
|
| 44 |
+
bot.settings.colorsEnabled = false;
|
| 45 |
+
logger.info("Bot sunucuya giriş yaptı.");
|
| 46 |
+
|
| 47 |
+
if (config.utils["auto-auth"].enabled) {
|
| 48 |
+
let password = config.utils["auto-auth"].password;
|
| 49 |
+
setTimeout(() => {
|
| 50 |
+
bot.chat(`/login ${password}`);
|
| 51 |
+
logger.info(`[${config["bot-account"]["username"]}] Login komutu kullanıldı.`);
|
| 52 |
+
}, 500);
|
| 53 |
+
|
| 54 |
+
setTimeout(async () => {
|
| 55 |
+
bot.chat(`/skyblock`);
|
| 56 |
+
logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`);
|
| 57 |
+
}, 5000);
|
| 58 |
+
|
| 59 |
+
setTimeout(async () => {
|
| 60 |
+
bot.chat(`/home`);
|
| 61 |
+
logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
|
| 62 |
+
}, 10000);
|
| 63 |
+
|
| 64 |
+
// Besleyici arama ve işlem mantığını sadeleştiren fonksiyon
|
| 65 |
+
async function tryFindAndActivateBesleyici() {
|
| 66 |
+
try {
|
| 67 |
+
const besleyici = Object.values(bot.entities).find(isBesleyiciEntity);
|
| 68 |
+
if (besleyici) {
|
| 69 |
+
// activateEntityAt çağrısını orijinal kullandığın şekilde bırakıyorum
|
| 70 |
+
bot.activateEntityAt(besleyici, besleyici.position);
|
| 71 |
+
logger.info(`[${config["bot-account"]["username"]}] Besleyici bulundu ve aktive edildi.`);
|
| 72 |
+
// /is home komutunu düzenli at
|
| 73 |
+
if (!periodicIsHomeInterval) {
|
| 74 |
+
periodicIsHomeInterval = setInterval(() => {
|
| 75 |
+
bot.chat(`/is home`);
|
| 76 |
+
}, 5000);
|
| 77 |
+
}
|
| 78 |
+
return true;
|
| 79 |
+
} else {
|
| 80 |
+
return false;
|
| 81 |
+
}
|
| 82 |
+
} catch (err) {
|
| 83 |
+
logger.error(`Besleyici arama sırasında hata: ${err.message}`);
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
|
| 88 |
+
// İlk kontrol: her 5 dakika bir (300000 ms) çalışacak şekilde ayarlandı (orijinal mantık)
|
| 89 |
+
besleyiciCheckInterval = setInterval(async () => {
|
| 90 |
+
const found = await tryFindAndActivateBesleyici();
|
| 91 |
+
if (!found) {
|
| 92 |
+
// Besleyici yoksa önce skyblock sonra home komutlarını sırayla at
|
| 93 |
+
setTimeout(() => {
|
| 94 |
bot.chat(`/skyblock`);
|
| 95 |
+
logger.info(`[${config["bot-account"]["username"]}] Bölgede besleyici minyon bulunamadı. Skyblock'a ışınlanma komutu kullanıldı.`);
|
| 96 |
+
}, 5000);
|
| 97 |
+
|
| 98 |
+
setTimeout(() => {
|
|
|
|
|
|
|
|
|
|
| 99 |
bot.chat(`/home`);
|
| 100 |
+
logger.info(`[${config["bot-account"]["username"]}] Bölgede besleyici minyon bulunamadı. Home konumuna ışınlanma komutu kullanıldı.`);
|
| 101 |
+
}, 10000);
|
| 102 |
+
|
| 103 |
+
// 13s aralıkla tekrar kontrol et (orijinal kodda vardı)
|
| 104 |
+
setTimeout(() => {
|
| 105 |
+
const innerCheck = setInterval(async () => {
|
| 106 |
+
const found2 = await tryFindAndActivateBesleyici();
|
| 107 |
+
if (found2) {
|
| 108 |
+
clearInterval(innerCheck);
|
| 109 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
}, 13000);
|
| 111 |
+
// Eğer uzun süre bulunamazsa innerCheck sonsuza gitmesin istersen burada bir timeout ekleyebilirsin.
|
| 112 |
+
}, 12000);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
// /is home komutunu 16s sonra tekrar at (orijinal mantık)
|
| 115 |
+
setTimeout(() => {
|
| 116 |
+
bot.chat(`/is home`);
|
| 117 |
+
}, 16000);
|
| 118 |
+
}
|
| 119 |
+
}, 300000); // 5 dakika
|
| 120 |
|
| 121 |
+
// İlk küçük bekleme ile hemen bir deneme yap (orijinal kodda 2s içinde kontrol vardı)
|
| 122 |
+
setTimeout(() => {
|
| 123 |
+
tryFindAndActivateBesleyici();
|
| 124 |
+
}, 2000);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
if (config.utils["chat-messages"].enabled) {
|
| 128 |
+
logger.info("Started chat-messages module");
|
| 129 |
+
|
| 130 |
+
let messages = config.utils["chat-messages"]["messages"];
|
| 131 |
+
|
| 132 |
+
if (config.utils["chat-messages"].repeat) {
|
| 133 |
+
let delay = config.utils["chat-messages"]["repeat-delay"];
|
| 134 |
+
let i = 0;
|
| 135 |
+
|
| 136 |
+
setInterval(() => {
|
| 137 |
+
bot.chat(`${messages[i]}`);
|
| 138 |
+
|
| 139 |
+
if (i + 1 === messages.length) {
|
| 140 |
+
i = 0;
|
| 141 |
+
} else i++;
|
| 142 |
+
}, delay * 1000);
|
| 143 |
+
} else {
|
| 144 |
+
messages.forEach((msg) => {
|
| 145 |
+
bot.chat(msg);
|
| 146 |
+
});
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
|
| 150 |
+
const pos = config.position;
|
| 151 |
|
| 152 |
+
if (config.position.enabled) {
|
| 153 |
+
logger.info(
|
| 154 |
+
`Starting moving to target location (${pos.x}, ${pos.y}, ${pos.z})`,
|
| 155 |
+
);
|
| 156 |
+
bot.pathfinder.setGoal(new GoalBlock(pos.x, pos.y, pos.z));
|
| 157 |
+
}
|
| 158 |
|
| 159 |
+
if (config.utils["anti-afk"].enabled) {
|
| 160 |
+
if (config.utils["anti-afk"].sneak) {
|
| 161 |
+
bot.setControlState("sneak", true);
|
| 162 |
+
}
|
| 163 |
|
| 164 |
+
if (config.utils["anti-afk"].jump) {
|
| 165 |
+
bot.setControlState("jump", true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
}
|
| 167 |
|
| 168 |
+
if (config.utils["anti-afk"]["hit"].enabled) {
|
| 169 |
+
let delay = config.utils["anti-afk"]["hit"]["delay"];
|
| 170 |
+
let attackMobs = config.utils["anti-afk"]["hit"]["attack-mobs"];
|
| 171 |
+
|
| 172 |
+
setInterval(() => {
|
| 173 |
+
if (attackMobs) {
|
| 174 |
+
let entity = bot.nearestEntity(
|
| 175 |
+
(e) =>
|
| 176 |
+
e.type !== "object" &&
|
| 177 |
+
e.type !== "player" &&
|
| 178 |
+
e.type !== "global" &&
|
| 179 |
+
e.type !== "orb" &&
|
| 180 |
+
e.type !== "other",
|
| 181 |
+
);
|
| 182 |
+
|
| 183 |
+
if (entity) {
|
| 184 |
+
bot.attack(entity);
|
| 185 |
+
return;
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
bot.swingArm("right", true);
|
| 190 |
+
}, delay);
|
| 191 |
+
}
|
| 192 |
|
| 193 |
+
if (config.utils["anti-afk"].rotate) {
|
| 194 |
+
setInterval(() => {
|
| 195 |
+
bot.look(bot.entity.yaw + 1, bot.entity.pitch, true);
|
| 196 |
+
}, 100);
|
|
|
|
| 197 |
}
|
| 198 |
|
| 199 |
+
if (config.utils["anti-afk"]["circle-walk"].enabled) {
|
| 200 |
+
let radius = config.utils["anti-afk"]["circle-walk"]["radius"];
|
| 201 |
+
setInterval(() => {
|
| 202 |
+
circleWalk(bot, radius);
|
| 203 |
+
}, 30000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
}
|
| 205 |
+
}
|
| 206 |
+
});
|
| 207 |
+
|
| 208 |
+
bot.on('windowOpen', function (window) {
|
| 209 |
+
try {
|
| 210 |
+
if (window.title && window.title.includes("ʙᴇsʟᴇʏiᴄi ᴍiɴʏᴏɴ ᴘᴀɴᴇʟi")) {
|
| 211 |
+
// Besleyici minyon paneli
|
| 212 |
+
const cooked = window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef");
|
| 213 |
+
if (cooked.length > 0) {
|
| 214 |
+
// Orijinal nbt parsing mantığını korudum
|
| 215 |
+
const loreRaw = cooked[0]?.nbt?.value?.display?.value?.Lore?.value?.value[1];
|
| 216 |
+
const parsed = loreRaw ? JSON.parse(loreRaw) : null;
|
| 217 |
+
const extraText = parsed?.extra?.[0]?.text;
|
| 218 |
+
const minyoncani = Number((extraText || "").split("/")[0]);
|
| 219 |
+
if (!isNaN(minyoncani) && minyoncani <= 2) {
|
| 220 |
+
bot.clickWindow(36, 0, 0);
|
| 221 |
logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
|
| 222 |
bot.closeWindow(window);
|
| 223 |
+
} else {
|
| 224 |
+
logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için beslemeye gerek duyulmadı.`);
|
|
|
|
|
|
|
|
|
|
| 225 |
bot.closeWindow(window);
|
| 226 |
+
}
|
| 227 |
+
} else {
|
| 228 |
+
bot.closeWindow(window);
|
| 229 |
+
}
|
| 230 |
+
} else {
|
| 231 |
+
bot.closeWindow(window);
|
| 232 |
}
|
| 233 |
+
} catch (err) {
|
| 234 |
+
logger.error(`windowOpen işlenirken hata: ${err.message}`);
|
| 235 |
+
try { bot.closeWindow(window); } catch {}
|
| 236 |
+
}
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
bot.on("chat", (username, message) => {
|
| 240 |
+
if (config.utils["chat-log"]) {
|
| 241 |
+
logger.info(`<${username}> ${message}`);
|
| 242 |
+
}
|
| 243 |
+
});
|
| 244 |
+
|
| 245 |
+
bot.on("goal_reached", () => {
|
| 246 |
+
if (config.position.enabled) {
|
| 247 |
+
logger.info(`Bot arrived to target location. ${bot.entity.position}`);
|
| 248 |
+
}
|
| 249 |
+
});
|
| 250 |
+
|
| 251 |
+
bot.on("death", () => {
|
| 252 |
+
logger.warn(
|
| 253 |
+
`Bot has been died and was respawned at ${bot.entity.position}`,
|
| 254 |
+
);
|
| 255 |
+
});
|
| 256 |
+
|
| 257 |
+
if (config.utils["auto-reconnect"]) {
|
| 258 |
+
bot.on("end", () => {
|
| 259 |
+
// Temizleme: interval'leri kapat
|
| 260 |
+
try {
|
| 261 |
+
if (besleyiciCheckInterval) clearInterval(besleyiciCheckInterval);
|
| 262 |
+
if (periodicIsHomeInterval) clearInterval(periodicIsHomeInterval);
|
| 263 |
+
} catch (e) {}
|
| 264 |
+
setTimeout(() => {
|
| 265 |
+
createBot();
|
| 266 |
+
}, config.utils["auto-reconnect-delay"]);
|
| 267 |
});
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
bot.on("kicked", (reason) => {
|
| 271 |
+
let reasonText = "";
|
| 272 |
+
try {
|
| 273 |
+
const parsed = JSON.parse(reason);
|
| 274 |
+
reasonText = parsed.text || parsed.extra?.[0]?.text || "";
|
| 275 |
+
reasonText = reasonText?.replace(/§./g, "");
|
| 276 |
+
logger.warn(`Bot sunucudan atıldı. Sebep: ${reasonText}`);
|
| 277 |
+
} catch {
|
| 278 |
+
logger.warn(`Bot sunucudan atıldı. Sebep: Bulunamadı.`);
|
| 279 |
+
}
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
bot.on("error", (err) => logger.error(`${err.message}`));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
}
|
| 284 |
|
|
|
|
| 285 |
function circleWalk(bot, radius) {
|
| 286 |
+
// Make bot walk in square with center in bot's current position without stopping
|
| 287 |
+
return new Promise(() => {
|
| 288 |
+
const pos = bot.entity.position;
|
| 289 |
+
const x = pos.x;
|
| 290 |
+
const y = pos.y;
|
| 291 |
+
const z = pos.z;
|
| 292 |
+
|
| 293 |
+
const points = [
|
| 294 |
+
[x + radius, y, z],
|
| 295 |
+
[x, y, z + radius],
|
| 296 |
+
[x - radius, y, z],
|
| 297 |
+
[x, y, z - radius],
|
| 298 |
+
];
|
| 299 |
+
|
| 300 |
+
let i = 0;
|
| 301 |
+
setTimeout(() => {
|
| 302 |
+
if (i === points.length) i = 0;
|
| 303 |
+
const defaultMove = new Movements(bot);
|
| 304 |
+
bot.pathfinder.setMovements(defaultMove);
|
| 305 |
+
bot.pathfinder.setGoal(new GoalXZ(points[i][0], points[i][2]));
|
| 306 |
+
i++;
|
| 307 |
+
}, 1000);
|
| 308 |
+
});
|
| 309 |
}
|
| 310 |
|
| 311 |
createBot();
|
|
|
|
| 317 |
app.get("/", (req, res) => res.send("Pinglendi")); //değiştirebilirsiniz.
|
| 318 |
|
| 319 |
app.listen(
|
| 320 |
+
port,
|
| 321 |
+
() =>
|
| 322 |
+
console.log(`Bot bu adres üzerinde çalışıyor: http://localhost:${port}`), //port
|
| 323 |
);
|
| 324 |
|
| 325 |
process.on('uncaughtException', function (err) {
|
| 326 |
+
console.error("Hata aldım!");
|
| 327 |
+
console.log(err);
|
| 328 |
+
});
|