Skip to content

Commit

Permalink
Merge pull request #130 from zeroBzeroT/pathfinder-update
Browse files Browse the repository at this point in the history
adapted for node.js 18
  • Loading branch information
bierdosenhalter authored Oct 12, 2023
2 parents 7326a25 + a6ea67e commit 67e9b18
Show file tree
Hide file tree
Showing 7 changed files with 3,744 additions and 3,815 deletions.
29 changes: 16 additions & 13 deletions 0Bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const armorManager = require('mineflayer-armor-manager');
const autoEat = require('mineflayer-auto-eat');
const pathFinder = require('mineflayer-pathfinder').pathfinder;
const Movements = require('mineflayer-pathfinder').Movements;
// ReSharper disable once InconsistentNaming
const { GoalNear } = require('mineflayer-pathfinder').goals;
const { autototem } = require('mineflayer-auto-totem');
const tpsPlugin = require('./tps.js')(mineflayer);
Expand All @@ -25,12 +26,12 @@ dotenv.config();

try { setTerminalTitle(hideEmail(process.env.minecraftUsername) + ' | ' + server) } catch (e) { }

const discordLink = 'https://discord.gg/WmXCfTA';
const discordLink = process.env.discordLink;
const changeTopicToStats = true;
const logStatusToChat = false;

const doAdvertising = false;
const promoted = '0b0t.org';
const promoted = process.env.promotedServer;

const intervalDiscordTopic = 60 * 5; // seconds
const intervalMove = 5; // seconds
Expand Down Expand Up @@ -155,9 +156,6 @@ function bindEvents(bot) {
fs.writeFileSync('session.json', JSON.stringify(bot._client.session));
});

// TPA REQUEST
bot.chatAddPattern(/^([a-zA-Z0-9_]{3,16}) wants to teleport to you\.$/, 'tpRequest', 'tpa request');

bot.on('tpRequest', function (username) {
if (isWhitelisted(username)) {
bot.chat(`/tpy ${username}`);
Expand Down Expand Up @@ -189,6 +187,9 @@ function bindEvents(bot) {
bot.autoEat.options.startAt = 17.5;
bot.autoEat.enable();

// TPA REQUEST
bot.chatAddPattern(/^([a-zA-Z0-9_]{3,16}) wants to teleport to you\.$/, 'tpRequest', 'tpa request');

minecraftConnected = true;
updateDiscordTopic();
});
Expand All @@ -200,7 +201,7 @@ function bindEvents(bot) {
if (username === 'queue') {
setDiscordChannelTopic(`:hourglass: ${server} | Queue: ${message}`);
} else if (username === '15m') {
//tps = "TPS: " + message + " | ";
// Ignore
} else if (message.toLowerCase().startsWith('/register')) {
bot.chat(`/register ${process.env.authMePassword} ${process.env.authMePassword}`);
} else if (message.toLowerCase().startsWith('/login')) {
Expand All @@ -209,6 +210,8 @@ function bindEvents(bot) {
// Ignore
} else if (message.toLowerCase() === '~discord' || message.toLowerCase() === '!discord' || message.toLowerCase() === '?discord') {
bot.chat(`> Join ${discordLink} for the ${server} discord chat bridge.`);
} else if (message.toLowerCase() === '~tps' || message.toLowerCase() === '!tps' || message.toLowerCase() === '?tps') {
bot.chat(`> Current approximate tps: ${minecraftBot.getTps()}`);
} else if (message.toLowerCase() === '~leave' && isWhitelisted(username.toLowerCase())) {
bot.quit();
} else if (discordConnected) {
Expand Down Expand Up @@ -298,6 +301,8 @@ function bindEvents(bot) {

message = message.replace('%server%', server);
message = message.replace('%promoted%', promoted);
message = message.replace('%discord%', discordLink);
message = message.replace(/[\r\n]/g, '');

bot.chat(`> ${message}`);
lastTimeBroadcast = bot.time.age;
Expand Down Expand Up @@ -346,8 +351,6 @@ function bindEvents(bot) {
setDiscordChannelTopic(`:sos: ${server} | Error`);

if (err.code === undefined && logStatusToChat) {
//sendToChat(`:sos: **Bridge for server '${server}' had an error. Attempting to reconnect in 30 s...**`, true);

setTimeout(relog, 5 * 60 * 1000);
console.log('Undefined error: Maybe invalid credentials OR bot needs to wait because it relogged too quickly.');
}
Expand Down Expand Up @@ -442,16 +445,16 @@ function exitHandler() {
process.exit(1);
}

// do something when app is closing
// do something when App is closing
process.on('exit', exitHandler.bind(null, {}));

// clicking the 'X' on Windows
process.on('SIGHUP', exitHandler.bind(null, {}));

// catches ctrl+c event
// catches Ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {}));

// catches "kill pid" (for example: nodemon restart)
// catches "kill PID" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler.bind(null, {}));
process.on('SIGUSR2', exitHandler.bind(null, {}));

Expand Down Expand Up @@ -486,7 +489,7 @@ function sizeOf(data) {
}

/**
* formatted utc time
* formatted UTC time
*/
function utcDateTime() {
const m = new Date();
Expand All @@ -499,7 +502,7 @@ function utcDateTime() {
}

/**
* java String#hashCode
* Java String#hashCode
*/
function hashCode(str) {
let hash = 0;
Expand Down
3 changes: 2 additions & 1 deletion 0Bot.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<NodeExePath>C:\Program Files\nodejs\node.exe</NodeExePath>
<JavaScriptTestFramework>Tape</JavaScriptTestFramework>
<NodeExeArguments>--unhandled-rejections=strict</NodeExeArguments>
<ScriptArguments>9b9t.com</ScriptArguments>
<ScriptArguments>0b0t.org</ScriptArguments>
<Environment>BROWSER=none</Environment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# 0Bot
Minecraft bot based on *mineflayer* to promote 0b0t.org and add a bridge between the server running 0Bot and the 0b0t discord. Also has basic command capabilities.

Minecraft bot based on mineflayer to promote 0b0t.org and add a bridge between the server running 0Bot and the 0b0t discord. Also has basic command capabilities.

## Ingame Functions

- !discord shows the promoted (0b0t) discord link
## In-game Functions
- **!discord** shows the promoted (0b0t) discord link
- **!tps** shows the approximated tps
- tpa accept for whitelisted users
- basic anti afk
- auto totem, equip and eat
- simple broadcast

## NPM packets

- discord.js
- mineflayer
- mineflayer-armor-manager
Expand All @@ -23,37 +21,41 @@ Minecraft bot based on mineflayer to promote 0b0t.org and add a bridge between t
- forever-monitor (optional)

## Usage
Needs **Node.js 18+** to run.

Needs **Node.js 14+** to run.
```sh
npm run debug
```

forever start 0Bot.js [server]
```sh
npm run forever start 0Bot.js [server]
```

Create the following files in your project root folder:

### .env

minecraftUsername=un
minecraftPassword=pw
discordToken=dt
authMePassword=apw
eMail=aem
discordLink=https://discord.0b0t.org/
promotedServer=0b0t.org

### channels.json

{
"0b0t.org": "687391771218411609",
}

### whitelist.json

### whitelist.json (lowercase)
[
"0bop"
]

### promotion.txt

%promoted% - The best server
%promoted% has 1.12.2 dupe
...

## Sources

- adapted tps code from https://github.com/SiebeDW/mineflayer-tps/
- rewritten TPS code from https://github.com/SiebeDW/mineflayer-tps/
Loading

0 comments on commit 67e9b18

Please sign in to comment.