improve url loading in draw and music playurl

This commit is contained in:
ChomeNS 2022-12-18 15:07:50 +07:00
parent a153a0d4f7
commit 0b21f0ffb8
2 changed files with 11 additions and 7 deletions

View file

@ -9,10 +9,11 @@ module.exports = {
trusted: 0, trusted: 0,
usage: '<image url (JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF)>', usage: '<image url (JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF)>',
execute: async function (bot, username, sender, prefix, args, config, hash, ownerhash, selector) { execute: async function (bot, username, sender, prefix, args, config, hash, ownerhash, selector) {
let image
try { try {
const url = args.join(' ') const url = args.join(' ')
const image = await axios.get('https://http-proxy.nongsonchome.repl.co', { image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
params: { params: {
uri: url uri: url
}, },
@ -32,8 +33,9 @@ module.exports = {
.toBuffer({ resolveWithObject: true }) .toBuffer({ resolveWithObject: true })
bot.draw(data, info) bot.draw(data, info)
} catch (e) { } catch (_err) {
bot.tellraw(selector, { text: 'SyntaxError: Invalid URL', color: 'red' }) const e = image.data.toString()
bot.tellraw(selector, { text: e, color: 'red' })
} }
} }
} }

View file

@ -48,9 +48,10 @@ async function play (bot, values, discord, channeldc, selector, config) {
} }
async function playUrl (bot, values, discord, channeldc, selector, config) { async function playUrl (bot, values, discord, channeldc, selector, config) {
let response
try { try {
const url = values.join(' ') const url = values.join(' ')
const response = await axios.get('https://http-proxy.nongsonchome.repl.co', { response = await axios.get('https://http-proxy.nongsonchome.repl.co', {
params: { params: {
uri: url uri: url
}, },
@ -68,15 +69,16 @@ async function playUrl (bot, values, discord, channeldc, selector, config) {
} else { } else {
bot.tellraw(selector, [{ text: 'Added ', color: 'white' }, { text: song.name, color: 'gold' }, { text: ' to the song queue', color: 'white' }]) bot.tellraw(selector, [{ text: 'Added ', color: 'white' }, { text: song.name, color: 'gold' }, { text: ' to the song queue', color: 'white' }])
} }
} catch (e) { } catch (_err) {
const e = response.data.toString()
if (discord) { if (discord) {
const Embed = new MessageEmbed() const Embed = new MessageEmbed()
.setColor(config.discord.embedsColors.error) .setColor(config.discord.embedsColors.error)
.setTitle('Error') .setTitle('Error')
.setDescription('```SyntaxError: Invalid URL```') .setDescription(`\`\`\`${e}\`\`\``)
channeldc.send({ embeds: [Embed] }) channeldc.send({ embeds: [Embed] })
} else { } else {
bot.tellraw(selector, { text: 'SyntaxError: Invalid URL', color: 'red' }) bot.tellraw(selector, { text: e, color: 'red' })
} }
} }
} }