Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -1,240 +1,242 @@
|
|
| 1 |
-
const mineflayer = require("mineflayer");
|
| 2 |
-
const Movements = require("mineflayer-pathfinder").Movements;
|
| 3 |
-
const pathfinder = require("mineflayer-pathfinder").pathfinder;
|
| 4 |
-
const { GoalBlock, GoalXZ, GoalNear } = require("mineflayer-pathfinder").goals;
|
| 5 |
-
|
| 6 |
-
const config = require("./settings.json");
|
| 7 |
-
|
| 8 |
-
const loggers = require("./logging.js");
|
| 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 |
-
bot.once("spawn", async() => {
|
| 23 |
-
const defaultMove = new Movements(bot);
|
| 24 |
-
bot.pathfinder.setMovements(defaultMove);
|
| 25 |
-
bot.settings.colorsEnabled = false;
|
| 26 |
-
logger.info("Bot sunucuya giriş yaptı.");
|
| 27 |
-
|
| 28 |
-
if (config.utils["auto-auth"].enabled) {
|
| 29 |
-
|
| 30 |
-
let password = config.utils["auto-auth"].password;
|
| 31 |
-
setTimeout(() => {
|
| 32 |
-
bot.chat(`/login ${password}`);
|
| 33 |
-
logger.info(`[${config["bot-account"]["username"]}] Login komutu kullanıldı.`);
|
| 34 |
-
}, 500);
|
| 35 |
-
|
| 36 |
-
setTimeout(async () => {
|
| 37 |
-
bot.chat(`/skyblock`);
|
| 38 |
-
logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`);
|
| 39 |
-
}, 5000);
|
| 40 |
-
setTimeout(async () => {
|
| 41 |
-
bot.chat(`/home`);
|
| 42 |
-
logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
|
| 43 |
-
}, 10000);
|
| 44 |
-
setInterval(async () => {
|
| 45 |
-
if(Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("ʙᴇsʟᴇʏiᴄi ")).length > 0){
|
| 46 |
-
bot.activateEntityAt(bot.entities[Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("ʙᴇsʟᴇʏiᴄi "))[0]], bot.entities[Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("ʙᴇsʟᴇʏiᴄi "))[0]].position)
|
| 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 |
-
e.type !== "
|
| 104 |
-
e.type !== "
|
| 105 |
-
e.type !== "
|
| 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 |
-
if(
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
bot.
|
| 142 |
-
|
| 143 |
-
bot.closeWindow(window);
|
| 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 |
-
logger.warn(`Bot sunucudan atıldı.Sebep:
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
const
|
| 203 |
-
const
|
| 204 |
-
|
| 205 |
-
const
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
[x
|
| 209 |
-
[x, y, z
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
const
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
app.
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
)
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
| 240 |
})
|
|
|
|
| 1 |
+
const mineflayer = require("mineflayer");
|
| 2 |
+
const Movements = require("mineflayer-pathfinder").Movements;
|
| 3 |
+
const pathfinder = require("mineflayer-pathfinder").pathfinder;
|
| 4 |
+
const { GoalBlock, GoalXZ, GoalNear } = require("mineflayer-pathfinder").goals;
|
| 5 |
+
|
| 6 |
+
const config = require("./settings.json");
|
| 7 |
+
|
| 8 |
+
const loggers = require("./logging.js");
|
| 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 |
+
bot.once("spawn", async() => {
|
| 23 |
+
const defaultMove = new Movements(bot);
|
| 24 |
+
bot.pathfinder.setMovements(defaultMove);
|
| 25 |
+
bot.settings.colorsEnabled = false;
|
| 26 |
+
logger.info("Bot sunucuya giriş yaptı.");
|
| 27 |
+
|
| 28 |
+
if (config.utils["auto-auth"].enabled) {
|
| 29 |
+
|
| 30 |
+
let password = config.utils["auto-auth"].password;
|
| 31 |
+
setTimeout(() => {
|
| 32 |
+
bot.chat(`/login ${password}`);
|
| 33 |
+
logger.info(`[${config["bot-account"]["username"]}] Login komutu kullanıldı.`);
|
| 34 |
+
}, 500);
|
| 35 |
+
|
| 36 |
+
setTimeout(async () => {
|
| 37 |
+
bot.chat(`/skyblock`);
|
| 38 |
+
logger.info(`[${config["bot-account"]["username"]}] Skyblock'a ışınlanma komutu kullanıldı.`);
|
| 39 |
+
}, 5000);
|
| 40 |
+
setTimeout(async () => {
|
| 41 |
+
bot.chat(`/home`);
|
| 42 |
+
logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
|
| 43 |
+
}, 10000);
|
| 44 |
+
setInterval(async () => {
|
| 45 |
+
if(Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("ʙᴇsʟᴇʏiᴄi ")).length > 0){
|
| 46 |
+
bot.activateEntityAt(bot.entities[Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("ʙᴇsʟᴇʏiᴄi "))[0]], bot.entities[Object.keys(bot.entities).filter(ff => JSON.stringify(bot.entities[ff]).includes("ʙᴇsʟᴇʏiᴄi "))[0]].position)
|
| 47 |
+
}else{
|
| 48 |
+
console.log("Bölgemde besleyici minyon yok.")
|
| 49 |
+
};
|
| 50 |
+
}, 30000);
|
| 51 |
+
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (config.utils["chat-messages"].enabled) {
|
| 55 |
+
logger.info("Started chat-messages module");
|
| 56 |
+
|
| 57 |
+
let messages = config.utils["chat-messages"]["messages"];
|
| 58 |
+
|
| 59 |
+
if (config.utils["chat-messages"].repeat) {
|
| 60 |
+
let delay = config.utils["chat-messages"]["repeat-delay"];
|
| 61 |
+
let i = 0;
|
| 62 |
+
|
| 63 |
+
setInterval(() => {
|
| 64 |
+
bot.chat(`${messages[i]}`);
|
| 65 |
+
|
| 66 |
+
if (i + 1 === messages.length) {
|
| 67 |
+
i = 0;
|
| 68 |
+
} else i++;
|
| 69 |
+
}, delay * 1000);
|
| 70 |
+
} else {
|
| 71 |
+
messages.forEach((msg) => {
|
| 72 |
+
bot.chat(msg);
|
| 73 |
+
});
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
const pos = config.position;
|
| 78 |
+
|
| 79 |
+
if (config.position.enabled) {
|
| 80 |
+
logger.info(
|
| 81 |
+
`Starting moving to target location (${pos.x}, ${pos.y}, ${pos.z})`,
|
| 82 |
+
);
|
| 83 |
+
bot.pathfinder.setGoal(new GoalBlock(pos.x, pos.y, pos.z));
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if (config.utils["anti-afk"].enabled) {
|
| 87 |
+
if (config.utils["anti-afk"].sneak) {
|
| 88 |
+
bot.setControlState("sneak", true);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if (config.utils["anti-afk"].jump) {
|
| 92 |
+
bot.setControlState("jump", true);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if (config.utils["anti-afk"]["hit"].enabled) {
|
| 96 |
+
let delay = config.utils["anti-afk"]["hit"]["delay"];
|
| 97 |
+
let attackMobs = config.utils["anti-afk"]["hit"]["attack-mobs"];
|
| 98 |
+
|
| 99 |
+
setInterval(() => {
|
| 100 |
+
if (attackMobs) {
|
| 101 |
+
let entity = bot.nearestEntity(
|
| 102 |
+
(e) =>
|
| 103 |
+
e.type !== "object" &&
|
| 104 |
+
e.type !== "player" &&
|
| 105 |
+
e.type !== "global" &&
|
| 106 |
+
e.type !== "orb" &&
|
| 107 |
+
e.type !== "other",
|
| 108 |
+
);
|
| 109 |
+
|
| 110 |
+
if (entity) {
|
| 111 |
+
bot.attack(entity);
|
| 112 |
+
return;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
bot.swingArm("right", true);
|
| 117 |
+
}, delay);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if (config.utils["anti-afk"].rotate) {
|
| 121 |
+
setInterval(() => {
|
| 122 |
+
bot.look(bot.entity.yaw + 1, bot.entity.pitch, true);
|
| 123 |
+
}, 100);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
if (config.utils["anti-afk"]["circle-walk"].enabled) {
|
| 127 |
+
let radius = config.utils["anti-afk"]["circle-walk"]["radius"];
|
| 128 |
+
setInterval(() => {
|
| 129 |
+
circleWalk(bot, radius);
|
| 130 |
+
}, 30000);
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
});
|
| 134 |
+
|
| 135 |
+
bot.on('windowOpen', function (window) {
|
| 136 |
+
if(window.title.includes("ʙᴇsʟᴇʏiᴄi ᴍiɴʏᴏɴ ᴘᴀɴᴇʟi")){
|
| 137 |
+
//Besleyici minyon paneli
|
| 138 |
+
if(window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef").length > 0){
|
| 139 |
+
var minyoncani = Number((JSON.parse(window.slots.filter(xx => xx?.name && xx?.name == "cooked_beef")[0]?.nbt?.value?.display?.value?.Lore?.value?.value[1])?.extra[0].text).split("/")[0]);
|
| 140 |
+
if(minyoncani <= 2){
|
| 141 |
+
bot.clickWindow(36,0,0);
|
| 142 |
+
logger.info(`[${config["bot-account"]["username"]}] Minyon canı ${minyoncani} olduğu için besleyici minyon beslendi.`);
|
| 143 |
+
bot.closeWindow(window);
|
| 144 |
+
}else{
|
| 145 |
+
bot.closeWindow(window);
|
| 146 |
+
}
|
| 147 |
+
}else{
|
| 148 |
+
bot.closeWindow(window);
|
| 149 |
+
}
|
| 150 |
+
}else{
|
| 151 |
+
bot.closeWindow(window);
|
| 152 |
+
}
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
bot.on("chat", (username, message) => {
|
| 156 |
+
if (config.utils["chat-log"]) {
|
| 157 |
+
logger.info(`<${username}> ${message}`);
|
| 158 |
+
}
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
+
bot.on("goal_reached", () => {
|
| 162 |
+
if (config.position.enabled) {
|
| 163 |
+
logger.info(`Bot arrived to target location. ${bot.entity.position}`);
|
| 164 |
+
}
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
bot.on("death", () => {
|
| 168 |
+
logger.warn(
|
| 169 |
+
`Bot has been died and was respawned at ${bot.entity.position}`,
|
| 170 |
+
);
|
| 171 |
+
});
|
| 172 |
+
|
| 173 |
+
if (config.utils["auto-reconnect"]) {
|
| 174 |
+
bot.on("end", () => {
|
| 175 |
+
setTimeout(() => {
|
| 176 |
+
createBot();
|
| 177 |
+
}, config.utils["auto-reconnect-delay"]);
|
| 178 |
+
});
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
bot.on("kicked", (reason) => {
|
| 182 |
+
let reasonText = JSON.parse(reason).text;
|
| 183 |
+
if (reasonText === "") {
|
| 184 |
+
reasonText = JSON.parse(reason).extra[0].text;
|
| 185 |
+
}
|
| 186 |
+
try{
|
| 187 |
+
reasonText = reasonText?.replace(/§./g, "");
|
| 188 |
+
logger.warn(`Bot sunucudan atıldı.Sebep: ${reasonText}`);
|
| 189 |
+
}catch{
|
| 190 |
+
logger.warn(`Bot sunucudan atıldı.Sebep: Bulunamadı.`);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
bot.on("error", (err) => logger.error(`${err.message}`));
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
function circleWalk(bot, radius) {
|
| 200 |
+
// Make bot walk in square with center in bot's wthout stopping
|
| 201 |
+
return new Promise(() => {
|
| 202 |
+
const pos = bot.entity.position;
|
| 203 |
+
const x = pos.x;
|
| 204 |
+
const y = pos.y;
|
| 205 |
+
const z = pos.z;
|
| 206 |
+
|
| 207 |
+
const points = [
|
| 208 |
+
[x + radius, y, z],
|
| 209 |
+
[x, y, z + radius],
|
| 210 |
+
[x - radius, y, z],
|
| 211 |
+
[x, y, z - radius],
|
| 212 |
+
];
|
| 213 |
+
|
| 214 |
+
let i = 0;
|
| 215 |
+
setTimeout(() => {
|
| 216 |
+
if (i === points.length) i = 0;
|
| 217 |
+
const defaultMove = new Movements(bot);
|
| 218 |
+
bot.pathfinder.setMovements(defaultMove);
|
| 219 |
+
bot.pathfinder.setGoal(new GoalXZ(points[i][0], points[i][2]));
|
| 220 |
+
i++;
|
| 221 |
+
}, 1000);
|
| 222 |
+
});
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
createBot();
|
| 226 |
+
|
| 227 |
+
const express = require("express");
|
| 228 |
+
const app = express();
|
| 229 |
+
const port = process.env.PORT || 7860; //buraya karışmayın.
|
| 230 |
+
|
| 231 |
+
app.get("/", (req, res) => res.send("Pinglendi")); //değiştirebilirsiniz.
|
| 232 |
+
|
| 233 |
+
app.listen(
|
| 234 |
+
port,
|
| 235 |
+
() =>
|
| 236 |
+
console.log(`Bot bu adres üzerinde çalışıyor: http://localhost:${port}`), //port
|
| 237 |
+
);
|
| 238 |
+
|
| 239 |
+
process.on('uncaughtException', function (err) {
|
| 240 |
+
console.error("Hata aldım!");
|
| 241 |
+
console.log(err)
|
| 242 |
})
|