forked from wmantly/mc-bot-town
here
This commit is contained in:
@@ -2,7 +2,6 @@ module.exports = {
|
||||
'help': {
|
||||
desc: `Print the allowed commands.`,
|
||||
async function(from){
|
||||
console.log('called help', from)
|
||||
let intro = [
|
||||
'I am a bot owned and operated by',
|
||||
'wmantly <wmantly@gmail.com>',
|
||||
@@ -70,10 +69,10 @@ module.exports = {
|
||||
allowed: ['wmantly', 'useless666', 'tux4242',],
|
||||
ignoreLock: true,
|
||||
async function(from, botName, action) {
|
||||
this.whisper(from, `Loading ${plugin}`);
|
||||
this.whisper(from, `Loading ${action}`);
|
||||
if(botName in this.constructor.bots){
|
||||
let bot = this.constructor.bots[botName];
|
||||
let status = await bot.pluginLoad(plugin);
|
||||
let status = await bot.pluginLoad(action);
|
||||
return this.whisper(from, `plugin status ${status}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,128 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
const {sleep} = require('../../utils');
|
||||
|
||||
let myAccounts = ['wmantly', 'useless666', 'tux4242']
|
||||
|
||||
let germans = ['YTMatze', 'mytzor']
|
||||
|
||||
let townMemebers = [
|
||||
'wmantly', 'useless666', 'tux4242',
|
||||
'VinceNL',
|
||||
'Ethan63020', 'Ethan63021',
|
||||
'pi_chef',
|
||||
'EXLAlphaWolf', 'Sillychubbs',
|
||||
'BearSkates420', 'hloop',
|
||||
'ogeiDNight', 'BobinaBlu', 'Roby_G_27',
|
||||
'kawiimeowz', 'RaindropCake24', 'KimiKava',
|
||||
'Keebyys',
|
||||
'YTMatze', 'mytzor',
|
||||
'jj_disaster', 'Cuttaway',
|
||||
'sonic_joe',
|
||||
]
|
||||
|
||||
let sites = {
|
||||
fo: {
|
||||
bot: 'jimin',
|
||||
desc: `Get an invite to the Farming outpost.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', 'nootbot', 'VinceNL', 'Ethan63020', 'Ethan63021', 'KimiKava', 'kawiimeowz', 'RaindropCake24', 'AndyNyg', 'AndyNyg_II'],
|
||||
},
|
||||
mega:{
|
||||
bot: 'ayay',
|
||||
desc: `Get an invite to the Farming outpost 2.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', '__Ethan63020', '__Ethan63021', 'VinceNL', 'nootbot'],
|
||||
},
|
||||
guardian: {
|
||||
bot: 'art',
|
||||
desc: 'blah',
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', 'Ethan63020', 'Ethan63021', 'VinceNL', 'nootbot'],
|
||||
},
|
||||
fo2: {
|
||||
bot: 'henry',
|
||||
desc: `Get an invite to the Farming outpost 2.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', 'Ethan63020', 'Ethan63021', 'VinceNL', 'nootbot'],
|
||||
},
|
||||
foend: {
|
||||
bot: 'ez',
|
||||
desc: `Get an invite to the Farming outpost in the end.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut',],
|
||||
},
|
||||
sb: {
|
||||
bot: 'owen',
|
||||
desc: `Get an invite to the Sky Base.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', 'Ethan63020', 'Ethan63021', 'VinceNL', 'nootbot'],
|
||||
},
|
||||
core: {
|
||||
bot: 'nova',
|
||||
desc: `Get an invite to the Core.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', 'Ethan63020', 'Ethan63021', 'VinceNL', 'nootbot', 'AndyNyg', 'AndyNyg_II','Lost_Imback', 'KimiKava', 'kawiimeowz', 'RaindropCake24',],
|
||||
},
|
||||
art: {
|
||||
bot: 'art',
|
||||
desc: 'Invite to art',
|
||||
allowed: ['wmantly', 'useless666', 'tux4242']
|
||||
},
|
||||
german: {
|
||||
bot: 'linda',
|
||||
desc: `Get an invite you Germans area.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'owenshorts', 'VinceNL', 'Ethan63020', 'Ethan63021', 'pi_chef', 'YTMatze', 'mytzor', 'pi_chef', '1_cut', 'nootbot', 'Lost_Imback',],
|
||||
},
|
||||
}
|
||||
|
||||
function getSiteFromBot(name){
|
||||
for(let site in sites){
|
||||
if(sites[site].bot === name){
|
||||
return sites[site];
|
||||
}
|
||||
}
|
||||
}
|
||||
const Database = require('../storage/database');
|
||||
const Invite = require('../invite');
|
||||
|
||||
module.exports = {
|
||||
'.invite': {
|
||||
desc: `The bot will /accept an /invite from you.`,
|
||||
allowed: ['wmantly', 'useless666', 'tux4242', 'owenshorts', 'pi_chef', '1_cut',],
|
||||
ignoreLock: true,
|
||||
async function(from){
|
||||
async function(from) {
|
||||
const allowed = await Database.isPlayerAllowedAtSite('*', from);
|
||||
// Allow if player has permission at any site
|
||||
const sites = await Database.getInviteSites();
|
||||
const hasAnySite = sites.some(s => {
|
||||
const players = s.players ? s.players.split(',') : [];
|
||||
return players.includes(from);
|
||||
});
|
||||
if (!hasAnySite) return;
|
||||
|
||||
await this.whisper('Coming');
|
||||
await this.say(`/invite accept`);
|
||||
}
|
||||
},
|
||||
'inv': {
|
||||
desc: `Have bot.\n Site -- one'`,
|
||||
desc: `Have a bot invite you to a site.\n Usage: inv <site>`,
|
||||
ignoreLock: true,
|
||||
async function(from, site){
|
||||
async function(from, site) {
|
||||
this.__unLockCommand();
|
||||
|
||||
if(sites[site] && sites[site].allowed.includes(from)){
|
||||
let bot = this.constructor.bots[sites[site].bot];
|
||||
if (!site) return;
|
||||
|
||||
if(!bot.isReady){
|
||||
try{
|
||||
await bot.connect();
|
||||
}catch(error){
|
||||
console.log('inv error connecting to bot');
|
||||
this.whisper('Bot is not available right now, try again in 30 seconds.');
|
||||
}
|
||||
var clear = setTimeout(()=>{
|
||||
bot.pluginUnload('Tp');
|
||||
bot.quit()
|
||||
}, 10000);
|
||||
}
|
||||
await bot.pluginLoad('Tp');
|
||||
await bot.bot.chat(`/invite ${from}`);
|
||||
await bot.whisper(from, `accept invite from ${bot.bot.entity.username} within 10 seconds...`);
|
||||
bot.on('message', async (message) =>{
|
||||
if(message.toString() === `${from} teleported to you.`){
|
||||
await bot.pluginUnload('Tp');
|
||||
const siteData = await Database.getInviteSiteByName(site);
|
||||
if (!siteData) return;
|
||||
|
||||
if(clear){
|
||||
clearTimeout(clear);
|
||||
bot.quit();
|
||||
}
|
||||
}
|
||||
});
|
||||
const allowed = await Database.isPlayerAllowedAtSite(site, from);
|
||||
if (!allowed) return;
|
||||
|
||||
try {
|
||||
const bot = this.constructor.bots[siteData.bot_name];
|
||||
if (!bot) return;
|
||||
|
||||
await Invite.executeInvite(siteData.bot_name, from);
|
||||
} catch (error) {
|
||||
console.log('inv error:', error);
|
||||
this.whisper('Bot is not available right now, try again in 30 seconds.');
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const { sleep } = require('../../utils');
|
||||
|
||||
// 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'];
|
||||
|
||||
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];
|
||||
|
||||
module.exports = {
|
||||
'scan': {
|
||||
desc: 'Force chest area scan',
|
||||
@@ -28,14 +33,22 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
'withdraw': {
|
||||
desc: 'Withdraw items from storage',
|
||||
desc: 'Withdraw items from storage (use "3s" for 3 shulkers)',
|
||||
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);
|
||||
|
||||
// Parse count — "3s" means 3 shulkers, "10" means 10 items
|
||||
const str = (countStr || '1').toString().trim();
|
||||
if (str.endsWith('s') || str.endsWith('S')) {
|
||||
const shulkerCount = parseInt(str) || 1;
|
||||
await storage.handleCommand(from, 'withdraw-shulkers', itemName, shulkerCount);
|
||||
} else {
|
||||
const count = parseInt(str) || 1;
|
||||
await storage.handleCommand(from, 'withdraw', itemName, count);
|
||||
}
|
||||
}
|
||||
},
|
||||
'find': {
|
||||
@@ -70,6 +83,17 @@ module.exports = {
|
||||
await storage.handleCommand(from, 'organize');
|
||||
}
|
||||
},
|
||||
'consolidate': {
|
||||
desc: 'Merge partially filled shulkers',
|
||||
allowed: owners,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
console.log(`Storage command 'consolidate' from ${from}`);
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return this.whisper(from, 'Storage plugin not loaded');
|
||||
await storage.handleCommand(from, 'consolidate');
|
||||
}
|
||||
},
|
||||
'addplayer': {
|
||||
desc: 'Add player to storage',
|
||||
allowed: owners,
|
||||
@@ -103,4 +127,107 @@ module.exports = {
|
||||
await storage.handleCommand(from, 'players');
|
||||
}
|
||||
},
|
||||
'.trade': {
|
||||
desc: 'Handle trade deposits/withdrawals for storage',
|
||||
allowed: team,
|
||||
ignoreLock: true,
|
||||
async function(from) {
|
||||
const storage = this.plunginsLoaded['Storage'];
|
||||
if (!storage) return;
|
||||
|
||||
storage._busy = true;
|
||||
try {
|
||||
const pending = storage.pendingWithdrawals.get(from);
|
||||
|
||||
await this.say('/trade accept');
|
||||
let window = await this.once('windowOpen');
|
||||
|
||||
// If there's a pending withdrawal, place items in bot's trade slots
|
||||
if (pending) {
|
||||
console.log(`Storage trade: Withdrawal pickup for ${from} — ${pending.count}x ${pending.itemName} (mode: ${pending.mode})`);
|
||||
|
||||
let placed = 0;
|
||||
for (const slotNum of botSlots) {
|
||||
if (placed >= 12) break;
|
||||
|
||||
// Find matching item in bot inventory portion of trade window
|
||||
for (let i = window.inventoryStart; i < window.inventoryEnd; i++) {
|
||||
const item = window.slots[i];
|
||||
if (!item) continue;
|
||||
|
||||
if (pending.mode === 'shulkers') {
|
||||
if (!item.name.includes('shulker_box')) continue;
|
||||
} else {
|
||||
if (item.name !== pending.itemName) continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bot.moveSlotItem(i, slotNum);
|
||||
await sleep(200);
|
||||
placed++;
|
||||
break;
|
||||
} catch (error) {
|
||||
console.log(`Storage trade: Could not move item to slot ${slotNum}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Storage trade: Placed ${placed} stack(s) in trade window`);
|
||||
}
|
||||
|
||||
// Poll for customer confirmation (lime_dye at slot 53)
|
||||
let timeoutCheck = setTimeout(() => {
|
||||
this.bot.closeWindow(window);
|
||||
this.whisper(from, 'Trade timed out.');
|
||||
}, 120000);
|
||||
|
||||
let confirmationCheck = setInterval(async () => {
|
||||
try {
|
||||
const indicator = window.slots[53];
|
||||
if (indicator && indicator.name === 'lime_dye') {
|
||||
this.bot.moveSlotItem(37, 37);
|
||||
}
|
||||
} catch (e) {
|
||||
// window may have closed
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// Wait for trade to complete
|
||||
await this.once('windowClose');
|
||||
clearInterval(confirmationCheck);
|
||||
|
||||
if (timeoutCheck._destroyed) {
|
||||
storage._busy = false;
|
||||
return;
|
||||
}
|
||||
clearTimeout(timeoutCheck);
|
||||
|
||||
if (pending) {
|
||||
// Withdrawal complete — clear pending
|
||||
if (pending.timeoutId) clearTimeout(pending.timeoutId);
|
||||
storage.pendingWithdrawals.delete(from);
|
||||
this.whisper(from, `Withdrawal complete! Enjoy your ${pending.itemName}.`);
|
||||
} else {
|
||||
// Deposit — collect items from bot inventory and sort into storage
|
||||
await sleep(500);
|
||||
|
||||
const hotbarNames = new Set((storage.config.hotbarItems || []).map(h => h.name));
|
||||
const itemsReceived = [];
|
||||
for (const item of this.bot.inventory.items()) {
|
||||
if (hotbarNames.has(item.name)) continue;
|
||||
itemsReceived.push({ name: item.name, id: item.type, count: item.count, nbt: item.nbt });
|
||||
}
|
||||
|
||||
if (itemsReceived.length > 0) {
|
||||
this.whisper(from, `Received ${itemsReceived.length} item type(s). Sorting into storage.`);
|
||||
await storage.handleTrade(from, itemsReceived);
|
||||
} else {
|
||||
this.whisper(from, 'No items received.');
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
storage._busy = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user