← back to browse
goat command

help

Show all commands

0
views
0
likes
0
installs

Aliases: menu, commands

raw source
const fs = require("fs-extra");
const path = require("path");
const https = require("https");

module.exports = {
  config: {
    name: "help",
    aliases: ["menu", "commands"],
    version: "6.4",
    author: "EryXenX",
    shortDescription: "Show all commands",
    longDescription: "Show all commands in clean UI",
    category: "system",
    guide: "{pn}help [command name]"
  },

  onStart: async function ({ message, args, prefix }) {
    const allCommands = global.GoatBot.commands;

    const fancyFont = (str) =>
      str.replace(/[A-Za-z]/g, (c) => {
        const map = {
          A:"๐€",B:"๐",C:"๐‚",D:"๐ƒ",E:"๐„",F:"๐…",G:"๐†",H:"๐‡",
          I:"๐ˆ",J:"๐‰",K:"๐Š",L:"๐‹",M:"๐Œ",N:"๐",O:"๐Ž",P:"๐",
          Q:"๐",R:"๐‘",S:"๐’",T:"๐“",U:"๐”",V:"๐•",W:"๐–",X:"๐—",
          Y:"๐˜",Z:"๐™",
          a:"๐š",b:"๐›",c:"๐œ",d:"๐",e:"๐ž",f:"๐Ÿ",g:"๐ ",h:"๐ก",
          i:"๐ข",j:"๐ฃ",k:"๐ค",l:"๐ฅ",m:"๐ฆ",n:"๐ง",o:"๐จ",p:"๐ฉ",
          q:"๐ช",r:"๐ซ",s:"๐ฌ",t:"๐ญ",u:"๐ฎ",v:"๐ฏ",w:"๐ฐ",x:"๐ฑ",
          y:"๐ฒ",z:"๐ณ"
        };
        return map[c] || c;
      });

    const categoryFont = (str) =>
      str.split("").map(c => {
        const map = {
          A:"๐€",B:"๐",C:"๐‚",D:"๐ƒ",E:"๐„",F:"๐…",G:"๐†",H:"๐‡",
          I:"๐ˆ",J:"๐‰",K:"๐Š",L:"๐‹",M:"๐Œ",N:"๐",O:"๐Ž",P:"๐",
          Q:"๐",R:"๐‘",S:"๐’",T:"๐“",U:"๐”",V:"๐•",W:"๐–",X:"๐—",
          Y:"๐˜",Z:"๐™"
        };
        return map[c] || c;
      }).join("");

    const cleanCategoryName = (text) => text ? text.toLowerCase() : "others";

    if (args[0]) {
      const cmdName = args[0].toLowerCase();
      const cmd =
        allCommands.get(cmdName) ||
        [...allCommands.values()].find(c => c.config.aliases?.includes(cmdName));

      if (!cmd)
        return message.reply(
`โŒ ${fancyFont(`Command '${cmdName}' not found!`)}
โžค Try ${prefix}help to see full list`
        );

      const usage = typeof cmd.config.guide === "string"
        ? cmd.config.guide.replace("{pn}", cmd.config.name)
        : cmd.config.name;

      const infoMsg =
`โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
 ๐Ÿงฉ ๐‚๐Œ๐ƒ ๐ˆ๐๐…๐Ž
โ”—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”›
 โœฆ Name     : ${cmd.config.name}
 โœฆ Aliases  : ${cmd.config.aliases?.join(", ") || "None"}
 โœฆ Category : ${categoryFont((cmd.config.category || "Others").toUpperCase())}
 โœฆ Version  : v${cmd.config.version || "1.0"}
 โœฆ Author   : ${cmd.config.author || "Unknown"}
 โœฆ Usage    : ${prefix}${usage}
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
 ๐Ÿ“ ${(cmd.config.longDescription || cmd.config.shortDescription || "No description")}`;

      return message.reply(infoMsg);
    }

    const categories = {};

    for (const [name, cmd] of allCommands) {
      const cat = cleanCategoryName(cmd.config.category);
      if (!categories[cat]) categories[cat] = [];
      categories[cat].push(name);
    }

    let msg =
`โ•ญโ”€ ๐‚๐Ž๐Œ๐Œ๐€๐๐ƒ๐’ ๐Œ๐„๐๐”
โ”œ Prefix : ${prefix}
โ”œ Total  : ${allCommands.size}
โ”œ Author : Ridh `;

    for (const cat of Object.keys(categories).sort()) {
      const catTitle = categoryFont(cat.toUpperCase());
      msg += `\nโ”Œโ”€ ${catTitle} โ”€โ”\n`;
      for (const cmdName of categories[cat].sort()) {
        msg += `โ”‚ โŽ™ ${fancyFont(cmdName)}\n`;
      }
      msg += `โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜\n`;
    }

    msg += `\nโ•ฐโ”€ Use: ${prefix}help <command>`;

    const gifURLs = [
      "https://i.imgur.com/Xw6JTfn.gif",
      "https://i.imgur.com/mW0yjZb.gif",
      "https://i.imgur.com/KQBcxOV.gif"
    ];

    const randomGifURL = gifURLs[Math.floor(Math.random() * gifURLs.length)];
    const gifFolder = path.join(__dirname, "cache");

    if (!fs.existsSync(gifFolder))
      fs.mkdirSync(gifFolder, { recursive: true });

    const gifName = path.basename(randomGifURL);
    const gifPath = path.join(gifFolder, gifName);

    if (!fs.existsSync(gifPath))
      await downloadGif(randomGifURL, gifPath);

    return message.reply({
      body: msg,
      attachment: fs.createReadStream(gifPath)
    });
  }
};

function downloadGif(url, dest) {
  return new Promise((resolve, reject) => {
    const file = fs.createWriteStream(dest);
    https.get(url, (res) => {
      if (res.statusCode !== 200) {
        fs.unlink(dest, () => {});
        return reject();
      }
      res.pipe(file);
      file.on("finish", () => file.close(resolve));
    }).on("error", (err) => {
      fs.unlink(dest, () => {});
      reject(err);
    });
  });
}

View raw file