Facebook
From kshitiz, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 122
  1. const axios = require("axios");
  2. const fs = require("fs");
  3. const path = require("path");
  4.  
  5. module.exports = {
  6.   config: {
  7.     name: "anivfx",
  8.     aliases: ["animevfx", "vfxanime"],
  9.  
  10.  
  11.     author: "Vex_Kshitiz",// dont change this saar
  12.  
  13.  
  14.     version: "1.0",
  15.     cooldowns: 10,
  16.     role: 0,
  17.     shortDescription: "",
  18.     longDescription: "vfx animation video",
  19.     category: "anime",
  20.     guide: "{p}anivfx",
  21.   },
  22.  
  23.   onStart: async function ({ api, event, message }) {
  24.     function getRandomUsername() {
  25.  
  26.  
  27.  
  28.       const usernames = ['.jams0'];
  29.  
  30.    
  31.  
  32.  
  33.  
  34.  
  35.       const randomIndex = Math.floor(Math.random() * usernames.length);
  36.       return usernames[randomIndex];
  37.     }
  38.  
  39.     api.setMessageReaction("?", event.messageID, (err) => {}, true);
  40.  
  41.     try {
  42.       const username = getRandomUsername();
  43.       const response = await axios.get(`https://vfx-animation.onrender.com/kshitiz?username=${username}`);
  44.       const user = response.data.user || "@user_unknown";
  45.       const postData = response.data.posts;
  46.       const selectedUrl = getRandomUrl(postData);
  47.  
  48.       const videoResponse = await axios.get(selectedUrl, { responseType: "stream" });
  49.  
  50.       const tempVideoPath = path.join(__dirname, "cache", `tuktuk.mp4`);
  51.       const writer = fs.createWriteStream(tempVideoPath);
  52.       videoResponse.data.pipe(writer);
  53.  
  54.       writer.on("finish", async () => {
  55.         const stream = fs.createReadStream(tempVideoPath);
  56.         await message.reply({
  57.           body: ``,
  58.           attachment: stream,
  59.         });
  60.         api.setMessageReaction("?", event.messageID, (err) => {}, true);
  61.         fs.unlink(tempVideoPath, (err) => {
  62.           if (err) console.error(err);
  63.           console.log(`Deleted`);
  64.         });
  65.       });
  66.     } catch (error) {
  67.       console.error(error);
  68.       message.reply("Sorry, an error occurred.");
  69.     }
  70.   }
  71. };
  72.  
  73. let usedUrls = [];
  74.  
  75. function getRandomUrl(postData) {
  76.   if (usedUrls.length === postData.length) {
  77.     usedUrls = [];
  78.   }
  79.  
  80.   let randomIndex;
  81.   let selectedPost;
  82.   do {
  83.     randomIndex = Math.floor(Math.random() * postData.length);
  84.     selectedPost = postData[randomIndex].replace(/\\/g, "/");
  85.   } while (usedUrls.includes(selectedPost));
  86.  
  87.   usedUrls.push(selectedPost);
  88.   return selectedPost;
  89. }
  90.