// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const path = require("path"); module.exports = { config: { name: "install2", aliases: ["ins2"], version: "1.0.0", author: "saju_islam", countDown: 3, role: 2, category: "owner", description: "Install command file safely", guide: { en: "Reply to command code with install2\nOR: install2 filename.js " } }, onStart: async function ({ args, event, message }) { try { let rawCode = ""; let fileName = ""; // Reply to a message containing command code if (event.messageReply?.body) { rawCode = event.messageReply.body.trim(); const match = rawCode.match(/name\s*:\s*["'`]([^"'`]+)["'`]/); if (match) { fileName = match[1] + ".js"; } } // install2 filename.js else if (args.length >= 2) { fileName = args.shift(); rawCode = args.join(" "); } if (!rawCode || !fileName) { return message.reply( "❌ Command code/name paoa jayni.\n\n" + "ব্যবহার:\n" + "1. Code reply করে install2\n" + "2. install2 filename.js " ); } // Normalize and validate filename fileName = path.basename(fileName); if (!/^[a-zA-Z0-9_-]+\.js$/.test(fileName)) { return message.reply("❌ Invalid filename! Example: test.js"); } // Basic code check if (!rawCode.includes("module.exports")) { return message.reply("❌ Eta valid GoatBot command code mone hocche na."); } const cmdsDir = path.join(process.cwd(), "scripts", "cmds"); const filePath = path.join(cmdsDir, fileName); fs.ensureDirSync(cmdsDir); const existed = fs.existsSync(filePath); // Save command source fs.writeFileSync(filePath, rawCode, "utf8"); if (!fs.existsSync(filePath)) { return message.reply("❌ File save failed."); } return message.reply( (existed ? "♻️ OVERWRITE SUCCESS" : "✅ INSTALL SUCCESS") + "\n\n" + "📄 File: " + fileName + "\n" + "📂 Folder: scripts/cmds/\n" + "💾 Source saved successfully.\n\n" + "⚠️ Command load korte Bot Restart de." ); } catch (err) { console.error("[install2]", err); return message.reply( "❌ Install2 error:\n" + (err.message || "Unknown error") ); } } };