diff --git a/commands/random-img/bunny.js b/commands/random-img/bunny.js index 7edb14d3..c21dcde8 100644 --- a/commands/random-img/bunny.js +++ b/commands/random-img/bunny.js @@ -25,7 +25,17 @@ module.exports = class BunnyCommand extends Command { const { body } = await request .get('https://api.bunnies.io/v2/loop/random/') .query({ media: 'gif,png' }); - return msg.say({ files: [body.media.gif || body.media.poster] }); + let fileToSend; + let fileType = 'gif'; + const gif = await request.get(body.media.gif); + if (Buffer.byteLength(gif.body) > 8e+6) { + const poster = await request.get(body.media.poster); + fileToSend = poster.body; + fileType = 'png'; + } else { + fileToSend = gif.body; + } + return msg.say({ files: [{ attachment: fileToSend, name: `${body.id}.${fileType}` }] }); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); }