Facebook
From kshitiz, 4 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 397
  1. const fs = require("fs-extra");
  2. const axios = require("axios");
  3.  
  4. module.exports = {
  5.  
  6.   threadStates: {},
  7.  
  8.   config: {
  9.     name: 'autoinsta',
  10.     version: '1.0',
  11.     author: 'Kshitiz',
  12.     countDown: 5,
  13.     role: 0,
  14.     shortDescription: 'auto video downloader',
  15.     longDescription: '',
  16.     category: 'media',
  17.     guide: {
  18.       en: '{p}{n}',
  19.     }
  20.   },
  21.   onStart: async function ({ api, event }) {
  22.     const threadID = event.threadID;
  23.  
  24.    
  25.     if (!this.threadStates[threadID]) {
  26.       this.threadStates[threadID] = {
  27.         autoInstaEnabled: false,
  28.       };
  29.     }
  30.  
  31.    
  32.     if (event.body.toLowerCase().includes('autoinsta')) {
  33.      
  34.       if (event.body.toLowerCase().includes('on')) {
  35.        
  36.         this.threadStates[threadID].autoInstaEnabled = true;
  37.         api.sendMessage("AutoInsta is now ON.", event.threadID, event.messageID);
  38.       } else if (event.body.toLowerCase().includes('off')) {
  39.        
  40.         this.threadStates[threadID].autoInstaEnabled = false;
  41.         api.sendMessage("AutoInsta is now OFF.", event.threadID, event.messageID);
  42.       } else {
  43.        
  44.         api.sendMessage("type 'autoinsta on' to turn on and\n'autoinsta off' to turn off.", event.threadID, event.messageID);
  45.       }
  46.     }
  47.   },
  48.   onChat: async function ({ api, event }) {
  49.     const threadID = event.threadID;
  50.  
  51.    
  52.     if (this.threadStates[threadID] && this.threadStates[threadID].autoInstaEnabled && this.checkLink(event.body)) {
  53.       var { url } = this.checkLink(event.body);
  54.       this.downLoad(url, api, event);
  55.       api.setMessageReaction("?", event.messageID, (err) => {}, true);
  56.     }
  57.   },
  58.   downLoad: function (url, api, event) {
  59.     var time = Date.now();
  60.     var path = __dirname + `/cache/${time}.mp4`;
  61.     this.getLink(url).then(res => {
  62.       axios({
  63.         method: "GET",
  64.         url: res,
  65.         responseType: "arraybuffer"
  66.       }).then(res => {
  67.         fs.writeFileSync(path, Buffer.from(res.data, "utf-8"));
  68.         if (fs.statSync(path).size / 1024 / 1024 > 25) {
  69.           return api.sendMessage("The file is too large, cannot be sent", event.threadID, () => fs.unlinkSync(path), event.messageID);
  70.         }
  71.         api.sendMessage({
  72.           body: "Successful Download!",
  73.           attachment: fs.createReadStream(path)
  74.         }, event.threadID, () => fs.unlinkSync(path), event.messageID);
  75.       }).catch(err => console.error(err));
  76.     }).catch(err => console.error(err));
  77.   },
  78.   getLink: function (url) {
  79.     return new Promise((resolve, reject) => {
  80.       axios({
  81.         method: "GET",
  82.         url: `https://for-devs.rishadapis.repl.co/api/instadl?url=${url}&apikey=fuck`
  83.       }).then(res => resolve(res.data.video)).catch(err => reject(err));
  84.     });
  85.   },
  86.   checkLink: function (url) {
  87.     if (url.includes("instagram")) {
  88.       return {
  89.         url: url
  90.       };
  91.     }
  92.     return null;
  93.   }
  94. };
  95.