goat
command
commandstore
๐ Goatstore - Your Command Marketplace
0
views
0
likes
0
installs
Aliases: cs, ogs, cmdtore
raw source
const axios = require("axios");
const fs = require('fs-extra');
const path = require('path');
const GoatStor = "https://goatstore.vercel.app";
// Helper function to get modules/cmds directory path safely
function getCmdsDir() {
const mainPath = global.GoatBot?.mainPath || process.cwd();
const possibleDir = path.join(mainPath, "modules", "cmds");
// Ensure directory exists
fs.ensureDirSync(possibleDir);
return possibleDir;
}
// Helper function to dynamically register and load new command into GoatBot memory
function autoLoadCommand(filePath, fileName) {
try {
// Clear node require cache to load fresh file
delete require.cache[require.resolve(filePath)];
const command = require(filePath);
if (!command || !command.config || !command.config.name) {
return { success: false, error: "Invalid command file format or missing config.name" };
}
const cmdName = command.config.name.toLowerCase();
// 1. Try standard GoatBot loadCommand method if available
if (global.GoatBot && typeof global.GoatBot.loadCommand === 'function') {
try {
global.GoatBot.loadCommand({
api: global.GoatBot.api,
threadModel: global.GoatBot.threadModel,
userModel: global.GoatBot.userModel,
dashBoardModel: global.GoatBot.dashBoardModel,
globalModel: global.GoatBot.globalModel,
threadsData: global.GoatBot.threadsData,
usersData: global.GoatBot.usersData,
dashBoardData: global.GoatBot.dashBoardData,
globalData: global.GoatBot.globalData,
fileName: `${fileName}.js`,
path: filePath
});
} catch (e) {
console.warn("Standard loadCommand failed, switching to manual map insertion:", e.message);
}
}
// 2. Fallback / Direct insertion into GoatBot Global Memory Collections
if (global.GoatBot) {
// Register main command name
if (global.GoatBot.commands) global.GoatBot.commands.set(cmdName, command);
if (global.GoatBot.cmds) global.GoatBot.cmds.set(cmdName, command);
// Register command aliases
if (command.config.aliases && Array.isArray(command.config.aliases)) {
for (const alias of command.config.aliases) {
const cleanAlias = alias.toLowerCase();
if (global.GoatBot.aliases) global.GoatBot.aliases.set(cleanAlias, cmdName);
}
}
}
return { success: true, name: cmdName };
} catch (e) {
return { success: false, error: e.message };
}
}
module.exports = {
config: {
name: "commandstore",
aliases: ["cs", "ogs", "cmdtore"],
version: "0.0.6",
role: 1,
author: "ArYAN",
shortDescription: {
en: "๐ Goatstore - Your Command Marketplace"
},
longDescription: {
en: "๐ Browse, search, upload, install and manage your commands in the GoatStore marketplace with easy sharing cmds."
},
category: "๐ ๐ฎ๐ฟ๐ธ๐ฒ๐",
cooldowns: 0,
},
onStart: async ({ api, event, args, message }) => {
const sendBeautifulMessage = (content) => {
const header = "โญโโใ ๐GoatStore ใโโโฎ\n";
const footer = "\nโฐโโโโโโโโโโโโโโโฏ";
return message.reply(header + content + footer);
};
try {
if (!args[0]) {
return sendBeautifulMessage(
"\n" +
`โญโโฏ ${event.body} show <ID>\nโ ๐ฆ Get command code info\nโฐ Example: show 1\n\n` +
`โญโโฏ ${event.body} install <ID> [fileName]\nโ ๐ฅ Install command directly\nโฐ Example: install 1 or install 1 music\n\n` +
`โญโโฏ ${event.body} page <number>\nโ ๐ Browse commands\nโฐ Example: page 1\n\n` +
`โญโโฏ ${event.body} search <query>\nโ ๐ Search commands\nโฐ Example: search music\n\n` +
`โญโโฏ ${event.body} trending\nโ ๐ฅ View trending\nโฐ Most popular commands\n\n` +
`โญโโฏ ${event.body} status\nโ ๐ View statistics\nโฐ Marketplace insights\n\n` +
`โญโโฏ ${event.body} like <ID>\nโ ๐ Like a command\nโฐ Example: like 1\n\n` +
`โญโโฏ ${event.body} upload <name>\nโ โฌ๏ธ Upload command\nโฐ Example: upload goatstore\n\n` +
"๐ซ ๐ง๐ถ๐ฝ: Use `goatstore` menu for options"
);
}
const command = args[0].toLowerCase();
const commandsDir = getCmdsDir();
switch (command) {
case "show": {
const itemID = parseInt(args[1]);
if (isNaN(itemID)) return sendBeautifulMessage("\n[โ ๏ธ]โ Please provide a valid item ID.");
const response = await axios.get(`${GoatStor}/api/item/${itemID}`);
const item = response.data;
const bangladeshTime = new Date(item.createdAt).toLocaleString('en-US', { timeZone: 'Asia/Dhaka' });
return sendBeautifulMessage(
"\n" +
`โญโโฏ ๐ ๐ก๐ฎ๐บ๐ฒ\nโฐ ${item.itemName}\n\n` +
`โญโโฏ ๐ ๐๐\nโฐ ${item.itemID}\n\n` +
`โญโโฏ โ๏ธ ๐ง๐๐ฝ๐ฒ\nโฐ ${item.type || 'Unknown'}\n\n` +
`โญโโฏ ๐ ๐๐ฒ๐๐ฐ๐ฟ๐ถ๐ฝ๐๐ถ๐ผ๐ป\nโฐ ${item.description}\n\n` +
`โญโโฏ ๐จโ๐ป ๐๐๐๐ต๐ผ๐ฟ\nโฐ ${item.authorName}\n\n` +
`โญโโฏ ๐
๐๐ฑ๐ฑ๐ฒ๐ฑ\nโฐ ${bangladeshTime}\n\n` +
`โญโโฏ ๐ ๐ฉ๐ถ๐ฒ๐๐\nโฐ ${item.views}\n\n` +
`โญโโฏ ๐ ๐๐ถ๐ธ๐ฒ๐\nโฐ ${item.likes}\n\n` +
`โญโโฏ ๐ ๐ฅ๐ฎ๐ ๐๐ถ๐ป๐ธ\nโฐ ${GoatStor}/raw/${item.rawID}`
);
}
case "install": {
let itemID;
let customFileName;
if (!args[1]) {
return sendBeautifulMessage("\n[โ ๏ธ]โ Please provide an Item ID.\nExample: `goatstore install 1` or `goatstore install 1 mycmd`");
}
if (!isNaN(parseInt(args[1]))) {
itemID = parseInt(args[1]);
customFileName = args[2] ? args[2].replace(/\.js$/i, "") : null;
} else if (args[2] && !isNaN(parseInt(args[2]))) {
customFileName = args[1].replace(/\.js$/i, "");
itemID = parseInt(args[2]);
} else {
return sendBeautifulMessage("\n[โ ๏ธ]โ Please provide a valid numerical Item ID.");
}
try {
message.reply("โณ Fetching command code from GoatStore...");
const response = await axios.get(`${GoatStor}/api/item/${itemID}`);
const item = response.data;
if (!item || !item.rawID) {
return sendBeautifulMessage("\nโ Command not found on GoatStore.");
}
// Fetch raw code
const rawResponse = await axios.get(`${GoatStor}/raw/${item.rawID}`);
const code = typeof rawResponse.data === 'object' ? JSON.stringify(rawResponse.data, null, 2) : rawResponse.data;
if (!code) {
return sendBeautifulMessage("\nโ Failed to retrieve code from GoatStore.");
}
// Determine file name
const fileName = (customFileName || item.itemName || `cmd_${itemID}`).toLowerCase().replace(/[^a-z0-9_-]/gi, "");
const filePath = path.join(commandsDir, `${fileName}.js`);
// Write file into modules/cmds
fs.ensureDirSync(commandsDir);
fs.writeFileSync(filePath, code, 'utf8');
// Load and activate in memory
const loadResult = autoLoadCommand(filePath, fileName);
let loadStatusText = `โก๏ธ Command '${loadResult.name || fileName}' loaded & activated in memory!`;
if (!loadResult.success) {
loadStatusText = `โ ๏ธ Saved to modules/cmds, but auto-load failed: ${loadResult.error}`;
}
return sendBeautifulMessage(
"\n" +
`โญโโฏ โ
๐ฆ๐๐ฎ๐๐๐\nโฐ Installed & Activated successfully!\n\n` +
`โญโโฏ ๐ฆ ๐๐ถ๐น๐ฒ ๐ก๐ฎ๐บ๐ฒ\nโฐ ${fileName}.js\n\n` +
`โญโโฏ ๐ ๐๐\nโฐ ${item.itemID}\n\n` +
`โญโโฏ ๐ ๐ฃ๐ฎ๐๐ต\nโฐ modules/cmds/${fileName}.js\n\n` +
`๐ ${loadStatusText}`
);
} catch (err) {
console.error("Install Error:", err);
return sendBeautifulMessage(`\nโ Failed to install command: ${err.message}`);
}
}
case "page": {
const page = parseInt(args[1]) || 1;
const { data: { items, total } } = await axios.get(`${GoatStor}/api/items?page=${page}&limit=5`);
const totalPages = Math.ceil(total / 5);
if (page <= 0 || page > totalPages) {
return sendBeautifulMessage("\n[โ ๏ธ]โ Invalid page number.");
}
const itemsList = items.map((item, index) =>
`โญโโฏ ${index + 1}. ๐ฆ ${item.itemName}\n` +
`โ ๐ ๐๐: ${item.itemID}\n` +
`โ โ๏ธ ๐ง๐๐ฝ๐ฒ: ${item.type}\n` +
`โ ๐ ๐๐ฒ๐๐ฐ๐ฟ๐ถ๐ฝ๐๐ถ๐ผ๐ป: ${item.description}\n` +
`โ ๐ ๐ฉ๐ถ๐ฒ๐๐: ${item.views}\n` +
`โ ๐ ๐๐ถ๐ธ๐ฒ๐: ${item.likes}\n` +
`โฐ ๐จโ๐ป ๐๐๐๐ต๐ผ๐ฟ: ${item.authorName}\n`
).join("\n");
return sendBeautifulMessage(`\n๐ ๐ฃ๐ฎ๐ด๐ฒ ${page}/${totalPages}\n\n${itemsList}`);
}
case "search": {
const query = args.slice(1).join(" ");
if (!query) return sendBeautifulMessage("\n[โ ๏ธ]โ Please provide a search query.");
const { data } = await axios.get(`${GoatStor}/api/items?search=${encodeURIComponent(query)}`);
const results = data.items || data;
if (!results || !results.length) return sendBeautifulMessage("\nโ No matching results found.");
const searchList = results.slice(0, 5).map((item, index) =>
`โญโโฏ ${index + 1}. ๐ฆ ${item.itemName}\n` +
`โ ๐ ๐๐: ${item.itemID}\n` +
`โ โ๏ธ ๐ง๐๐ฝ๐ฒ: ${item.type || 'GoatBot'}\n` +
`โ ๐ ๐ฉ๐ถ๐ฒ๐๐: ${item.views || 0}\n` +
`โ ๐ ๐๐ถ๐ธ๐ฒ๐: ${item.likes || 0}\n` +
`โฐ ๐จโ๐ป ๐๐๐๐ต๐ผ๐ฟ: ${item.authorName || 'Unknown'}\n`
).join("\n");
return sendBeautifulMessage(`\n๐ Query: "${query}"\n\n${searchList}`);
}
case "trending": {
const { data } = await axios.get(`${GoatStor}/api/trending`);
const trendingList = data.slice(0, 5).map((item, index) =>
`โญโโฏ ${index + 1}. ๐ฅ ${item.itemName}\n` +
`โ ๐ ๐๐: ${item.itemID}\n` +
`โ ๐ ๐๐ถ๐ธ๐ฒ๐: ${item.likes}\n` +
`โฐ ๐ ๐ฉ๐ถ๐ฒ๐๐: ${item.views}\n`
).join("\n");
return sendBeautifulMessage(`\n${trendingList}`);
}
case "status": {
const { data: stats } = await axios.get(`${GoatStor}/api/stats`);
const { hosting, totalCommands, totalLikes, dailyActiveUsers, topAuthors, topViewed } = stats;
const uptimeStr = hosting?.uptime ? `${hosting.uptime.years || 0}y ${hosting.uptime.months || 0}m ${hosting.uptime.days || 0}d ${hosting.uptime.hours || 0}h ${hosting.uptime.minutes || 0}m ${hosting.uptime.seconds || 0}s` : "N/A";
const authorList = (topAuthors || []).map((a, i) =>
`${i + 1}. ${a._id || 'Unknown'} (${a.count})`
).join('\n') || 'None';
const viewedList = (topViewed || []).map((v, i) =>
`${i + 1}. ${v.itemName} ๐๐: ${v.itemID}\n ๐ฉ๐ถ๐ฒ๐๐: ${v.views}`
).join('\n\n') || 'None';
return sendBeautifulMessage(
`\nโญโโฏ ๐ฆ Total Commands: ${totalCommands || 0}\n` +
`โโโฏ ๐ Total Likes: ${totalLikes || 0}\n` +
`โโโฏ ๐ฅ Daily Users: ${dailyActiveUsers || 0}\n` +
`โฐโโฏ โฐ Uptime: ${uptimeStr}\n\n` +
`โโใ ๐ Top Authors ใโโ\nโฐ${authorList}\n\n` +
`โโใ ๐ฅ Most Viewed ใโโ\nโฐ${viewedList}\n` +
(hosting?.system ? (
`\n ๐ ๐๐ผ๐๐๐ถ๐ป๐ด ๐๐ป๐ณ๐ผ\n` +
`โญโโฏ ๐ป ๐ฆ๐๐๐๐ฒ๐บ\n` +
`โ ๐ง ${hosting.system.platform} (${hosting.system.arch})\n` +
`โ ๐ Node ${hosting.system.nodeVersion}\n` +
`โฐ ๐ฅ๏ธ CPU Cores: ${hosting.system.cpuCores}`
) : "")
);
}
case "like": {
const likeItemId = parseInt(args[1]);
if (isNaN(likeItemId)) return sendBeautifulMessage("\n[โ ๏ธ]โ Please provide a valid item ID.");
const { data } = await axios.post(`${GoatStor}/api/items/${likeItemId}/like`);
if (data.success) {
return sendBeautifulMessage(
`\nโญโโฏ โจ ๐ฆ๐๐ฎ๐๐๐\nโฐ Successfully liked!\n\nโญโโฏ ๐ ๐ง๐ผ๐๐ฎ๐น ๐๐ถ๐ธ๐ฒ๐\nโฐ ${data.likes}`
);
} else {
return sendBeautifulMessage("\n[โ ๏ธ]โ Failed to like the command.");
}
}
case "upload": {
const commandName = args[1];
if (!commandName) return sendBeautifulMessage("\n[โ ๏ธ]โ Please provide a command name.\nExample: `goatstore upload testCmd`");
const cleanCmdName = commandName.replace(/\.js$/i, "");
const commandPath = path.join(commandsDir, `${cleanCmdName}.js`);
if (!fs.existsSync(commandPath)) return sendBeautifulMessage(`\nโ File '${cleanCmdName}.js' not found in modules/cmds directory.`);
try {
const code = fs.readFileSync(commandPath, 'utf8');
let commandFile;
try {
delete require.cache[require.resolve(commandPath)];
commandFile = require(commandPath);
} catch (err) {
return sendBeautifulMessage(`\n[โ ๏ธ]โ Invalid command file structure: ${err.message}`);
}
const uploadData = {
itemName: commandFile.config?.name || cleanCmdName,
description: commandFile.config?.longDescription?.en || commandFile.config?.shortDescription?.en || "No description provided",
type: "GoatBot",
code: code,
authorName: commandFile.config?.author || "Unknown"
};
let response;
try {
response = await axios.post(`${GoatStor}/v1/paste`, uploadData);
} catch (postErr) {
response = await axios.post(`${GoatStor}/api/upload`, uploadData);
}
if (response.data && (response.data.success || response.data.itemID)) {
const itemID = response.data.itemID || response.data.id;
const link = response.data.link || `${GoatStor}/raw/${response.data.rawID || itemID}`;
return sendBeautifulMessage(
"\n" +
`โญโโฏ โ
๐ฆ๐๐ฎ๐๐๐\nโฐ Command uploaded successfully!\n\n` +
`โญโโฏ ๐ ๐ก๐ฎ๐บ๐ฒ\nโฐ ${uploadData.itemName}\n\n` +
`โญโโฏ ๐ ๐๐\nโฐ ${itemID}\n\n` +
`โญโโฏ ๐จโ๐ป ๐๐๐๐ต๐ผ๐ฟ\nโฐ ${uploadData.authorName}\n\n` +
`โญโโฏ ๐ ๐ฅ๐ฎ๐ ๐๐ถ๐ป๐ธ\nโฐ ${link}`
);
}
return sendBeautifulMessage("\n[โ ๏ธ]โ Failed to upload the command. Server returned an invalid response.");
} catch (error) {
console.error("Upload error:", error?.response?.data || error.message);
return sendBeautifulMessage(`\n[โ ๏ธ]โ Upload error: ${error?.response?.data?.message || error.message}`);
}
}
default:
return sendBeautifulMessage("\n[โ ๏ธ]โ Invalid subcommand. Use `goatstore` menu for options");
}
} catch (err) {
console.error("GoatStore Error:", err);
return sendBeautifulMessage("\n[โ ๏ธ]โ An unexpected error occurred.");
}
}
};