Files
Magic-Garden-Bot/verify_autofeed.js
2025-12-09 23:21:09 +00:00

84 lines
2.0 KiB
JavaScript

const fs = require('fs');
// Mock DOM/Window
const callbacks = {};
global.window = {
MagicBot: {
state: {
inventory: { items: [] },
garden: {},
shops: {}
},
automation: {
autoFeed: true,
petDiet: new Set(['Tomato'])
},
events: {
emit: (event, data) => { }
},
on: (event, callback) => {
callbacks[event] = callback;
},
sendMsg: (msg) => {
console.log("SEND_MSG:", JSON.stringify(msg));
},
sellAll: null // Will be overwritten
}
};
// Start MB definition
const MB = global.window.MagicBot;
// Mock Inventory with Pet and Food
MB.state.inventory.items = [
{
id: "pet_1",
itemType: "Pet",
petSpecies: "Worm",
quantity: 1
},
{
id: "crop_tomato_1",
itemType: "Produce",
species: "Tomato",
quantity: 5
},
{
id: "crop_carrot_1",
itemType: "Produce",
species: "Carrot",
quantity: 5
}
];
// Load main.js content to get the logic
// We need to strip the wrapping IIFE or just eval it.
// However, the file reads `const MB = window.MagicBot;`.
// If we eval it, it should attach methods to our mock MB.
const mainJsPath = '/home/matiss/Documents/Code/magicbot/extension/modules/main.js';
const mainJsContent = fs.readFileSync(mainJsPath, 'utf8');
try {
eval(mainJsContent);
} catch (e) {
// Ignore errors related to interval or DOM if any,
// but main.js mostly sets up interval and methods.
console.log("Eval loaded with some harmless errors likely:", e.message);
}
// Re-enable automation and set diet after main.js reset it
MB.automation.autoFeed = true;
MB.automation.petDiet = new Set(['Tomato']);
// Test Feeding
console.log("\n--- TEST: Explicit Feed ---");
console.log("Pet Diet:", [...MB.automation.petDiet]);
MB.feedPets();
// Test Auto Sell Trigger
console.log("\n--- TEST: Auto Sell Trigger ---");
MB.sellAll();