Suvarii commited on
Commit
ba3eee4
·
verified ·
1 Parent(s): 0c73648

Update bot.js

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