Facebook
From Emma ♡ , 8 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 463
  1. const fs = require("fs");
  2. const axios = require("axios");
  3. const path = require("path");
  4. const FormData = require("form-data");
  5.  
  6. module.exports = {
  7.   config: {
  8.     name: "2",
  9.     aliases: ["2"],
  10.     version: "1.1",
  11.     author: "JARiF | Fuck Vortex",
  12.     countDown: 5,
  13.     role: 0,
  14.     category: "ddfd",
  15.   },
  16.  
  17.   onStart: async function ({ event, api, args }) {
  18.     try {
  19.       if (args.length >= 2 || (event.type === "message_reply" && event.messageReply.attachments.length > 0 && event.messageReply.attachments[0].type === "photo")) {
  20.         const message = event.body;
  21.         api.sendMessage({ body: "Please wait....", mentions: [{ tag: message.senderID, id: message.senderID }] }, event.threadID);
  22.  
  23.         const imageUrl = event.type === "message_reply" ? event.messageReply.attachments[0].url : args[0];
  24.         const prompt = event.type === "message_reply" ? "same pose, same person, same environment, all same just add anime effect,anime look,boy will be a boy,girl will be a girl" : args.slice(1).join(" ");
  25.  
  26.         const formData = new FormData();
  27.         formData.append("key", "6ac6780f27041c31be2da98f4f55704e");
  28.         formData.append("image", imageUrl);
  29.  
  30.         const imgbbResponse = await axios.post("https://api.imgbb.com/1/upload", formData, {
  31.           headers: formData.getHeaders(),
  32.         });
  33.         const imgbbImageUrl = imgbbResponse.data.data.url;
  34.  
  35.         const response = await axios.get(`https://jarif-art.blackxlegend1.repl.co/transform?imgurl=${imgbbImageUrl}&prompt;=${prompt}&apikey=upol-vai-pro`, {
  36.           responseType: "arraybuffer",
  37.         });
  38.  
  39.         const imageBuffer = Buffer.from(response.data);
  40.         const pathSave = path.join(__dirname, "art.png");
  41.  
  42.         await saveArrayBufferToFile(imageBuffer, pathSave);
  43.  
  44.         api.sendMessage({ body: "Here is your generated image:", attachment: fs.createReadStream(pathSave) }, event.threadID, () => {
  45.           fs.unlinkSync(pathSave);
  46.         });
  47.       } else if (event.type === "message_reply") {
  48.         api.sendMessage({ body: "Reply with an image." }, event.threadID);
  49.       } else {
  50.         api.sendMessage({ body: "Please provide an image link and a prompt, or reply with an image." }, event.threadID);
  51.       }
  52.     } catch (e) {
  53.       console.error(e);
  54.       api.sendMessage({ body: "❌ | Something went wrong." }, event.threadID);
  55.     }
  56.   },
  57. };
  58.  
  59. async function saveArrayBufferToFile(arrayBuffer, filePath) {
  60.   return new Promise((resolve, reject) => {
  61.     fs.writeFile(filePath, Buffer.from(arrayBuffer), (err) => {
  62.       if (err) {
  63.         reject(err);
  64.       } else {
  65.         resolve();
  66.       }
  67.     });
  68.   });
  69. }
  70.