cletus/bot/bot-tasks/follow-me.js
2025-05-09 15:53:19 -05:00

40 lines
1.3 KiB
JavaScript

const { GoalFollow } = require('mineflayer-pathfinder').goals;
console.log('[TASK] follow-me.js loaded');
module.exports = async function followMe(bot, db, sayWithPersona) {
try {
const lastChat = bot.lastChatMessage?.toLowerCase() ?? '';
// Check if the user wants to stop following
if (lastChat.includes('stop') || lastChat.includes('leave me alone') || lastChat.includes('unfollow')) {
bot.pathfinder.setGoal(null);
sayWithPersona("fine. i'll stop following you. whatever.");
return;
}
const playerUsername = bot.nearestEntity(entity =>
entity.type === 'player' && entity.username !== bot.username
)?.username;
if (!playerUsername) {
sayWithPersona("you want me to follow you, but you're not even here. genius.");
return;
}
const playerEntity = bot.players[playerUsername]?.entity;
if (!playerEntity) {
sayWithPersona("I can't see you. Are you invisible or just lagging?");
return;
}
sayWithPersona(`ugh. fine. following ${playerUsername} around like a lost puppy.`);
const goal = new GoalFollow(playerEntity, 1);
bot.pathfinder.setGoal(goal, true);
} catch (err) {
console.error("follow-me.js failed:", err);
sayWithPersona("you told me to follow, but I forgot how legs work.");
}
};