Spaces:
Paused
Paused
Download bot.js from AiTestTeamXx/Curst: direct link, hf CLI and curl.
- Browser
- Download file 11.1 kB
-
https://huggingface.co/spaces/AiTestTeamXx/Curst/resolve/82dafb33ea2da5c19ed1b45528c3c4c19ad5b8d0/bot.js
- Command line
-
hf download hf://spaces/AiTestTeamXx/Curst@82dafb33ea2da5c19ed1b45528c3c4c19ad5b8d0/bot.js
-
curl -L -o bot.js https://huggingface.co/spaces/AiTestTeamXx/Curst/resolve/82dafb33ea2da5c19ed1b45528c3c4c19ad5b8d0/bot.js
11.1 kB
| const mineflayer = require("mineflayer"); | |
| const Movements = require("mineflayer-pathfinder").Movements; | |
| const pathfinder = require("mineflayer-pathfinder").pathfinder; | |
| const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals; | |
| const util = require("util"); | |
| const config = require("./settings.json"); | |
| const loggers = require("./logging.js"); | |
| const logger = loggers.logger; | |
| // --- AYARLAR --- | |
| const HOME_ARRIVAL_DELAY_MS = 2000; | |
| const POST_ACTION_DELAY_MS = 4000; | |
| const WINDOW_OPEN_TIMEOUT_MS = 6000; | |
| const PERIODIC_CHECK_INTERVAL_MS = 10 * 60 * 1000; | |
| const FULL_FEED_COOLDOWN_MS = 50 * 60 * 1000; | |
| const GO_HOME_COMMAND = "/home"; | |
| const RETURN_ISLAND_COMMAND = "/is home"; | |
| const BESLEYICI_NAMES = (config.utils && config.utils["besleyici-names"]) || ["Besleyici", "ʙᴇsʟᴇʏiᴄi"]; | |
| function createBot() { | |
| const bot = mineflayer.createBot({ | |
| username: config["bot-account"]["username"], | |
| auth: config["bot-account"]["type"], | |
| host: config.server.ip, | |
| port: config.server.port, | |
| version: config.server.version, | |
| brand: 'vanilla', | |
| }); | |
| bot.loadPlugin(pathfinder); | |
| // --- SADECE TİMİNG SIFIRLAMA İÇİN EKLENEN KISIM --- | |
| let lastFullFeedAt = 0; | |
| let windowOpenResolvers = []; | |
| let periodicHandle = null; | |
| let activeTimeouts = []; | |
| function setSafeTimeout(fn, delay) { | |
| const t = setTimeout(fn, delay); | |
| activeTimeouts.push(t); | |
| return t; | |
| } | |
| function stopPeriodicHomeChecks() { | |
| if (periodicHandle) clearInterval(periodicHandle); | |
| periodicHandle = null; | |
| activeTimeouts.forEach(t => clearTimeout(t)); | |
| activeTimeouts = []; | |
| } | |
| // ------------------------------------------------ | |
| // --- SENİN ORİJİNAL FONKSİYONLARIN (TAMAMEN AYNI) --- | |
| function stripColorCodes(s) { | |
| if (!s || typeof s !== "string") return s; | |
| return s.replace(/§[0-9a-fk-or]/gi, ""); | |
| } | |
| function safeDisplayNameToString(e) { | |
| try { | |
| if (e && e.displayName && typeof e.displayName.toString === "function") { | |
| return e.displayName.toString(); | |
| } | |
| } catch (err) {} | |
| return null; | |
| } | |
| function getEntityReadableName(e) { | |
| if (!e) return ""; | |
| const disp = safeDisplayNameToString(e); | |
| if (disp) return stripColorCodes(disp); | |
| if (e.name && typeof e.name === "string") return stripColorCodes(e.name); | |
| if (e.username && typeof e.username === "string") return stripColorCodes(e.username); | |
| return ""; | |
| } | |
| function normalizeForMatch(s) { | |
| if (!s || typeof s !== "string") return ""; | |
| let t = stripColorCodes(s); | |
| if (t.normalize) t = t.normalize("NFKD").replace(/[\u0300-\u036f]/g, ""); | |
| return t.toLowerCase(); | |
| } | |
| const TARGET_NAME_NORMS = BESLEYICI_NAMES.map(n => normalizeForMatch(n)); | |
| function isBesleyiciName(name) { | |
| if (!name) return false; | |
| const norm = normalizeForMatch(name); | |
| return TARGET_NAME_NORMS.some(t => norm.includes(t)); | |
| } | |
| function safeGet(obj, pathArray) { | |
| try { | |
| let cur = obj; | |
| for (const p of pathArray) { | |
| if (cur == null) return undefined; | |
| cur = cur[p]; | |
| } | |
| return cur; | |
| } catch (e) { return undefined; } | |
| } | |
| function deepSearchForString(root, targetLower) { | |
| const results = []; | |
| const visited = new WeakSet(); | |
| function recurse(obj, path) { | |
| if (obj == null || typeof obj === "function") return; | |
| if (typeof obj === "string") { | |
| const norm = normalizeForMatch(obj); | |
| if (norm.includes(targetLower)) results.push({ path, value: obj }); | |
| return; | |
| } | |
| if (typeof obj !== "object") return; | |
| if (visited.has(obj)) return; | |
| visited.add(obj); | |
| for (const key of Object.keys(obj)) { | |
| recurse(obj[key], `${path}.${key}`); | |
| } | |
| } | |
| try { recurse(root, "root"); } catch (e) {} | |
| return results; | |
| } | |
| function parseWindowTitleToString(titleObj) { | |
| try { | |
| if (!titleObj) return ""; | |
| if (typeof titleObj === "string") return titleObj; | |
| const s = titleObj.toString(); | |
| if (s && s !== "[object Object]") return s; | |
| return JSON.stringify(titleObj); | |
| } catch (err) { return ""; } | |
| } | |
| function extractMinyonCanFromSlot(slot) { | |
| try { | |
| if (!slot) return null; | |
| function tryParseLoreText(text) { | |
| try { | |
| if (!text || typeof text !== "string") return null; | |
| let plain = text; | |
| try { | |
| const maybe = JSON.parse(text); | |
| if (maybe && typeof maybe === "object") { | |
| if (maybe.extra && Array.isArray(maybe.extra) && maybe.extra.length > 0) { | |
| if (typeof maybe.extra[0].text === "string") plain = maybe.extra[0].text; | |
| } else if (typeof maybe.text === "string") { | |
| plain = maybe.text; | |
| } | |
| } | |
| } catch (e) {} | |
| const xyMatch = plain.match(/(\d{1,4})\s*\/\s*(\d{1,4})/); | |
| if (xyMatch) return Number(xyMatch[1]); | |
| const numMatch = plain.match(/(\d{1,4})/); | |
| if (numMatch) return Number(numMatch[1]); | |
| return null; | |
| } catch (e) { return null; } | |
| } | |
| if (slot.nbt) { | |
| const lore = safeGet(slot.nbt, ["value", "display", "value", "Lore", "value"]); | |
| if (Array.isArray(lore)) { | |
| for (const line of lore) { | |
| const res = tryParseLoreText(line.value || line); | |
| if (res != null) return res; | |
| } | |
| } | |
| } | |
| const full = util.inspect(slot, { depth: null }); | |
| return tryParseLoreText(full); | |
| } catch (err) { return null; } | |
| } | |
| async function goHome() { | |
| logger.info(`[${config["bot-account"]["username"]}] ${GO_HOME_COMMAND} komutu gönderiliyor.`); | |
| bot.chat(GO_HOME_COMMAND); | |
| } | |
| async function returnIsland() { | |
| logger.info(`[${config["bot-account"]["username"]}] ${RETURN_ISLAND_COMMAND} komutu gönderiliyor.`); | |
| bot.chat(RETURN_ISLAND_COMMAND); | |
| } | |
| async function scanAndFeed() { | |
| if (Date.now() < (lastFullFeedAt + FULL_FEED_COOLDOWN_MS)) return; | |
| const arr = Object.values(bot.entities); | |
| let best = null; | |
| for (const e of arr) { | |
| const name = getEntityReadableName(e); | |
| if (isBesleyiciName(name)) { | |
| best = { entity: e, path: "displayName/name" }; | |
| break; | |
| } | |
| for (const target of TARGET_NAME_NORMS) { | |
| const deep = deepSearchForString(e, target); | |
| if (deep.length > 0) { | |
| best = { entity: e, path: deep[0].path }; | |
| break; | |
| } | |
| } | |
| if (best) break; | |
| } | |
| if (!best) { | |
| logger.info(`[${config["bot-account"]["username"]}] /home sonrası tarama: besleyici minyon bulunamadı.`); | |
| return; | |
| } | |
| const dist = bot.entity.position.distanceTo(best.entity.position); | |
| // SENİN LOGUN: 'Armor Stand' bulundu id:... | |
| logger.info(`[${config["bot-account"]["username"]}] '${best.entity.name || 'Armor Stand'}' bulundu id:${best.entity.id} path:${best.path} dist:${dist.toFixed(2)} — aktive ediliyor.`); | |
| if (dist > 7) { | |
| logger.warn(`safeActivateEntityPreferAt: entity id:${best.entity.id} uzak (${dist.toFixed(2)}). Max 7 blok.`); | |
| logger.warn(`[${config["bot-account"]["username"]}] 'Besleyici' aktive edilemedi (id:${best.entity.id}).`); | |
| return; | |
| } | |
| try { | |
| if (bot.lookAt) await bot.lookAt(best.entity.position.offset(0, 1.0, 0), true); | |
| await new Promise(r => setTimeout(r, 200)); | |
| logger.info(`activateEntityAt çağrıldı id:${best.entity.id}`); | |
| if (typeof bot.activateEntityAt === "function") bot.activateEntityAt(best.entity, best.entity.position); | |
| else if (typeof bot.activateEntity === "function") bot.activateEntity(best.entity); | |
| await new Promise((resolve) => { | |
| const timer = setTimeout(() => resolve(), WINDOW_OPEN_TIMEOUT_MS); | |
| windowOpenResolvers.push(() => { clearTimeout(timer); resolve(); }); | |
| }); | |
| } catch (err) {} | |
| } | |
| bot.once("spawn", async () => { | |
| bot.pathfinder.setMovements(new Movements(bot)); | |
| logger.info("Bot sunucuya giriş yaptı."); | |
| if (config.utils && config.utils["auto-auth"] && config.utils["auto-auth"].enabled) { | |
| const password = config.utils["auto-auth"].password; | |
| setSafeTimeout(() => { | |
| bot.chat(`/login ${password}`); | |
| logger.info(`[${config["bot-account"]["username"]}] Login komutu kullanıldı.`); | |
| }, 2500); | |
| setSafeTimeout(() => { | |
| bot.chat(`/skyblock`); | |
| logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`); | |
| }, 7500); | |
| setSafeTimeout(async () => { | |
| await goHome(); | |
| await new Promise(r => setTimeout(r, HOME_ARRIVAL_DELAY_MS)); | |
| await scanAndFeed(); | |
| await new Promise(r => setTimeout(r, POST_ACTION_DELAY_MS)); | |
| await returnIsland(); | |
| periodicHandle = setInterval(async () => { | |
| if (Date.now() < (lastFullFeedAt + FULL_FEED_COOLDOWN_MS)) return; | |
| await goHome(); | |
| await new Promise(r => setTimeout(r, HOME_ARRIVAL_DELAY_MS)); | |
| await scanAndFeed(); | |
| await new Promise(r => setTimeout(r, POST_ACTION_DELAY_MS)); | |
| await returnIsland(); | |
| }, PERIODIC_CHECK_INTERVAL_MS); | |
| }, 12500); | |
| } | |
| }); | |
| bot.on("windowOpen", (window) => { | |
| const title = parseWindowTitleToString(window.title).toLowerCase(); | |
| if (!title.includes("besleyici") && !parseWindowTitleToString(window.title).includes("ʙᴇsʟᴇʏiᴄi")) { | |
| logger.info(`[${config["bot-account"]["username"]}] Bi chest açıldı ama window title ı uyuşmadığı için kapatıldı. ${parseWindowTitleToString(window.title)}`); | |
| bot.closeWindow(window); | |
| return; | |
| } | |
| const beefSlot = window.slots.find(s => s?.name === "cooked_beef"); | |
| const can = extractMinyonCanFromSlot(beefSlot); | |
| if (can != null) { | |
| if (can <= 2) { | |
| bot.clickWindow(36, 0, 0); | |
| lastFullFeedAt = Date.now(); | |
| logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${can} olduğu için beslendi. 50dk bekleme aktif.`); | |
| } else if (can >= 10) { | |
| lastFullFeedAt = Date.now(); | |
| logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${can} (tam). 50dk bekleme aktif.`); | |
| } else { | |
| logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${can} olduğu için yenilenmedi.`); | |
| } | |
| } | |
| setSafeTimeout(() => { try { bot.closeWindow(window); } catch(e){} }, 500); | |
| while (windowOpenResolvers.length > 0) windowOpenResolvers.shift()(); | |
| }); | |
| bot.on("end", () => { | |
| logger.warn("Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor..."); | |
| stopPeriodicHomeChecks(); | |
| if (config.utils && config.utils["auto-reconnect"]) { | |
| setTimeout(() => createBot(), config.utils["auto-reconnect-delay"]); | |
| } | |
| }); | |
| bot.on("kicked", (reason) => logger.warn(`Bot sunucudan atıldı: ${util.inspect(reason)}`)); | |
| bot.on("error", (err) => logger.error(`${err}`)); | |
| } | |
| createBot(); | |
| const express = require("express"); | |
| const app = express(); | |
| app.get("/", (req, res) => res.send("Bot Aktif")); | |
| app.listen(process.env.PORT || 7860); |