plugins
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
const {sleep} = require('../utils');
|
||||
const conf = require('../conf');
|
||||
const {CJbot} = require('../model/minecraft');
|
||||
@ -10,7 +8,15 @@ const inventoryViewer = require('mineflayer-web-inventory');
|
||||
const commands = require('./commands');
|
||||
const {onJoin} = require('./player_list');
|
||||
const {Ai} = require('./ai');
|
||||
// const plugins = {
|
||||
// Swing: require('./swing'),
|
||||
// }
|
||||
|
||||
CJbot.pluginAdd(require('./swing'));
|
||||
CJbot.pluginAdd(require('./craft'));
|
||||
CJbot.pluginAdd(require('./tp'));
|
||||
CJbot.pluginAdd(require('./ai'));
|
||||
CJbot.pluginAdd(require('./guardianFarm'));
|
||||
|
||||
for(let name in conf.mc.bots){
|
||||
if(CJbot.bots[name]) continue;
|
||||
@ -23,81 +29,11 @@ for(let name in conf.mc.bots){
|
||||
}
|
||||
}
|
||||
|
||||
bot.on('onReady', async function(argument) {
|
||||
// inventoryViewer(bot.bot);
|
||||
try{
|
||||
// onJoin(bot);
|
||||
// await sleep(1000);
|
||||
// bot.bot.setControlState('jump', true);
|
||||
// setTimeout(()=> bot.bot.setControlState('jump', false), 5000);
|
||||
if(bot.hasAi){
|
||||
console.log(`${bot.bot.entity.username} has AI`);
|
||||
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;
|
||||
if(message.toString().startsWith('<') && message.toString().split('>')[0].includes(bot.bot.entity.username)) return;
|
||||
console.log(`Message ${type}: ${message.toString()}`)
|
||||
messages.push('>', message.toString());
|
||||
});
|
||||
|
||||
await sleep(500);
|
||||
|
||||
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'),
|
||||
bulbaItems
|
||||
))
|
||||
|
||||
|
||||
setInterval(async ()=>{
|
||||
let result;
|
||||
// if(messages.length ===0) return;
|
||||
|
||||
try{
|
||||
result = await aiChat.chat(JSON.stringify({
|
||||
messages, currentTime:Date.now()+1}
|
||||
));
|
||||
}catch(error){
|
||||
console.log('error AI API', error, result);
|
||||
messages = [];
|
||||
return ;
|
||||
}
|
||||
|
||||
try{
|
||||
messages = [''];
|
||||
if(!result.response.text()) return;
|
||||
|
||||
for(let message of JSON.parse(result.response.text())){
|
||||
console.log('toSay', message.delay, message.text);
|
||||
if(message.text === '___') return;
|
||||
setTimeout(async (message)=>{
|
||||
await bot.sayAiSafe(message.text);
|
||||
}, message.delay*1000, message);
|
||||
}
|
||||
}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);
|
||||
}
|
||||
|
||||
}catch(error){
|
||||
console.log('error in onReady', error);
|
||||
if(conf.mc.bots[name].plugins){
|
||||
for(let pluginName in conf.mc.bots[name].plugins){
|
||||
bot.pluginLoad(pluginName, conf.mc.bots[name].plugins[pluginName]);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on('error', console.log);
|
||||
|
||||
// bot.on('message', function(message, type){
|
||||
// console.log(`${type}: ${message.toString()}`)
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
(async ()=>{try{
|
||||
|
Reference in New Issue
Block a user