mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 14:20:51 +02:00
Fix Bunny GIFs being too big
This commit is contained in:
@@ -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!`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user