Fix Bunny GIFs being too big

This commit is contained in:
Dragon Fire
2020-06-04 12:37:23 -04:00
parent 6c4b778834
commit 3fb382612a
+11 -1
View File
@@ -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!`);
}