new
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
const {sleep} = require('../utils');
|
||||
const conf = require('../conf');
|
||||
@ -8,7 +9,7 @@ const inventoryViewer = require('mineflayer-web-inventory');
|
||||
|
||||
const commands = require('./commands');
|
||||
const {onJoin} = require('./player_list');
|
||||
const ai = require('./ai');
|
||||
const {Ai} = require('./ai');
|
||||
|
||||
|
||||
for(let name in conf.mc.bots){
|
||||
@ -31,7 +32,10 @@ for(let name in conf.mc.bots){
|
||||
// setTimeout(()=> bot.bot.setControlState('jump', false), 5000);
|
||||
if(bot.hasAi){
|
||||
console.log(`${bot.bot.entity.username} has AI`);
|
||||
let messages = [];
|
||||
let messages = [''];
|
||||
|
||||
let bulbaItems = await axios.get('https://webstore.bulbastore.uk/api/listings');
|
||||
bulbaItems = bulbaItems.data.listings.map(i=>i.listing_name);
|
||||
|
||||
bot.bot.on('message', (message, type)=>{
|
||||
if(type === 'game_info') return;
|
||||
@ -42,18 +46,22 @@ for(let name in conf.mc.bots){
|
||||
|
||||
await sleep(500);
|
||||
|
||||
let aiChat = await ai.run(
|
||||
let aiChat = new Ai(conf.ai.prompt(
|
||||
bot.bot.entity.username,
|
||||
conf.ai.interval,
|
||||
Object.values(bot.getPlayers()).map(player=>`<[${player.lvl}] ${player.username}>`).join('\n')
|
||||
);
|
||||
Object.values(bot.getPlayers()).map(player=>`<[${player.lvl}] ${player.username}>`).join('\n'),
|
||||
bulbaItems
|
||||
))
|
||||
|
||||
|
||||
setInterval(async ()=>{
|
||||
let result;
|
||||
if(messages.length ===0) return;
|
||||
// if(messages.length ===0) return;
|
||||
|
||||
try{
|
||||
result = await aiChat.sendMessage(messages);
|
||||
result = await aiChat.chat(JSON.stringify({
|
||||
messages, currentTime:Date.now()+1}
|
||||
));
|
||||
}catch(error){
|
||||
console.log('error AI API', error, result);
|
||||
messages = [];
|
||||
@ -61,7 +69,7 @@ for(let name in conf.mc.bots){
|
||||
}
|
||||
|
||||
try{
|
||||
messages = [];
|
||||
messages = [''];
|
||||
if(!result.response.text()) return;
|
||||
|
||||
for(let message of JSON.parse(result.response.text())){
|
||||
@ -73,6 +81,9 @@ for(let name in conf.mc.bots){
|
||||
}
|
||||
}catch(error){
|
||||
console.log('Error in AI message loop', error, result);
|
||||
if(result || result.response || result.response.text()){
|
||||
console.log(result.response.text())
|
||||
}
|
||||
}
|
||||
}, conf.ai.interval*1000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user