Advertisement
samiroexpikachu

Dalle3 command

Feb 9th, 2024
198
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.28 KB | Source Code | 1 0
  1. const axios = require("axios");
  2. const fs = require("fs-extra");
  3. const path = require("path");
  4. const KievRPSSecAuth = "";
  5. const _U = "";
  6. const uid = event.senderID
  7. module.exports = {
  8.   config: {
  9.     name: "dalle",
  10.     aliases: ["dalle3"],
  11.     version: "1.0.2",
  12.     author: "Samir Œ ",
  13.     role: 0,
  14.     countDown: 5,
  15.     shortDescription: {
  16.       en: "dalle"
  17.     },
  18.     longDescription: {
  19.       en: ""
  20.     },
  21.     category: "dalle",
  22.     guide: {
  23.       en: "{prefix}dalle <search query> -<number of images>"
  24.     }
  25.   },
  26.  
  27.   onStart: async function ({ api, event, args }) {
  28.     const permission = [`${uid}`];
  29.     if (!permission.includes(event.senderID)) {
  30.       api.sendMessage(
  31.         "You don't have enough permission to use this command. Only admin can do it.",
  32.         event.threadID,
  33.         event.messageID
  34.       );
  35.       return;
  36.     }
  37.  
  38.     const keySearch = args.join(" ");
  39.     const indexOfHyphen = keySearch.indexOf('-');
  40.     const keySearchs = indexOfHyphen !== -1 ? keySearch.substr(0, indexOfHyphen).trim() : keySearch.trim();
  41.     const numberSearch = parseInt(keySearch.split("-").pop().trim()) || 4;
  42.  
  43.     try {
  44.       const res = await axios.get(`https://api-dalle-gen.onrender.com/dalle3?auth_cookie_U=${_U}&auth_cookie_KievRPSSecAuth=${KievRPSSecAuth}&prompt=${encodeURIComponent(keySearchs)}`);
  45.       const data = res.data.results.images;
  46.  
  47.       if (!data || data.length === 0) {
  48.         api.sendMessage("No images found for the provided query.", event.threadID, event.messageID);
  49.         return;
  50.       }
  51.  
  52.       const imgData = [];
  53.       for (let i = 0; i < Math.min(numberSearch, data.length); i++) {
  54.         const imgResponse = await axios.get(data[i].url, { responseType: 'arraybuffer' });
  55.         const imgPath = path.join(__dirname, 'cache', `${i + 1}.jpg`);
  56.         await fs.outputFile(imgPath, imgResponse.data);
  57.         imgData.push(fs.createReadStream(imgPath));
  58.       }
  59.  
  60.       await api.sendMessage({
  61.         attachment: imgData,
  62.         body: `Here's your generated image`
  63.      }, event.threadID, event.messageID);
  64.  
  65.    } catch (error) {
  66.      console.error(error);
  67.      api.sendMessage("cookie of the command. Is expired", event.threadID, event.messageID);
  68.    } finally {
  69.      await fs.remove(path.join(__dirname, 'cache'));
  70.    }
  71.  }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement