forked from wmantly/mc-bot-town
storage
This commit is contained in:
@@ -144,4 +144,46 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
},
|
||||
'summon': {
|
||||
desc: `Summon a bot online indefinitely`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242'],
|
||||
ignoreLock: true,
|
||||
async function(from, botName){
|
||||
if(botName in this.constructor.bots){
|
||||
let bot = this.constructor.bots[botName];
|
||||
|
||||
if (!bot.isReady){
|
||||
try{
|
||||
await bot.connect();
|
||||
this.whisper(from, `${botName} is now online`);
|
||||
}catch(error){
|
||||
this.whisper(from, `Failed to summon ${botName}. Try again later.`);
|
||||
}
|
||||
} else {
|
||||
this.whisper(from, `${botName} is already online`);
|
||||
}
|
||||
} else {
|
||||
this.whisper(from, `Unknown bot: ${botName}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
'dismiss': {
|
||||
desc: `Send a bot offline`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242'],
|
||||
ignoreLock: true,
|
||||
async function(from, botName){
|
||||
if(botName in this.constructor.bots){
|
||||
let bot = this.constructor.bots[botName];
|
||||
|
||||
if(bot.isReady){
|
||||
bot.quit();
|
||||
this.whisper(from, `${botName} is now offline`);
|
||||
} else {
|
||||
this.whisper(from, `${botName} is already offline`);
|
||||
}
|
||||
} else {
|
||||
this.whisper(from, `Unknown bot: ${botName}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const conf = require('.');
|
||||
|
||||
module.exports = {
|
||||
default: require('./default'),
|
||||
fun: require('./fun'),
|
||||
invite: require('./invite'),
|
||||
trade: require('./trade'),
|
||||
};
|
||||
storage: require('./storage'),
|
||||
};
|
||||
106
nodejs/controller/commands/storage.js
Normal file
106
nodejs/controller/commands/storage.js
Normal file
@@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
|
||||
// Owner players who can run admin commands
|
||||
const owners = ['wmantly', 'useless666', 'tux4242'];
|
||||
// Team players who can use basic storage features
|
||||
const team = [...owners, 'pi_chef', 'Ethan', 'Vince_NL'];
|
||||
|
||||
module.exports = {
|
||||
'scan': {
|
||||
desc: 'Force chest area scan',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'scan' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'scan');
|
||||
}
|
||||
},
|
||||
'status': {
|
||||
desc: 'Show storage stats',
|
||||
allowed: team,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'status' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'status');
|
||||
}
|
||||
},
|
||||
'withdraw': {
|
||||
desc: 'Withdraw items from storage',
|
||||
allowed: team,
|
||||
async function(from, itemName, countStr) {
|
||||
console.log(`Storage command 'withdraw' from ${from}: ${itemName} x${countStr}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
const count = parseInt(countStr) || 1;
|
||||
await storage.handleCommand(from, 'withdraw', itemName, count);
|
||||
}
|
||||
},
|
||||
'find': {
|
||||
desc: 'Search for an item',
|
||||
allowed: team,
|
||||
async function(from, itemName) {
|
||||
console.log(`Storage command 'find' from ${from}: ${itemName}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'find', itemName);
|
||||
}
|
||||
},
|
||||
'chests': {
|
||||
desc: 'List tracked chests',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'chests' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'chests');
|
||||
}
|
||||
},
|
||||
'organize': {
|
||||
desc: 'Force full re-sort',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'organize' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'organize');
|
||||
}
|
||||
},
|
||||
'addplayer': {
|
||||
desc: 'Add player to storage',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from, name, role = 'team') {
|
||||
console.log(`Storage command 'addplayer' from ${from}: ${name} as ${role}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'addplayer', name, role);
|
||||
}
|
||||
},
|
||||
'removeplayer': {
|
||||
desc: 'Remove player from storage',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from, name) {
|
||||
console.log(`Storage command 'removeplayer' from ${from}: ${name}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'removeplayer', name);
|
||||
}
|
||||
},
|
||||
'players': {
|
||||
desc: 'List authorized players',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'players' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'players');
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -30,6 +30,45 @@ module.exports = {
|
||||
'.trade': {
|
||||
desc: 'Bot will take trade requests',
|
||||
async function(from){
|
||||
// Check if bot has StoragePlugin
|
||||
if (this.plunginsLoaded['Storage']) {
|
||||
// Storage bot flow
|
||||
await this.say('/trade accept');
|
||||
let window = await this.once('windowOpen');
|
||||
|
||||
// Collect items received from player
|
||||
const itemsReceived = [];
|
||||
const customerSlots = [5, 6, 7, 8, 14, 15, 16, 17, 23, 24, 25, 26];
|
||||
|
||||
for (const slotNum of customerSlots) {
|
||||
const item = window.slots[slotNum];
|
||||
if (item) {
|
||||
itemsReceived.push({
|
||||
name: item.name,
|
||||
id: item.type,
|
||||
count: item.count,
|
||||
nbt: item.nbt
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm and log trade
|
||||
this.bot.moveSlotItem(37, 37);
|
||||
|
||||
// Wait for trade to complete
|
||||
await this.once('windowClose');
|
||||
|
||||
// Handle the trade items
|
||||
if (itemsReceived.length > 0) {
|
||||
await this.plunginsLoaded['Storage'].handleTrade(from, itemsReceived);
|
||||
this.whisper(from, `Received ${itemsReceived.length} item type(s). Sorting into storage.`);
|
||||
} else {
|
||||
this.whisper(from, `No items received.`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Original sign-based flow for non-storage bots
|
||||
/*
|
||||
todo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user