mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-27 09:35:35 -05:00
6895a37104
i totally did not used the search icon thing in vscode
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
/* eslint-disable max-len */
|
|
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) {
|
|
try {
|
|
const url = args.join(' ');
|
|
|
|
const image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
|
|
params: {
|
|
uri: url,
|
|
},
|
|
responseType: 'arraybuffer',
|
|
});
|
|
|
|
const loaded = sharp(image.data);
|
|
|
|
const metadata = await loaded
|
|
.metadata();
|
|
|
|
const {width, height} = resize(metadata.width, metadata.height);
|
|
|
|
const {data, info} = await loaded
|
|
.resize({fit: 'fill', kernel: 'nearest', width, height})
|
|
.raw()
|
|
.toBuffer({resolveWithObject: true});
|
|
|
|
bot.draw(data, info);
|
|
} catch (e) {
|
|
bot.tellraw('@a', {text: 'SyntaxError: Invalid URL', color: 'red'});
|
|
}
|
|
},
|
|
};
|