From 930c82c95ca5b3c570e0657f2fafc1d5260a6958 Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Wed, 27 Sep 2023 18:44:04 +0530 Subject: [PATCH] Bot Improvements --- config.json | 2 +- index.js | 50 +++++++++++++++++++------ install.bat | 28 +++++++------- package-lock.json | 94 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 5 files changed, 151 insertions(+), 26 deletions(-) diff --git a/config.json b/config.json index 7c70eb4..526103c 100644 --- a/config.json +++ b/config.json @@ -35,5 +35,5 @@ "Test 4 " ] }, -"webhookUrl": "https://discord.com/api/webhooks/1154108207929757747/qSDcSAzxhFxClz3GwyAy1UiUDe8OZP4F8vieomaUApSx-rbYiHN3HtBnLVsZiMMCGQp6" +"webhookUrl":"webhookURL" } \ No newline at end of file diff --git a/index.js b/index.js index 1cc17bc..27589b2 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,13 @@ let mineflayer = require('mineflayer'); const axios = require('axios'); const fs = require('fs'); const pathfinder = require('mineflayer-pathfinder').pathfinder; +const Movements = require('mineflayer-pathfinder').Movements const express = require('express'); const WebSocket = require('ws'); const mineflayerViewer = require('prismarine-viewer').mineflayer; const imagePath = './image/Imperials.png'; // Path to your image +const pvp = require('mineflayer-pvp').plugin; +const { GoalNear } = require('mineflayer-pathfinder').goals // Read the image file and convert it to base64 const image = fs.readFileSync(imagePath); @@ -26,7 +29,7 @@ const blacklisted = config.blacklist; const port = config.port; let server; -let chatLog = []; +let chatLog = new Set(); let antiafk = config.antiafk; let bot; let spamming = false; @@ -75,10 +78,11 @@ const main = () => { `; sendWebhookMessage(webhookUrl, imperialsText); sendWebhookMessage(webhookUrl, '‏'); - bot.setMaxListeners(21); - + bot.setMaxListeners(1000); + bot.loadPlugin(pathfinder); - + bot.loadPlugin(pvp); + const mcData = require('minecraft-data')(bot.version); bot.once("login", async () => { sendWebhookMessage(webhookUrl, `> ### *[${username}]* joined ${serverIP}`); @@ -104,8 +108,13 @@ const main = () => { bot.viewer.drawLine('path', path) } }) + bot.waitForTicks(50); + bot.chat('/register ' + password); + bot.waitForTicks(50); + bot.chat("/login " + config.password); bot.chat('hello'); }) + const defaultMove = new Movements(bot) // Event listener for incoming chat messages bot.on('chat', (username, message) => { @@ -166,11 +175,12 @@ const main = () => { bot.attack(bot.targetEntity, true); } bot.targetEntity = entity; - bot.attack(bot.targetEntity, true); + bot.pvp.attack(bot.targetEntity); } } } else if (bot.targetEntity) { sendWSmessage('Lost sight of ' + bot.targetEntity.type); + bot.pvp.stop() bot.targetEntity = null; } } @@ -264,7 +274,7 @@ const main = () => { } sendWebhookMessage(webhookUrl, `## THE BOT HAS DIED`) }); - +localhostApp(); }; function generateRandomString(length) { @@ -333,35 +343,52 @@ function killMyself(){ bot.activateItem(); }); } else { - sendWebhookMessage(webhookUrl, '> [BOT] I dont have a flint and steel to kill myself'); - sendWSmessage(`[BOT] I dont have a flint and steel to kill myself`); - } + sendWebhookMessage(webhookUrl, '> [BOT] I dont have a flint and steel to kill myself. Trying using lava'); + sendWSmessage(`[BOT] I dont have a flint and steel to kill myself. Trying using lava`); + const lavaBlock = bot.findBlock({ + matching: block => block.name === 'lava', + maxDistance: 512, + }); + if (lavaBlock) { + bot.pathfinder.setMovements(defaultMove); + const p = lavaBlock.position; + bot.pathfinder.setGoal(new GoalNear(p.x, p.y, p.z, 512)) + } else { + sendWebhookMessage('No nearby lava blocks found.'); + sendWSmessage('No nearby lava blocks found.'); + } +} } function sendWSmessage(messageWS){ connections.forEach(ws => { if (ws.readyState === ws.OPEN) { + chatLog.add(String(messageWS)); ws.send(String(messageWS)); } }); } main(); +function localhostApp(){ wss.on('connection', ws => { connections.push(ws); + ws.send(String(Array.from(chatLog).join('\n'))); ws.on('close', () => { // Remove closed connections from the list - sendWebhookMessage(webhookUrl, 'WebSocket Connection closed'); connections = connections.filter(conn => conn !== ws); }); bot.on('chat', (username, message) => { + chatLog.add(`[${username}] ${message}`); ws.send(`[${username}] ${message}`); }); bot.on("death", (err) => { + chatLog.add(`THE BOT HAS DIED`); ws.send(`THE BOT HAS DIED`); }); bot.on('whisper', (username, message) => { + chatLog.add(`[WHISPER] ${username} whispers: ` + message); ws.send(`[WHISPER] ${username} whispers: ` + message); }) }); @@ -768,4 +795,5 @@ app.get('/spam', (req, res) => { } sendWSmessage(`Spamming: ` + spamming); res.send(`Spamming: ` + spamming); -}); \ No newline at end of file +}); +} \ No newline at end of file diff --git a/install.bat b/install.bat index 1d2d3f6..ec31dac 100644 --- a/install.bat +++ b/install.bat @@ -1,16 +1,18 @@ -@echo off -@echo Installing mineflayer.... +@echo off +@echo Installing dependencies npm install mineflayer -@echo Installing axios.... -npm install axios -@echo Installing fs.... -npm install fs -@echo Installing mineflayer-pathfinder..... -npm install mineflayer-pathfinder -@echo Installing express..... -npm install express -@echo Installing ws.... -npm install ws -@echo Installing prismarine viewer.... +pause +npm install axios +pause +npm install fs +pause +npm install mineflayer-pathfinder +pause +npm install mineflayer-pvp +pause +npm install express +pause +npm install ws +pause npm install prismarine-viewer pause diff --git a/package-lock.json b/package-lock.json index 14cf3cc..758b764 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "fs": "^0.0.1-security", "mineflayer": "^4.14.0", "mineflayer-pathfinder": "^2.4.5", + "mineflayer-pvp": "^1.3.2", "prismarine-viewer": "^1.25.0", "ws": "^8.14.2" } @@ -1316,6 +1317,79 @@ "vec3": "^0.1.7" } }, + "node_modules/mineflayer-pvp": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mineflayer-pvp/-/mineflayer-pvp-1.3.2.tgz", + "integrity": "sha512-CI2T5w4ceiQdQRCFdrCs3OYmvO9G0cOx2qovUt6f27gknpVI90Ihe1qYhf+zBZJCg9uP1oJ1Pemlzw46Mm3wcA==", + "dependencies": { + "mineflayer": "^4.0.0", + "mineflayer-pathfinder": "^2.0.0", + "mineflayer-utils": "^0.1.4" + } + }, + "node_modules/mineflayer-utils": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/mineflayer-utils/-/mineflayer-utils-0.1.4.tgz", + "integrity": "sha512-8+0dbGAjA6FO62/W80v5k44AuSAcwJUMdpMAAGhjI9AdCDz+UuyTnNkPBncF4EcLY7yUUdtA7m/OXQZKFdWOlg==", + "dependencies": { + "@types/node": "^14.0.27", + "mineflayer": "^2.27.0", + "prismarine-entity": "^1.0.0", + "require-self": "^0.2.3", + "typescript": "^3.9.7" + } + }, + "node_modules/mineflayer-utils/node_modules/@types/node": { + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" + }, + "node_modules/mineflayer-utils/node_modules/minecraft-data": { + "version": "2.221.0", + "resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-2.221.0.tgz", + "integrity": "sha512-0AhqzbIKb6WqPSF6qBevaPryeWOz545hLxt6q+gfJF8YIQX/YfkyX/nXWhl+pSIS2rTBcQ0RJkRCtTeRzQwHDA==" + }, + "node_modules/mineflayer-utils/node_modules/mineflayer": { + "version": "2.41.0", + "resolved": "https://registry.npmjs.org/mineflayer/-/mineflayer-2.41.0.tgz", + "integrity": "sha512-IFFy4NgF24FU2PkAwazJphl2F+3gpbpN578ex0sq1XfcBBRge3kCz1UC2KDMjKI+V/8vffOL+OEnug9jt3f7Vw==", + "dependencies": { + "minecraft-data": "^2.70.0", + "minecraft-protocol": "^1.17.0", + "prismarine-biome": "^1.1.0", + "prismarine-block": "^1.6.0", + "prismarine-chat": "^1.0.0", + "prismarine-chunk": "^1.20.3", + "prismarine-entity": "^1.0.0", + "prismarine-item": "^1.5.0", + "prismarine-physics": "^1.0.4", + "prismarine-recipe": "^1.1.0", + "prismarine-windows": "^1.5.0", + "prismarine-world": "^3.2.0", + "protodef": "^1.8.0", + "typed-emitter": "^1.2.0", + "vec3": "^0.1.6" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/mineflayer-utils/node_modules/prismarine-entity": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/prismarine-entity/-/prismarine-entity-1.2.0.tgz", + "integrity": "sha512-4dQ9LYl6HDJQrwZHjSKU4D5VNyHRnfrjcw7eVLlbRPkuR50utW5mmfPi4ys9U7tHNmGWHC/cwjH9xzT75LUovQ==", + "dependencies": { + "vec3": "^0.1.4" + } + }, + "node_modules/mineflayer-utils/node_modules/prismarine-windows": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/prismarine-windows/-/prismarine-windows-1.6.0.tgz", + "integrity": "sha512-026LG1yR76Xb62kM+W83IWT7Wy2yKplllbXNFBF2m0Lr4k4YpYKnpLb8tRft8MLOLRbYAt/KnxE/YKvRZul7kw==", + "dependencies": { + "prismarine-item": "^1.4.0" + } + }, "node_modules/mojangson": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/mojangson/-/mojangson-2.0.4.tgz", @@ -1754,6 +1828,14 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/require-self": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/require-self/-/require-self-0.2.3.tgz", + "integrity": "sha512-keGBWkK0PWJGFAd6IznpjM5zZzySbsrvzq0ElXpZ4G8hzymV9I+/OnC916MF5mRxHRWSZKGIyCFJ73BZFz3xaA==", + "bin": { + "require-self": "bin/require-self" + } + }, "node_modules/ret": { "version": "0.1.15", "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", @@ -2041,6 +2123,18 @@ "resolved": "https://registry.npmjs.org/typed-emitter/-/typed-emitter-1.4.0.tgz", "integrity": "sha512-weBmoo3HhpKGgLBOYwe8EB31CzDFuaK7CCL+axXhUYhn4jo6DSkHnbefboCF5i4DQ2aMFe0C/FdTWcPdObgHyg==" }, + "node_modules/typescript": { + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "node_modules/uint4": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/uint4/-/uint4-0.1.2.tgz", diff --git a/package.json b/package.json index 20ce5bc..0a8301a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ImperialBot", - "version": "1.0.0", + "version": "1.0.1", "description": "Bot to monitor any bases or locations with side utilities", "main": "index.js", "scripts": { @@ -16,6 +16,7 @@ "fs": "^0.0.1-security", "mineflayer": "^4.14.0", "mineflayer-pathfinder": "^2.4.5", + "mineflayer-pvp": "^1.3.2", "prismarine-viewer": "^1.25.0", "ws": "^8.14.2" }