← back to browse
goat command

help

Shows all commands or details.

0
views
0
likes
0
installs

Aliases: menu

raw source
const axios = require("axios");
const { getPrefix } = global.utils;
const { commands, aliases } = global.GoatBot;

let xfont = null;
let yfont = null;
let categoryEmoji = null;

async function loadResources() {
 try {
 const [catRes, cmdRes, emojiRes] = await Promise.all([
 axios.get("https://raw.githubusercontent.com/Saim-x69x/sakura/main/xfont.json"),
 axios.get("https://raw.githubusercontent.com/Saim-x69x/sakura/main/yfont.json"),
 axios.get("https://raw.githubusercontent.com/Saim-x69x/sakura/main/category.json")
 ]);
 xfont = catRes.data;
 yfont = cmdRes.data;
 categoryEmoji = emojiRes.data;
 } catch (err) {}
}

function fontConvert(text, type = "command") {
 const fontMap = type === "category" ? xfont : yfont;
 if (!fontMap) return text;
 return text.split("").map(ch => fontMap[ch] || ch).join("");
}

function getCategoryEmoji(cat) {
 return categoryEmoji?.[cat.toLowerCase()] || "๐Ÿ—‚๏ธ";
}

function levenshteinDistance(a, b) {
 const matrix = Array(b.length + 1).fill(0).map(() => Array(a.length + 1).fill(0));
 for (let i = 0; i <= a.length; i++) matrix[0][i] = i;
 for (let j = 0; j <= b.length; j++) matrix[j][0] = j;
 for (let j = 1; j <= b.length; j++) {
 for (let i = 1; i <= a.length; i++) {
 const cost = a[i - 1] === b[j - 1] ? 0 : 1;
 matrix[j][i] = Math.min(
 matrix[j][i - 1] + 1,
 matrix[j - 1][i] + 1,
 matrix[j - 1][i - 1] + cost
 );
 }
 }
 return matrix[b.length][a.length];
}

function getClosestCommand(name) {
 const lower = name.toLowerCase();
 let best = null, dist = Infinity;
 for (const cmd of commands.keys()) {
 const d = levenshteinDistance(lower, cmd.toLowerCase());
 if (d < dist) {
 dist = d;
 best = cmd;
 }
 }
 return dist <= 3 ? best : null;
}

function roleTextToString(role) {
 switch (role) {
 case 0: return "All Users";
 case 1: return "Group Admins";
 case 2: return "VIP Users";
 case 3: return "Bot Admin";
 case 4: return "Bot Creator";
 default: return "Unknown";
 }
}

module.exports = {
 config: {
 name: "help",
 aliases: "menu",
 version: "2.0",
 author: "rocky404",
 countDown: 5,
 role: 0,
 shortDescription: { en: "Shows all commands or details." },
 longDescription: { en: "Display categories, command lists or specific command info." },
 category: "info",
 guide: { en: "{pn}, {pn} [command], {pn} -c [category]" }
 },

 onStart: async function ({ message, args, event, role }) {
 const prefix = getPrefix(event.threadID);

 if (!xfont || !yfont || !categoryEmoji) await loadResources();

 const categories = {};
 for (const [name, cmd] of commands) {
 if (!cmd?.config || typeof cmd.onStart !== "function") continue;
 if (cmd.config.role > role) continue;
 const cat = (cmd.config.category || "UNCATEGORIZED").toUpperCase();
 if (!categories[cat]) categories[cat] = [];
 categories[cat].push(name);
 }

 const helpImage = "https://files.catbox.moe/uoljwh.mp4";
 const input = args.join(" ").trim();

 if (args[0] === "-c" && args[1]) {
 const categoryName = args[1].toUpperCase();
 if (!categories[categoryName]) {
 return message.reply(`โŒ Category "${categoryName}" not found.`);
 }

 const emoji = getCategoryEmoji(categoryName);
 const list = categories[categoryName];
 const total = list.length;

 let msg = "";
 msg += "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n";
 msg += `๐‚๐€๐“๐„๐†๐Ž๐‘๐˜: ${emoji} | ${fontConvert(categoryName, "category")}\n`;
 msg += "โ•ญโ”€โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ\n";

 for (const cmd of list.sort()) {
 msg += `โ•Ž แฏ“โœง. ${fontConvert(cmd, "command")}\n`;
 }

 msg += "โ”•โ”โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”แฅซแญก\n";
 msg += "โ€ข ๐™ฝ๐šŽ๐šŽ๐š ๐š‘๐šŽ๐š•๐š™ ๐š ๐š’๐š๐š‘ ๐šŠ ๐šŒ๐š˜๐š–๐š–๐šŠ๐š—๐š? ๐š„๐šœ๐šŽ /๐š‘๐šŽ๐š•๐š™ <๐šŒ๐š˜๐š–๐š–๐šŠ๐š—๐š๐š—๐šŠ๐š–๐šŽ>.\n";
 msg += "โ•ญโ”€โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ\n";
 msg += `โ•Ž ๐Ÿ”ข ๐“๐จ๐ญ๐š๐ฅ ๐‚๐จ๐ฆ๐ฆ๐š๐ง๐๐ฌ: ${total}\n`;
 msg += `โ•Ž โšก๏ธ ๐๐ซ๐ž๐Ÿ๐ข๐ฑ: ${prefix}\n`;
 msg += "โ•Ž ๐Ÿ‘ค ๐‚๐ซ๐ž๐š๐ญ๐จ๐ซ: JABED\n";
 msg += "โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ";

 return message.reply({
 body: msg,
 attachment: await global.utils.getStreamFromURL(helpImage)
 });
 }

 if (!input) {
 let msg = "";
 msg += "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n";
 msg += "๐™ฐ๐šŸ๐šŠ๐š’๐š•๐šŠ๐š‹๐š•๐šŽ ๐™ฒ๐š˜๐š–๐š–๐šŠ๐š—๐š๐šœ:\n";
 msg += "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n";

 for (const cat of Object.keys(categories).sort()) {
 msg += `โ”โ”€โ”ใ€” ${getCategoryEmoji(cat)} | ${fontConvert(cat, "category")} ใ€•\n`;
 for (const cmd of categories[cat].sort()) {
 msg += `โ•Žแฏ“โœง. ${fontConvert(cmd, "command")}\n`;
 }
 msg += "โ”•โ”โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”แฅซแญก\n";
 }

 msg += "โ€ข ๐™ฝ๐šŽ๐šŽ๐š ๐š‘๐šŽ๐š•๐š™ ๐š ๐š’๐š๐š‘ ๐šŠ ๐šŒ๐š˜๐š–๐š–๐šŠ๐š—๐š? ๐š„๐šœ๐šŽ /๐š‘๐šŽ๐š•๐š™ <๐šŒ๐š˜๐š–๐š–๐šŠ๐š—๐š๐š—๐šŠ๐š–๐šŽ>.\n";
 msg += "โ•ญโ”€โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ\n";
 msg += `โ•Ž ๐Ÿ”ข ๐“๐จ๐ญ๐š๐ฅ ๐‚๐จ๐ฆ๐ฆ๐š๐ง๐๐ฌ: ${commands.size}\n`;
 msg += `โ•Ž โšก๏ธ ๐๐ซ๐ž๐Ÿ๐ข๐ฑ: ${prefix}\n`;
 msg += "โ•Ž ๐Ÿ‘ค ๐‚๐ซ๐ž๐š๐ญ๐จ๐ซ: JABED\n";
 msg += "โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€เญจเงŽโ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ";

 return message.reply({
 body: msg,
 attachment: await global.utils.getStreamFromURL(helpImage)
 });
 }

 const cmdName = input.toLowerCase();
 const cmd = commands.get(cmdName) || commands.get(aliases.get(cmdName));

 if (!cmd || !cmd.config) {
 const suggestion = getClosestCommand(cmdName);
 return message.reply(
 suggestion
 ? `โŒ Command "${cmdName}" not found.\n๐Ÿ‘‰ Maybe you meant: ${suggestion}`
 : `โŒ Command "${cmdName}" not found.`
 );
 }

 const c = cmd.config;
 const usage = c.guide?.en?.replace(/{pn}/g, `${prefix}${c.name}`) || "No usage.";

 const msg = `
โ•ญโ•โ•โ• [ ๐˜Š๐˜–๐˜”๐˜”๐˜ˆ๐˜•๐˜‹ ๐˜๐˜•๐˜๐˜– ] โ•โ•โ•โ•ฎ
โ•Ž๐Ÿงฉ Name : ${c.name}
โ•Ž๐Ÿ“ฆ Category : ${(c.category || "UNCATEGORIZED").toUpperCase()}
โ•Ž๐Ÿ“œ Description: ${c.longDescription?.en || "No description."}
โ•Ž๐Ÿ” Aliases : ${c.aliases ? c.aliases.join(", ") : "None"}
โ•Žโš™๏ธ Version : ${c.version || "1.0"}
โ•Ž๐Ÿ” Permission : ${c.role} (${roleTextToString(c.role)})
โ•Žโฑ๏ธ Cooldown : ${c.countDown || 5}s
โ•Ž๐Ÿ‘‘ Author : ${c.author || "Unknown"}
โ•Ž๐Ÿ“– Usage : ${usage}
โ•ฐโ•โ•โ•โ•โ•โ•โ•โ•โ•เญจเงŽโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฏ`;

 return message.reply(msg);
 }
};

View raw file