cletus/bot/bot-tasks/craft-items.js
2025-05-09 15:53:19 -05:00

32 lines
No EOL
1,020 B
JavaScript

// bot-tasks/craft-item.js
module.exports = async function craftItem(bot, db, sayWithPersona) {
if (!bot.allowDestruction) {
sayWithPersona("i'm not supposed to break things unless you tell me to.");
return;
}
try {
const itemName = 'planks'; // Placeholder. Later, parse this from command/context.
const count = 4;
const item = bot.registry.itemsByName[itemName];
if (!item) {
sayWithPersona(`you tried to craft ${itemName}, but it doesn't even exist.`);
return;
}
const recipe = bot.recipesFor(item.id, null, 1)[0];
if (!recipe) {
sayWithPersona(`you don't know how to make ${itemName}. learn it first.`);
return;
}
sayWithPersona(`you're crafting ${count} ${itemName}. hope you're happy.`);
await bot.craft(recipe, count, null);
} catch (err) {
console.error("craft-item.js failed:", err);
sayWithPersona("you tried to craft something and screwed it up.");
}
};