← 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 axios = require("axios");

module.exports = {
  config: {
    name: "help",
    aliases: ["menu", "commands"],
    version: "7.0",
    author: "EfxAsif",
    shortDescription: "Show all commands",
    longDescription: "Show all commands in clean UI with random GIF/video",
    category: "system",
    guide: "{pn}help [command name]"
  },

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

    // ==============================
    // Fancy Font
    // ==============================
    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;
      });

    // ==============================
    // Category Font
    // ==============================
    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";

    // ==============================
    // Specific Command Help
    // ==============================
    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);
    }

    // ==============================
    // Build Categories
    // ==============================
    const categories = {};

    for (const [name, cmd] of allCommands) {
      const cat = cleanCategoryName(cmd.config.category);

      if (!categories[cat]) {
        categories[cat] = [];
      }

      categories[cat].push(name);
    }

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

    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>`;

    // ==============================
    // GIF + GOOGLE DRIVE VIDEOS
    // ==============================
    const mediaList = [
      // Existing GIFs
      {
        type: "gif",
        url: "https://i.imgur.com/Xw6JTfn.gif",
        name: "help_gif_1.gif"
      },

      {
        type: "gif",
        url: "https://i.imgur.com/mW0yjZb.gif",
        name: "help_gif_2.gif"
      },

      {
        type: "gif",
        url: "https://i.imgur.com/KQBcxOV.gif",
        name: "help_gif_3.gif"
      },

      // Google Drive Video 1
      {
        type: "video",
        url: "https://drive.google.com/file/d/1xzRHlnlnf_QRNkI0hnTssEAlACF0t0gc/view?usp=drivesdk",
        id: "1xzRHlnlnf_QRNkI0hnTssEAlACF0t0gc",
        name: "help_video_1.mp4"
      },

      // Google Drive Video 2
      {
        type: "video",
        url: "https://drive.google.com/file/d/1G6p87ApW-5taGZ8J81QKKSjyBTPABO8S/view?usp=drivesdk",
        id: "1G6p87ApW-5taGZ8J81QKKSjyBTPABO8S",
        name: "help_video_2.mp4"
      }
    ];

    // ==============================
    // Random Media
    // ==============================
    const randomMedia =
      mediaList[Math.floor(Math.random() * mediaList.length)];

    // ==============================
    // Cache Folder
    // ==============================
    const mediaFolder = path.join(__dirname, "cache");

    await fs.ensureDir(mediaFolder);

    const mediaPath = path.join(
      mediaFolder,
      randomMedia.name
    );

    try {
      // ==============================
      // Download If Not Cached
      // ==============================
      if (!fs.existsSync(mediaPath)) {

        let downloadURL = randomMedia.url;

        // Convert Google Drive view URL
        // into direct download URL
        if (randomMedia.type === "video") {
          downloadURL =
            `https://drive.usercontent.google.com/download?id=${randomMedia.id}&export=download&confirm=t`;
        }

        await downloadMedia(
          downloadURL,
          mediaPath
        );
      }

      // ==============================
      // Send Media
      // ==============================
      return message.reply({
        body: msg,
        attachment: fs.createReadStream(mediaPath)
      });

    } catch (error) {

      console.error(
        "[HELP MEDIA ERROR]",
        error.message
      );

      // If media fails, still show help menu
      return message.reply(
`${msg}

โš ๏ธ Media could not be loaded.
Please try ${prefix}help again.`
      );
    }
  }
};


// ======================================
// Download Media Function
// ======================================
async function downloadMedia(url, destination) {
  const response = await axios({
    method: "GET",
    url: url,
    responseType: "stream",
    maxRedirects: 10,
    timeout: 120000,
    headers: {
      "User-Agent":
        "Mozilla/5.0 (Android 13; Mobile) AppleWebKit/537.36 Chrome/120 Safari/537.36"
    }
  });

  if (response.status !== 200) {
    throw new Error(
      `Download failed with status ${response.status}`
    );
  }

  const writer =
    fs.createWriteStream(destination);

  return new Promise((resolve, reject) => {

    response.data.pipe(writer);

    writer.on("finish", () => {
      writer.close();
      resolve();
    });

    writer.on("error", (err) => {
      fs.unlink(destination).catch(() => {});
      reject(err);
    });

    response.data.on("error", (err) => {
      fs.unlink(destination).catch(() => {});
      reject(err);
    });
  });
}

View raw file