AnshorFalahi

Untitled

May 24th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const sharp = require('sharp');
  2.  
  3. exports.run = {
  4.   usage: ['swap'],
  5.   use: 'reply media & enter url Img',
  6.   category: 'converter',
  7.   async: async (m, { client, text, Func, Scraper }) => {
  8.     let q = m.quoted ? m.quoted : m;
  9.     let mime = (q.msg || q).mimetype || '';
  10.  
  11.     if (!text) return m.reply("Masukkan URL foto untuk dilakukan swap face, gunakan fitur #tourl");
  12.     if (!mime) return m.reply('Harap balas dengan media');
  13.  
  14.     client.sendReact(m.chat, '🕒', m.key);
  15.  
  16.     try {
  17.       let media = await q.download();
  18.       let link = await Scraper.uploadImageV3(media);
  19.       let url = link.data.url;
  20.  
  21.       const result = `https://anabot.my.id/api/ai/swapFace?imageUrlTarget=${url}&imageUrlSource=${text}&apikey=Klamsky`;
  22.       let buffer = await Func.fetchBuffer(result);
  23.  
  24.       sharp(buffer)
  25.         .metadata()
  26.         .then(({ width, height }) => {
  27.           let cropWidth = Math.floor(width / 3);
  28.           let cropHeight = height;
  29.           let left = width - cropWidth;
  30.  
  31.           return sharp(buffer)
  32.             .extract({ left: left, top: 0, width: cropWidth, height: cropHeight })
  33.             .toBuffer();
  34.         })
  35.         .then(croppedBuffer => {
  36.           client.sendFile(m.chat, croppedBuffer, 'swap.jpg', 'Berhasil melakukan swap face dan crop.', m);
  37.         })
  38.         .catch(err => {
  39.           console.error(err);
  40.           m.reply('Terjadi kesalahan saat melakukan crop pada gambar.');
  41.         });
  42.  
  43.     } catch (error) {
  44.       console.error(error);
  45.       m.reply('Terjadi kesalahan saat melakukan swap face.');
  46.     }
  47.   },
  48.   error: false,
  49.   cache: true,
  50.   location: __filename
  51. };
  52.  
Add Comment
Please, Sign In to add comment