2022-11-27 02:35:28 -05:00
|
|
|
const { resize } = require('../util/image')
|
|
|
|
const axios = require('axios')
|
|
|
|
const sharp = require('sharp')
|
2022-10-15 08:53:48 -04:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'draw',
|
|
|
|
description: 'Draws an image',
|
|
|
|
alias: [],
|
|
|
|
trusted: 0,
|
|
|
|
usage: '<image url (JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF)>',
|
2022-12-14 08:51:30 -05:00
|
|
|
execute: async function (bot, username, sender, prefix, args, config, hash, ownerhash, selector) {
|
2022-12-18 03:07:50 -05:00
|
|
|
let image
|
2022-10-15 08:57:16 -04:00
|
|
|
try {
|
2022-11-27 02:35:28 -05:00
|
|
|
const url = args.join(' ')
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-12-18 03:07:50 -05:00
|
|
|
image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
|
2022-10-15 08:57:16 -04:00
|
|
|
params: {
|
2022-11-27 02:35:28 -05:00
|
|
|
uri: url
|
2022-10-15 08:57:16 -04:00
|
|
|
},
|
2022-11-27 02:35:28 -05:00
|
|
|
responseType: 'arraybuffer'
|
|
|
|
})
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const loaded = sharp(image.data)
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-10-15 08:57:16 -04:00
|
|
|
const metadata = await loaded
|
2022-11-27 02:35:28 -05:00
|
|
|
.metadata()
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const { width, height } = resize(metadata.width, metadata.height)
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const { data, info } = await loaded
|
|
|
|
.resize({ fit: 'fill', kernel: 'nearest', width, height })
|
|
|
|
.raw()
|
|
|
|
.toBuffer({ resolveWithObject: true })
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.draw(data, info)
|
2022-12-18 03:07:50 -05:00
|
|
|
} catch (_err) {
|
|
|
|
const e = image.data.toString()
|
|
|
|
bot.tellraw(selector, { text: e, color: 'red' })
|
2022-10-15 08:57:16 -04:00
|
|
|
}
|
2022-11-27 02:35:28 -05:00
|
|
|
}
|
|
|
|
}
|