chomens-bot-js/commands/draw.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

/* eslint-disable max-len */
2022-10-15 08:53:48 -04:00
const {resize} = require('../util/image');
const axios = require('axios');
const sharp = require('sharp');
module.exports = {
name: 'draw',
description: 'Draws an image',
alias: [],
trusted: 0,
usage: '<image url (JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF)>',
execute: async function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
const url = args.join(' ');
2022-10-15 08:53:48 -04:00
const image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
params: {
uri: url,
},
responseType: 'arraybuffer',
});
2022-10-15 08:53:48 -04:00
const loaded = sharp(image.data);
2022-10-15 08:53:48 -04:00
const metadata = await loaded
.metadata();
2022-10-15 08:53:48 -04:00
const {width, height} = resize(metadata.width, metadata.height);
2022-10-15 08:53:48 -04: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
bot.draw(data, info);
} catch (e) {
2022-11-16 06:41:30 -05:00
bot.tellraw(selector, {text: 'SyntaxError: Invalid URL', color: 'red'});
}
2022-10-15 08:53:48 -04:00
},
};