Advertisement
samiroexpikachu

Background blur

Oct 4th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2. const TinyURL = require('tinyurl');
  3. const fs = require('fs');
  4. const path = require('path');
  5.  
  6. module.exports = {
  7.   config: {  name: "blur",
  8.     version: "1.0",
  9.     author: "Samir Œ",
  10.     countDown: 5,
  11.     role: 2,
  12.     description: {
  13.       vi: "Tạo ảnh ảo giác từ ảnh gốc",
  14.       en: "Create an illusion image from the original image"
  15.     },
  16.     category: "image",
  17.     guide: {
  18.       vi: "{pn} [prompt] - Trả lời một hình ảnh với lệnh này",
  19.       en: "{pn} [prompt] - Reply to an image with this command"
  20.     }
  21.   },
  22.  
  23.   onStart: async function ({ api, args, message, event }) {
  24.     const { messageReply } = event;
  25.     if (!messageReply || !messageReply.attachments || messageReply.attachments.length === 0) {
  26.       return message.reply("Please reply to an image with this command.");
  27.     }
  28.  
  29.     const imageUrl = messageReply.attachments[0].url;
  30.     const prompt = args.join(" ") || "34";
  31.  
  32.     try {
  33.       const shortenedUrl = await TinyURL.shorten(imageUrl);
  34.       const { data } = await axios.get(`https://samirxpikachuiox.onrender.com/api/shorten?url=${encodeURIComponent(shortenedUrl)}`);
  35.       const shortLink = data.short;
  36.  
  37.       const illusionUrl = `https://samirxpikachuiox.onrender.com/bgblur?url=${encodeURIComponent(shortLink)}&strength=${encodeURIComponent(prompt)}`;
  38.       const imageResponse = await axios.get(illusionUrl, { responseType: 'arraybuffer' });
  39.       const imagePath = path.join(__dirname, 'blurredImage.png');
  40.  
  41.       fs.writeFileSync(imagePath, imageResponse.data);
  42.  
  43.       await message.reply({
  44.         attachment: fs.createReadStream(imagePath),
  45.       });
  46.     } catch (error) {
  47.       message.reply(`An error occurred: ${error.message}`);
  48.     }
  49.   }
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement