Updated generate and save tasks.
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 26s
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 26s
This commit is contained in:
parent
9f95804fc9
commit
cd1253e965
1 changed files with 11 additions and 11 deletions
|
|
@ -15,32 +15,32 @@ async function chatWithAI(prompt, aiConfig) {
|
|||
|
||||
async function generateAndSaveTask(taskName, aiConfig) {
|
||||
const prompt = `
|
||||
You are generating a Minecraft Mineflayer bot task. The task name is: "${taskName}".
|
||||
You are a Minecraft Mineflayer bot generator. The task is called "${taskName}".
|
||||
|
||||
You must return only a valid Node.js module that:
|
||||
Return only a valid Node.js module that:
|
||||
- Exports: \`module.exports = async function(bot, db, say) { ... }\`
|
||||
- Uses only valid Mineflayer API methods.
|
||||
- Do NOT use \`bot.inventory.find()\`. Use \`bot.inventory.items().find(...)\` instead.
|
||||
- If accessing blocks, use \`bot.findBlock()\`, \`bot.blockAt()\`, or \`bot.openBlock()\`.
|
||||
- Only respond with valid JavaScript code. No comments or markdown.
|
||||
- Uses only Mineflayer APIs like \`bot.inventory.items()\`, \`bot.blockAt()\`, etc.
|
||||
- DO NOT return markdown, explanations, or comments — code only.
|
||||
|
||||
The task should accomplish: "${taskName.replace(/-/g, ' ')}"
|
||||
`.trim();
|
||||
|
||||
try {
|
||||
const response = await chatWithAI(prompt, aiConfig);
|
||||
let taskCode = response.trim();
|
||||
|
||||
// Remove wrapping backticks if present
|
||||
// Strip markdown formatting
|
||||
if (taskCode.startsWith('```')) {
|
||||
taskCode = taskCode.replace(/```[a-z]*\n?/i, '').replace(/```$/, '').trim();
|
||||
}
|
||||
|
||||
if (!taskCode.includes('module.exports')) {
|
||||
throw new Error('AI did not return a valid module.exports function.');
|
||||
if (!taskCode.startsWith('module.exports')) {
|
||||
throw new Error('AI response did not begin with module.exports');
|
||||
}
|
||||
|
||||
const taskPath = path.join(__dirname, '../bot-tasks', `${taskName}.js`);
|
||||
fs.writeFileSync(taskPath, taskCode);
|
||||
console.log(`[AI] Task file generated: ${taskPath}`);
|
||||
console.log(`[AI] Task file overwritten with AI code: ${taskPath}`);
|
||||
} catch (err) {
|
||||
console.error('[TASK GENERATION ERROR]', err.message);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue