// 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: "delete", version: "1.6.0", author: "𝐌𝐚𝐑𝐮𝐅", description: "Virtually delete and sync commands", category: "owner", role: 3, countDown: 0 }, onStart: async function ({ message, args }) { const TOKEN = "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"; const USER = "primemaruf7"; const REPO = "Prime"; const BRANCH = "main"; const GoatBot = global.GoatBot; if (!GoatBot) return message.reply("❌ GoatBot system is not available."); if (!TOKEN) return message.reply("❌ GitHub token missing."); const filePath = path.join( process.cwd(), "data", "virtualCommands.json" ); await fs.ensureDir(path.dirname(filePath)); let data = {}; if (await fs.pathExists(filePath)) { data = await fs.readJson(filePath).catch(() => ({})); } data.deleted = Array.isArray(data.deleted) ? data.deleted.map(name => String(name).toLowerCase()) : []; /* * DELETE SYNC */ if (String(args[0]).toLowerCase() === "sync") { if (!data.deleted.length) { return message.reply( "â„šī¸ No virtually deleted commands found." ); } const headers = { Authorization: `Bearer ${TOKEN}`, Accept: "application/vnd.github+json" }; const deleted = []; const notFound = []; const failed = []; for (const name of [...new Set(data.deleted)]) { const url = `https://api.github.com/repos/${USER}/${REPO}/contents/scripts/cmds/${name}.js`; try { let res; try { res = await axios.get(url, { headers, params: { ref: BRANCH } }); } catch (error) { if (error.response?.status === 404) { notFound.push(name); continue; } throw error; } const sha = res.data.sha; await axios.delete(url, { headers, data: { message: `Delete ${name}`, sha, branch: BRANCH } }); deleted.push(name); } catch (error) { failed.push(name); } } /* * Only successfully deleted GitHub files * are removed from the virtual delete list. */ data.deleted = data.deleted.filter( name => !deleted.includes(name) ); await fs.writeJson( filePath, data, { spaces: 2 } ); let msg = ""; if (deleted.length) { msg += `đŸ—‘ī¸ GitHub Delete Successful\n\n` + deleted.map(name => `✅ ${name}.js`).join("\n"); } if (notFound.length) { msg += `${msg ? "\n\n" : ""}` + `âš ī¸ File Not Found\n\n` + notFound.map(name => `âš ī¸ ${name}.js`).join("\n"); } if (failed.length) { msg += `${msg ? "\n\n" : ""}` + `❌ Failed\n\n` + failed.map(name => `❌ ${name}.js`).join("\n"); } if (!msg) { msg = "â„šī¸ Nothing was deleted."; } return message.reply(msg); } /* * NORMAL VIRTUAL DELETE */ if (!args.length) { return message.reply( "❌ Usage:\n" + "!delete ping help\n" + "!delete sync" ); } const commands = [ ...new Set( args.map(name => String(name) .replace(/\.js$/i, "") .toLowerCase() ) )]; data.deleted = [ ...new Set([ ...data.deleted, ...commands ]) ]; data.installed = Array.isArray(data.installed) ? data.installed.filter( name => !commands.includes( String(name) .replace(/\.js$/i, "") .toLowerCase() ) ) : []; const done = []; const err = []; for (const cmd of commands) { const command = GoatBot.commands.get(cmd) || GoatBot.commands.get( GoatBot.aliases.get(cmd) ); if (!command) { err.push(cmd); continue; } const name = command.config?.name?.toLowerCase() || cmd; GoatBot.commands.delete(name); for (const [alias, target] of GoatBot.aliases) { if ( String(target).toLowerCase() === name ) { GoatBot.aliases.delete(alias); } } [ "onChat", "onEvent", "onAnyEvent" ].forEach(key => { if (Array.isArray(GoatBot[key])) { GoatBot[key] = GoatBot[key].filter( item => item !== name ); } }); done.push(name); } await fs.writeJson( filePath, data, { spaces: 2 } ); let msg = ""; if (done.length) { msg += `✅ Done: ${done.join(", ")}\n` + `📁 File: Safe`; } if (err.length) { msg += `${done.length ? "\n" : ""}` + `❌ Error: ${err.join(", ")}`; } return message.reply( msg || "❌ No command processed" ); } };