← back to browse
goat command

album

๐€๐ฅ๐›๐ฎ๐ฆ ๐•๐ข๐๐ž๐จ Random

0
views
0
likes
0
installs

Aliases: al

raw source
const axios = require("axios");
const fs = require("fs");
const path = require("path");
const FormData = require("form-data");

module.exports = {
  config: {
    name: "album",
    aliases: ["al"],
    version: "5.1.0",
    author: "Azadx69x",
    countDown: 2,
    role: 0,
    shortDescription: "๐€๐ฅ๐›๐ฎ๐ฆ ๐•๐ข๐๐ž๐จ Random",
    longDescription: "Random album videos",
    category: "media"
  },

  albumSystem: new Map(),
  albumBaseUrl: null,
  videoQueue: new Map(),
  
  async loadAlbumBaseUrl() {
    if (this.albumBaseUrl) return;
    try {
      const res = await axios.get(
        "https://raw.githubusercontent.com/ncazad/Azad69x/refs/heads/main/baseApiUrl.json"
      );
      this.albumBaseUrl = res.data.album.replace(/\/$/, "");
      console.log("Album API base URL loaded:", this.albumBaseUrl);
    } catch (e) {
      console.error("Failed to load album base URL:", e.message);
      this.albumBaseUrl = null;
    }
  },
  
  async fetchAlbumVideo(category) {
    await this.loadAlbumBaseUrl();
    if (!this.albumBaseUrl) return null;
    
    if (!this.videoQueue.has(category) || this.videoQueue.get(category).length === 0) {
      try {
        const res = await axios.get(`${this.albumBaseUrl}/api/album?category=${encodeURIComponent(category)}`);
        let videos = [];
        if (res.data?.url) videos.push(res.data.url);
        if (res.data?.videos?.length) videos = videos.concat(res.data.videos);

        if (!videos.length) return null;

        videos = this.shuffleArray(videos);
        this.videoQueue.set(category, videos);
      } catch (e) {
        console.error(`Failed to fetch video for ${category}:`, e.message);
        return null;
      }
    }

    const queue = this.videoQueue.get(category);
    const videoUrl = queue.shift();
    this.videoQueue.set(category, queue);
    return videoUrl;
  },
  
  shuffleArray(arr) {
    for (let i = arr.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      [arr[i], arr[j]] = [arr[j], arr[i]];
    }
    return arr;
  },
  
  async uploadToCatbox(videoPath) {
    const form = new FormData();
    form.append("reqtype", "fileupload");
    form.append("fileToUpload", fs.createReadStream(videoPath));

    const res = await axios.post("https://catbox.moe/user/api.php", form, { headers: form.getHeaders() });
    fs.unlinkSync(videoPath);
    return res.data.trim();
  },
  
  onStart: async function ({ message, event, args }) {
    const displayNames = [
      "๐€๐™๐€๐ƒ๐—69๐—๐…๐… ๐Ÿผ","๐€๐ง๐ข๐ฆ๐ž ๐Ÿ’ซ","๐€๐จ๐“ โšก","๐€๐ญ๐ญ๐ข๐ญ๐ฎ๐๐ž ๐Ÿ˜ผ",
      "๐๐š๐›๐ฒ ๐Ÿ‘ถ","๐‚๐š๐ญ ๐Ÿˆ","๐‚๐จ๐ฎ๐ฉ๐ฅ๐ž ๐Ÿ’‘","๐ƒ๐ซ๐š๐ ๐จ๐ง๐๐š๐ฅ๐ฅ ๐Ÿ‰",
      "๐…๐ฅ๐จ๐ฐ๐ž๐ซ ๐ŸŒบ","๐…๐จ๐จ๐ญ๐›๐š๐ฅ๐ฅ โšฝ","๐…๐ซ๐ž๐ž๐…๐ข๐ซ๐ž ๐Ÿ”ฅ","๐…๐ซ๐ข๐ž๐ง๐๐ฌ ๐Ÿซ‚",
      "๐…๐ฎ๐ง๐ง๐ฒ ๐Ÿคฃ","๐‡๐จ๐ซ๐ง๐ฒ ๐Ÿ’ฆ","๐‡๐จ๐ญ ๐Ÿฅต","๐ˆ๐ฌ๐ฅ๐š๐ฆ๐ข๐œ ๐Ÿ˜Š",
      "๐‹๐จ๐…๐ˆ ๐ŸŽถ","๐‹๐จ๐ฏ๐ž ๐Ÿ’","๐‹๐ฒ๐ซ๐ข๐œ๐ฌ ๐ŸŽต","๐’๐š๐ ๐Ÿ˜ฟ"
    ];

    const realCategories = [
      "Azadx69xff","anime","aot","attitude","baby","cat","couple","dragonball",
      "flower","football","freefire","friends","funny","horny","hot","islamic",
      "lofi","love","lyrics","sad"
    ];
    
    if (args[0] && args[0].toLowerCase() === "add" && args[1]) {
      const cat = args[1].toLowerCase();
      if (!realCategories.includes(cat)) return message.reply("โŒ Invalid category name.");

      if (!this.albumSystem.has(event.senderID)) this.albumSystem.set(event.senderID, []);
      this.albumSystem.get(event.senderID).push(cat);

      return message.reply(`โœ… Album category "${cat}" added to your list.`);
    }
    
    const itemsPerPage = 10;
    const page = parseInt(args[0]) || 1;
    const totalPages = Math.ceil(displayNames.length / itemsPerPage);
    if (page < 1 || page > totalPages) return message.reply("โŒ Invalid page");

    const startIndex = (page - 1) * itemsPerPage;
    const categoriesToShow = displayNames.slice(startIndex, startIndex + itemsPerPage);

    let text = "โ•ญโ”€โ๐€๐‹๐๐”๐Œ ๐•๐ˆ๐ƒ๐„๐Ž ๐‹๐ˆ๐’๐“โโ”€โ•ฎ\n\n";
    categoriesToShow.forEach((cat, i) => text += `โœฆ ${i + 1}. ${cat}\n`);
    text += `\nโ•ฐโ”€โ ๐๐š๐ ๐ž : ${page}/${totalPages} โโ”€โ•ฏ\n`;
    text += "๐Ÿ’ฌ ๐‘๐ž๐ฉ๐ฅ๐ฒ ๐š ๐ง๐ฎ๐ฆ๐›๐ž๐ซ ๐ญ๐จ ๐ ๐ž๐ญ ๐š ๐ฏ๐ข๐๐ž๐จ ๐Ÿฑ";

    const sent = await message.reply(text);

    global.GoatBot.onReply.set(sent.messageID, {
      commandName: "album",
      author: event.senderID,
      pageCategories: categoriesToShow.map((_, i) => realCategories[startIndex + i]),
      pageDisplayNames: categoriesToShow,
      messageID: sent.messageID
    });
  },
  
  onReply: async function ({ message, event, Reply }) {
    if (event.senderID !== Reply.author) return;
    
    const num = parseInt(event.body);
    if (isNaN(num)) return;

    const index = num - 1;
    const category = Reply.pageCategories[index];
    const displayName = Reply.pageDisplayNames[index];
    if (!category) return message.reply("โŒ Invalid number");

    const videoUrl = await this.fetchAlbumVideo(category);
    if (!videoUrl) return message.reply(`โŒ No videos found for ${displayName}`);

    try { await message.unsend(Reply.messageID); } catch(e){}

    await message.reply({
      body: `โœจ ๐€๐‹๐๐”๐Œ ๐•๐ˆ๐ƒ๐„๐Ž ๐ŸŒธ\n\n๐Ÿ“ ๐‚๐š๐ญ๐ž๐ ๐จ๐ซ๐ฒ : ${displayName}\n\n๐Ÿธ ๐„๐ง๐ฃ๐จ๐ฒ ๐˜๐จ๐ฎ๐ซ ๐•๐ข๐๐ž๐จ ๐Ÿ–ค`,
      attachment: await global.utils.getStreamFromURL(videoUrl)
    });
  }
};

View raw file