Skip to content

Commit

Permalink
Bot Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Sep 27, 2023
1 parent 9109dbb commit 930c82c
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
"Test 4 "
]
},
"webhookUrl": "https://discord.com/api/webhooks/1154108207929757747/qSDcSAzxhFxClz3GwyAy1UiUDe8OZP4F8vieomaUApSx-rbYiHN3HtBnLVsZiMMCGQp6"
"webhookUrl":"webhookURL"
}
50 changes: 39 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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}`);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -264,7 +274,7 @@ const main = () => {
}
sendWebhookMessage(webhookUrl, `## THE BOT HAS DIED`)
});

localhostApp();
};

function generateRandomString(length) {
Expand Down Expand Up @@ -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);
})
});
Expand Down Expand Up @@ -768,4 +795,5 @@ app.get('/spam', (req, res) => {
}
sendWSmessage(`Spamming: ` + spamming);
res.send(`Spamming: ` + spamming);
});
});
}
28 changes: 15 additions & 13 deletions install.bat
Original file line number Diff line number Diff line change
@@ -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
94 changes: 94 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
}
Expand Down

0 comments on commit 930c82c

Please sign in to comment.