← back to browse
goat command

album

Manage and view video/photo albums

0
views
0
likes
0
installs
raw source
const axios = require("axios");
const path = require("path");
const fs = require("fs");

const API_CONFIG_URL =
  "https://raw.githubusercontent.com/cyber-ullash/cyber-ullash/refs/heads/main/UllashApi.json";

const getApiUrl = async () => {
  try {
    const response = await axios.get(API_CONFIG_URL);
    const albumUrl = response.data.album;
    if (!albumUrl) {
      throw new Error("Album API URL not found in the JSON data.");
    }
    return albumUrl;
  } catch (error) {
    console.error("API URL :", error);
    throw new Error("API URL");
  }
};

module.exports.config = {
  name: "album",
  version: "1.0.1",
  role: 0,
  author: "๐“†ฉ๐‘…๐‘œ๐’ท๐’พ๐“ƒ๐“†ช ๐’œ๐“๐’พ",
  description: "Manage and view video/photo albums",
  usePrefix: true,
  prefix: true,
  category: "Media",
  category: "media",
  usages: "Empty to see list, or album [category] to get media.",
  countDown: 5,
};

module.exports.onStart = async function ({ api, event, args }) {
  const { threadID, messageID, senderID } = event;

  const albumOptionsPage1 = [
    "funny",
    "islamic",
    "sad",
    "anime",
    "cartoon",
    "love",
    "horny",
    "couple",
    "flower",
    "marvel",
  ];
  const albumOptionsPage2 = [
    "aesthetic",
    "sigma",
    "lyrics",
    "cat",
    "18plus",
    "freefire",
    "football",
    "girl",
    "friends",
    "cricket",
  ];

  const toBold = (text) =>
    text.replace(/[a-z]/g, (c) =>
      String.fromCodePoint(0x1d41a + c.charCodeAt(0) - 97)
    );
  const toBoldNumber = (num) =>
    String(num).replace(/[0-9]/g, (c) =>
      String.fromCodePoint(0x1d7ec + parseInt(c))
    );

  const formatOptions = (options, startIndex = 1) =>
    options
      .map((opt, i) => `โœจ | ${toBoldNumber(i + startIndex)}. ${toBold(opt)}`)
      .join("\n");

  if (args[0] === "2") {
    const message2 =
      "๐Ÿ’ซ ๐‚๐ก๐จ๐จ๐ฌ๐ž ๐š๐ง ๐š๐ฅ๐›๐ฎ๐ฆ ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ ๐๐š๐›๐ฒ ๐Ÿ’ซ\n" +
      "โœบโ”โ”โ”โ”โ”โ”โ”โ—ˆโ—‰โ—ˆโ”โ”โ”โ”โ”โ”โ”โœบ\n" +
      formatOptions(albumOptionsPage2, 11) +
      "\nโœบโ”โ”โ”โ”โ”โ”โ”โ—ˆโ—‰โ—ˆโ”โ”โ”โ”โ”โ”โ”โœบ\n๐ŸŽฏ | ๐๐š๐ ๐ž [๐Ÿ/๐Ÿ]\nโœบโ”โ”โ”โ”โ”โ”โ”โ—ˆโ—‰โ—ˆโ”โ”โ”โ”โ”โ”โ”โœบ";

    await api.sendMessage(
      { body: message2 },
      threadID,
      (error, info) => {
        if (!error && info && info.messageID) {
          if (global.GoatBot?.onReply) { global.GoatBot.onReply.set(info.messageID, { 
            name: this.config.name,
            type: "reply",
            messageID: info.messageID,
            author: senderID,
            link: albumOptionsPage2,
           }); }
        }
      },
      messageID
    );
    return;
  }

  if (!args[0] || args[0].toLowerCase() === "list") {
    api.setMessageReaction("โ˜ข๏ธ", messageID, () => {}, true);

    const message =
      "๐Ÿ’ซ ๐‚๐ก๐จ๐จ๐ฌ๐ž ๐š๐ง ๐š๐ฅ๐›๐ฎ๐ฆ ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ ๐๐š๐›๐ฒ ๐Ÿ’ซ\n" +
      "โœบโ”โ”โ”โ”โ”โ”โ”โ—ˆโ—‰โ—ˆโ”โ”โ”โ”โ”โ”โ”โœบ\n" +
      formatOptions(albumOptionsPage1) +
      `\nโœบโ”โ”โ”โ”โ”โ”โ”โ—ˆโ—‰โ—ˆโ”โ”โ”โ”โ”โ”โ”โœบ\n๐ŸŽฏ | ๐๐š๐ ๐ž [๐Ÿ/๐Ÿ]\nโ„น | ๐“๐ฒ๐ฉ๐ž: ${global.config.PREFIX}album 2 - ๐ง๐ž๐ฑ๐ญ ๐ฉ๐š๐ ๐ž\nโœบโ”โ”โ”โ”โ”โ”โ”โ—ˆโ—‰โ—ˆโ”โ”โ”โ”โ”โ”โ”โœบ`;

    await api.sendMessage(
      { body: message },
      threadID,
      (error, info) => {
        if (!error && info && info.messageID) {
          if (global.GoatBot?.onReply) { global.GoatBot.onReply.set(info.messageID, { 
            name: this.config.name,
            type: "reply",
            messageID: info.messageID,
            author: senderID,
            link: albumOptionsPage1,
           }); }
        }
      },
      messageID
    );
    return;
  }

  const validCategories = [
    "cartoon",
    "marvel",
    "lofi",
    "sad",
    "islamic",
    "funny",
    "horny",
    "anime",
    "love",
    "baby",
    "lyrics",
    "sigma",
    "aesthetic",
    "cat",
    "flower",
    "freefire",
    "sex",
    "girl",
    "football",
    "friend",
    "cricket",
    "couple",
    "18plus",
    "freefire",
  ];

  const command = args[0].toLowerCase();

  if (!validCategories.includes(command)) {
    return api.sendMessage(
      "โŒ ๐ˆ๐ง๐ฏ๐š๐ฅ๐ข๐ ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ! ๐“๐ฒ๐ฉ๐ž '/album' ๐ญ๐จ ๐ฌ๐ž๐ž ๐ฅ๐ข๐ฌ๐ญ.",
      threadID,
      messageID
    );
  }

  return api.sendMessage(
    `๐Ÿ“ ๐‹๐จ๐š๐๐ข๐ง๐  ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ: ๐š๐ฅ๐›๐ฎ๐ฆ - ${command}...`,
    threadID,
    messageID
  );
};

module.exports.onReply = async function ({ api, event, handleReply: _origReply }) {
  const handleReply = Reply || _origReply || {};
  api.unsendMessage(handleReply.messageID);

  const adminID = "100091520325159";
  const replyNum = parseInt(event.body);
  if (isNaN(replyNum)) {
    return api.sendMessage(
      "โŒ ๐๐ฅ๐ž๐š๐ฌ๐ž ๐ซ๐ž๐ฉ๐ฅ๐ฒ ๐ฐ๐ข๐ญ๐ก ๐š ๐ฏ๐š๐ฅ๐ข๐ ๐ง๐ฎ๐ฆ๐›๐ž๐ซ.",
      event.threadID,
      event.messageID
    );
  }

  const categories = [
    "funny",
    "islamic",
    "sad",
    "anime",
    "cartoon",
    "love",
    "horny",
    "couple",
    "flower",
    "marvel",
    "aesthetic",
    "sigma",
    "lyrics",
    "cat",
    "18plus",
    "freefire",
    "football",
    "girl",
    "friend",
    "cricket",
  ];

  if (replyNum < 1 || replyNum > categories.length) {
    return api.sendMessage(
      "โŒ ๐ˆ๐ง๐ฏ๐š๐ฅ๐ข๐ ๐ฌ๐ž๐ฅ๐ž๐œ๐ญ๐ข๐จ๐ง.",
      event.threadID,
      event.messageID
    );
  }

  const selectedCategory = categories[replyNum - 1];

  if (
    (selectedCategory === "horny" || selectedCategory === "18plus") &&
    event.senderID !== adminID
  ) {
    return api.sendMessage(
      "๐Ÿšซ ๐˜๐จ๐ฎ ๐š๐ซ๐ž ๐ง๐จ๐ญ ๐š๐ฎ๐ญ๐ก๐จ๐ซ๐ข๐ณ๐ž๐ ๐Ÿ๐จ๐ซ ๐ญ๐ก๐ข๐ฌ ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ.",
      event.threadID,
      event.messageID
    );
  }

  const captions = {
    funny: "๐Ÿคฃ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐…๐ฎ๐ง๐ง๐ฒ ๐ฏ๐ข๐๐ž๐จ",
    islamic: "๐Ÿ˜‡ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐ˆ๐ฌ๐ฅ๐š๐ฆ๐ข๐œ ๐ฏ๐ข๐๐ž๐จ",
    sad: "๐Ÿฅบ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐’๐š๐ ๐ฏ๐ข๐๐ž๐จ",
    anime: "๐Ÿ˜˜ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐€๐ง๐ข๐ฆ๐ž ๐ฏ๐ข๐๐ž๐จ",
    cartoon: "๐Ÿ˜‡ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‚๐š๐ซ๐ญ๐จ๐จ๐ง ๐ฏ๐ข๐๐ž๐จ",
    love: "๐Ÿ˜‡ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‹๐จ๐ฏ๐ž ๐ฏ๐ข๐๐ž๐จ",
    horny: "๐Ÿฅต > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‡๐จ๐ซ๐ง๐ฒ ๐ฏ๐ข๐๐ž๐จ",
    couple: "โค๏ธ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‚๐จ๐ฎ๐ฉ๐ฅ๐ž ๐ฏ๐ข๐๐ž๐จ",
    flower: "๐ŸŒธ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐…๐ฅ๐จ๐ฐ๐ž๐ซ ๐ฏ๐ข๐๐ž๐จ",
    marvel: "๐ŸŽฏ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐Œ๐š๐ซ๐ฏ๐ž๐ฅ ๐ฏ๐ข๐๐ž๐จ",
    aesthetic: "๐ŸŽ€ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐€๐ž๐ฌ๐ญ๐ก๐ž๐ญ๐ข๐œ ๐ฏ๐ข๐๐ž๐จ",
    sigma: "๐Ÿค > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐’๐ข๐ ๐ฆ๐š ๐ฏ๐ข๐๐ž๐จ",
    lyrics: "๐Ÿฅฐ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‹๐ฒ๐ซ๐ข๐œ๐ฌ ๐ฏ๐ข๐๐ž๐จ",
    cat: "๐Ÿฑ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‚๐š๐ญ ๐ฏ๐ข๐๐ž๐จ",
    "18plus": "๐Ÿ”ž > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐Ÿ๐Ÿ–+ ๐ฏ๐ข๐๐ž๐จ",
    freefire: "๐ŸŽฎ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐…๐ซ๐ž๐ž๐Ÿ๐ข๐ซ๐ž ๐ฏ๐ข๐๐ž๐จ",
    football: "โšฝ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐…๐จ๐จ๐ญ๐›๐š๐ฅ๐ฅ ๐ฏ๐ข๐๐ž๐จ",
    girl: "๐Ÿ‘ง > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐†๐ข๐ซ๐ฅ ๐ฏ๐ข๐๐ž๐จ",
    friend: "๐Ÿ‘ซ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐…๐ซ๐ข๐ž๐ง๐๐ฌ ๐ฏ๐ข๐๐ž๐จ",
    cricket: "๐Ÿ > ๐๐š๐ฐ ๐๐š๐›๐ฒ ๐‚๐ซ๐ข๐œ๐ค๐ž๐ญ ๐ฏ๐ข๐๐ž๐จ",
  };

  try {
    const BASE_API_URL = await getApiUrl();
    const res = await axios.get(
      `${BASE_API_URL}/album?type=${selectedCategory}`
    );
    const mediaUrl = res.data.data;

    if (!mediaUrl) {
      return api.sendMessage(
        "โš ๏ธ ๐๐จ ๐œ๐จ๐ง๐ญ๐ž๐ง๐ญ ๐Ÿ๐จ๐ฎ๐ง๐ ๐ข๐ง ๐ญ๐ก๐ข๐ฌ ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ.",
        event.threadID,
        event.messageID
      );
    }

    const response = await axios({
      method: "get",
      url: mediaUrl,
      responseType: "stream",
    });

    const filename = path.basename(mediaUrl).split("?")[0];
    const filePath = path.join(__dirname, "cache", `${Date.now()}_${filename}`);
    const writer = fs.createWriteStream(filePath);

    response.data.pipe(writer);

    writer.on("finish", () => {
      api.sendMessage(
        {
          body:
            captions[selectedCategory] ||
            `๐ŸŽฌ ๐๐จ๐ฐ ๐๐š๐›๐ฒ ${selectedCategory} ๐œ๐จ๐ง๐ญ๐ž๐ง๐ญ`,
          attachment: fs.createReadStream(filePath),
        },
        event.threadID,
        () => fs.unlinkSync(filePath),
        event.messageID
      );
    });

    writer.on("error", (err) => {
      console.error("Write Error:", err);
      api.sendMessage(
        "โŒ ๐…๐š๐ข๐ฅ๐ž๐ ๐ญ๐จ ๐ฌ๐ž๐ง๐ ๐ฏ๐ข๐๐ž๐จ.",
        event.threadID,
        event.messageID
      );
    });
  } catch (err) {
    console.error("Axios Error:", err.message);
    return api.sendMessage(
      "โŒ ๐’๐จ๐ฆ๐ž๐ญ๐ก๐ข๐ง๐  ๐ฐ๐ž๐ง๐ญ ๐ฐ๐ซ๐จ๐ง๐ . ๐“๐ซ๐ฒ ๐š๐ ๐š๐ข๐ง!",
      event.threadID,
      event.messageID
    );
  }
};

View raw file