const axios = require("axios"); const FormData = require("form-data"); const fs = require("fs"); const path = require("path"); module.exports = { config: { name: "animealbum", aliases: ["anialbum"], version: "1.0", author: "Rocky Chowdhury", countDown: 2, role: 0, description: "Reply with a number to get a video, or reply to a video with /animealbum add ", category: "media" }, onStart: async function ({ message, event, args }) { try { const apiJsonUrl = "https://raw.githubusercontent.com/Saim-x69x/sakura/main/ApiUrl.json"; const apiRes = await axios.get(apiJsonUrl); const baseUrl = apiRes.data.apiv1; if (args[0]?.toLowerCase() === "add") { const category = args[1]?.toLowerCase(); if (!category) { return message.reply( "āŒ š‚ššš­šžš šØš«š² š¢š¬ š«šžšŖš®š¢š«šžš!\n✨ š”š¬ššš šž: /ššš§š¢š¦šžššš„š›š®š¦ šššš <šœššš­šžš šØš«š²>" ); } if (!event.messageReply || !event.messageReply.attachments?.length) { return message.reply( "āŒ šš„šžššš¬šž š«šžš©š„š² š­šØ šš šÆš¢ššžšØ š­šØ šššš š¢š­ š­šØ š­š”šž ššš§š¢š¦šžššš„š›š®š¦." ); } const attachment = event.messageReply.attachments[0]; if (!attachment.type.includes("video")) { return message.reply("āŒ š“š”šž š«šžš©š„š¢šžš šŸš¢š„šž š¢š¬ š§šØš­ šš šÆš¢ššžšØ."); } const videoUrl = attachment.url; const videoPath = path.resolve(__dirname, "temp_video.mp4"); const videoResp = await axios.get(videoUrl, { responseType: "stream" }); const writer = fs.createWriteStream(videoPath); videoResp.data.pipe(writer); await new Promise((resolve, reject) => { writer.on("finish", resolve); writer.on("error", reject); }); const form = new FormData(); form.append("reqtype", "fileupload"); form.append("fileToUpload", fs.createReadStream(videoPath)); const catboxResp = await axios.post( "https://catbox.moe/user/api.php", form, { headers: form.getHeaders() } ); fs.unlinkSync(videoPath); const catboxUrl = catboxResp.data.trim(); if (!catboxUrl.startsWith("https://")) { return message.reply( "āš ļø š”š©š„šØššš šŸššš¢š„šžš. šš„šžššš¬šž š­š«š² ššš ššš¢š§ š„ššš­šžš«." ); } const apiURL = `${baseUrl}/api/albumadd?category=${encodeURIComponent( category )}&url=${encodeURIComponent(catboxUrl)}`; const apiResp2 = await axios.get(apiURL); const data = apiResp2.data; if (!data?.message || !data?.url) { return message.reply( "āš ļø š’šØš¦šžš­š”š¢š§š  š°šžš§š­ š°š«šØš§š . š“š«š² ššš ššš¢š§ š„ššš­šžš«." ); } return message.reply(`${data.message}\nšŸ”— ${data.url}`); } const listUrl = "https://raw.githubusercontent.com/Saim-x69x/sakura/main/anialbumcategory.json"; const res = await axios.get(listUrl); const displayNames = res.data.display; const realCategories = res.data.real; const itemsPerPage = 10; const page = parseInt(args[0]) || 1; const totalPages = Math.ceil(displayNames.length / itemsPerPage); if (page < 1 || page > totalPages) { return message.reply( `āŒ šˆš§šÆššš„š¢š š©ššš šž!\nšŸ“„ šš„šžššš¬šž šœš”šØšØš¬šž š›šžš­š°šžšžš§ 1-${totalPages}` ); } const startIndex = (page - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; const categoriesToShow = displayNames.slice(startIndex, endIndex); let text = "šŸŽ„ š€ššˆšŒš„ š€š‹šš”šŒ š•šˆšƒš„šŽš’\n" + "ā•­ā”€ā”€ā”€ā”€ā”€ā”€ā”€āœ¦ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•®\n"; categoriesToShow.forEach((cat, i) => { text += `ā”‚āŒÆ ${startIndex + i + 1}. ${cat}\n`; }); text += "ā•°ā”€ā”€ā”€ā”€ā”€ā”€ā”€āœ¦ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•Æ\n" + `šŸ“„ šššš šž: ${page}/${totalPages}\n`; if (page < totalPages) { text += `āž”ļø š“š²š©šž /ššš§š¢š¦šžššš„š›š®š¦ ${ page + 1 } šŸšØš« š§šžš±š­ š©ššš šž\n`; } text += "šŸŽÆ š‘šžš©š„š² š°š¢š­š” šš š§š®š¦š›šžš« š­šØ š šžš­ šš šÆš¢ššžšØ"; const sent = await message.reply(text); global.GoatBot.onReply.set(sent.messageID, { commandName: module.exports.config.name, author: event.senderID, startIndex, endIndex, displayNames, realCategories, listMsgID: sent.messageID, baseUrl }); } catch (e) { return message.reply( "āš ļø š€š§ š®š§šžš±š©šžšœš­šžš šžš«š«šØš« šØšœšœš®š«š«šžš. šš„šžššš¬šž š­š«š² ššš ššš¢š§ š„ššš­šžš«." ); } }, onReply: async function ({ message, Reply, event }) { if (event.senderID !== Reply.author) return; const num = parseInt(event.body.trim()); const index = num - 1; if (isNaN(num) || index < Reply.startIndex || index >= Reply.endIndex) { return message.reply( "āŒ šˆš§šÆššš„š¢š š§š®š¦š›šžš«. šš„šžššš¬šž š«šžš©š„š² š°š¢š­š” šš šÆššš„š¢š šØš§šž." ); } try { message.unsend(Reply.listMsgID); } catch {} try { const category = Reply.realCategories[index]; const link = `${Reply.baseUrl}/api/album?category=${category}`; const res = await axios.get(link); if (!res.data?.url) { return message.reply( "āš ļø š…ššš¢š„šžš š­šØ šŸšžš­šœš” šÆš¢ššžšØ." ); } await message.reply({ body: "šŸŽ¬ š˜šŽš”š‘ š•šˆšƒš„šŽ šˆš’ š‘š„š€šƒš˜!\n" + `šŸ“‚ š‚ššš­šžš šØš«š² āž¤ ${Reply.displayNames[index]}\n` + "✨ š„š§š£šØš²!", attachment: await global.utils.getStreamFromURL(res.data.url) }); } catch (e) { return message.reply( "āŒ š„š«š«šØš« š°š”š¢š„šž š¬šžš§šš¢š§š  šÆš¢ššžšØ." ); } } };