mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2025-03-22 02:05:09 -04:00
fix error on invalid url (using try catch)
This commit is contained in:
parent
be52cb86b2
commit
29e7adebe8
1 changed files with 21 additions and 16 deletions
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable max-len */
|
||||
const {resize} = require('../util/image');
|
||||
const axios = require('axios');
|
||||
const sharp = require('sharp');
|
||||
|
@ -9,27 +10,31 @@ module.exports = {
|
|||
trusted: 0,
|
||||
usage: '<image url (JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF)>',
|
||||
execute: async function(bot, username, usernameraw, sender, prefix, args) {
|
||||
const url = args.join(' ');
|
||||
try {
|
||||
const url = args.join(' ');
|
||||
|
||||
const image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
|
||||
params: {
|
||||
uri: url,
|
||||
},
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
const image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
|
||||
params: {
|
||||
uri: url,
|
||||
},
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
const loaded = sharp(image.data);
|
||||
const loaded = sharp(image.data);
|
||||
|
||||
const metadata = await loaded
|
||||
.metadata();
|
||||
const metadata = await loaded
|
||||
.metadata();
|
||||
|
||||
const {width, height} = resize(metadata.width, metadata.height);
|
||||
const {width, height} = resize(metadata.width, metadata.height);
|
||||
|
||||
const {data, info} = await loaded
|
||||
.resize({fit: 'fill', kernel: 'nearest', width, height})
|
||||
.raw()
|
||||
.toBuffer({resolveWithObject: true});
|
||||
const {data, info} = await loaded
|
||||
.resize({fit: 'fill', kernel: 'nearest', width, height})
|
||||
.raw()
|
||||
.toBuffer({resolveWithObject: true});
|
||||
|
||||
bot.draw(data, info);
|
||||
bot.draw(data, info);
|
||||
} catch (e) {
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: 'SyntaxError: Invalid URL', color: 'red'}));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue