← back to browse
goat command

help

Show all commands

0
views
0
likes
0
installs

Aliases: menu

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

// --- Fonts ---
const smallCapsMap = {
  a:'แด€', b:'ส™', c:'แด„', d:'แด…', e:'แด‡', f:'๊œฐ',
  g:'ษข', h:'สœ', i:'ษช', j:'แดŠ', k:'แด‹', l:'สŸ',
  m:'แด', n:'ษด', o:'แด', p:'แด˜', q:'วซ', r:'ส€',
  s:'๊œฑ', t:'แด›', u:'แดœ', v:'แด ', w:'แดก', x:'x',
  y:'ส', z:'แดข'
};

const cmdFontMap = {
  ...smallCapsMap,
  '0':'โฐ','1':'ยน','2':'ยฒ','3':'ยณ','4':'โด',
  '5':'โต','6':'โถ','7':'โท','8':'โธ','9':'โน'
};

const toSmallCaps = t =>
  t.toLowerCase().split("").map(c => smallCapsMap[c] || c).join("");

const toCmdFont = t =>
  t.toLowerCase().split("").map(c => cmdFontMap[c] || c).join("");

module.exports = {
  config: {
    name: "help",
    aliases: ["menu"],
    version: "6.0",
    author: "๐€๐‘๐ˆ๐˜๐€๐",
    shortDescription: "Show all commands",
    longDescription: "Full command list with video",
    category: "system",
    guide: "{pn}help [command]"
  },

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

    const cleanCategoryName = (text) => {
      if (!text) return "OTHERS";
      return text
        .normalize("NFKD")
        .replace(/[^\w\s-]/g, "")
        .replace(/\s+/g, " ")
        .trim()
        .toUpperCase();
    };

    // --- organize commands ---
    for (const [, cmd] of allCommands) {
      if (!cmd?.config || cmd.config.name === "help") continue;
      const cat = cleanCategoryName(cmd.config.category);
      if (!categories[cat]) categories[cat] = [];
      categories[cat].push(cmd.config.name);
    }

    // --- video list ---
    const videoURLs = [
      "https://i.imgur.com/IJOTdkf.mp4",
      "https://i.imgur.com/amKPt9x.mp4",
      "https://i.imgur.com/Aj0skDe.mp4",
      "https://i.imgur.com/2mRF8gL.mp4",
      "https://i.imgur.com/AMv8IqG.mp4",
      "https://i.imgur.com/mUpxBMI.mp4",
      "https://i.imgur.com/dhcx6pW.mp4",
      "https://i.imgur.com/SF4abeL.mp4",
      "https://i.imgur.com/qw9KVTY.mp4"
    ];

    const cacheDir = path.join(__dirname, "cache");
    if (!fs.existsSync(cacheDir)) fs.mkdirSync(cacheDir, { recursive: true });

    const indexFile = path.join(cacheDir, "help_video_index.json");
    let index = 0;

    if (fs.existsSync(indexFile)) {
      try {
        index = (JSON.parse(fs.readFileSync(indexFile)).index + 1) % videoURLs.length;
      } catch {}
    }

    fs.writeFileSync(indexFile, JSON.stringify({ index }));

    const videoPath = path.join(cacheDir, `help_video_${index}.mp4`);
    if (!fs.existsSync(videoPath)) {
      await downloadFile(videoURLs[index], videoPath);
    }

    // --- single command ---
    if (args[0]) {
      const query = args[0].toLowerCase();

      const cmd =
        allCommands.get(query) ||
        [...allCommands.values()].find(c =>
          (c.config?.aliases || []).map(a => a.toLowerCase()).includes(query)
        );

      if (!cmd || !cmd.config) {
        return message.reply(`โŒ Command "${query}" not found.`);
      }

      const {
        name,
        version,
        category,
        shortDescription,
        longDescription,
        aliases,
        guide
      } = cmd.config;

      const desc =
        typeof longDescription === "string"
          ? longDescription
          : longDescription?.en ||
            shortDescription?.en ||
            shortDescription ||
            "No description";

      const usage =
        (typeof guide === "string"
          ? guide
          : guide?.en || `{pn}${name}`)
          .replace(/{pn}/g, prefix);

      return message.reply({
        body:
          `๐ŸŒธ COMMAND INFO ๐ŸŒธ\n\n` +
          `๐ŸŽ€ Name: ${name}\n\n` +
          `๐ŸŽ€ Category: ${category || "None"}\n\n` +
          `๐ŸŽ€ Description: ${desc}\n\n` +
          `๐ŸŽ€ Aliases: ${aliases?.length ? aliases.join(", ") : "None"}\n\n` +
          `๐ŸŽ€ Usage: ${usage}\n\n` +
          `๐ŸŽ€ Author: ๐€๐‘๐ˆ๐˜๐€๐\n\n` +
          `๐ŸŽ€ Version: ${version || "1.0"}`,
        attachment: fs.createReadStream(videoPath)
      });
    }

    // --- full menu ---
    let msg = "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”๐’ฌ\nโ”‹ ๐“Šˆ๐Ÿ“ ARIYAN BOT CMDS ๐Ÿ“๐“Љ\nโ”•โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”๐’ฌ\n\n\n";

    const sortedCategories = Object.keys(categories).sort();

    for (const cat of sortedCategories) {
      msg += `โ•ญโ”โ”โ”๐“Šˆ ๐Ÿ ${toSmallCaps(cat)} ๐“Љ\n`;
      const commands = categories[cat].sort();

      for (let i = 0; i < commands.length; i += 2) {
        const a = toCmdFont(commands[i]);
        const b = commands[i + 1] ? toCmdFont(commands[i + 1]) : null;
        msg += b ? `โ”‹โŒฌ ${a}   โŒฌ ${b}\n` : `โ”‹โŒฌ ${a}\n`;
      }

      msg += `โ”•โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”๐’ฌ\n\n`;
    }

    msg +=
      `โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”๐’ฌ\n` +
      ` ๐“Šˆ๐ŸŽ€๐“Љ Total Commands: ${allCommands.size - 1}\n` +
      ` ๐“Šˆ๐Ÿ”‘๐“Љ Prefix: ${prefix}\n` +
      ` ๐“Šˆ๐Ÿ‘‘๐“Љ Owner: ARIYAN\n` +
      `โ”•โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”๐’ฌ`;

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

// --- downloader ---
function downloadFile(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