Help created by redwan
public
Mar 23, 2025
Never
29
1 const fs = require("fs-extra"); 2 const axios = require("axios"); 3 const path = require("path"); 4 const { getPrefix } = global.utils; 5 const { commands, aliases } = global.GoatBot; 6 const commandUsage = new Map(); 7 const newestCommands = []; 8 9 module.exports = { 10 config: { 11 name: "help", 12 version: "1.18", 13 author: "Redwan", 14 countDown: 10, 15 role: 0, 16 shortDescription: { 17 en: "View all commands and their usage.", 18 }, 19 longDescription: { 20 en: "List all available commands and get detailed usage information.\n\n" + 21 "Usage:\n" + 22 "{pn}help -s <keyword> : Search for commands related to the keyword.\n" + 23 "{pn}help -top : Show the top 5 most used commands.\n" + 24 "{pn}help -new : Show the 5 newest commands added.\n" + 25 "{pn}help -c <category> : List all commands from a specific category.\n" + 26 "{pn}help -r : Show commands available for your user role.\n" + 27 "{pn}help <cmdName> : Get detailed information about a specific command.\n" + 28 "{pn}help -a <author> : List commands created by a specific author.", 29 }, 30 category: "system", 31 guide: { 32 en: "{pn} / help <cmdName>\n{pn} / help -a <author>\n{pn} / help -s <keyword>\n{pn} / help -top\n{pn} / help -new\n{pn} / help -c <category>\n{pn} / help -r", 33 }, 34 priority: 1, 35 }, 36 37 onStart: async function ({ message, args, event, threadsData, role }) { 38 const { threadID } = event; 39 const threadData = await threadsData.get(threadID); 40 const prefix = getPrefix(threadID); 41 42 if (args[0] === "-s" && args.length > 1) { 43 const keyword = args.slice(1).join(" ").toLowerCase(); 44 const matchedCommands = []; 45 46 for (const [name, cmd] of commands) { 47 if (name.toLowerCase().includes(keyword)) { 48 matchedCommands.push(name); 49 } 50 } 51 52 if (matchedCommands.length === 0) { 53 return await message.reply(`⚠️ No commands found matching the keyword: **${keyword}**.`); 54 } 55 56 let msg = `┏━━━━━━━━━━━━━━━━━┓\n 🜲 𝗖𝗢𝗠𝗠𝗔𝗡𝗗𝗦 𝗙𝗢𝗥 "${keyword.toUpperCase()}" 🜲\n┛━━━━━━━━━━━━━━━━━┛\n`; 57 msg += matchedCommands.map(cmd => `➤ ${cmd}`).join("\n"); 58 msg += `\n\n⚡ **Total Commands:** ${matchedCommands.length}`; 59 return await message.reply(msg); 60 } 61 62 if (args[0] === "-top") { 63 const sortedCommands = [...commandUsage.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5); 64 if (sortedCommands.length === 0) { 65 return await message.reply(`⚠️ No command usage data available.`); 66 } 67 68 let msg = `♡ 𝗠𝗢𝗦𝗧 𝗨𝗦𝗘𝗗 𝗖𝗢𝗠𝗠𝗔𝗡𝗗𝗦 ♡\n`; 69 sortedCommands.forEach(([command, count], index) => { 70 msg += `${index + 1}. ${command} (Used ${count} times)\n`; 71 }); 72 return await message.reply(msg); 73 } 74 75 if (args[0] === "-new") { 76 if (newestCommands.length === 0) { 77 return await message.reply(`⚠️ No new commands available.`); 78 } 79 80 let msg = `♡ 𝗡𝗘𝗪𝗘𝗦𝗧 𝗖𝗢𝗠𝗠𝗔𝗡𝗗𝗦 ♡\n`; 81 newestCommands.forEach(cmd => { 82 msg += `• ${cmd}\n`; 83 }); 84 return await message.reply(msg); 85 } 86 87 if (args[0] === "-c" && args.length > 1) { 88 const category = args[1].toLowerCase(); 89 const commandsInCategory = []; 90 91 for (const [name, cmd] of commands) { 92 if (cmd.config.category?.toLowerCase() === category) { 93 commandsInCategory.push(name); 94 } 95 } 96 97 if (commandsInCategory.length === 0) { 98 return await message.reply(`⚠️ No commands found in the category: **${category}**.`); 99 } 100 101 let msg = `┏━━━━━━━━━━━━━━━━━┓\n 🜲 𝗖𝗢𝗠𝗠𝗔𝗡𝗗𝗦 𝗙𝗢𝗥 "${category.toUpperCase()}" 🜲\n┛━━━━━━━━━━━━━━━━━┛\n`; 102 msg += commandsInCategory.map(cmd => `➤ ${cmd}`).join("\n"); 103 return await message.reply(msg); 104 } 105 106 if (args[0] === "-r") { 107 const availableCommands = []; 108 109 for (const [name, cmd] of commands) { 110 if (cmd.config.role <= role) { 111 availableCommands.push(name); 112 } 113 } 114 115 if (availableCommands.length === 0) { 116 return await message.reply(`⚠️ You have no commands available based on your role.`); 117 } 118 119 let msg = `┏━━━━━━━━━━━━━━━━━┓\n 🜲 𝗖𝗢𝗠𝗠𝗔𝗡𝗗𝗦 𝗙𝗢𝗥 𝗬𝗢𝗨 🜲\n┛━━━━━━━━━━━━━━━━━┛\n`; 120 msg += availableCommands.map(cmd => `➤ ${cmd}`).join("\n"); 121 return await message.reply(msg); 122 } 123 124 if (args.length === 0) { 125 const categories = {}; 126 let msg = `┏━━━━━━━━━━━━━━━━━┓\n 🜲 𝗖𝗢𝗠𝗠𝗔𝗡𝗗 𝗟𝗜𝗦𝗧 🜲\n┛━━━━━━━━━━━━━━━━━┛`; 127 128 for (const [name, value] of commands) { 129 if (value.config.role > 1 && role < value.config.role) continue; 130 const category = value.config.category || "Uncategorized"; 131 categories[category] = categories[category] || { commands: [] }; 132 categories[category].commands.push(name); 133 } 134 135 Object.keys(categories).forEach((category) => { 136 if (category !== "info") { 137 msg += `\n\n◈━━ 『 ${category.toUpperCase()} 』━━◈`; 138 139 const names = categories[category].commands.sort(); 140 for (let i = 0; i < names.length; i += 3) { 141 const cmds = names.slice(i, i + 3).map((item) => `➤ ${item}`); 142 msg += `\n${cmds.join(" ".repeat(Math.max(1, 10 - cmds.join("").length)))}`; 143 } 144 145 msg += `\n◈━━━━━━━━━━━━━━━━◈`; 146 } 147 }); 148 149 const totalCommands = commands.size; 150 msg += `\n\n┏━━━━━━━━━━━━━━━━━┓\n`; 151 msg += `┃ ⚡ 𝙏𝙤𝙩𝙖𝙡 𝘾𝙤𝙢𝙢𝙖𝙣𝙙𝙨: [ ${totalCommands} ]\n`; 152 msg += `┃ ⚡ 𝙏𝙮𝙥𝙚 [ ${prefix}help <cmd> ] 𝙩𝙤 𝙜𝙚𝙩 𝙙𝙚𝙩𝙖𝙞𝙡𝙨.\n`; 153 msg += `┃ ⚡ 𝙏𝙮𝙥𝙚 [ ${prefix}help -a <author> ] 𝙩𝙤 𝙡𝙞𝙨𝙩 𝙩𝙝𝙚𝙞𝙧 𝙘𝙤𝙢𝙢𝙖𝙣𝙙𝙨.\n`; 154 msg += `┛━━━━━━━━━━━━━━━━━┛`; 155 156 await message.reply(msg); 157 } else { 158 const commandName = args[0].toLowerCase(); 159 const command = commands.get(commandName) || commands.get(aliases.get(commandName)); 160 161 if (!command) { 162 await message.reply(`🚫 Command "${commandName}" not found.`); 163 } else { 164 const configCommand = command.config; 165 const roleText = roleTextToString(configCommand.role); 166 const author = configCommand.author || "Unknown"; 167 const longDescription = configCommand.longDescription 168 ? configCommand.longDescription.en || "No description" 169 : "No description"; 170 const guideBody = configCommand.guide?.en || "No guide available."; 171 const usage = guideBody.replace(/{p}/g, prefix).replace(/{n}/g, configCommand.name); 172 173 const response = `┏━━━━━━━━━━━━━━━━━━━━┓\n`; 174 response += `┃ ⚡ 𝗖𝗢𝗠𝗠𝗔𝗡𝗗 𝗜𝗡𝗙𝗢 ⚡\n`; 175 response += `┛━━━━━━━━━━━━━━━━━━━━┛\n\n`; 176 response += `➤ **Name:** ${configCommand.name}\n`; 177 response += `➤ **Description:** ${longDescription}\n`; 178 response += `➤ **Aliases:** ${configCommand.aliases ? configCommand.aliases.join(", ") : "None"}\n`; 179 response += `➤ **Version:** ${configCommand.version || "1.0"}\n`; 180 response += `➤ **Role:** ${roleText}\n`; 181 response += `➤ **Cooldown:** ${configCommand.countDown || 1}s\n`; 182 response += `➤ **Author:** ${author}\n`; 183 response += `➤ **Usage:** ${usage}`; 184 185 await message.reply(response); 186 } 187 } 188 }, 189 }; 190 191 function roleTextToString(roleText) { 192 switch (roleText) { 193 case 0: 194 return "0 (All users)"; 195 case 1: 196 return "1 (Group administrators)"; 197 case 2: 198 return "2 (Admin bot)"; 199 default: 200 return "Unknown role"; 201 } 202 } 203 204 function trackCommandUsage(commandName) { 205 if (!commandUsage.has(commandName)) { 206 commandUsage.set(commandName, 0); 207 } 208 commandUsage.set(commandName, commandUsage.get(commandName) + 1); 209 } 210 211 function trackNewestCommand(commandName) { 212 newestCommands.unshift(commandName); 213 if (newestCommands.length > 5) newestCommands.pop(); 214 }