// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); module.exports = { config: { name: "push", version: "3.2.0", author: "RS RIFAT", role: 3, category: "owner" }, onStart: async function ({ message, args }) { const configPath = path.join(process.cwd(), "scripts/cmds/pushconfig.json"); if (!await fs.pathExists(configPath)) { return message.reply("⚠️ [ CONFIG MISSING ]\n\n'pushconfig.json' was not found!\nPlease create it inside the 'scripts/cmds/' directory."); } const { token: TOKEN, user: USER, repo: REPO } = await fs.readJson(configPath); const BRANCH = "main"; if (!TOKEN || TOKEN === "তোমার_github_token_এখানে") { return message.reply("🔑 [ AUTHENTICATION ERROR ]\n\nPlease set your GitHub Personal Access Token in pushconfig.json."); } if (!USER || !REPO) { return message.reply("❌ [ CONFIGURATION ERROR ]\n\nGitHub 'user' or 'repo' is missing in pushconfig.json!"); } if (!args[0]) { return message.reply("📌 [ USAGE GUIDE ]\n\nCommand: push \nExample: push mycommand or push cmd1 cmd2"); } const headers = { Authorization: `Bearer ${TOKEN}` }; const dir = path.join(process.cwd(), "scripts/cmds"); const files = [...new Set(args.map(a => a.replace(".js", "")))]; // Single file if (files.length === 1) { const name = files[0]; const filePath = path.join(dir, `${name}.js`); if (!await fs.pathExists(filePath)) { return message.reply(`📂 [ FILE NOT FOUND ]\n\nCould not locate local file: ${name}.js`); } const content = await fs.readFile(filePath, "utf8"); const url = `https://api.github.com/repos/${USER}/${REPO}/contents/scripts/cmds/${name}.js`; let sha; try { const res = await axios.get(url, { headers, params: { ref: BRANCH } }); sha = res.data.sha; } catch {} try { await axios.put(url, { message: `${sha ? "Update" : "Add"} ${name}`, content: Buffer.from(content).toString("base64"), branch: BRANCH, ...(sha && { sha }) }, { headers }); return message.reply(sha ? `🔄 [ UPDATE SUCCESSFUL ]\n\n📄 File: ${name}.js\n✨ Existing file updated on GitHub repository.` : `🚀 [ DEPLOYMENT SUCCESSFUL ]\n\n📄 File: ${name}.js\n🎉 New file created on GitHub repository.` ); } catch (e) { return message.reply(`💥 [ PUSH FAILED ]\n\n🔴 Error: ${e.response?.data?.message || e.message}`); } } // Multiple files let uploaded = 0, rewritten = 0, failed = 0; let logs = []; for (const name of files) { try { const filePath = path.join(dir, `${name}.js`); if (!await fs.pathExists(filePath)) { failed++; logs.push(`✖️️ ${name}.js - File not found locally`); continue; } const content = await fs.readFile(filePath, "utf8"); const url = `https://api.github.com/repos/${USER}/${REPO}/contents/scripts/cmds/${name}.js`; let sha; try { const res = await axios.get(url, { headers, params: { ref: BRANCH } }); sha = res.data.sha; } catch {} await axios.put(url, { message: `${sha ? "Update" : "Add"} ${name}`, content: Buffer.from(content).toString("base64"), branch: BRANCH, ...(sha && { sha }) }, { headers }); if (sha) { rewritten++; logs.push(`🔄 ${name}.js - Overwritten`); } else { uploaded++; logs.push(`✅ ${name}.js - Uploaded`); } } catch (e) { failed++; logs.push(`❌ ${name}.js - Failed (${e.response?.data?.message || "Error"})`); } } return message.reply( `📦 [ DEPLOYMENT SUMMARY ]\n\n✨ Created: ${uploaded}\n🔄 Updated: ${rewritten}\n💥 Failed: ${failed}\n\n📋 Logs:\n${logs.join("\n")}` ); } };