File size: 1,350 Bytes
2821330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const axios = require('axios');
const fs = require('fs-extra');

module.exports.config = {
  name: "removebg",
  hasPermission: 0,
  version: "1",
  description: "Remove Background Image",
  usePrefix: false,
  credits: "Jonell Magallanes",
  commandCategory: "Image",
  cooldowns: 2,
};
module.exports.run = async function ({ api, event, args })  {
  const pathie = './modules/commands/cache/removed_bg.png';
  const { threadID, messageID } = event;

  const photoLink = event.messageReply.attachments[0].url || args.join(" ");

  try {
    api.sendMessage("⏳ | Removing background from your image...", threadID, messageID);

    const response = await axios.get(`https://jonellccprojectapis10.adaptable.app/api/rbg?imageUrl=${encodeURIComponent(photoLink)}`);
    const removedBgImageUrl = response.data.image_data;

    const imgResponse = await axios.get(removedBgImageUrl, { responseType: "stream" });

    const writeStream = fs.createWriteStream(pathie);
    imgResponse.data.pipe(writeStream);

    writeStream.on('finish', () => {
      api.sendMessage({
        body: "✅ | Background removed successfully",
        attachment: fs.createReadStream(pathie)
      }, threadID, () => fs.unlinkSync(pathie), messageID);
    });
  } catch (error) {
    api.sendMessage(`❎ | Error removing background: ${error}`, threadID, messageID);
  }
};