2024-10-11 09:46:18 -04:00

89 lines
2.2 KiB
JavaScript

'use strict';
const {sleep} = require('../../utils');
const botSlots = [0, 1, 2, 3, 9, 10, 11, 12, 18, 19, 20, 21];
const customerSlots = [5, 6, 7, 8, 14, 15, 16, 17, 23, 24, 25, 26];
function findChestBySign(bot, text){
let sign = bot.bot.findBlock({
useExtraInfo: true,
maxDistance: 32,
matching: (block)=> {
if(block.name.includes('sign') && block.signText.includes(text)){
return true;
}
}
});
return bot.bot.findBlock({
point: sign.position,
// maxDistance: 1,
useExtraInfo: true,
matching: block => block.name === 'chest'
});
}
module.exports = {
'.trade': {
desc: 'Bot will take trade requests',
async function(from){
/*
todo
* Do... something if the users chest is full
*/
// Make the user has a chest then can add too.
let chestBlock = findChestBySign(this, from);
if(!chestBlock) return this.whisper(from, `You aren't allowed to trade with me...`);
await this.say('/trade accept');
let window = await this.once('windowOpen');
// If the process is taking to long, just stop
let timeoutCheck = setTimeout(()=>{
this.bot.closeWindow('window');
this.bot.removeAllListeners('windowOpen');
this.whisper(from, `I have things to do, I cant wait on you all day!`)
}, 120000);
// Check to see if the remote user has agreed to the trade.
let confirmationCheck = setInterval(async ()=>{
if(window.containerItems().filter(item => item?.slot == 53)[0].name == 'lime_dye'){
this.bot.moveSlotItem(37, 37);
}
}, 500);
// Clean up when the trade is done
await this.once('windowClose');
clearInterval(confirmationCheck);
// If the trade took so long it timed out, just kill the whole thing.
if(timeoutCheck._destroyed) return;
clearTimeout(timeoutCheck)
// Give MC a moment
// await sleep(1000);
let goBack = await this.goToReturn({where: chestBlock, reTry: true})
let isPutAway = await this.dumpToChest(chestBlock)
await goBack();
await this.whisper(from, `I put ${isPutAway ? 'all' : 'some'} items in your chest.`);
}
},
'test': {
desc: 'go away',
allowed: ['useless666'],
async function(from){
let chestBlock = findChestBySign(this, from);
}
}
}