mindcraft/main.js
2023-08-17 00:00:57 -07:00

36 lines
943 B
JavaScript

import { createBot } from 'mineflayer';
import { pathfinder } from 'mineflayer-pathfinder';
import { plugin } from 'mineflayer-collectblock';
import { getChatResponse } from './chat.js';
import { executeCode, writeCode } from './act.js';
async function handleMessage(username, message) {
if (username === bot.username) return;
console.log('received message from', username, ':', message);
let chat = await getChatResponse(bot, username, message);
bot.chat(chat);
let actResult = await executeCode(bot);
if (actResult) {
console.log('completed action');
}
}
const bot = createBot({
host: '127.0.0.1',
port: 55916,
username: 'andy'
})
bot.loadPlugin(pathfinder)
bot.loadPlugin(plugin)
// await writeCode(bot, 'all', ['all: Now, you should set your own personal goal.']);
// executeCode(bot);
console.log('bot created')
bot.on('chat', handleMessage);
bot.on('whisper', handleMessage);