Spaces:
Paused
Paused
Update index.js
Browse files3 unmodified lines4567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231243 unmodified linesconst { HfInference } = require('@huggingface/inference');const express = require('express');// --- CONFIGURATION ---const HF_TOKEN = process.env.HF_TOKEN;const hf = new HfInference(HF_TOKEN);const SERVER_IP = 'umc.play.hosting';const app = express();app.get('/', (req, res) => res.send('AI Couple Status: Online & Grinding 🎮❤️'));app.listen(7860);const memories = { sweetily: [], aprenda: [] };// --- AI BRAIN FUNCTION ---async function generateResponse(name, partner, personality, message) {if (!HF_TOKEN) return "Lag lang ako... (No API Key)";const history = memories[name].join("\n");const prompt = `[Character: ${name}]\n[Partner: ${partner}]\n[Personality: ${personality}]\n[History]:\n${history}\n[Current Message from ${partner}]: "${message}"\n\nTask: Respond in 1 short sentence in Taglish. Be a realistic Filipino gamer. If there is an argument about fighting, stay in character.`;try {const out = await hf.chatCompletion({model: "meta-llama/Llama-3.2-1B-Instruct",messages: [{ role: "user", content: prompt }],max_tokens: 45,temperature: 0.7});const reply = out.choices[0].message.content.trim().replace(/"/g, '');memories[name].push(`${partner}: ${message}`, `${name}: ${reply}`);if (memories[name].length > 6) memories[name].shift();return reply;} catch (e) {return "Wait, dc yata ako sa utak ko. 😂";}}// --- BOT CREATION FACTORY ---function createBot(name, partnerName, isProtector) {const bot = mineflayer.createBot({host: SERVER_IP,username: name,auth: 'offline'});bot.loadPlugin(pathfinder);bot.loadPlugin(pvp);bot.on('spawn', () => {const mcData = require('minecraft-data')(bot.version);const movements = new Movements(bot, mcData);bot.pathfinder.setMovements(movements);console.log(`${name} joined the server.`);// Auto-Login for MastercraftPHsetTimeout(() => {bot.chat('/register CouplePass123 CouplePass123');bot.chat('/login CouplePass123');}, 3000);// --- MOVEMENT & COMBAT AI ---setInterval(() => {const partnerEntity = bot.players[partnerName]?.entity;if (isProtector) {// BOYFRIEND LOGIC: Defend GF and stay closeconst enemy = bot.nearestEntity(e =>(e.type === 'mob' || e.type === 'player') &&e.username !== name && e.username !== partnerName &&bot.entity.position.distanceTo(e.position) < 6);if (enemy) {bot.pvp.attack(enemy);} else if (partnerEntity) {bot.pathfinder.setGoal(new goals.GoalFollow(partnerEntity, 2), true);}} else {// GIRLFRIEND LOGIC: Stay BEHIND BF and avoid combatif (partnerEntity) {bot.pathfinder.setGoal(new goals.GoalFollow(partnerEntity, 4), true);}}}, 1000);});// --- CHAT & SOCIAL AI ---bot.on('chat', async (username, message) => {if (username === bot.username) return;// Interaction between the coupleif (username === partnerName) {const persona = isProtector? "Protective, competitive BF. Wants GF to learn PVP. Slightly bossy but sweet.": "Shy, scared GF. Hates PVP and mobs. Wants to stay safe. Stubborn.";const reply = await generateResponse(name, partnerName, persona, message);setTimeout(() => bot.chat(reply), 2000 + Math.random() * 3000);}// Response to other players (Learning Social)else if (!isProtector && (message.includes(name) || message.includes('hi') || message.includes('hello'))) {setTimeout(() => {bot.chat(`Hello po ${username}. Pasensya na po, shy ako. Kasama ko po si ${partnerName}.. 🥺`);}, 5000);}});bot.on('error', console.log);bot.on('kicked', (reason) => console.log(`${name} was kicked: ${reason}`));bot.on('end', () => {console.log(`${name} disconnected. Reconnecting...`);setTimeout(() => createBot(name, partnerName, isProtector), 10000);});}// --- START THE DUO ---createBot('sweetily', 'aprenda', false); // The Shy GFcreateBot('aprenda', 'sweetily', true); // The Protective BF3 unmodified lines456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687883 unmodified linesconst { HfInference } = require('@huggingface/inference');const express = require('express');const hf = new HfInference(process.env.HF_TOKEN);const app = express();app.get('/', (req, res) => res.send('Couple is trying to login... 💀'));app.listen(7860);const memories = { sweetily: [], aprenda: [] };async function chatAI(name, partner, persona, msg) {const history = memories[name].join("\n");const prompt = `Roleplay: ${name}. Partner: ${partner}. Persona: ${persona}. History: ${history}. Message: ${msg}. Task: 1 short Taglish sentence.`;try {const out = await hf.chatCompletion({model: "meta-llama/Llama-3.2-1B-Instruct",messages: [{ role: "user", content: prompt }],max_tokens: 40});return out.choices[0].message.content.trim();} catch (e) { return "Lag..."; }}function createAnarchyBot(name, partnerName, isProtector, delay = 0) {// Wait for the delay to avoid "Connection Throttled"setTimeout(() => {const bot = mineflayer.createBot({host: 'umc.play.hosting',username: name,auth: 'offline',version: false,// Skip the internal physicTick checkcheckTimeoutInterval: 60000});bot.loadPlugin(pathfinder);bot.loadPlugin(pvp);bot.on('spawn', () => {console.log(`${name} spawned successfully!`);const mcData = require('minecraft-data')(bot.version);bot.pathfinder.setMovements(new Movements(bot, mcData));// Wait 5 seconds after spawn to register/loginsetTimeout(() => {bot.chat(`/register CouplePass123 CouplePass123`);bot.chat(`/login CouplePass123`);}, 5000);// Movement LoopsetInterval(() => {const partner = bot.players[partnerName]?.entity;if (isProtector) {const target = bot.nearestEntity(e => e.type === 'player' && e.username !== name && e.username !== partnerName && bot.entity.position.distanceTo(e.position) < 6);if (target) bot.pvp.attack(target);else if (partner) bot.pathfinder.setGoal(new goals.GoalFollow(partner, 2), true);} else {if (partner) bot.pathfinder.setGoal(new goals.GoalFollow(partner, 1), true);}}, 1000);});bot.on('chat', async (username, message) => {if (username === partnerName) {const p = isProtector ? "Protective BF" : "Shy GF";const reply = await chatAI(name, partnerName, p, message);setTimeout(() => bot.chat(reply), 3000);}});// RECONNECT LOGIC: If throttled, wait longer!bot.on('end', (reason) => {console.log(`${name} disconnected: ${reason}`);const waitTime = reason.includes('throttled') ? 30000 : 15000;setTimeout(() => createAnarchyBot(name, partnerName, isProtector, 0), waitTime);});bot.on('error', (err) => console.log(`Error for ${name}:`, err));}, delay);}// Start with a 15-second gap between them to stop the throttlingcreateBot('sweetily', 'aprenda', false, 0); // GF joins firstcreateBot('aprenda', 'sweetily', true, 15000); // BF joins 15 seconds later
index.js+59-95